RabbitCommon v2.2.6
Loading...
Searching...
No Matches
QUIWidget.h
1#ifndef QUIWIDGET_H
2#define QUIWIDGET_H
3
18#include <QDialog>
19#include <QMutex>
20
21#include "rabbitcommon_export.h"
22
23class QLabel;
24class QPushButton;
25class QToolButton;
26class QVBoxLayout;
27class QHBoxLayout;
28class QFrame;
29class QSpacerItem;
30class QLineEdit;
31class QComboBox;
32class QAbstractButton;
33
34#ifdef quc
35#if (QT_VERSION < QT_VERSION_CHECK(5,7,0))
36#include <QtDesigner/QDesignerExportWidget>
37#else
38#include <QtUiPlugin/QDesignerExportWidget>
39#endif
40
41class QDESIGNER_WIDGET_EXPORT QUIWidget : public QDialog
42 #else
43class RABBITCOMMON_EXPORT QUIWidget : public QDialog
44 #endif
45
46{
47 Q_OBJECT
48
49 Q_PROPERTY(QString title READ getTitle WRITE setTitle)
50 Q_PROPERTY(Qt::Alignment alignment READ getAlignment WRITE setAlignment)
51
52public:
53 //将部分对象作为枚举值暴露给外部
54 enum Widget {
55 Lab_Ico = 0, //左上角图标
56 BtnMenu = 1, //下拉菜单按钮
57 BtnMenu_Min = 2, //最小化按钮
58 BtnMenu_Max = 3, //最大化按钮
59 BtnMenu_Close = 4 //关闭按钮
60 };
61
62 //样式枚举
63 enum Style {
64 Style_Silvery = 0, //银色样式
65 Style_Blue = 1, //蓝色样式
66 Style_LightBlue = 2, //淡蓝色样式
67 Style_DarkBlue = 3, //深蓝色样式
68 Style_Gray = 4, //灰色样式
69 Style_LightGray = 5, //浅灰色样式
70 Style_DarkGray = 6, //深灰色样式
71 Style_Black = 7, //黑色样式
72 Style_LightBlack = 8, //浅黑色样式
73 Style_DarkBlack = 9, //深黑色样式
74 Style_PSBlack = 10, //PS黑色样式
75 Style_FlatBlack = 11, //黑色扁平样式
76 Style_FlatWhite = 12 //白色扁平样式
77 };
78 Q_ENUM(Style)
79
80 explicit QUIWidget(QWidget *parent = 0, bool bQuitOnClose = false);
81 virtual ~QUIWidget();
82
83public:
84 //设置全局样式
85 static void setStyle(const QString &qssFile);
86 static void setStyle(QUIWidget::Style style); // 仅在 DEBUG 下有效
87
88 //设置窗体居中显示
89 static void setFormInCenter(QWidget *frm);
90
91 //根据QSS样式获取对应颜色值
92 static void getQssColor(const QString &qss,
93 QString &textColor,
94 QString &panelColor,
95 QString &borderColor,
96 QString &normalColorStart,
97 QString &normalColorEnd,
98 QString &darkColorStart,
99 QString &darkColorEnd,
100 QString &highColor);
101
102 //设置翻译文件
103 static void setTranslator(const QString &qmFile);
104 //设置编码
105 static void setCode();
106
107 //弹出消息框
108 static void showMessageBoxInfo(const QString &info, int closeSec = 0);
109 //弹出错误框
110 static void showMessageBoxError(const QString &info, int closeSec = 0);
111 //弹出询问框
112 static int showMessageBoxQuestion(const QString &info);
113
114 //弹出输入框
115 static QString showInputBox(bool &ok, const QString &title, int type = 0, int closeSec = 0,
116 QString defaultValue = QString(), bool pwd = false);
117
118protected:
119 bool eventFilter(QObject *obj, QEvent *evt) override;
120
121private:
122 QVBoxLayout *verticalLayout1;
123 QWidget *widgetMain;
124 QVBoxLayout *verticalLayout2;
125 QWidget *widget_title;
126 QHBoxLayout *horizontalLayout4;
127 QLabel *lab_Ico;
128 QLabel *lab_Title;
129 QWidget *widget_menu;
130 QHBoxLayout *horizontalLayout;
131 QToolButton *btnMenu;
132 QPushButton *btnMenu_Min;
133 QPushButton *btnMenu_Max;
134 QPushButton *btnMenu_Close;
135 QWidget *widget;
136 QVBoxLayout *verticalLayout3;
137
138private:
139 bool max; //是否处于最大化状态
140 QRect location; //鼠标移动窗体后的坐标位置
141 QWidget *mainWidget; //主窗体对象
142
143 QString title; //标题
144 Qt::Alignment alignment; //标题文本对齐
145
146public:
147 QLabel *getLabIco() const;
148 QLabel *getLabTitle() const;
149 QToolButton *getBtnMenu() const;
150 QPushButton *getBtnMenuMin() const;
151 QPushButton *getBtnMenuMax() const;
152 QPushButton *getBtnMenuMClose() const;
153
154 Style getStyle() const;
155 QString getTitle() const;
156 Qt::Alignment getAlignment() const;
157
158 QSize sizeHint() const override;
159 QSize minimumSizeHint() const override;
160
161private slots:
162 void initControl(); //初始化控件
163 void initForm(); //初始化窗体
164 void changeStyle(); //更换样式
165
166private slots:
167 void on_btnMenu_Min_clicked();
168 void on_btnMenu_Max_clicked();
169 void on_btnMenu_Close_clicked();
170
171public Q_SLOTS:
172 //设置部件图标
173 void setIcon(QUIWidget::Widget widget, QChar str, quint32 size = 9);
174 //设置部件图片
175 void setPixmap(QUIWidget::Widget widget, const QString &file, const QSize &size = QSize(16, 16));
176 //设置部件是否可见
177 void setVisible(QUIWidget::Widget widget, bool visible = true);
178 //设置只有关闭按钮
179 void setOnlyCloseBtn();
180
181 //设置标题栏高度
182 void setTitleHeight(int height);
183 //设置按钮统一宽度
184 void setBtnWidth(int width);
185
186 //设置标题及文本样式
187 void setTitle(const QString &title);
188 void setAlignment(Qt::Alignment alignment);
189
190 //设置主窗体
191 //参数: bUsed: true, 使用 mainWidget 的标题与图标
192 void setMainWidget(QWidget *mainWidget, bool bUsed = true);
193
194Q_SIGNALS:
195 void sigChangeStyle(const QString &qssFile);
196
197protected:
198 virtual void resizeEvent(QResizeEvent *event) override;
199 virtual void showEvent(QShowEvent *event) override;
200};
201
202
203class RABBITCOMMON_EXPORT QUIMessageBox : public QDialog
204{
205 Q_OBJECT
206
207public:
208 explicit QUIMessageBox(QWidget *parent = 0);
210
211 static QUIMessageBox *Instance()
212 {
213 static QMutex mutex;
214
215 if (!self) {
216 QMutexLocker locker(&mutex);
217
218 if (!self) {
219 self = new QUIMessageBox;
220 }
221 }
222
223 return self;
224 }
225
226protected:
227 void closeEvent(QCloseEvent *);
228 bool eventFilter(QObject *obj, QEvent *evt);
229
230private:
231 static QUIMessageBox *self;
232
233 QVBoxLayout *verticalLayout1;
234 QWidget *widget_title;
235 QHBoxLayout *horizontalLayout3;
236 QLabel *lab_Ico;
237 QLabel *lab_Title;
238 QLabel *labTime;
239 QWidget *widget_menu;
240 QHBoxLayout *horizontalLayout4;
241 QPushButton *btnMenu_Close;
242 QWidget *widgetMain;
243 QVBoxLayout *verticalLayout2;
244 QFrame *frame;
245 QVBoxLayout *verticalLayout4;
246 QHBoxLayout *horizontalLayout1;
247 QLabel *labIcoMain;
248 QSpacerItem *horizontalSpacer1;
249 QLabel *labInfo;
250 QHBoxLayout *horizontalLayout2;
251 QSpacerItem *horizontalSpacer2;
252 QPushButton *btnOk;
253 QPushButton *btnCancel;
254
255private:
256 int closeSec; //总显示时间
257 int currentSec; //当前已显示时间
258
259private slots:
260 void initControl(); //初始化控件
261 void initForm(); //初始化窗体
262 void checkSec(); //校验倒计时
263
264private slots:
265 void on_btnOk_clicked();
266 void on_btnMenu_Close_clicked();
267
268public:
269 void setMessage(const QString &msg, int type, int closeSec = 0);
270};
271
272
273class RABBITCOMMON_EXPORT QUIInputBox : public QDialog
274{
275 Q_OBJECT
276
277public:
278 explicit QUIInputBox(QWidget *parent = 0);
279 ~QUIInputBox();
280
281 static QUIInputBox *Instance()
282 {
283 static QMutex mutex;
284
285 if (!self) {
286 QMutexLocker locker(&mutex);
287
288 if (!self) {
289 self = new QUIInputBox;
290 }
291 }
292
293 return self;
294 }
295
296protected:
297 void closeEvent(QCloseEvent *);
298 bool eventFilter(QObject *obj, QEvent *evt);
299
300private:
301 static QUIInputBox *self;
302
303 QVBoxLayout *verticalLayout1;
304 QWidget *widget_title;
305 QHBoxLayout *horizontalLayout1;
306 QLabel *lab_Ico;
307 QLabel *lab_Title;
308 QLabel *labTime;
309 QWidget *widget_menu;
310 QHBoxLayout *horizontalLayout2;
311 QPushButton *btnMenu_Close;
312 QWidget *widgetMain;
313 QVBoxLayout *verticalLayout2;
314 QFrame *frame;
315 QVBoxLayout *verticalLayout3;
316 QLabel *labInfo;
317 QLineEdit *txtValue;
318 QComboBox *cboxValue;
319 QHBoxLayout *lay;
320 QSpacerItem *horizontalSpacer;
321 QPushButton *btnOk;
322 QPushButton *btnCancel;
323
324private:
325 int closeSec; //总显示时间
326 int currentSec; //当前已显示时间
327 QString value; //当前值
328
329private slots:
330 void initControl(); //初始化控件
331 void initForm(); //初始化窗体
332 void checkSec(); //校验倒计时
333
334private slots:
335 void on_btnOk_clicked();
336 void on_btnMenu_Close_clicked();
337
338public:
339 void setParameter(const QString &title, int type = 0, int closeSec = 0,
340 QString defaultValue = QString(), bool pwd = false);
341
342 QString getValue()const;
343
344};
345
346
347class RABBITCOMMON_EXPORT IconHelper : public QObject
348{
349 Q_OBJECT
350public:
351 explicit IconHelper(QObject *parent = 0);
352 static IconHelper *Instance()
353 {
354 static QMutex mutex;
355
356 if (!self) {
357 QMutexLocker locker(&mutex);
358
359 if (!self) {
360 self = new IconHelper;
361 }
362 }
363
364 return self;
365 }
366
367 void setIcon(QLabel *lab, QChar c, quint32 size = 9);
368 void setIcon(QAbstractButton *btn, QChar c, quint32 size = 9);
369
370private:
371 static IconHelper *self; //对象自身
372 QFont iconFont; //图形字体
373};
374
375#endif // QUIWIDGET_H