-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainframe.h
312 lines (252 loc) · 7.62 KB
/
mainframe.h
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
#ifndef MAINFRAME_H
#define MAINFRAME_H
#include <QWidget>
#include <QMainWindow>
#include <QDialog>
#include <QMutex>
#include <QLabel>
#include <QPushButton>
#include <QToolButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QFrame>
#include <QSpacerItem>
#include <QLineEdit>
#include <QComboBox>
#include <QAbstractButton>
#include <QGuiApplication>
#include <QScreen>
#include <QMouseEvent>
#include <QEvent>
#include <QTimer>
#include <QFontDatabase>
#include <QtSvg/QSvgRenderer>
#include <QPixmap>
#include <QPainter>
#include <dwmapi.h>
#include <windowsx.h>
#include <qt_windows.h>
class MainFrame : public QWidget
{
Q_OBJECT
public:
enum Widget {
Label_Icon = 0,
Btn_MenuMin = 1,
Btn_MenuMax = 2,
Btn_MenuClose = 3
};
public:
MainFrame(QWidget *parent = nullptr);
~MainFrame();
static void setFormInCenter(QWidget *frm);
static void getQssColor(const QString &qss,
QString &textColor,
QString &panelColor,
QString &borderColor,
QString &normalColorStart,
QString &normalColorEnd,
QString &darkColorStart,
QString &darkColorEnd,
QString &highColor);
static void showMessageBoxInfo(const QString &info, int closeSec = 0);
static void showMessageBoxError(const QString &info, int closeSec = 0);
static int showMessageBoxQuestion(const QString &info);
static QString showInputBox(bool &ok, const QString &title, int type = 0, int closeSec = 0,
QString defaultValue = QString(), bool pwd = false);
protected:
bool eventFilter(QObject *obj, QEvent *evt) override;
private:
QVBoxLayout *vbL_MainFrame;
QWidget *widget_Main;
QVBoxLayout *vbL_Main;
QWidget *widget_Title;
QHBoxLayout *hbL_Title;
QLabel *label_Icon;
QLabel *label_Title;
QWidget *widget_Menu;
QHBoxLayout *hbL_Menu;
QPushButton *btn_MenuMin;
QPushButton *btn_MenuMax;
QPushButton *btn_MenuClose;
QWidget *widget_Central;
QVBoxLayout *vbL_Central;
private:
bool isMaximized;
QRect location;
QWidget *centralWidget;
QString title;
Qt::Alignment alignment;
public:
QLabel *getLabIco() const;
QLabel *getLabTitle() const;
QPushButton *getBtnMenuMin() const;
QPushButton *getBtnMenuMax() const;
QPushButton *getBtnMenuClose() const;
QString getTitle() const;
Qt::Alignment getAlignment() const;
QSize sizeHint() const override;
QSize minimumSizeHint()const override;
private:
void initControl();
void initForm();
private Q_SLOTS:
void handleBtnMenuMinClick();
void handleBtnMenuMaxClick();
void handleBtnMenuCloseClick();
public:
//设置部件图标
void setIcon(MainFrame::Widget widget, QChar str, quint32 size = 9);
//设置部件图片
void setPixmap(MainFrame::Widget widget, const QString &file, const QSize &size = QSize(16, 16));
//设置部件是否可见
void setVisible(MainFrame::Widget widget, bool visible = true);
//设置只有关闭按钮
void setOnlyCloseBtn();
//设置标题栏高度
void setTitleHeight(int height);
//设置按钮统一宽度
void setBtnWidth(int width);
//设置标题及文本样式
void setTitle(const QString &title);
void setAlignment(Qt::Alignment alignment);
//设置主窗体
void setCentralWidget(QWidget *widget);
};
class QMFMessageBox : public QDialog
{
Q_OBJECT
public:
explicit QMFMessageBox(QWidget *parent = 0);
~QMFMessageBox();
static QMFMessageBox *Instance()
{
static QMutex mutex;
if (!self) {
QMutexLocker locker(&mutex);
if (!self) {
self = new QMFMessageBox;
}
}
return self;
}
protected:
void closeEvent(QCloseEvent *);
bool eventFilter(QObject *obj, QEvent *evt);
private:
static QMFMessageBox *self;
QVBoxLayout *vbL_QMFMessageBox;
QWidget *widget_Title;
QHBoxLayout *hbL_Title;
QLabel *label_Icon;
QLabel *label_Title;
QLabel *label_Time;
QWidget *widget_Menu;
QHBoxLayout *hbL_Menu;
QPushButton *btn_MenuClose;
QWidget *widget_Main;
QVBoxLayout *vbL_Main;
QFrame *frame;
QVBoxLayout *vbl_Frame;
QHBoxLayout *hbL_Inner1;
QLabel *label_IconMain;
QSpacerItem *hSpacer_1;
QLabel *label_Info;
QHBoxLayout *hbL_Inner2;
QSpacerItem *hSpacer_2;
QPushButton *btn_Ok;
QPushButton *btn_Cancel;
private:
int closeSec; //总显示时间
int currentSec; //当前已显示时间
private slots:
void initControl(); //初始化控件
void initForm(); //初始化窗体
void checkSec(); //校验倒计时
private slots:
void handleBtnOkClick();
void handleBtnMenuCloseClick();
void handleBtnCancelClick();//
public:
void setMessage(const QString &msg, int type, int closeSec = 0);
};
class QMFInputBox : public QDialog
{
Q_OBJECT
public:
explicit QMFInputBox(QWidget *parent = 0);
~QMFInputBox();
static QMFInputBox *Instance()
{
static QMutex mutex;
if (!self) {
QMutexLocker locker(&mutex);
if (!self) {
self = new QMFInputBox;
}
}
return self;
}
protected:
void closeEvent(QCloseEvent *);
bool eventFilter(QObject *obj, QEvent *evt);
private:
static QMFInputBox *self;
QVBoxLayout *vbL_QMFInputBox;
QWidget *widget_Title;
QHBoxLayout *hbL_Title;
QLabel *label_Icon;
QLabel *label_Title;
QLabel *label_Time;
QWidget *widget_Menu;
QHBoxLayout *hbL_Menu;
QPushButton *btn_MenuClose;
QWidget *widget_Main;
QVBoxLayout *vbL_Main;
QFrame *frame;
QVBoxLayout *vbL_Frame;
QLabel *label_Info;
QLineEdit *txtValue;
QComboBox *cboxValue;
QHBoxLayout *hbL_Inner;
QSpacerItem *hSpacer;
QPushButton *btn_Ok;
QPushButton *btn_Cancel;
private:
int closeSec; //总显示时间
int currentSec; //当前已显示时间
QString value; //当前值
private slots:
void initControl(); //初始化控件
void initForm(); //初始化窗体
void checkSec(); //校验倒计时
private slots:
void handleBtnOkClick();
void handleBtnCancelClick();
public:
void setParameter(const QString &title, int type = 0, int closeSec = 0,
QString defaultValue = QString(), bool pwd = false);
QString getValue()const;
};
class IconHelper : public QObject
{
public:
explicit IconHelper(QObject *parent = 0);
static IconHelper *Instance()
{
static QMutex mutex;
if (!self) {
QMutexLocker locker(&mutex);
if (!self) {
self = new IconHelper;
}
}
return self;
}
void setIcon(QLabel *lab, QChar c, quint32 size);
void setIcon(QAbstractButton *btn, QChar c, quint32 size);
private:
static IconHelper *self;
QFont iconFont;
};
#endif // MAINFRAME_H