-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathBase_Dialog.cpp
More file actions
109 lines (91 loc) · 2.65 KB
/
Base_Dialog.cpp
File metadata and controls
109 lines (91 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "Base_Dialog.h"
#include "Title_Bar.h"
#include "Skin.h"
#include "NcFramelessHelper.h"
Base_Dialog::Base_Dialog(QWidget *parent)
: QDialog(parent)
,resizable_(true)
{
layout_ = new QVBoxLayout(this);
title_bar_ = new Title_Bar(this);
title_bar_->set_show_style(Title_Bar::DIALOG_STYLE);
layout_->addWidget(title_bar_, 0, Qt::AlignTop);
layout_->setContentsMargins(0, 0, 0, 0);
layout_->setSpacing(0);
setContentsMargins(skin()->margin_left(), skin()->margin_top(),
skin()->margin_right(), skin()->margin_bottom()
);
setLayout(layout_);
setWindowFlags(Qt::FramelessWindowHint);
setAttribute(Qt::WA_OpaquePaintEvent);
setStyleSheet(QString::fromLocal8Bit("*{font-size:11px; font-family:\"宋体\";}"));
//通过边框拉动大小
resize_helper = new NcFramelessHelper();
resize_helper->activateOn(this);
}
Base_Dialog::~Base_Dialog()
{
delete resize_helper;
}
void Base_Dialog::set_resizable( bool b )
{
if (b == resizable_)
{
return;
}
if (resizable_)
{
resize_helper->removeFrom(this);
}else{
resize_helper->activateOn(this);
}
resizable_ = b;
}
bool Base_Dialog::isMaximized() const
{
return title_bar_->is_window_maximized();
}
QString Base_Dialog::windowTitle() const
{
return title_bar_->text();
}
void Base_Dialog::setWindowTitle( const QString &title )
{
title_bar_->set_text(title);
}
void Base_Dialog::resizeEvent( QResizeEvent *e )
{
if (isMaximized())
{
clearMask();
return;
}
//圆角窗口
//生成一张位图
QBitmap pixmap(e->size());
//QPainter用于在位图上绘画
QPainter painter(&pixmap);
// 圆角平滑
painter.setRenderHints(QPainter::Antialiasing, true);
//填充位图矩形框(用白色填充)
painter.fillRect(rect(), Qt::color0);
painter.setBrush(Qt::color1);
//在位图上画圆角矩形(用黑色填充)
painter.drawRoundedRect(this->rect(),
skin()->round_radius_x(),
skin()->round_radius_y()
);
//使用setmask过滤即可
setMask(pixmap);
}
void Base_Dialog::paintEvent( QPaintEvent * )
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
QMargins margin(skin()->border_left(),
skin()->border_top(),
skin()->border_right(),
skin()->border_bottom()
);
qDrawBorderPixmap(&painter, background_rect(), margin, skin()->background());
}