改进大量代码
parent
91dcb82516
commit
f42a149321
|
@ -0,0 +1,11 @@
|
|||
HEADERS += $$PWD/qextserialport.h
|
||||
HEADERS += $$PWD/qextserialport_global.h
|
||||
HEADERS += $$PWD/qextserialport_p.h
|
||||
|
||||
SOURCES += $$PWD/qextserialport.cpp
|
||||
win32 {
|
||||
SOURCES += $$PWD/qextserialport_win.cpp
|
||||
}
|
||||
unix {
|
||||
SOURCES += $$PWD/qextserialport_unix.cpp
|
||||
}
|
|
@ -1,7 +1,5 @@
|
|||
HEADERS += \
|
||||
$$PWD/appconfig.h \
|
||||
$$PWD/quiwidget.h
|
||||
$$PWD/appconfig.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/appconfig.cpp \
|
||||
$$PWD/quiwidget.cpp
|
||||
$$PWD/appconfig.cpp
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,875 +0,0 @@
|
|||
#ifndef QUIWIDGET_H
|
||||
#define QUIWIDGET_H
|
||||
|
||||
#define TIMEMS qPrintable(QTime::currentTime().toString("HH:mm:ss zzz"))
|
||||
#define TIME qPrintable(QTime::currentTime().toString("HH:mm:ss"))
|
||||
#define QDATE qPrintable(QDate::currentDate().toString("yyyy-MM-dd"))
|
||||
#define QTIME qPrintable(QTime::currentTime().toString("HH-mm-ss"))
|
||||
#define DATETIME qPrintable(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss"))
|
||||
#define STRDATETIME qPrintable(QDateTime::currentDateTime().toString("yyyy-MM-dd-HH-mm-ss"))
|
||||
#define STRDATETIMEMS qPrintable(QDateTime::currentDateTime().toString("yyyy-MM-dd-HH-mm-ss-zzz"))
|
||||
|
||||
//定义换行符
|
||||
#ifdef Q_OS_WIN
|
||||
#define NEWLINE "\r\n"
|
||||
#else
|
||||
#define NEWLINE "\n"
|
||||
#endif
|
||||
|
||||
//定义无边框标题栏高度+对话框最小宽高
|
||||
#ifdef __arm__
|
||||
#define TitleMinSize 40
|
||||
#define DialogMinWidth 350
|
||||
#define DialogMinHeight 180
|
||||
#else
|
||||
#define TitleMinSize 30
|
||||
#define DialogMinWidth 280
|
||||
#define DialogMinHeight 150
|
||||
#endif
|
||||
|
||||
/**
|
||||
* QUI无边框窗体控件 作者:feiyangqingyun(QQ:517216493)
|
||||
* 1:内置 N >= 17 套精美样式,可直接切换,也可自定义样式路径
|
||||
* 2:可设置部件(左上角图标/最小化按钮/最大化按钮/关闭按钮)的图标或者图片及是否可见
|
||||
* 3:可集成设计师插件,直接拖曳使用,所见即所得
|
||||
* 4:如果需要窗体可拖动大小,设置 setSizeGripEnabled(true);
|
||||
* 5:可设置全局样式 setStyle
|
||||
* 6:可弹出消息框,可选阻塞模式和不阻塞,默认不阻塞 showMessageBoxInfo
|
||||
* 7:可弹出错误框,可选阻塞模式和不阻塞,默认不阻塞 showMessageBoxError
|
||||
* 8:可弹出询问框 showMessageBoxError
|
||||
* 9:可弹出右下角信息框 showTipBox
|
||||
* 10:可弹出输入框 showInputBox
|
||||
* 11:可弹出时间范围选择框 showDateSelect
|
||||
* 12:消息框支持设置倒计时关闭
|
||||
* 13:集成图形字体设置方法及根据指定文字获取图片
|
||||
* 14:集成设置窗体居中显示/设置翻译文件/设置编码/设置延时/设置系统时间等静态方法
|
||||
* 15:集成获取应用程序文件名/文件路径 等方法
|
||||
*/
|
||||
|
||||
#include "head.h"
|
||||
|
||||
#ifdef quc
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(5,7,0))
|
||||
#include <QtDesigner/QDesignerExportWidget>
|
||||
#else
|
||||
#include <QtUiPlugin/QDesignerExportWidget>
|
||||
#endif
|
||||
|
||||
class QDESIGNER_WIDGET_EXPORT QUIWidget : public QDialog
|
||||
#else
|
||||
class QUIWidget : public QDialog
|
||||
#endif
|
||||
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_ENUMS(Style)
|
||||
Q_PROPERTY(QString title READ getTitle WRITE setTitle)
|
||||
Q_PROPERTY(Qt::Alignment alignment READ getAlignment WRITE setAlignment)
|
||||
Q_PROPERTY(bool minHide READ getMinHide WRITE setMinHide)
|
||||
Q_PROPERTY(bool exitAll READ getExitAll WRITE setExitAll)
|
||||
|
||||
public:
|
||||
//将部分对象作为枚举值暴露给外部
|
||||
enum Widget {
|
||||
Lab_Ico = 0, //左上角图标
|
||||
BtnMenu = 1, //下拉菜单按钮
|
||||
BtnMenu_Min = 2, //最小化按钮
|
||||
BtnMenu_Max = 3, //最大化按钮
|
||||
BtnMenu_Normal = 4, //还原按钮
|
||||
BtnMenu_Close = 5 //关闭按钮
|
||||
};
|
||||
|
||||
//样式枚举
|
||||
enum Style {
|
||||
Style_Silvery = 0, //银色样式
|
||||
Style_Blue = 1, //蓝色样式
|
||||
Style_LightBlue = 2, //淡蓝色样式
|
||||
Style_DarkBlue = 3, //深蓝色样式
|
||||
Style_Gray = 4, //灰色样式
|
||||
Style_LightGray = 5, //浅灰色样式
|
||||
Style_DarkGray = 6, //深灰色样式
|
||||
Style_Black = 7, //黑色样式
|
||||
Style_LightBlack = 8, //浅黑色样式
|
||||
Style_DarkBlack = 9, //深黑色样式
|
||||
Style_PSBlack = 10, //PS黑色样式
|
||||
Style_FlatBlack = 11, //黑色扁平样式
|
||||
Style_FlatWhite = 12, //白色扁平样式
|
||||
Style_FlatBlue = 13, //蓝色扁平样式
|
||||
Style_Purple = 14, //紫色样式
|
||||
Style_BlackBlue = 15, //黑蓝色样式
|
||||
Style_BlackVideo = 16 //视频监控黑色样式
|
||||
};
|
||||
|
||||
public:
|
||||
explicit QUIWidget(QWidget *parent = 0);
|
||||
~QUIWidget();
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
QVBoxLayout *verticalLayout1;
|
||||
QWidget *widgetMain;
|
||||
QVBoxLayout *verticalLayout2;
|
||||
QWidget *widgetTitle;
|
||||
QHBoxLayout *horizontalLayout4;
|
||||
QLabel *labIco;
|
||||
QLabel *labTitle;
|
||||
QWidget *widgetMenu;
|
||||
QHBoxLayout *horizontalLayout;
|
||||
QToolButton *btnMenu;
|
||||
QPushButton *btnMenu_Min;
|
||||
QPushButton *btnMenu_Max;
|
||||
QPushButton *btnMenu_Close;
|
||||
QWidget *widget;
|
||||
QVBoxLayout *verticalLayout3;
|
||||
|
||||
private:
|
||||
QString title; //标题
|
||||
Qt::Alignment alignment;//标题文本对齐
|
||||
bool minHide; //最小化隐藏
|
||||
bool exitAll; //退出整个程序
|
||||
QWidget *mainWidget; //主窗体对象
|
||||
|
||||
public:
|
||||
QLabel *getLabIco() const;
|
||||
QLabel *getLabTitle() const;
|
||||
QToolButton *getBtnMenu() const;
|
||||
QPushButton *getBtnMenuMin() const;
|
||||
QPushButton *getBtnMenuMax() const;
|
||||
QPushButton *getBtnMenuMClose() const;
|
||||
|
||||
QString getTitle() const;
|
||||
Qt::Alignment getAlignment() const;
|
||||
bool getMinHide() const;
|
||||
bool getExitAll() const;
|
||||
|
||||
QSize sizeHint() const;
|
||||
QSize minimumSizeHint() const;
|
||||
|
||||
private slots:
|
||||
void initControl(); //初始化控件
|
||||
void initForm(); //初始化窗体
|
||||
void changeStyle(); //更换样式
|
||||
|
||||
private slots:
|
||||
void on_btnMenu_Min_clicked();
|
||||
void on_btnMenu_Max_clicked();
|
||||
void on_btnMenu_Close_clicked();
|
||||
|
||||
public Q_SLOTS:
|
||||
//设置部件图标
|
||||
void setIcon(QUIWidget::Widget widget, const QChar &str, quint32 size = 12);
|
||||
void setIconMain(const QChar &str, quint32 size = 12);
|
||||
//设置部件图片
|
||||
void setPixmap(QUIWidget::Widget widget, const QString &file, const QSize &size = QSize(16, 16));
|
||||
//设置部件是否可见
|
||||
void setVisible(QUIWidget::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 setMinHide(bool minHide);
|
||||
|
||||
//设置退出时候直接退出整个应用程序
|
||||
void setExitAll(bool exitAll);
|
||||
|
||||
//设置主窗体
|
||||
void setMainWidget(QWidget *mainWidget);
|
||||
|
||||
Q_SIGNALS:
|
||||
void changeStyle(const QString &qssFile);
|
||||
void closing();
|
||||
};
|
||||
|
||||
//弹出信息框类
|
||||
class QUIMessageBox : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static QUIMessageBox *Instance();
|
||||
explicit QUIMessageBox(QWidget *parent = 0);
|
||||
~QUIMessageBox();
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *);
|
||||
void closeEvent(QCloseEvent *);
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
static QScopedPointer<QUIMessageBox> self;
|
||||
|
||||
QVBoxLayout *verticalLayout1;
|
||||
QWidget *widgetTitle;
|
||||
QHBoxLayout *horizontalLayout3;
|
||||
QLabel *labIco;
|
||||
QLabel *labTitle;
|
||||
QLabel *labCountDown;
|
||||
QWidget *widgetMenu;
|
||||
QHBoxLayout *horizontalLayout4;
|
||||
QPushButton *btnMenu_Close;
|
||||
QWidget *widgetMain;
|
||||
QVBoxLayout *verticalLayout2;
|
||||
QFrame *frame;
|
||||
QVBoxLayout *verticalLayout4;
|
||||
QHBoxLayout *horizontalLayout1;
|
||||
QLabel *labIcoMain;
|
||||
QSpacerItem *horizontalSpacer1;
|
||||
QLabel *labInfo;
|
||||
QHBoxLayout *horizontalLayout2;
|
||||
QSpacerItem *horizontalSpacer2;
|
||||
QPushButton *btnOk;
|
||||
QPushButton *btnCancel;
|
||||
|
||||
private:
|
||||
int closeSec; //总显示时间
|
||||
int currentSec; //当前已显示时间
|
||||
|
||||
private slots:
|
||||
void initControl(); //初始化控件
|
||||
void initForm(); //初始化窗体
|
||||
void checkSec(); //校验倒计时
|
||||
|
||||
private slots:
|
||||
void on_btnOk_clicked();
|
||||
void on_btnMenu_Close_clicked();
|
||||
|
||||
public Q_SLOTS:
|
||||
void setIconMain(const QChar &str, quint32 size = 12);
|
||||
void setIconMsg(const QString &png, const QChar &str);
|
||||
void setMessage(const QString &msg, int type, int closeSec = 0);
|
||||
};
|
||||
|
||||
//右下角弹出框类
|
||||
class QUITipBox : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static QUITipBox *Instance();
|
||||
explicit QUITipBox(QWidget *parent = 0);
|
||||
~QUITipBox();
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *);
|
||||
void closeEvent(QCloseEvent *);
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
static QScopedPointer<QUITipBox> self;
|
||||
|
||||
QVBoxLayout *verticalLayout;
|
||||
QWidget *widgetTitle;
|
||||
QHBoxLayout *horizontalLayout2;
|
||||
QLabel *labIco;
|
||||
QLabel *labTitle;
|
||||
QLabel *labCountDown;
|
||||
QWidget *widgetMenu;
|
||||
QHBoxLayout *horizontalLayout;
|
||||
QPushButton *btnMenu_Close;
|
||||
QWidget *widgetMain;
|
||||
QVBoxLayout *verticalLayout2;
|
||||
QLabel *labInfo;
|
||||
|
||||
QPropertyAnimation *animation;
|
||||
bool fullScreen;
|
||||
|
||||
private:
|
||||
int closeSec; //总显示时间
|
||||
int currentSec; //当前已显示时间
|
||||
|
||||
private slots:
|
||||
void initControl(); //初始化控件
|
||||
void initForm(); //初始化窗体
|
||||
void checkSec(); //校验倒计时
|
||||
|
||||
private slots:
|
||||
void on_btnMenu_Close_clicked();
|
||||
|
||||
public Q_SLOTS:
|
||||
void setIconMain(const QChar &str, quint32 size = 12);
|
||||
void setTip(const QString &title, const QString &tip, bool fullScreen = false, bool center = true, int closeSec = 0);
|
||||
void hide();
|
||||
};
|
||||
|
||||
|
||||
//弹出输入框类
|
||||
class QUIInputBox : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static QUIInputBox *Instance();
|
||||
explicit QUIInputBox(QWidget *parent = 0);
|
||||
~QUIInputBox();
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *);
|
||||
void closeEvent(QCloseEvent *);
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
static QScopedPointer<QUIInputBox> self;
|
||||
|
||||
QVBoxLayout *verticalLayout1;
|
||||
QWidget *widgetTitle;
|
||||
QHBoxLayout *horizontalLayout1;
|
||||
QLabel *labIco;
|
||||
QLabel *labTitle;
|
||||
QLabel *labCountDown;
|
||||
QWidget *widgetMenu;
|
||||
QHBoxLayout *horizontalLayout2;
|
||||
QPushButton *btnMenu_Close;
|
||||
QWidget *widgetMain;
|
||||
QVBoxLayout *verticalLayout2;
|
||||
QFrame *frame;
|
||||
QVBoxLayout *verticalLayout3;
|
||||
QLabel *labInfo;
|
||||
QLineEdit *txtValue;
|
||||
QComboBox *cboxValue;
|
||||
QHBoxLayout *lay;
|
||||
QSpacerItem *horizontalSpacer;
|
||||
QPushButton *btnOk;
|
||||
QPushButton *btnCancel;
|
||||
|
||||
private:
|
||||
int closeSec; //总显示时间
|
||||
int currentSec; //当前已显示时间
|
||||
QString value; //当前值
|
||||
|
||||
private slots:
|
||||
void initControl(); //初始化控件
|
||||
void initForm(); //初始化窗体
|
||||
void checkSec(); //校验倒计时
|
||||
|
||||
private slots:
|
||||
void on_btnOk_clicked();
|
||||
void on_btnMenu_Close_clicked();
|
||||
|
||||
public:
|
||||
QString getValue()const;
|
||||
|
||||
public Q_SLOTS:
|
||||
void setIconMain(const QChar &str, quint32 size = 12);
|
||||
void setParameter(const QString &title, int type = 0, int closeSec = 0,
|
||||
QString placeholderText = QString(), bool pwd = false,
|
||||
const QString &defaultValue = QString());
|
||||
|
||||
};
|
||||
|
||||
//弹出日期选择对话框
|
||||
class QUIDateSelect : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static QUIDateSelect *Instance();
|
||||
explicit QUIDateSelect(QWidget *parent = 0);
|
||||
~QUIDateSelect();
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *);
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
static QScopedPointer<QUIDateSelect> self;
|
||||
|
||||
QVBoxLayout *verticalLayout;
|
||||
QWidget *widgetTitle;
|
||||
QHBoxLayout *horizontalLayout1;
|
||||
QLabel *labIco;
|
||||
QLabel *labTitle;
|
||||
QWidget *widgetMenu;
|
||||
QHBoxLayout *horizontalLayout;
|
||||
QPushButton *btnMenu_Close;
|
||||
QWidget *widgetMain;
|
||||
QVBoxLayout *verticalLayout1;
|
||||
QFrame *frame;
|
||||
QGridLayout *gridLayout;
|
||||
QLabel *labStart;
|
||||
QPushButton *btnOk;
|
||||
QLabel *labEnd;
|
||||
QPushButton *btnClose;
|
||||
QDateTimeEdit *dateStart;
|
||||
QDateTimeEdit *dateEnd;
|
||||
|
||||
private:
|
||||
QString startDateTime; //开始时间
|
||||
QString endDateTime; //结束时间
|
||||
QString format; //日期时间格式
|
||||
|
||||
private slots:
|
||||
void initControl(); //初始化控件
|
||||
void initForm(); //初始化窗体
|
||||
|
||||
private slots:
|
||||
void on_btnOk_clicked();
|
||||
void on_btnMenu_Close_clicked();
|
||||
|
||||
public:
|
||||
//获取当前选择的开始时间和结束时间
|
||||
QString getStartDateTime() const;
|
||||
QString getEndDateTime() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
void setIconMain(const QChar &str, quint32 size = 12);
|
||||
void setFormat(const QString &format);
|
||||
|
||||
};
|
||||
|
||||
//图形字体处理类
|
||||
class IconHelper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static IconHelper *Instance();
|
||||
explicit IconHelper(QObject *parent = 0);
|
||||
|
||||
//获取图形字体
|
||||
QFont getIconFont();
|
||||
|
||||
//设置图形字体到标签
|
||||
void setIcon(QLabel *lab, const QChar &str, quint32 size = 12);
|
||||
//设置图形字体到按钮
|
||||
void setIcon(QAbstractButton *btn, const QChar &str, quint32 size = 12);
|
||||
|
||||
//获取指定图形字体,可以指定文字大小,图片宽高,文字对齐
|
||||
QPixmap getPixmap(const QColor &color, const QChar &str, quint32 size = 12,
|
||||
quint32 pixWidth = 15, quint32 pixHeight = 15,
|
||||
int flags = Qt::AlignCenter);
|
||||
|
||||
//根据按钮获取该按钮对应的图标
|
||||
QPixmap getPixmap(QToolButton *btn, bool normal);
|
||||
QPixmap getPixmap(QToolButton *btn, int type);
|
||||
|
||||
//指定QFrame导航按钮样式,带图标
|
||||
void setStyle(QFrame *frame, QList<QToolButton *> btns, QList<int> pixChar,
|
||||
quint32 iconSize = 12, quint32 iconWidth = 15, quint32 iconHeight = 15,
|
||||
const QString &normalBgColor = "#2FC5A2",
|
||||
const QString &darkBgColor = "#3EA7E9",
|
||||
const QString &normalTextColor = "#EEEEEE",
|
||||
const QString &darkTextColor = "#FFFFFF");
|
||||
|
||||
//指定导航面板样式,不带图标
|
||||
static void setStyle(QWidget *widget, const QString &type = "left", int borderWidth = 3,
|
||||
const QString &borderColor = "#029FEA",
|
||||
const QString &normalBgColor = "#292F38",
|
||||
const QString &darkBgColor = "#1D2025",
|
||||
const QString &normalTextColor = "#54626F",
|
||||
const QString &darkTextColor = "#FDFDFD");
|
||||
|
||||
//移除导航面板样式,防止重复
|
||||
void removeStyle(QList<QToolButton *> btns);
|
||||
|
||||
//指定QWidget导航面板样式,带图标和效果切换
|
||||
void setStyle(QWidget *widget, QList<QToolButton *> btns, QList<int> pixChar,
|
||||
quint32 iconSize = 12, quint32 iconWidth = 15, quint32 iconHeight = 15,
|
||||
const QString &type = "left", int borderWidth = 3,
|
||||
const QString &borderColor = "#029FEA",
|
||||
const QString &normalBgColor = "#292F38",
|
||||
const QString &darkBgColor = "#1D2025",
|
||||
const QString &normalTextColor = "#54626F",
|
||||
const QString &darkTextColor = "#FDFDFD");
|
||||
|
||||
struct StyleColor {
|
||||
quint32 iconSize;
|
||||
quint32 iconWidth;
|
||||
quint32 iconHeight;
|
||||
quint32 borderWidth;
|
||||
QString type;
|
||||
QString borderColor;
|
||||
QString normalBgColor;
|
||||
QString normalTextColor;
|
||||
QString hoverBgColor;
|
||||
QString hoverTextColor;
|
||||
QString pressedBgColor;
|
||||
QString pressedTextColor;
|
||||
QString checkedBgColor;
|
||||
QString checkedTextColor;
|
||||
|
||||
StyleColor() {
|
||||
iconSize = 12;
|
||||
iconWidth = 15;
|
||||
iconHeight = 15;
|
||||
borderWidth = 3;
|
||||
type = "left";
|
||||
borderColor = "#029FEA";
|
||||
normalBgColor = "#292F38";
|
||||
normalTextColor = "#54626F";
|
||||
hoverBgColor = "#40444D";
|
||||
hoverTextColor = "#FDFDFD";
|
||||
pressedBgColor = "#404244";
|
||||
pressedTextColor = "#FDFDFD";
|
||||
checkedBgColor = "#44494F";
|
||||
checkedTextColor = "#FDFDFD";
|
||||
}
|
||||
};
|
||||
|
||||
//指定QWidget导航面板样式,带图标和效果切换+悬停颜色+按下颜色+选中颜色
|
||||
void setStyle(QWidget *widget, QList<QToolButton *> btns, QList<int> pixChar, const StyleColor &styleColor);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
static QScopedPointer<IconHelper> self;
|
||||
|
||||
QFont iconFont; //图形字体
|
||||
QList<QToolButton *> btns; //按钮队列
|
||||
QList<QPixmap> pixNormal; //正常图片队列
|
||||
QList<QPixmap> pixDark; //加深图片队列
|
||||
QList<QPixmap> pixHover; //悬停图片队列
|
||||
QList<QPixmap> pixPressed; //按下图片队列
|
||||
QList<QPixmap> pixChecked; //选中图片队列
|
||||
};
|
||||
|
||||
//托盘图标类
|
||||
class TrayIcon : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static TrayIcon *Instance();
|
||||
explicit TrayIcon(QObject *parent = 0);
|
||||
|
||||
private:
|
||||
static QScopedPointer<TrayIcon> self;
|
||||
|
||||
QWidget *mainWidget; //对应所属主窗体
|
||||
QSystemTrayIcon *trayIcon; //托盘对象
|
||||
QMenu *menu; //右键菜单
|
||||
bool exitDirect; //是否直接退出
|
||||
|
||||
private slots:
|
||||
void iconIsActived(QSystemTrayIcon::ActivationReason reason);
|
||||
|
||||
public Q_SLOTS:
|
||||
//设置是否直接退出,如果不是直接退出则发送信号给主界面
|
||||
void setExitDirect(bool exitDirect);
|
||||
|
||||
//设置所属主窗体
|
||||
void setMainWidget(QWidget *mainWidget);
|
||||
|
||||
//显示消息
|
||||
void showMessage(const QString &title, const QString &msg,
|
||||
QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information, int msecs = 5000);
|
||||
|
||||
//设置图标
|
||||
void setIcon(const QString &strIcon);
|
||||
//设置提示信息
|
||||
void setToolTip(const QString &tip);
|
||||
//设置是否可见
|
||||
void setVisible(bool visible);
|
||||
//退出所有
|
||||
void closeAll();
|
||||
|
||||
Q_SIGNALS:
|
||||
void trayIconExit();
|
||||
};
|
||||
|
||||
|
||||
//全局静态方法类
|
||||
class QUIHelper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
//桌面宽度高度
|
||||
static int deskWidth();
|
||||
static int deskHeight();
|
||||
|
||||
//程序文件名称+当前所在路径
|
||||
static QString appName();
|
||||
static QString appPath();
|
||||
|
||||
//初始化随机数种子
|
||||
static void initRand();
|
||||
//获取uuid
|
||||
static QString getUuid();
|
||||
|
||||
//初始化数据库
|
||||
static void initDb(const QString &dbName);
|
||||
//初始化文件,不存在则拷贝
|
||||
static void initFile(const QString &sourceName, const QString &targetName);
|
||||
|
||||
//检查ini配置文件
|
||||
static bool checkIniFile(const QString &iniFile);
|
||||
|
||||
//设置图标到按钮
|
||||
static void setIconBtn(QAbstractButton *btn, const QString &png, const QChar &str);
|
||||
|
||||
//新建目录
|
||||
static void newDir(const QString &dirName);
|
||||
|
||||
//写入消息到额外的的消息日志文件
|
||||
static void writeInfo(const QString &info, bool needWrite = false, const QString &filePath = "log");
|
||||
static void writeError(const QString &info, bool needWrite = false, const QString &filePath = "log");
|
||||
|
||||
//设置无边框窗体
|
||||
static void setFramelessForm(QWidget *widgetMain, QWidget *widgetTitle, QLabel *labIco, QPushButton *btnClose, bool tool = true);
|
||||
|
||||
//设置全局样式
|
||||
static void setStyle(QUIWidget::Style style);
|
||||
static void setStyle(const QString &qssFile, QString &paletteColor, QString &textColor);
|
||||
static void setStyle(const QString &qssFile, QString &textColor,
|
||||
QString &panelColor, QString &borderColor,
|
||||
QString &normalColorStart, QString &normalColorEnd,
|
||||
QString &darkColorStart, QString &darkColorEnd,
|
||||
QString &highColor);
|
||||
|
||||
//根据QSS样式获取对应颜色值
|
||||
static void getQssColor(const QString &qss, QString &textColor,
|
||||
QString &panelColor, QString &borderColor,
|
||||
QString &normalColorStart, QString &normalColorEnd,
|
||||
QString &darkColorStart, QString &darkColorEnd,
|
||||
QString &highColor);
|
||||
|
||||
//九宫格图片 horzSplit-宫格1/3/7/9宽度 vertSplit-宫格1/3/7/9高度 dstWidth-目标图片宽度 dstHeight-目标图片高度
|
||||
static QPixmap ninePatch(const QString &picName, int horzSplit, int vertSplit, int dstWidth, int dstHeight);
|
||||
static QPixmap ninePatch(const QPixmap &pix, int horzSplit, int vertSplit, int dstWidth, int dstHeight);
|
||||
|
||||
//设置标签颜色
|
||||
static void setLabStyle(QLabel *lab, quint8 type, const QString &bgColor = "", const QString &textColor = "");
|
||||
|
||||
//设置窗体居中显示
|
||||
static void setFormInCenter(QWidget *frm);
|
||||
//设置翻译文件
|
||||
static void setTranslator(const QString &qmFile = ":/image/qt_zh_CN.qm");
|
||||
//设置编码
|
||||
static void setCode();
|
||||
//设置字体
|
||||
static void setFont(const QString &ttfFile = ":/image/DroidSansFallback.ttf",
|
||||
const QString &fontName = "Microsoft Yahei", int fontSize = 12);
|
||||
//设置延时
|
||||
static void sleep(int msec);
|
||||
//设置系统时间
|
||||
static void setSystemDateTime(const QString &year, const QString &month, const QString &day,
|
||||
const QString &hour, const QString &min, const QString &sec);
|
||||
//设置开机自启动
|
||||
static void runWithSystem(const QString &strName, const QString &strPath, bool autoRun = true);
|
||||
|
||||
//从字符串获取IP地址
|
||||
static QString getIP(const QString &url);
|
||||
//判断是否是IP地址
|
||||
static bool isIP(const QString &ip);
|
||||
//判断是否是MAC地址
|
||||
static bool isMac(const QString &mac);
|
||||
//判断是否是合法的电话号码
|
||||
static bool isTel(const QString &tel);
|
||||
//判断是否是合法的邮箱地址
|
||||
static bool isEmail(const QString &email);
|
||||
|
||||
//IP地址字符串与整型转换
|
||||
static QString ipv4IntToString(quint32 ip);
|
||||
static quint32 ipv4StringToInt(const QString &ip);
|
||||
|
||||
//16进制字符串转10进制
|
||||
static int strHexToDecimal(const QString &strHex);
|
||||
//10进制字符串转10进制
|
||||
static int strDecimalToDecimal(const QString &strDecimal);
|
||||
//2进制字符串转10进制
|
||||
static int strBinToDecimal(const QString &strBin);
|
||||
|
||||
//16进制字符串转2进制字符串
|
||||
static QString strHexToStrBin(const QString &strHex);
|
||||
//10进制转2进制字符串一个字节
|
||||
static QString decimalToStrBin1(int decimal);
|
||||
//10进制转2进制字符串两个字节
|
||||
static QString decimalToStrBin2(int decimal);
|
||||
//10进制转16进制字符串,补零.
|
||||
static QString decimalToStrHex(int decimal);
|
||||
|
||||
//int转字节数组
|
||||
static QByteArray intToByte(int i);
|
||||
static QByteArray intToByteRec(int i);
|
||||
|
||||
//字节数组转int
|
||||
static int byteToInt(const QByteArray &data);
|
||||
static int byteToIntRec(const QByteArray &data);
|
||||
static quint32 byteToUInt(const QByteArray &data);
|
||||
static quint32 byteToUIntRec(const QByteArray &data);
|
||||
|
||||
//ushort转字节数组
|
||||
static QByteArray ushortToByte(ushort i);
|
||||
static QByteArray ushortToByteRec(ushort i);
|
||||
|
||||
//字节数组转ushort
|
||||
static int byteToUShort(const QByteArray &data);
|
||||
static int byteToUShortRec(const QByteArray &data);
|
||||
|
||||
//异或加密算法
|
||||
static QString getXorEncryptDecrypt(const QString &str, char key);
|
||||
//异或校验
|
||||
static uchar getOrCode(const QByteArray &data);
|
||||
//计算校验码
|
||||
static uchar getCheckCode(const QByteArray &data);
|
||||
|
||||
//CRC校验
|
||||
static quint16 getRevCrc_16(quint8 *data, int len, quint16 init, const quint16 *table);
|
||||
static quint16 getCrc_16(quint8 *data, int len, quint16 init, const quint16 *table);
|
||||
static quint16 getModbus16(quint8 *data, int len);
|
||||
static QByteArray getCRCCode(const QByteArray &data);
|
||||
|
||||
//字节数组与Ascii字符串互转
|
||||
static void initAsciiStr();
|
||||
static QString byteArrayToAsciiStr(const QByteArray &data);
|
||||
static QByteArray asciiStrToByteArray(const QString &data);
|
||||
|
||||
//16进制字符串与字节数组互转
|
||||
static char hexStrToChar(char data);
|
||||
static QByteArray hexStrToByteArray(const QString &data);
|
||||
static QString byteArrayToHexStr(const QByteArray &data);
|
||||
|
||||
//获取保存的文件
|
||||
static QString getSaveName(const QString &filter, QString defaultDir = QCoreApplication::applicationDirPath());
|
||||
//获取选择的文件
|
||||
static QString getFileName(const QString &filter, QString defaultDir = QCoreApplication::applicationDirPath());
|
||||
//非阻塞保存文件对话框
|
||||
static QString saveFileName(const QString &filter, const QString &defaultDir = "", const QString &fileName = "");
|
||||
//获取选择的文件集合
|
||||
static QStringList getFileNames(const QString &filter, QString defaultDir = QCoreApplication::applicationDirPath());
|
||||
//获取选择的目录
|
||||
static QString getFolderName();
|
||||
|
||||
//获取文件名,含拓展名
|
||||
static QString getFileNameWithExtension(const QString &strFilePath);
|
||||
//获取选择文件夹中的文件
|
||||
static QStringList getFolderFileNames(const QStringList &filter);
|
||||
|
||||
//文件夹是否存在
|
||||
static bool folderIsExist(const QString &strFolder);
|
||||
//文件是否存在
|
||||
static bool fileIsExist(const QString &strFile);
|
||||
//复制文件
|
||||
static bool copyFile(const QString &sourceFile, const QString &targetFile);
|
||||
//删除文件夹下所有文件
|
||||
static void deleteDirectory(const QString &path);
|
||||
|
||||
//判断IP地址及端口是否在线
|
||||
static bool ipLive(const QString &ip, int port, int timeout = 1000);
|
||||
//获取网页所有源代码
|
||||
static QString getHtml(const QString &url);
|
||||
//获取本机公网IP地址
|
||||
static QString getNetIP(const QString &html);
|
||||
//获取本机IP
|
||||
static QString getLocalIP();
|
||||
//获取本机IP地址集合
|
||||
static QStringList getLocalIPs();
|
||||
//Url地址转为IP地址
|
||||
static QString urlToIP(const QString &url);
|
||||
|
||||
//字符串补全
|
||||
static QString getValue(quint8 value);
|
||||
//判断是否通外网
|
||||
static bool isWebOk();
|
||||
|
||||
//初始化表格
|
||||
static void initTableView(QTableView *tableView, int rowHeight = 25,
|
||||
bool headVisible = false, bool edit = false,
|
||||
bool stretchLast = true);
|
||||
|
||||
//弹出框
|
||||
static int showMessageBox(const QString &info, int type = 0, int closeSec = 0, bool exec = false);
|
||||
//弹出消息框
|
||||
static void showMessageBoxInfo(const QString &info, int closeSec = 0, bool exec = false);
|
||||
//弹出错误框
|
||||
static void showMessageBoxError(const QString &info, int closeSec = 0, bool exec = false);
|
||||
//弹出询问框
|
||||
static int showMessageBoxQuestion(const QString &info);
|
||||
|
||||
//弹出+隐藏右下角信息框
|
||||
static void showTipBox(const QString &title, const QString &tip, bool fullScreen = false,
|
||||
bool center = true, int closeSec = 0);
|
||||
static void hideTipBox();
|
||||
|
||||
//弹出输入框
|
||||
static QString showInputBox(const QString &title, int type = 0, int closeSec = 0,
|
||||
const QString &placeholderText = QString(), bool pwd = false,
|
||||
const QString &defaultValue = QString());
|
||||
//弹出日期选择框
|
||||
static void showDateSelect(QString &dateStart, QString &dateEnd, const QString &format = "yyyy-MM-dd");
|
||||
|
||||
|
||||
//设置按钮样式
|
||||
static QString setPushButtonQss(QPushButton *btn, //按钮对象
|
||||
int radius = 5, //圆角半径
|
||||
int padding = 8, //间距
|
||||
const QString &normalColor = "#34495E", //正常颜色
|
||||
const QString &normalTextColor = "#FFFFFF", //文字颜色
|
||||
const QString &hoverColor = "#4E6D8C", //悬停颜色
|
||||
const QString &hoverTextColor = "#F0F0F0", //悬停文字颜色
|
||||
const QString &pressedColor = "#2D3E50", //按下颜色
|
||||
const QString &pressedTextColor = "#B8C6D1"); //按下文字颜色
|
||||
//设置文本框样式
|
||||
static QString setLineEditQss(QLineEdit *txt, //文本框对象
|
||||
int radius = 3, //圆角半径
|
||||
int borderWidth = 2, //边框大小
|
||||
const QString &normalColor = "#DCE4EC", //正常颜色
|
||||
const QString &focusColor = "#34495E"); //选中颜色
|
||||
//设置进度条样式
|
||||
static QString setProgressBarQss(QProgressBar *bar,
|
||||
int barHeight = 8, //进度条高度
|
||||
int barRadius = 5, //进度条半径
|
||||
int fontSize = 9, //文字字号
|
||||
const QString &normalColor = "#E8EDF2", //正常颜色
|
||||
const QString &chunkColor = "#E74C3C"); //进度颜色
|
||||
//设置滑块条样式
|
||||
static QString setSliderQss(QSlider *slider, //滑动条对象
|
||||
int sliderHeight = 8, //滑动条高度
|
||||
const QString &normalColor = "#E8EDF2", //正常颜色
|
||||
const QString &grooveColor = "#1ABC9C", //滑块颜色
|
||||
const QString &handleBorderColor = "#1ABC9C", //指示器边框颜色
|
||||
const QString &handleColor = "#FFFFFF", //指示器颜色
|
||||
const QString &textColor = "#000000"); //文字颜色
|
||||
//设置单选框样式
|
||||
static QString setRadioButtonQss(QRadioButton *rbtn, //单选框对象
|
||||
int indicatorRadius = 8, //指示器圆角角度
|
||||
const QString &normalColor = "#D7DBDE", //正常颜色
|
||||
const QString &checkColor = "#34495E"); //选中颜色
|
||||
//设置滚动条样式
|
||||
static QString setScrollBarQss(QWidget *scroll, //滚动条对象
|
||||
int radius = 6, //圆角角度
|
||||
int min = 120, //指示器最小长度
|
||||
int max = 12, //滚动条最大长度
|
||||
const QString &bgColor = "#606060", //背景色
|
||||
const QString &handleNormalColor = "#34495E", //指示器正常颜色
|
||||
const QString &handleHoverColor = "#1ABC9C", //指示器悬停颜色
|
||||
const QString &handlePressedColor = "#E74C3C"); //指示器按下颜色
|
||||
};
|
||||
|
||||
//全局变量控制
|
||||
class QUIConfig
|
||||
{
|
||||
public:
|
||||
//全局图标
|
||||
static QChar IconMain; //标题栏左上角图标
|
||||
static QChar IconMenu; //下拉菜单图标
|
||||
static QChar IconMin; //最小化图标
|
||||
static QChar IconMax; //最大化图标
|
||||
static QChar IconNormal; //还原图标
|
||||
static QChar IconClose; //关闭图标
|
||||
|
||||
static QString FontName; //全局字体名称
|
||||
static int FontSize; //全局字体大小
|
||||
|
||||
//样式表颜色值
|
||||
static QString TextColor; //文字颜色
|
||||
static QString PanelColor; //面板颜色
|
||||
static QString BorderColor; //边框颜色
|
||||
static QString NormalColorStart;//正常状态开始颜色
|
||||
static QString NormalColorEnd; //正常状态结束颜色
|
||||
static QString DarkColorStart; //加深状态开始颜色
|
||||
static QString DarkColorEnd; //加深状态结束颜色
|
||||
static QString HighColor; //高亮颜色
|
||||
};
|
||||
|
||||
#endif // QUIWIDGET_H
|
|
@ -21,17 +21,20 @@ CONFIG += warn_off
|
|||
INCLUDEPATH += $$PWD
|
||||
INCLUDEPATH += $$PWD/api
|
||||
INCLUDEPATH += $$PWD/form
|
||||
INCLUDEPATH += $$PWD/qextserialport
|
||||
|
||||
include ($$PWD/api/api.pri)
|
||||
include ($$PWD/form/form.pri)
|
||||
include ($$PWD/qextserialport/qextserialport.pri)
|
||||
|
||||
unix {
|
||||
INCLUDEPATH += $$PWD/../core_qui
|
||||
include ($$PWD/../core_qui/core_qui.pri)
|
||||
|
||||
INCLUDEPATH += $$PWD/../3rd_qextserialport
|
||||
include ($$PWD/../3rd_qextserialport/3rd_qextserialport.pri)
|
||||
|
||||
unix:!macx {
|
||||
contains(arma7, DEFINES) {
|
||||
INCLUDEPATH += /usr/local/openssl-1.0.2m-h3-gcc-4.9.2/include
|
||||
LIBS += -L/usr/local/openssl-1.0.2m-h3-gcc-4.9.2/lib -lssl -lcrypto
|
||||
LIBS += -L/usr/local/h3_rootfsv -lXdmcp
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
HEADERS += \
|
||||
$$PWD/qextserialport.h \
|
||||
$$PWD/qextserialport_global.h \
|
||||
$$PWD/qextserialport_p.h
|
||||
|
||||
SOURCES += $$PWD/qextserialport.cpp
|
||||
|
||||
win32:SOURCES += $$PWD/qextserialport_win.cpp
|
||||
unix:SOURCES += $$PWD/qextserialport_unix.cpp
|
|
@ -1,16 +0,0 @@
|
|||
使用方法:
|
||||
pro文件
|
||||
include(qextserialport/qextserialport.pri)
|
||||
|
||||
QextSerialPort *GSM_COM = new QextSerialPort(portName, QextSerialPort::EventDriven);
|
||||
isOpen = GSM_COM->open(QIODevice::ReadWrite);
|
||||
if (isOpen) {
|
||||
GSM_COM->flush();
|
||||
GSM_COM->setBaudRate(BAUD9600);
|
||||
GSM_COM->setDataBits(DATA_8);
|
||||
GSM_COM->setParity(PAR_NONE);
|
||||
GSM_COM->setStopBits(STOP_1);
|
||||
GSM_COM->setFlowControl(FLOW_OFF);
|
||||
GSM_COM->setTimeout(10);
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
HEADERS += \
|
||||
$$PWD/iconfont.h \
|
||||
$$PWD/iconhelper.h \
|
||||
$$PWD/quiconfig.h \
|
||||
$$PWD/quidateselect.h \
|
||||
$$PWD/quihead.h \
|
||||
$$PWD/quihelper.h \
|
||||
$$PWD/quiinputbox.h \
|
||||
$$PWD/quimessagebox.h \
|
||||
$$PWD/quistyle.h \
|
||||
$$PWD/quitipbox.h \
|
||||
$$PWD/quiwidget.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/iconfont.cpp \
|
||||
$$PWD/iconhelper.cpp \
|
||||
$$PWD/quiconfig.cpp \
|
||||
$$PWD/quidateselect.cpp \
|
||||
$$PWD/quihelper.cpp \
|
||||
$$PWD/quiinputbox.cpp \
|
||||
$$PWD/quimessagebox.cpp \
|
||||
$$PWD/quistyle.cpp \
|
||||
$$PWD/quitipbox.cpp \
|
||||
$$PWD/quiwidget.cpp
|
|
@ -0,0 +1,240 @@
|
|||
#include "iconfont.h"
|
||||
|
||||
QScopedPointer<IconFont> IconFont::self;
|
||||
IconFont *IconFont::Instance()
|
||||
{
|
||||
if (self.isNull()) {
|
||||
static QMutex mutex;
|
||||
QMutexLocker locker(&mutex);
|
||||
if (self.isNull()) {
|
||||
self.reset(new IconFont);
|
||||
}
|
||||
}
|
||||
|
||||
return self.data();
|
||||
}
|
||||
|
||||
IconFont::IconFont(QObject *parent) : QObject(parent)
|
||||
{
|
||||
//判断图形字体是否存在,不存在则加入
|
||||
QFontDatabase fontDb;
|
||||
if (!fontDb.families().contains("iconfont")) {
|
||||
int fontId = fontDb.addApplicationFont(":/image/iconfont.ttf");
|
||||
QStringList fontName = fontDb.applicationFontFamilies(fontId);
|
||||
if (fontName.count() == 0) {
|
||||
qDebug() << "load iconfont.ttf error";
|
||||
}
|
||||
}
|
||||
|
||||
if (fontDb.families().contains("iconfont")) {
|
||||
iconFont = QFont("iconfont");
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(4,8,0))
|
||||
iconFont.setHintingPreference(QFont::PreferNoHinting);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void IconFont::setIcon(QLabel *lab, const QChar &icon, quint32 size)
|
||||
{
|
||||
iconFont.setPixelSize(size);
|
||||
lab->setFont(iconFont);
|
||||
lab->setText(icon);
|
||||
}
|
||||
|
||||
void IconFont::setIcon(QAbstractButton *btn, const QChar &icon, quint32 size)
|
||||
{
|
||||
iconFont.setPixelSize(size);
|
||||
btn->setFont(iconFont);
|
||||
btn->setText(icon);
|
||||
}
|
||||
|
||||
QPixmap IconFont::getPixmap(const QColor &color, const QChar &icon, quint32 size,
|
||||
quint32 pixWidth, quint32 pixHeight, int flags)
|
||||
{
|
||||
QPixmap pix(pixWidth, pixHeight);
|
||||
pix.fill(Qt::transparent);
|
||||
|
||||
QPainter painter;
|
||||
painter.begin(&pix);
|
||||
painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
|
||||
painter.setPen(color);
|
||||
|
||||
iconFont.setPixelSize(size);
|
||||
painter.setFont(iconFont);
|
||||
painter.drawText(pix.rect(), flags, icon);
|
||||
painter.end();
|
||||
|
||||
return pix;
|
||||
}
|
||||
|
||||
QPixmap IconFont::getPixmap(QToolButton *btn, bool normal)
|
||||
{
|
||||
QPixmap pix;
|
||||
int index = btns.indexOf(btn);
|
||||
|
||||
if (index >= 0) {
|
||||
if (normal) {
|
||||
pix = pixNormal.at(index);
|
||||
} else {
|
||||
pix = pixDark.at(index);
|
||||
}
|
||||
}
|
||||
|
||||
return pix;
|
||||
}
|
||||
|
||||
void IconFont::setStyle(QWidget *widget, const QString &type, int borderWidth, const QString &borderColor,
|
||||
const QString &normalBgColor, const QString &darkBgColor,
|
||||
const QString &normalTextColor, const QString &darkTextColor)
|
||||
{
|
||||
QString strBorder;
|
||||
if (type == "top") {
|
||||
strBorder = QString("border-width:%1px 0px 0px 0px;padding:%1px %2px %2px %2px;")
|
||||
.arg(borderWidth).arg(borderWidth * 2);
|
||||
} else if (type == "right") {
|
||||
strBorder = QString("border-width:0px %1px 0px 0px;padding:%2px %1px %2px %2px;")
|
||||
.arg(borderWidth).arg(borderWidth * 2);
|
||||
} else if (type == "bottom") {
|
||||
strBorder = QString("border-width:0px 0px %1px 0px;padding:%2px %2px %1px %2px;")
|
||||
.arg(borderWidth).arg(borderWidth * 2);
|
||||
} else if (type == "left") {
|
||||
strBorder = QString("border-width:0px 0px 0px %1px;padding:%2px %2px %2px %1px;")
|
||||
.arg(borderWidth).arg(borderWidth * 2);
|
||||
}
|
||||
|
||||
QStringList qss;
|
||||
qss.append(QString("QWidget[flag=\"%1\"] QAbstractButton{border-style:none;border-radius:0px;padding:5px;color:%2;background:%3;}")
|
||||
.arg(type).arg(normalTextColor).arg(normalBgColor));
|
||||
|
||||
qss.append(QString("QWidget[flag=\"%1\"] QAbstractButton:hover,"
|
||||
"QWidget[flag=\"%1\"] QAbstractButton:pressed,"
|
||||
"QWidget[flag=\"%1\"] QAbstractButton:checked{"
|
||||
"border-style:solid;%2border-color:%3;color:%4;background:%5;}")
|
||||
.arg(type).arg(strBorder).arg(borderColor).arg(darkTextColor).arg(darkBgColor));
|
||||
|
||||
widget->setStyleSheet(qss.join(""));
|
||||
}
|
||||
|
||||
void IconFont::setStyle(QWidget *widget, QList<QToolButton *> btns, QList<QChar> icons,
|
||||
quint32 iconSize, quint32 iconWidth, quint32 iconHeight,
|
||||
const QString &type, int borderWidth, const QString &borderColor,
|
||||
const QString &normalBgColor, const QString &darkBgColor,
|
||||
const QString &normalTextColor, const QString &darkTextColor)
|
||||
{
|
||||
int btnCount = btns.count();
|
||||
int charCount = icons.count();
|
||||
if (btnCount <= 0 || charCount <= 0 || btnCount != charCount) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString strBorder;
|
||||
if (type == "top") {
|
||||
strBorder = QString("border-width:%1px 0px 0px 0px;padding:%1px %2px %2px %2px;")
|
||||
.arg(borderWidth).arg(borderWidth * 2);
|
||||
} else if (type == "right") {
|
||||
strBorder = QString("border-width:0px %1px 0px 0px;padding:%2px %1px %2px %2px;")
|
||||
.arg(borderWidth).arg(borderWidth * 2);
|
||||
} else if (type == "bottom") {
|
||||
strBorder = QString("border-width:0px 0px %1px 0px;padding:%2px %2px %1px %2px;")
|
||||
.arg(borderWidth).arg(borderWidth * 2);
|
||||
} else if (type == "left") {
|
||||
strBorder = QString("border-width:0px 0px 0px %1px;padding:%2px %2px %2px %1px;")
|
||||
.arg(borderWidth).arg(borderWidth * 2);
|
||||
}
|
||||
|
||||
//如果图标是左侧显示则需要让没有选中的按钮左侧也有加深的边框,颜色为背景颜色
|
||||
QStringList qss;
|
||||
if (btns.at(0)->toolButtonStyle() == Qt::ToolButtonTextBesideIcon) {
|
||||
qss.append(QString("QWidget[flag=\"%1\"] QAbstractButton{border-style:solid;border-radius:0px;%2border-color:%3;color:%4;background:%5;}")
|
||||
.arg(type).arg(strBorder).arg(normalBgColor).arg(normalTextColor).arg(normalBgColor));
|
||||
} else {
|
||||
qss.append(QString("QWidget[flag=\"%1\"] QAbstractButton{border-style:none;border-radius:0px;padding:5px;color:%2;background:%3;}")
|
||||
.arg(type).arg(normalTextColor).arg(normalBgColor));
|
||||
}
|
||||
|
||||
qss.append(QString("QWidget[flag=\"%1\"] QAbstractButton:hover,"
|
||||
"QWidget[flag=\"%1\"] QAbstractButton:pressed,"
|
||||
"QWidget[flag=\"%1\"] QAbstractButton:checked{"
|
||||
"border-style:solid;%2border-color:%3;color:%4;background:%5;}")
|
||||
.arg(type).arg(strBorder).arg(borderColor).arg(darkTextColor).arg(darkBgColor));
|
||||
|
||||
qss.append(QString("QWidget#%1{background:%2;}").arg(widget->objectName()).arg(normalBgColor));
|
||||
|
||||
qss.append(QString("QWidget>QToolButton{border-width:0px;}"));
|
||||
qss.append(QString("QWidget>QToolButton{background-color:%1;color:%2;}")
|
||||
.arg(normalBgColor).arg(normalTextColor));
|
||||
qss.append(QString("QWidget>QToolButton:hover,QWidget>QToolButton:pressed,QWidget>QToolButton:checked{background-color:%1;color:%2;}")
|
||||
.arg(darkBgColor).arg(darkTextColor));
|
||||
|
||||
widget->setStyleSheet(qss.join(""));
|
||||
|
||||
for (int i = 0; i < btnCount; i++) {
|
||||
//存储对应按钮对象,方便鼠标移上去的时候切换图片
|
||||
QPixmap pixNormal = getPixmap(normalTextColor, icons.at(i), iconSize, iconWidth, iconHeight);
|
||||
QPixmap pixDark = getPixmap(darkTextColor, icons.at(i), iconSize, iconWidth, iconHeight);
|
||||
|
||||
btns.at(i)->setIcon(QIcon(pixNormal));
|
||||
btns.at(i)->setIconSize(QSize(iconWidth, iconHeight));
|
||||
btns.at(i)->installEventFilter(this);
|
||||
|
||||
this->btns.append(btns.at(i));
|
||||
this->pixNormal.append(pixNormal);
|
||||
this->pixDark.append(pixDark);
|
||||
}
|
||||
}
|
||||
|
||||
void IconFont::setStyle(QFrame *frame, QList<QToolButton *> btns, QList<QChar> icons,
|
||||
quint32 iconSize, quint32 iconWidth, quint32 iconHeight,
|
||||
const QString &normalBgColor, const QString &darkBgColor,
|
||||
const QString &normalTextColor, const QString &darkTextColor)
|
||||
{
|
||||
int btnCount = btns.count();
|
||||
int charCount = icons.count();
|
||||
if (btnCount <= 0 || charCount <= 0 || btnCount != charCount) {
|
||||
return;
|
||||
}
|
||||
|
||||
QStringList qss;
|
||||
qss.append(QString("QFrame>QToolButton{border-style:none;border-width:0px;}"));
|
||||
qss.append(QString("QFrame>QToolButton{background-color:%1;color:%2;}")
|
||||
.arg(normalBgColor).arg(normalTextColor));
|
||||
qss.append(QString("QFrame>QToolButton:hover,QFrame>QToolButton:pressed,QFrame>QToolButton:checked{background-color:%1;color:%2;}")
|
||||
.arg(darkBgColor).arg(darkTextColor));
|
||||
|
||||
frame->setStyleSheet(qss.join(""));
|
||||
|
||||
for (int i = 0; i < btnCount; i++) {
|
||||
//存储对应按钮对象,方便鼠标移上去的时候切换图片
|
||||
QPixmap pixNormal = getPixmap(normalTextColor, icons.at(i), iconSize, iconWidth, iconHeight);
|
||||
QPixmap pixDark = getPixmap(darkTextColor, icons.at(i), iconSize, iconWidth, iconHeight);
|
||||
|
||||
btns.at(i)->setIcon(QIcon(pixNormal));
|
||||
btns.at(i)->setIconSize(QSize(iconWidth, iconHeight));
|
||||
btns.at(i)->installEventFilter(this);
|
||||
|
||||
this->btns.append(btns.at(i));
|
||||
this->pixNormal.append(pixNormal);
|
||||
this->pixDark.append(pixDark);
|
||||
}
|
||||
}
|
||||
|
||||
bool IconFont::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
if (watched->inherits("QToolButton")) {
|
||||
QToolButton *btn = (QToolButton *)watched;
|
||||
int index = btns.indexOf(btn);
|
||||
if (index >= 0) {
|
||||
if (event->type() == QEvent::Enter) {
|
||||
btn->setIcon(QIcon(pixDark.at(index)));
|
||||
} else if (event->type() == QEvent::Leave) {
|
||||
if (btn->isChecked()) {
|
||||
btn->setIcon(QIcon(pixDark.at(index)));
|
||||
} else {
|
||||
btn->setIcon(QIcon(pixNormal.at(index)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return QObject::eventFilter(watched, event);
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
#ifndef ICONFONT_H
|
||||
#define ICONFONT_H
|
||||
|
||||
#include <QtCore>
|
||||
#include <QtGui>
|
||||
#if (QT_VERSION > QT_VERSION_CHECK(5,0,0))
|
||||
#include <QtWidgets>
|
||||
#endif
|
||||
|
||||
#ifdef quc
|
||||
class Q_DECL_EXPORT IconFont : public QObject
|
||||
#else
|
||||
class IconFont : public QObject
|
||||
#endif
|
||||
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static IconFont *Instance();
|
||||
explicit IconFont(QObject *parent = 0);
|
||||
|
||||
void setIcon(QLabel *lab, const QChar &icon, quint32 size = 12);
|
||||
void setIcon(QAbstractButton *btn, const QChar &icon, quint32 size = 12);
|
||||
QPixmap getPixmap(const QColor &color, const QChar &icon, quint32 size = 12,
|
||||
quint32 pixWidth = 15, quint32 pixHeight = 15,
|
||||
int flags = Qt::AlignCenter);
|
||||
|
||||
//根据按钮获取该按钮对应的图标
|
||||
QPixmap getPixmap(QToolButton *btn, bool normal);
|
||||
|
||||
//指定导航面板样式,不带图标
|
||||
static void setStyle(QWidget *widget, const QString &type = "left", int borderWidth = 3,
|
||||
const QString &borderColor = "#029FEA",
|
||||
const QString &normalBgColor = "#292F38",
|
||||
const QString &darkBgColor = "#1D2025",
|
||||
const QString &normalTextColor = "#54626F",
|
||||
const QString &darkTextColor = "#FDFDFD");
|
||||
|
||||
//指定导航面板样式,带图标和效果切换
|
||||
void setStyle(QWidget *widget, QList<QToolButton *> btns, QList<QChar> icons,
|
||||
quint32 iconSize = 12, quint32 iconWidth = 15, quint32 iconHeight = 15,
|
||||
const QString &type = "left", int borderWidth = 3,
|
||||
const QString &borderColor = "#029FEA",
|
||||
const QString &normalBgColor = "#292F38",
|
||||
const QString &darkBgColor = "#1D2025",
|
||||
const QString &normalTextColor = "#54626F",
|
||||
const QString &darkTextColor = "#FDFDFD");
|
||||
|
||||
//指定导航按钮样式,带图标和效果切换
|
||||
void setStyle(QFrame *frame, QList<QToolButton *> btns, QList<QChar> icons,
|
||||
quint32 iconSize = 12, quint32 iconWidth = 15, quint32 iconHeight = 15,
|
||||
const QString &normalBgColor = "#2FC5A2",
|
||||
const QString &darkBgColor = "#3EA7E9",
|
||||
const QString &normalTextColor = "#EEEEEE",
|
||||
const QString &darkTextColor = "#FFFFFF");
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
static QScopedPointer<IconFont> self;
|
||||
QFont iconFont; //图形字体
|
||||
QList<QToolButton *> btns; //按钮队列
|
||||
QList<QPixmap> pixNormal; //正常图片队列
|
||||
QList<QPixmap> pixDark; //加深图片队列
|
||||
};
|
||||
#endif // ICONFONT_H
|
|
@ -0,0 +1,363 @@
|
|||
#include "iconhelper.h"
|
||||
|
||||
QScopedPointer<IconHelper> IconHelper::self;
|
||||
IconHelper *IconHelper::Instance()
|
||||
{
|
||||
if (self.isNull()) {
|
||||
static QMutex mutex;
|
||||
QMutexLocker locker(&mutex);
|
||||
if (self.isNull()) {
|
||||
self.reset(new IconHelper);
|
||||
}
|
||||
}
|
||||
|
||||
return self.data();
|
||||
}
|
||||
|
||||
IconHelper::IconHelper(QObject *parent) : QObject(parent)
|
||||
{
|
||||
//判断图形字体是否存在,不存在则加入
|
||||
QFontDatabase fontDb;
|
||||
if (!fontDb.families().contains("FontAwesome")) {
|
||||
int fontId = fontDb.addApplicationFont(":/image/fontawesome-webfont.ttf");
|
||||
QStringList fontName = fontDb.applicationFontFamilies(fontId);
|
||||
if (fontName.count() == 0) {
|
||||
qDebug() << "load fontawesome-webfont.ttf error";
|
||||
}
|
||||
}
|
||||
|
||||
if (fontDb.families().contains("FontAwesome")) {
|
||||
iconFont = QFont("FontAwesome");
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(4,8,0))
|
||||
iconFont.setHintingPreference(QFont::PreferNoHinting);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
QFont IconHelper::getIconFont()
|
||||
{
|
||||
return this->iconFont;
|
||||
}
|
||||
|
||||
void IconHelper::setIcon(QLabel *lab, const QChar &icon, quint32 size)
|
||||
{
|
||||
iconFont.setPixelSize(size);
|
||||
lab->setFont(iconFont);
|
||||
lab->setText(icon);
|
||||
}
|
||||
|
||||
void IconHelper::setIcon(QAbstractButton *btn, const QChar &icon, quint32 size)
|
||||
{
|
||||
iconFont.setPixelSize(size);
|
||||
btn->setFont(iconFont);
|
||||
btn->setText(icon);
|
||||
}
|
||||
|
||||
QPixmap IconHelper::getPixmap(const QColor &color, const QChar &icon, quint32 size,
|
||||
quint32 pixWidth, quint32 pixHeight, int flags)
|
||||
{
|
||||
QPixmap pix(pixWidth, pixHeight);
|
||||
pix.fill(Qt::transparent);
|
||||
|
||||
QPainter painter;
|
||||
painter.begin(&pix);
|
||||
painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
|
||||
painter.setPen(color);
|
||||
|
||||
iconFont.setPixelSize(size);
|
||||
painter.setFont(iconFont);
|
||||
painter.drawText(pix.rect(), flags, icon);
|
||||
painter.end();
|
||||
|
||||
return pix;
|
||||
}
|
||||
|
||||
QPixmap IconHelper::getPixmap(QToolButton *btn, bool normal)
|
||||
{
|
||||
QPixmap pix;
|
||||
int index = btns.indexOf(btn);
|
||||
if (index >= 0) {
|
||||
if (normal) {
|
||||
pix = pixNormal.at(index);
|
||||
} else {
|
||||
pix = pixDark.at(index);
|
||||
}
|
||||
}
|
||||
|
||||
return pix;
|
||||
}
|
||||
|
||||
QPixmap IconHelper::getPixmap(QToolButton *btn, int type)
|
||||
{
|
||||
QPixmap pix;
|
||||
int index = btns.indexOf(btn);
|
||||
if (index >= 0) {
|
||||
if (type == 0) {
|
||||
pix = pixNormal.at(index);
|
||||
} else if (type == 1) {
|
||||
pix = pixHover.at(index);
|
||||
} else if (type == 2) {
|
||||
pix = pixPressed.at(index);
|
||||
} else if (type == 3) {
|
||||
pix = pixChecked.at(index);
|
||||
}
|
||||
}
|
||||
|
||||
return pix;
|
||||
}
|
||||
|
||||
void IconHelper::setStyle(QFrame *frame, QList<QToolButton *> btns, QList<QChar> icons,
|
||||
quint32 iconSize, quint32 iconWidth, quint32 iconHeight,
|
||||
const QString &normalBgColor, const QString &darkBgColor,
|
||||
const QString &normalTextColor, const QString &darkTextColor)
|
||||
{
|
||||
int btnCount = btns.count();
|
||||
int charCount = icons.count();
|
||||
if (btnCount <= 0 || charCount <= 0 || btnCount != charCount) {
|
||||
return;
|
||||
}
|
||||
|
||||
QStringList qss;
|
||||
qss.append(QString("QFrame>QToolButton{border-style:none;border-width:0px;"
|
||||
"background-color:%1;color:%2;}").arg(normalBgColor).arg(normalTextColor));
|
||||
qss.append(QString("QFrame>QToolButton:hover,QFrame>QToolButton:pressed,QFrame>QToolButton:checked"
|
||||
"{background-color:%1;color:%2;}").arg(darkBgColor).arg(darkTextColor));
|
||||
|
||||
frame->setStyleSheet(qss.join(""));
|
||||
|
||||
//存储对应按钮对象,方便鼠标移上去的时候切换图片
|
||||
for (int i = 0; i < btnCount; i++) {
|
||||
QPixmap pixNormal = getPixmap(normalTextColor, icons.at(i), iconSize, iconWidth, iconHeight);
|
||||
QPixmap pixDark = getPixmap(darkTextColor, icons.at(i), iconSize, iconWidth, iconHeight);
|
||||
|
||||
QToolButton *btn = btns.at(i);
|
||||
btn->setIcon(QIcon(pixNormal));
|
||||
btn->setIconSize(QSize(iconWidth, iconHeight));
|
||||
btn->installEventFilter(this);
|
||||
|
||||
this->btns.append(btn);
|
||||
this->pixNormal.append(pixNormal);
|
||||
this->pixDark.append(pixDark);
|
||||
this->pixHover.append(pixDark);
|
||||
this->pixPressed.append(pixDark);
|
||||
this->pixChecked.append(pixDark);
|
||||
}
|
||||
}
|
||||
|
||||
void IconHelper::setStyle(QWidget *widget, const QString &type, int borderWidth, const QString &borderColor,
|
||||
const QString &normalBgColor, const QString &darkBgColor,
|
||||
const QString &normalTextColor, const QString &darkTextColor)
|
||||
{
|
||||
QString strBorder;
|
||||
if (type == "top") {
|
||||
strBorder = QString("border-width:%1px 0px 0px 0px;padding-top:%1px;padding-bottom:%2px;")
|
||||
.arg(borderWidth).arg(borderWidth * 2);
|
||||
} else if (type == "right") {
|
||||
strBorder = QString("border-width:0px %1px 0px 0px;padding-right:%1px;padding-left:%2px;")
|
||||
.arg(borderWidth).arg(borderWidth * 2);
|
||||
} else if (type == "bottom") {
|
||||
strBorder = QString("border-width:0px 0px %1px 0px;padding-bottom:%1px;padding-top:%2px;")
|
||||
.arg(borderWidth).arg(borderWidth * 2);
|
||||
} else if (type == "left") {
|
||||
strBorder = QString("border-width:0px 0px 0px %1px;padding-left:%1px;padding-right:%2px;")
|
||||
.arg(borderWidth).arg(borderWidth * 2);
|
||||
}
|
||||
|
||||
QStringList qss;
|
||||
qss.append(QString("QWidget[flag=\"%1\"] QAbstractButton{border-style:none;border-radius:0px;padding:5px;"
|
||||
"color:%2;background:%3;}").arg(type).arg(normalTextColor).arg(normalBgColor));
|
||||
|
||||
qss.append(QString("QWidget[flag=\"%1\"] QAbstractButton:hover,"
|
||||
"QWidget[flag=\"%1\"] QAbstractButton:pressed,"
|
||||
"QWidget[flag=\"%1\"] QAbstractButton:checked{"
|
||||
"border-style:solid;%2border-color:%3;color:%4;background:%5;}")
|
||||
.arg(type).arg(strBorder).arg(borderColor).arg(darkTextColor).arg(darkBgColor));
|
||||
|
||||
widget->setStyleSheet(qss.join(""));
|
||||
}
|
||||
|
||||
void IconHelper::removeStyle(QList<QToolButton *> btns)
|
||||
{
|
||||
for (int i = 0; i < btns.count(); i++) {
|
||||
for (int j = 0; j < this->btns.count(); j++) {
|
||||
if (this->btns.at(j) == btns.at(i)) {
|
||||
this->btns.at(j)->removeEventFilter(this);
|
||||
this->btns.removeAt(j);
|
||||
this->pixNormal.removeAt(j);
|
||||
this->pixDark.removeAt(j);
|
||||
this->pixHover.removeAt(j);
|
||||
this->pixPressed.removeAt(j);
|
||||
this->pixChecked.removeAt(j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void IconHelper::setStyle(QWidget *widget, QList<QToolButton *> btns, QList<QChar> icons,
|
||||
quint32 iconSize, quint32 iconWidth, quint32 iconHeight,
|
||||
const QString &type, int borderWidth, const QString &borderColor,
|
||||
const QString &normalBgColor, const QString &darkBgColor,
|
||||
const QString &normalTextColor, const QString &darkTextColor)
|
||||
{
|
||||
int btnCount = btns.count();
|
||||
int charCount = icons.count();
|
||||
if (btnCount <= 0 || charCount <= 0 || btnCount != charCount) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString strBorder;
|
||||
if (type == "top") {
|
||||
strBorder = QString("border-width:%1px 0px 0px 0px;padding-top:%1px;padding-bottom:%2px;")
|
||||
.arg(borderWidth).arg(borderWidth * 2);
|
||||
} else if (type == "right") {
|
||||
strBorder = QString("border-width:0px %1px 0px 0px;padding-right:%1px;padding-left:%2px;")
|
||||
.arg(borderWidth).arg(borderWidth * 2);
|
||||
} else if (type == "bottom") {
|
||||
strBorder = QString("border-width:0px 0px %1px 0px;padding-bottom:%1px;padding-top:%2px;")
|
||||
.arg(borderWidth).arg(borderWidth * 2);
|
||||
} else if (type == "left") {
|
||||
strBorder = QString("border-width:0px 0px 0px %1px;padding-left:%1px;padding-right:%2px;")
|
||||
.arg(borderWidth).arg(borderWidth * 2);
|
||||
}
|
||||
|
||||
//如果图标是左侧显示则需要让没有选中的按钮左侧也有加深的边框,颜色为背景颜色
|
||||
QStringList qss;
|
||||
if (btns.at(0)->toolButtonStyle() == Qt::ToolButtonTextBesideIcon) {
|
||||
qss.append(QString("QWidget[flag=\"%1\"] QAbstractButton{border-style:solid;border-radius:0px;%2border-color:%3;color:%4;background:%5;}")
|
||||
.arg(type).arg(strBorder).arg(normalBgColor).arg(normalTextColor).arg(normalBgColor));
|
||||
} else {
|
||||
qss.append(QString("QWidget[flag=\"%1\"] QAbstractButton{border-style:none;border-radius:0px;padding:5px;color:%2;background:%3;}")
|
||||
.arg(type).arg(normalTextColor).arg(normalBgColor));
|
||||
}
|
||||
|
||||
qss.append(QString("QWidget[flag=\"%1\"] QAbstractButton:hover,"
|
||||
"QWidget[flag=\"%1\"] QAbstractButton:pressed,"
|
||||
"QWidget[flag=\"%1\"] QAbstractButton:checked{"
|
||||
"border-style:solid;%2border-color:%3;color:%4;background:%5;}")
|
||||
.arg(type).arg(strBorder).arg(borderColor).arg(darkTextColor).arg(darkBgColor));
|
||||
|
||||
qss.append(QString("QWidget#%1{background:%2;}").arg(widget->objectName()).arg(normalBgColor));
|
||||
qss.append(QString("QWidget>QToolButton{border-width:0px;"
|
||||
"background-color:%1;color:%2;}").arg(normalBgColor).arg(normalTextColor));
|
||||
qss.append(QString("QWidget>QToolButton:hover,QWidget>QToolButton:pressed,QWidget>QToolButton:checked{"
|
||||
"background-color:%1;color:%2;}").arg(darkBgColor).arg(darkTextColor));
|
||||
|
||||
widget->setStyleSheet(qss.join(""));
|
||||
|
||||
//存储对应按钮对象,方便鼠标移上去的时候切换图片
|
||||
for (int i = 0; i < btnCount; i++) {
|
||||
QPixmap pixNormal = getPixmap(normalTextColor, icons.at(i), iconSize, iconWidth, iconHeight);
|
||||
QPixmap pixDark = getPixmap(darkTextColor, icons.at(i), iconSize, iconWidth, iconHeight);
|
||||
|
||||
QToolButton *btn = btns.at(i);
|
||||
btn->setIcon(QIcon(pixNormal));
|
||||
btn->setIconSize(QSize(iconWidth, iconHeight));
|
||||
btn->installEventFilter(this);
|
||||
|
||||
this->btns.append(btn);
|
||||
this->pixNormal.append(pixNormal);
|
||||
this->pixDark.append(pixDark);
|
||||
this->pixHover.append(pixDark);
|
||||
this->pixPressed.append(pixDark);
|
||||
this->pixChecked.append(pixDark);
|
||||
}
|
||||
}
|
||||
|
||||
void IconHelper::setStyle(QWidget *widget, QList<QToolButton *> btns, QList<QChar> icons, const IconHelper::StyleColor &styleColor)
|
||||
{
|
||||
int btnCount = btns.count();
|
||||
int charCount = icons.count();
|
||||
if (btnCount <= 0 || charCount <= 0 || btnCount != charCount) {
|
||||
return;
|
||||
}
|
||||
|
||||
quint32 iconSize = styleColor.iconSize;
|
||||
quint32 iconWidth = styleColor.iconWidth;
|
||||
quint32 iconHeight = styleColor.iconHeight;
|
||||
quint32 borderWidth = styleColor.borderWidth;
|
||||
QString type = styleColor.type;
|
||||
|
||||
QString strBorder;
|
||||
if (type == "top") {
|
||||
strBorder = QString("border-width:%1px 0px 0px 0px;padding-top:%1px;padding-bottom:%2px;")
|
||||
.arg(borderWidth).arg(borderWidth * 2);
|
||||
} else if (type == "right") {
|
||||
strBorder = QString("border-width:0px %1px 0px 0px;padding-right:%1px;padding-left:%2px;")
|
||||
.arg(borderWidth).arg(borderWidth * 2);
|
||||
} else if (type == "bottom") {
|
||||
strBorder = QString("border-width:0px 0px %1px 0px;padding-bottom:%1px;padding-top:%2px;")
|
||||
.arg(borderWidth).arg(borderWidth * 2);
|
||||
} else if (type == "left") {
|
||||
strBorder = QString("border-width:0px 0px 0px %1px;padding-left:%1px;padding-right:%2px;")
|
||||
.arg(borderWidth).arg(borderWidth * 2);
|
||||
}
|
||||
|
||||
//如果图标是左侧显示则需要让没有选中的按钮左侧也有加深的边框,颜色为背景颜色
|
||||
QStringList qss;
|
||||
if (btns.at(0)->toolButtonStyle() == Qt::ToolButtonTextBesideIcon) {
|
||||
qss.append(QString("QWidget[flag=\"%1\"] QAbstractButton{border-style:solid;border-radius:0px;%2border-color:%3;color:%4;background:%5;}")
|
||||
.arg(type).arg(strBorder).arg(styleColor.normalBgColor).arg(styleColor.normalTextColor).arg(styleColor.normalBgColor));
|
||||
} else {
|
||||
qss.append(QString("QWidget[flag=\"%1\"] QAbstractButton{border-style:none;border-radius:0px;padding:5px;color:%2;background:%3;}")
|
||||
.arg(type).arg(styleColor.normalTextColor).arg(styleColor.normalBgColor));
|
||||
}
|
||||
|
||||
qss.append(QString("QWidget[flag=\"%1\"] QAbstractButton:hover{border-style:solid;%2border-color:%3;color:%4;background:%5;}")
|
||||
.arg(type).arg(strBorder).arg(styleColor.borderColor).arg(styleColor.hoverTextColor).arg(styleColor.hoverBgColor));
|
||||
qss.append(QString("QWidget[flag=\"%1\"] QAbstractButton:pressed{border-style:solid;%2border-color:%3;color:%4;background:%5;}")
|
||||
.arg(type).arg(strBorder).arg(styleColor.borderColor).arg(styleColor.pressedTextColor).arg(styleColor.pressedBgColor));
|
||||
qss.append(QString("QWidget[flag=\"%1\"] QAbstractButton:checked{border-style:solid;%2border-color:%3;color:%4;background:%5;}")
|
||||
.arg(type).arg(strBorder).arg(styleColor.borderColor).arg(styleColor.checkedTextColor).arg(styleColor.checkedBgColor));
|
||||
|
||||
qss.append(QString("QWidget#%1{background:%2;}").arg(widget->objectName()).arg(styleColor.normalBgColor));
|
||||
qss.append(QString("QWidget>QToolButton{border-width:0px;background-color:%1;color:%2;}").arg(styleColor.normalBgColor).arg(styleColor.normalTextColor));
|
||||
qss.append(QString("QWidget>QToolButton:hover{background-color:%1;color:%2;}").arg(styleColor.hoverBgColor).arg(styleColor.hoverTextColor));
|
||||
qss.append(QString("QWidget>QToolButton:pressed{background-color:%1;color:%2;}").arg(styleColor.pressedBgColor).arg(styleColor.pressedTextColor));
|
||||
qss.append(QString("QWidget>QToolButton:checked{background-color:%1;color:%2;}").arg(styleColor.checkedBgColor).arg(styleColor.checkedTextColor));
|
||||
|
||||
widget->setStyleSheet(qss.join(""));
|
||||
|
||||
//存储对应按钮对象,方便鼠标移上去的时候切换图片
|
||||
for (int i = 0; i < btnCount; i++) {
|
||||
QPixmap pixNormal = getPixmap(styleColor.normalTextColor, icons.at(i), iconSize, iconWidth, iconHeight);
|
||||
QPixmap pixHover = getPixmap(styleColor.hoverTextColor, icons.at(i), iconSize, iconWidth, iconHeight);
|
||||
QPixmap pixPressed = getPixmap(styleColor.pressedTextColor, icons.at(i), iconSize, iconWidth, iconHeight);
|
||||
QPixmap pixChecked = getPixmap(styleColor.checkedTextColor, icons.at(i), iconSize, iconWidth, iconHeight);
|
||||
|
||||
QToolButton *btn = btns.at(i);
|
||||
btn->setIcon(QIcon(pixNormal));
|
||||
btn->setIconSize(QSize(iconWidth, iconHeight));
|
||||
btn->installEventFilter(this);
|
||||
|
||||
this->btns.append(btn);
|
||||
this->pixNormal.append(pixNormal);
|
||||
this->pixDark.append(pixHover);
|
||||
this->pixHover.append(pixHover);
|
||||
this->pixPressed.append(pixPressed);
|
||||
this->pixChecked.append(pixChecked);
|
||||
}
|
||||
}
|
||||
|
||||
bool IconHelper::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
if (watched->inherits("QToolButton")) {
|
||||
QToolButton *btn = (QToolButton *)watched;
|
||||
int index = btns.indexOf(btn);
|
||||
if (index >= 0) {
|
||||
if (event->type() == QEvent::Enter) {
|
||||
btn->setIcon(QIcon(pixHover.at(index)));
|
||||
} else if (event->type() == QEvent::MouseButtonPress) {
|
||||
btn->setIcon(QIcon(pixPressed.at(index)));
|
||||
} else if (event->type() == QEvent::Leave) {
|
||||
if (btn->isChecked()) {
|
||||
btn->setIcon(QIcon(pixChecked.at(index)));
|
||||
} else {
|
||||
btn->setIcon(QIcon(pixNormal.at(index)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return QObject::eventFilter(watched, event);
|
||||
}
|
|
@ -0,0 +1,121 @@
|
|||
#ifndef ICONHELPER_H
|
||||
#define ICONHELPER_H
|
||||
|
||||
#include <QtCore>
|
||||
#include <QtGui>
|
||||
#if (QT_VERSION > QT_VERSION_CHECK(5,0,0))
|
||||
#include <QtWidgets>
|
||||
#endif
|
||||
|
||||
#ifdef quc
|
||||
class Q_DECL_EXPORT IconHelper : public QObject
|
||||
#else
|
||||
class IconHelper : public QObject
|
||||
#endif
|
||||
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static IconHelper *Instance();
|
||||
explicit IconHelper(QObject *parent = 0);
|
||||
|
||||
//获取图形字体
|
||||
QFont getIconFont();
|
||||
|
||||
//设置图形字体到标签
|
||||
void setIcon(QLabel *lab, const QChar &icon, quint32 size = 12);
|
||||
//设置图形字体到按钮
|
||||
void setIcon(QAbstractButton *btn, const QChar &icon, quint32 size = 12);
|
||||
|
||||
//获取指定图形字体,可以指定文字大小,图片宽高,文字对齐
|
||||
QPixmap getPixmap(const QColor &color, const QChar &icon, quint32 size = 12,
|
||||
quint32 pixWidth = 15, quint32 pixHeight = 15,
|
||||
int flags = Qt::AlignCenter);
|
||||
|
||||
//根据按钮获取该按钮对应的图标
|
||||
QPixmap getPixmap(QToolButton *btn, bool normal);
|
||||
QPixmap getPixmap(QToolButton *btn, int type);
|
||||
|
||||
//指定QFrame导航按钮样式,带图标
|
||||
void setStyle(QFrame *frame, QList<QToolButton *> btns, QList<QChar> icons,
|
||||
quint32 iconSize = 12, quint32 iconWidth = 15, quint32 iconHeight = 15,
|
||||
const QString &normalBgColor = "#2FC5A2",
|
||||
const QString &darkBgColor = "#3EA7E9",
|
||||
const QString &normalTextColor = "#EEEEEE",
|
||||
const QString &darkTextColor = "#FFFFFF");
|
||||
|
||||
//指定导航面板样式,不带图标
|
||||
static void setStyle(QWidget *widget, const QString &type = "left", int borderWidth = 3,
|
||||
const QString &borderColor = "#029FEA",
|
||||
const QString &normalBgColor = "#292F38",
|
||||
const QString &darkBgColor = "#1D2025",
|
||||
const QString &normalTextColor = "#54626F",
|
||||
const QString &darkTextColor = "#FDFDFD");
|
||||
|
||||
//移除导航面板样式,防止重复
|
||||
void removeStyle(QList<QToolButton *> btns);
|
||||
|
||||
//指定QWidget导航面板样式,带图标和效果切换
|
||||
void setStyle(QWidget *widget, QList<QToolButton *> btns, QList<QChar> icons,
|
||||
quint32 iconSize = 12, quint32 iconWidth = 15, quint32 iconHeight = 15,
|
||||
const QString &type = "left", int borderWidth = 3,
|
||||
const QString &borderColor = "#029FEA",
|
||||
const QString &normalBgColor = "#292F38",
|
||||
const QString &darkBgColor = "#1D2025",
|
||||
const QString &normalTextColor = "#54626F",
|
||||
const QString &darkTextColor = "#FDFDFD");
|
||||
|
||||
struct StyleColor {
|
||||
quint32 iconSize;
|
||||
quint32 iconWidth;
|
||||
quint32 iconHeight;
|
||||
quint32 borderWidth;
|
||||
QString type;
|
||||
QString borderColor;
|
||||
QString normalBgColor;
|
||||
QString normalTextColor;
|
||||
QString hoverBgColor;
|
||||
QString hoverTextColor;
|
||||
QString pressedBgColor;
|
||||
QString pressedTextColor;
|
||||
QString checkedBgColor;
|
||||
QString checkedTextColor;
|
||||
|
||||
StyleColor() {
|
||||
iconSize = 12;
|
||||
iconWidth = 15;
|
||||
iconHeight = 15;
|
||||
borderWidth = 3;
|
||||
type = "left";
|
||||
borderColor = "#029FEA";
|
||||
normalBgColor = "#292F38";
|
||||
normalTextColor = "#54626F";
|
||||
hoverBgColor = "#40444D";
|
||||
hoverTextColor = "#FDFDFD";
|
||||
pressedBgColor = "#404244";
|
||||
pressedTextColor = "#FDFDFD";
|
||||
checkedBgColor = "#44494F";
|
||||
checkedTextColor = "#FDFDFD";
|
||||
}
|
||||
};
|
||||
|
||||
//指定QWidget导航面板样式,带图标和效果切换+悬停颜色+按下颜色+选中颜色
|
||||
void setStyle(QWidget *widget, QList<QToolButton *> btns, QList<QChar> icons, const StyleColor &styleColor);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
static QScopedPointer<IconHelper> self;
|
||||
|
||||
QFont iconFont; //图形字体
|
||||
QList<QToolButton *> btns; //按钮队列
|
||||
QList<QPixmap> pixNormal; //正常图片队列
|
||||
QList<QPixmap> pixDark; //加深图片队列
|
||||
QList<QPixmap> pixHover; //悬停图片队列
|
||||
QList<QPixmap> pixPressed; //按下图片队列
|
||||
QList<QPixmap> pixChecked; //选中图片队列
|
||||
};
|
||||
|
||||
#endif // ICONHELPER_H
|
|
@ -0,0 +1,25 @@
|
|||
#include "quiconfig.h"
|
||||
|
||||
QChar QUIConfig::IconMain = 0xf072;
|
||||
QChar QUIConfig::IconMenu = 0xf0d7;
|
||||
QChar QUIConfig::IconMin = 0xf068;
|
||||
QChar QUIConfig::IconMax = 0xf2d2;
|
||||
QChar QUIConfig::IconNormal = 0xf2d0;
|
||||
QChar QUIConfig::IconClose = 0xf00d;
|
||||
|
||||
#ifdef __arm__
|
||||
QString QUIConfig::FontName = "WenQuanYi Micro Hei";
|
||||
int QUIConfig::FontSize = 18;
|
||||
#else
|
||||
QString QUIConfig::FontName = "Microsoft Yahei";
|
||||
int QUIConfig::FontSize = 12;
|
||||
#endif
|
||||
|
||||
QString QUIConfig::TextColor = "#000000";
|
||||
QString QUIConfig::PanelColor = "#F0F0F0";
|
||||
QString QUIConfig::BorderColor = "#000000";
|
||||
QString QUIConfig::NormalColorStart = "#F0F0F0";
|
||||
QString QUIConfig::NormalColorEnd = "#F0F0F0";
|
||||
QString QUIConfig::DarkColorStart = "#F0F0F0";
|
||||
QString QUIConfig::DarkColorEnd = "#F0F0F0";
|
||||
QString QUIConfig::HighColor = "#00BB9E";
|
|
@ -0,0 +1,31 @@
|
|||
#ifndef QUICONFIG_H
|
||||
#define QUICONFIG_H
|
||||
|
||||
#include "quihead.h"
|
||||
|
||||
class QUIConfig
|
||||
{
|
||||
public:
|
||||
//全局图标
|
||||
static QChar IconMain; //标题栏左上角图标
|
||||
static QChar IconMenu; //下拉菜单图标
|
||||
static QChar IconMin; //最小化图标
|
||||
static QChar IconMax; //最大化图标
|
||||
static QChar IconNormal; //还原图标
|
||||
static QChar IconClose; //关闭图标
|
||||
|
||||
static QString FontName; //全局字体名称
|
||||
static int FontSize; //全局字体大小
|
||||
|
||||
//样式表颜色值
|
||||
static QString TextColor; //文字颜色
|
||||
static QString PanelColor; //面板颜色
|
||||
static QString BorderColor; //边框颜色
|
||||
static QString NormalColorStart;//正常状态开始颜色
|
||||
static QString NormalColorEnd; //正常状态结束颜色
|
||||
static QString DarkColorStart; //加深状态开始颜色
|
||||
static QString DarkColorEnd; //加深状态结束颜色
|
||||
static QString HighColor; //高亮颜色
|
||||
};
|
||||
|
||||
#endif // QUICONFIG_H
|
|
@ -0,0 +1,269 @@
|
|||
#include "quidateselect.h"
|
||||
|
||||
QScopedPointer<QUIDateSelect> QUIDateSelect::self;
|
||||
QUIDateSelect *QUIDateSelect::Instance()
|
||||
{
|
||||
if (self.isNull()) {
|
||||
static QMutex mutex;
|
||||
QMutexLocker locker(&mutex);
|
||||
if (self.isNull()) {
|
||||
self.reset(new QUIDateSelect);
|
||||
}
|
||||
}
|
||||
|
||||
return self.data();
|
||||
}
|
||||
|
||||
QUIDateSelect::QUIDateSelect(QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
this->initControl();
|
||||
this->initForm();
|
||||
}
|
||||
|
||||
QUIDateSelect::~QUIDateSelect()
|
||||
{
|
||||
delete widgetMain;
|
||||
}
|
||||
|
||||
void QUIDateSelect::showEvent(QShowEvent *)
|
||||
{
|
||||
QUIHelper::setIconBtn(btnOk, ":/image/btn_ok.png", 0xf00c);
|
||||
QUIHelper::setIconBtn(btnClose, ":/image/btn_close.png", 0xf00d);
|
||||
QUIHelper::setFormInCenter(this);
|
||||
this->activateWindow();
|
||||
}
|
||||
|
||||
bool QUIDateSelect::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
static QPoint mousePoint;
|
||||
static bool mousePressed = false;
|
||||
|
||||
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
|
||||
if (mouseEvent->type() == QEvent::MouseButtonPress) {
|
||||
if (mouseEvent->button() == Qt::LeftButton) {
|
||||
mousePressed = true;
|
||||
mousePoint = mouseEvent->globalPos() - this->pos();
|
||||
return true;
|
||||
}
|
||||
} else if (mouseEvent->type() == QEvent::MouseButtonRelease) {
|
||||
mousePressed = false;
|
||||
return true;
|
||||
} else if (mouseEvent->type() == QEvent::MouseMove) {
|
||||
if (mousePressed) {
|
||||
this->move(mouseEvent->globalPos() - mousePoint);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return QWidget::eventFilter(watched, event);
|
||||
}
|
||||
|
||||
void QUIDateSelect::initControl()
|
||||
{
|
||||
this->setObjectName(QString::fromUtf8("QUIDateSelect"));
|
||||
|
||||
verticalLayout = new QVBoxLayout(this);
|
||||
verticalLayout->setSpacing(0);
|
||||
verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
|
||||
verticalLayout->setContentsMargins(1, 1, 1, 1);
|
||||
|
||||
widgetTitle = new QWidget(this);
|
||||
widgetTitle->setObjectName(QString::fromUtf8("widgetTitle"));
|
||||
QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
||||
sizePolicy.setHorizontalStretch(0);
|
||||
sizePolicy.setVerticalStretch(0);
|
||||
sizePolicy.setHeightForWidth(widgetTitle->sizePolicy().hasHeightForWidth());
|
||||
widgetTitle->setSizePolicy(sizePolicy);
|
||||
|
||||
horizontalLayout1 = new QHBoxLayout(widgetTitle);
|
||||
horizontalLayout1->setSpacing(0);
|
||||
horizontalLayout1->setObjectName(QString::fromUtf8("horizontalLayout1"));
|
||||
horizontalLayout1->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
labIco = new QLabel(widgetTitle);
|
||||
labIco->setObjectName(QString::fromUtf8("labIco"));
|
||||
QSizePolicy sizePolicy1(QSizePolicy::Minimum, QSizePolicy::Preferred);
|
||||
sizePolicy1.setHorizontalStretch(0);
|
||||
sizePolicy1.setVerticalStretch(0);
|
||||
sizePolicy1.setHeightForWidth(labIco->sizePolicy().hasHeightForWidth());
|
||||
labIco->setSizePolicy(sizePolicy1);
|
||||
labIco->setAlignment(Qt::AlignCenter);
|
||||
horizontalLayout1->addWidget(labIco);
|
||||
|
||||
labTitle = new QLabel(widgetTitle);
|
||||
labTitle->setObjectName(QString::fromUtf8("labTitle"));
|
||||
QSizePolicy sizePolicy2(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
sizePolicy2.setHorizontalStretch(0);
|
||||
sizePolicy2.setVerticalStretch(0);
|
||||
sizePolicy2.setHeightForWidth(labTitle->sizePolicy().hasHeightForWidth());
|
||||
labTitle->setSizePolicy(sizePolicy2);
|
||||
labTitle->setAlignment(Qt::AlignLeading | Qt::AlignLeft | Qt::AlignVCenter);
|
||||
horizontalLayout1->addWidget(labTitle);
|
||||
|
||||
widgetMenu = new QWidget(widgetTitle);
|
||||
widgetMenu->setObjectName(QString::fromUtf8("widgetMenu"));
|
||||
sizePolicy1.setHeightForWidth(widgetMenu->sizePolicy().hasHeightForWidth());
|
||||
widgetMenu->setSizePolicy(sizePolicy1);
|
||||
|
||||
horizontalLayout = new QHBoxLayout(widgetMenu);
|
||||
horizontalLayout->setSpacing(0);
|
||||
horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
|
||||
horizontalLayout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
btnMenu_Close = new QPushButton(widgetMenu);
|
||||
btnMenu_Close->setObjectName(QString::fromUtf8("btnMenu_Close"));
|
||||
QSizePolicy sizePolicy3(QSizePolicy::Minimum, QSizePolicy::Expanding);
|
||||
sizePolicy3.setHorizontalStretch(0);
|
||||
sizePolicy3.setVerticalStretch(0);
|
||||
sizePolicy3.setHeightForWidth(btnMenu_Close->sizePolicy().hasHeightForWidth());
|
||||
btnMenu_Close->setSizePolicy(sizePolicy3);
|
||||
btnMenu_Close->setCursor(QCursor(Qt::ArrowCursor));
|
||||
btnMenu_Close->setFocusPolicy(Qt::NoFocus);
|
||||
btnMenu_Close->setFlat(true);
|
||||
|
||||
horizontalLayout->addWidget(btnMenu_Close);
|
||||
horizontalLayout1->addWidget(widgetMenu);
|
||||
verticalLayout->addWidget(widgetTitle);
|
||||
|
||||
widgetMain = new QWidget(this);
|
||||
widgetMain->setObjectName(QString::fromUtf8("widgetMainQUI"));
|
||||
|
||||
verticalLayout1 = new QVBoxLayout(widgetMain);
|
||||
verticalLayout1->setSpacing(6);
|
||||
verticalLayout1->setObjectName(QString::fromUtf8("verticalLayout1"));
|
||||
verticalLayout1->setContentsMargins(6, 6, 6, 6);
|
||||
|
||||
frame = new QFrame(widgetMain);
|
||||
frame->setObjectName(QString::fromUtf8("frame"));
|
||||
frame->setFrameShape(QFrame::Box);
|
||||
frame->setFrameShadow(QFrame::Sunken);
|
||||
|
||||
gridLayout = new QGridLayout(frame);
|
||||
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
|
||||
labStart = new QLabel(frame);
|
||||
labStart->setObjectName(QString::fromUtf8("labStart"));
|
||||
labStart->setFocusPolicy(Qt::TabFocus);
|
||||
gridLayout->addWidget(labStart, 0, 0, 1, 1);
|
||||
|
||||
btnOk = new QPushButton(frame);
|
||||
btnOk->setObjectName(QString::fromUtf8("btnOk"));
|
||||
btnOk->setMinimumSize(QSize(85, 0));
|
||||
btnOk->setCursor(QCursor(Qt::PointingHandCursor));
|
||||
btnOk->setFocusPolicy(Qt::StrongFocus);
|
||||
gridLayout->addWidget(btnOk, 0, 2, 1, 1);
|
||||
btnOk->setDefault(true);
|
||||
|
||||
labEnd = new QLabel(frame);
|
||||
labEnd->setObjectName(QString::fromUtf8("labEnd"));
|
||||
labEnd->setFocusPolicy(Qt::TabFocus);
|
||||
gridLayout->addWidget(labEnd, 1, 0, 1, 1);
|
||||
|
||||
btnClose = new QPushButton(frame);
|
||||
btnClose->setObjectName(QString::fromUtf8("btnClose"));
|
||||
btnClose->setMinimumSize(QSize(85, 0));
|
||||
btnClose->setCursor(QCursor(Qt::PointingHandCursor));
|
||||
btnClose->setFocusPolicy(Qt::StrongFocus);
|
||||
gridLayout->addWidget(btnClose, 1, 2, 1, 1);
|
||||
|
||||
dateStart = new QDateTimeEdit(frame);
|
||||
dateStart->setObjectName(QString::fromUtf8("dateStart"));
|
||||
QSizePolicy sizePolicy4(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
sizePolicy4.setHorizontalStretch(0);
|
||||
sizePolicy4.setVerticalStretch(0);
|
||||
sizePolicy4.setHeightForWidth(dateStart->sizePolicy().hasHeightForWidth());
|
||||
dateStart->setSizePolicy(sizePolicy4);
|
||||
dateStart->setCalendarPopup(true);
|
||||
gridLayout->addWidget(dateStart, 0, 1, 1, 1);
|
||||
|
||||
dateEnd = new QDateTimeEdit(frame);
|
||||
dateEnd->setObjectName(QString::fromUtf8("dateEnd"));
|
||||
sizePolicy4.setHeightForWidth(dateEnd->sizePolicy().hasHeightForWidth());
|
||||
dateEnd->setSizePolicy(sizePolicy4);
|
||||
dateEnd->setCalendarPopup(true);
|
||||
|
||||
gridLayout->addWidget(dateEnd, 1, 1, 1, 1);
|
||||
verticalLayout1->addWidget(frame);
|
||||
verticalLayout->addWidget(widgetMain);
|
||||
|
||||
QWidget::setTabOrder(labStart, labEnd);
|
||||
QWidget::setTabOrder(labEnd, dateStart);
|
||||
QWidget::setTabOrder(dateStart, dateEnd);
|
||||
QWidget::setTabOrder(dateEnd, btnOk);
|
||||
QWidget::setTabOrder(btnOk, btnClose);
|
||||
|
||||
labTitle->setText("日期时间选择");
|
||||
labStart->setText("开始时间");
|
||||
labEnd->setText("结束时间");
|
||||
btnOk->setText("确定");
|
||||
btnClose->setText("关闭");
|
||||
|
||||
dateStart->setDate(QDate::currentDate());
|
||||
dateEnd->setDate(QDate::currentDate().addDays(1));
|
||||
|
||||
dateStart->calendarWidget()->setGridVisible(true);
|
||||
dateEnd->calendarWidget()->setGridVisible(true);
|
||||
dateStart->calendarWidget()->setLocale(QLocale::Chinese);
|
||||
dateEnd->calendarWidget()->setLocale(QLocale::Chinese);
|
||||
setFormat("yyyy-MM-dd");
|
||||
|
||||
connect(btnOk, SIGNAL(clicked()), this, SLOT(on_btnOk_clicked()));
|
||||
connect(btnClose, SIGNAL(clicked()), this, SLOT(on_btnMenu_Close_clicked()));
|
||||
connect(btnMenu_Close, SIGNAL(clicked()), this, SLOT(on_btnMenu_Close_clicked()));
|
||||
}
|
||||
|
||||
void QUIDateSelect::initForm()
|
||||
{
|
||||
QUIHelper::setFramelessForm(this, widgetTitle, labIco, btnMenu_Close);
|
||||
this->setWindowTitle(this->labTitle->text());
|
||||
this->setFixedSize(QUIDialogMinWidth + 50, QUIDialogMinHeight);
|
||||
|
||||
QList<QPushButton *> btns = this->frame->findChildren<QPushButton *>();
|
||||
foreach (QPushButton *btn, btns) {
|
||||
btn->setMinimumWidth(QUIBtnMinWidth);
|
||||
btn->setIconSize(QSize(QUIIconWidth, QUIIconHeight));
|
||||
}
|
||||
|
||||
this->installEventFilter(this);
|
||||
}
|
||||
|
||||
void QUIDateSelect::on_btnOk_clicked()
|
||||
{
|
||||
if (dateStart->dateTime() > dateEnd->dateTime()) {
|
||||
QUIHelper::showMessageBoxError("开始时间不能大于结束时间!", 3);
|
||||
return;
|
||||
}
|
||||
|
||||
startDateTime = dateStart->dateTime().toString(format);
|
||||
endDateTime = dateEnd->dateTime().toString(format);
|
||||
|
||||
done(QMessageBox::Ok);
|
||||
close();
|
||||
}
|
||||
|
||||
void QUIDateSelect::on_btnMenu_Close_clicked()
|
||||
{
|
||||
done(QMessageBox::Cancel);
|
||||
close();
|
||||
}
|
||||
|
||||
QString QUIDateSelect::getStartDateTime() const
|
||||
{
|
||||
return this->startDateTime;
|
||||
}
|
||||
|
||||
QString QUIDateSelect::getEndDateTime() const
|
||||
{
|
||||
return this->endDateTime;
|
||||
}
|
||||
|
||||
void QUIDateSelect::setIconMain(const QChar &icon, quint32 size)
|
||||
{
|
||||
IconHelper::Instance()->setIcon(this->labIco, icon, size);
|
||||
}
|
||||
|
||||
void QUIDateSelect::setFormat(const QString &format)
|
||||
{
|
||||
this->format = format;
|
||||
this->dateStart->setDisplayFormat(format);
|
||||
this->dateEnd->setDisplayFormat(format);
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
#ifndef QUIDATESELECT_H
|
||||
#define QUIDATESELECT_H
|
||||
|
||||
#include "quihead.h"
|
||||
|
||||
class QUIDateSelect : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static QUIDateSelect *Instance();
|
||||
explicit QUIDateSelect(QWidget *parent = 0);
|
||||
~QUIDateSelect();
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *);
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
static QScopedPointer<QUIDateSelect> self;
|
||||
|
||||
QVBoxLayout *verticalLayout;
|
||||
QWidget *widgetTitle;
|
||||
QHBoxLayout *horizontalLayout1;
|
||||
QLabel *labIco;
|
||||
QLabel *labTitle;
|
||||
QWidget *widgetMenu;
|
||||
QHBoxLayout *horizontalLayout;
|
||||
QPushButton *btnMenu_Close;
|
||||
QWidget *widgetMain;
|
||||
QVBoxLayout *verticalLayout1;
|
||||
QFrame *frame;
|
||||
QGridLayout *gridLayout;
|
||||
QLabel *labStart;
|
||||
QPushButton *btnOk;
|
||||
QLabel *labEnd;
|
||||
QPushButton *btnClose;
|
||||
QDateTimeEdit *dateStart;
|
||||
QDateTimeEdit *dateEnd;
|
||||
|
||||
private:
|
||||
QString startDateTime; //开始时间
|
||||
QString endDateTime; //结束时间
|
||||
QString format; //日期时间格式
|
||||
|
||||
private slots:
|
||||
void initControl(); //初始化控件
|
||||
void initForm(); //初始化窗体
|
||||
|
||||
private slots:
|
||||
void on_btnOk_clicked();
|
||||
void on_btnMenu_Close_clicked();
|
||||
|
||||
public:
|
||||
//获取当前选择的开始时间和结束时间
|
||||
QString getStartDateTime() const;
|
||||
QString getEndDateTime() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
void setIconMain(const QChar &icon, quint32 size = 12);
|
||||
void setFormat(const QString &format);
|
||||
};
|
||||
|
||||
#endif // QUIDATESELECT_H
|
|
@ -0,0 +1,66 @@
|
|||
#ifndef QUIHEAD_H
|
||||
#define QUIHEAD_H
|
||||
|
||||
#ifndef TIMEMS
|
||||
#define TIMEMS qPrintable(QTime::currentTime().toString("HH:mm:ss zzz"))
|
||||
#endif
|
||||
#ifndef TIME
|
||||
#define TIME qPrintable(QTime::currentTime().toString("HH:mm:ss"))
|
||||
#endif
|
||||
#ifndef QDATE
|
||||
#define QDATE qPrintable(QDate::currentDate().toString("yyyy-MM-dd"))
|
||||
#endif
|
||||
#ifndef QTIME
|
||||
#define QTIME qPrintable(QTime::currentTime().toString("HH-mm-ss"))
|
||||
#endif
|
||||
#ifndef DATETIME
|
||||
#define DATETIME qPrintable(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss"))
|
||||
#endif
|
||||
#ifndef STRDATETIME
|
||||
#define STRDATETIME qPrintable(QDateTime::currentDateTime().toString("yyyy-MM-dd-HH-mm-ss"))
|
||||
#endif
|
||||
#ifndef STRDATETIMEMS
|
||||
#define STRDATETIMEMS qPrintable(QDateTime::currentDateTime().toString("yyyy-MM-dd-HH-mm-ss-zzz"))
|
||||
#endif
|
||||
|
||||
//数据 0
|
||||
#define data_zero (char)0x00
|
||||
|
||||
//定义换行符
|
||||
#ifdef Q_OS_WIN
|
||||
#define NEWLINE "\r\n"
|
||||
#else
|
||||
#define NEWLINE "\n"
|
||||
#endif
|
||||
|
||||
//定义无边框标题栏高度+对话框最小宽高
|
||||
#ifdef __arm__
|
||||
#define QUITitleMinSize 40
|
||||
#define QUIDialogMinWidth 350
|
||||
#define QUIDialogMinHeight 180
|
||||
#define QUIBtnMinWidth 90
|
||||
#define QUIIconWidth 22
|
||||
#define QUIIconHeight 22
|
||||
#else
|
||||
#define QUITitleMinSize 30
|
||||
#define QUIDialogMinWidth 280
|
||||
#define QUIDialogMinHeight 150
|
||||
#define QUIBtnMinWidth 80
|
||||
#define QUIIconWidth 18
|
||||
#define QUIIconHeight 18
|
||||
#endif
|
||||
|
||||
#include "head.h"
|
||||
#include "iconhelper.h"
|
||||
#include "iconfont.h"
|
||||
|
||||
#include "quihelper.h"
|
||||
#include "quiconfig.h"
|
||||
#include "quistyle.h"
|
||||
#include "quihead.h"
|
||||
#include "quimessagebox.h"
|
||||
#include "quitipbox.h"
|
||||
#include "quidateselect.h"
|
||||
#include "quiinputbox.h"
|
||||
|
||||
#endif // QUIHEAD_H
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,217 @@
|
|||
#ifndef QUIHELPER_H
|
||||
#define QUIHELPER_H
|
||||
|
||||
#include "quihead.h"
|
||||
|
||||
class QUIHelper
|
||||
{
|
||||
public:
|
||||
//获取uuid
|
||||
static QString getUuid();
|
||||
//获取当前鼠标所在屏幕
|
||||
static int getScreenIndex();
|
||||
|
||||
//桌面宽度高度
|
||||
static int deskWidth();
|
||||
static int deskHeight();
|
||||
|
||||
//程序文件名称+当前所在路径
|
||||
static QString appName();
|
||||
static QString appPath();
|
||||
|
||||
//初始化随机数种子
|
||||
static void initRand();
|
||||
|
||||
//初始化数据库
|
||||
static void initDb(const QString &dbName);
|
||||
//初始化文件,不存在则拷贝
|
||||
static void initFile(const QString &sourceName, const QString &targetName);
|
||||
|
||||
//检查ini配置文件
|
||||
static bool checkIniFile(const QString &iniFile);
|
||||
|
||||
//设置图标到按钮
|
||||
static void setIconBtn(QAbstractButton *btn, const QString &png, const QChar &str);
|
||||
|
||||
//新建目录
|
||||
static void newDir(const QString &dirName);
|
||||
|
||||
//写入消息到额外的的消息日志文件
|
||||
static void writeInfo(const QString &info, bool needWrite = false, const QString &filePath = "log");
|
||||
static void writeError(const QString &info, bool needWrite = false, const QString &filePath = "log");
|
||||
|
||||
//设置无边框窗体
|
||||
static void setFramelessForm(QWidget *widgetMain,
|
||||
bool tool = false, bool top = false, bool menu = true);
|
||||
static void setFramelessForm(QWidget *widgetMain, QWidget *widgetTitle,
|
||||
QLabel *labIco, QPushButton *btnClose,
|
||||
bool tool = true, bool top = true, bool menu = false);
|
||||
|
||||
//设置窗体居中显示
|
||||
static void setFormInCenter(QWidget *frm);
|
||||
//设置翻译文件
|
||||
static void setTranslator(const QString &qmFile = ":/image/qt_zh_CN.qm");
|
||||
//设置编码
|
||||
static void setCode();
|
||||
//设置字体
|
||||
static void setFont(const QString &ttfFile = ":/image/DroidSansFallback.ttf",
|
||||
const QString &fontName = "Microsoft Yahei", int fontSize = 12);
|
||||
|
||||
//设置延时
|
||||
static void sleep(int msec);
|
||||
//设置系统时间
|
||||
static void setSystemDateTime(const QString &year, const QString &month, const QString &day,
|
||||
const QString &hour, const QString &min, const QString &sec);
|
||||
//设置开机自启动
|
||||
static void runWithSystem(const QString &strName, const QString &strPath, bool autoRun = true);
|
||||
|
||||
//从字符串获取IP地址
|
||||
static QString getIP(const QString &url);
|
||||
//判断是否是IP地址
|
||||
static bool isIP(const QString &ip);
|
||||
//判断是否是MAC地址
|
||||
static bool isMac(const QString &mac);
|
||||
//判断是否是合法的电话号码
|
||||
static bool isTel(const QString &tel);
|
||||
//判断是否是合法的邮箱地址
|
||||
static bool isEmail(const QString &email);
|
||||
|
||||
//IP地址字符串与整型转换
|
||||
static QString ipv4IntToString(quint32 ip);
|
||||
static quint32 ipv4StringToInt(const QString &ip);
|
||||
|
||||
//16进制字符串转10进制
|
||||
static int strHexToDecimal(const QString &strHex);
|
||||
//10进制字符串转10进制
|
||||
static int strDecimalToDecimal(const QString &strDecimal);
|
||||
//2进制字符串转10进制
|
||||
static int strBinToDecimal(const QString &strBin);
|
||||
|
||||
//16进制字符串转2进制字符串
|
||||
static QString strHexToStrBin(const QString &strHex);
|
||||
//10进制转2进制字符串一个字节
|
||||
static QString decimalToStrBin1(int decimal);
|
||||
//10进制转2进制字符串两个字节
|
||||
static QString decimalToStrBin2(int decimal);
|
||||
//10进制转16进制字符串,补零.
|
||||
static QString decimalToStrHex(int decimal);
|
||||
|
||||
//int转字节数组
|
||||
static QByteArray intToByte(int i);
|
||||
static QByteArray intToByteRec(int i);
|
||||
|
||||
//字节数组转int
|
||||
static int byteToInt(const QByteArray &data);
|
||||
static int byteToIntRec(const QByteArray &data);
|
||||
static quint32 byteToUInt(const QByteArray &data);
|
||||
static quint32 byteToUIntRec(const QByteArray &data);
|
||||
|
||||
//ushort转字节数组
|
||||
static QByteArray ushortToByte(ushort i);
|
||||
static QByteArray ushortToByteRec(ushort i);
|
||||
|
||||
//字节数组转ushort
|
||||
static int byteToUShort(const QByteArray &data);
|
||||
static int byteToUShortRec(const QByteArray &data);
|
||||
|
||||
//异或加密算法
|
||||
static QString getXorEncryptDecrypt(const QString &str, char key);
|
||||
//异或校验
|
||||
static uchar getOrCode(const QByteArray &data);
|
||||
//计算校验码
|
||||
static uchar getCheckCode(const QByteArray &data);
|
||||
|
||||
//CRC校验
|
||||
static quint16 getCRC16Rec(quint8 *data, int len, quint16 init, const quint16 *table);
|
||||
static quint16 getCRC16(quint8 *data, int len, quint16 init, const quint16 *table);
|
||||
static quint16 getModbus16(quint8 *data, int len);
|
||||
static QByteArray getCRCCode(const QByteArray &data);
|
||||
|
||||
//字节数组与Ascii字符串互转
|
||||
static void initAsciiStr();
|
||||
static QString byteArrayToAsciiStr(const QByteArray &data);
|
||||
static QByteArray asciiStrToByteArray(const QString &data);
|
||||
|
||||
//16进制字符串与字节数组互转
|
||||
static char hexStrToChar(char data);
|
||||
static QByteArray hexStrToByteArray(const QString &data);
|
||||
static QString byteArrayToHexStr(const QByteArray &data);
|
||||
|
||||
//获取保存的文件
|
||||
static QString getSaveName(const QString &filter, QString defaultDir = QCoreApplication::applicationDirPath());
|
||||
//获取选择的文件
|
||||
static QString getFileName(const QString &filter, QString defaultDir = QCoreApplication::applicationDirPath());
|
||||
//非阻塞保存文件对话框
|
||||
static QString saveFileName(const QString &filter, const QString &defaultDir = "", const QString &fileName = "");
|
||||
//获取选择的文件集合
|
||||
static QStringList getFileNames(const QString &filter, QString defaultDir = QCoreApplication::applicationDirPath());
|
||||
//获取选择的目录
|
||||
static QString getFolderName();
|
||||
|
||||
//获取文件名,含拓展名
|
||||
static QString getFileNameWithExtension(const QString &strFilePath);
|
||||
//获取选择文件夹中的文件
|
||||
static QStringList getFolderFileNames(const QStringList &filter);
|
||||
|
||||
//文件夹是否存在
|
||||
static bool folderIsExist(const QString &strFolder);
|
||||
//文件是否存在
|
||||
static bool fileIsExist(const QString &strFile);
|
||||
//复制文件
|
||||
static bool copyFile(const QString &sourceFile, const QString &targetFile);
|
||||
//删除文件夹下所有文件
|
||||
static void deleteDirectory(const QString &path);
|
||||
|
||||
//判断IP地址及端口是否在线
|
||||
static bool ipLive(const QString &ip, int port, int timeout = 1000);
|
||||
//获取网页所有源代码
|
||||
static QString getHtml(const QString &url);
|
||||
//获取本机公网IP地址
|
||||
static QString getNetIP(const QString &html);
|
||||
//获取本机IP
|
||||
static QString getLocalIP();
|
||||
//获取本机IP地址集合
|
||||
static QStringList getLocalIPs();
|
||||
//Url地址转为IP地址
|
||||
static QString urlToIP(const QString &url);
|
||||
|
||||
//字符串补全
|
||||
static QString getValue(quint8 value);
|
||||
//判断是否通外网
|
||||
static bool isWebOk();
|
||||
|
||||
//定义标志位启用系统的还是自定义的对话框
|
||||
static bool isCustomUI;
|
||||
//弹出框
|
||||
static int showMessageBox(const QString &info, int type = 0, int closeSec = 0, bool exec = false);
|
||||
//弹出消息框
|
||||
static void showMessageBoxInfo(const QString &info, int closeSec = 0, bool exec = false);
|
||||
//弹出错误框
|
||||
static void showMessageBoxError(const QString &info, int closeSec = 0, bool exec = false);
|
||||
//弹出询问框
|
||||
static int showMessageBoxQuestion(const QString &info);
|
||||
|
||||
//弹出+隐藏右下角信息框
|
||||
static void showTipBox(const QString &title, const QString &tip, bool fullScreen = false,
|
||||
bool center = true, int closeSec = 0);
|
||||
static void hideTipBox();
|
||||
|
||||
//弹出输入框
|
||||
static QString showInputBox(const QString &title, int type = 0, int closeSec = 0,
|
||||
const QString &placeholderText = QString(), bool pwd = false,
|
||||
const QString &defaultValue = QString());
|
||||
//弹出日期选择框
|
||||
static void showDateSelect(QString &dateStart, QString &dateEnd, const QString &format = "yyyy-MM-dd");
|
||||
|
||||
|
||||
//初始化表格
|
||||
static void initTableView(QTableView *tableView, int rowHeight = 25,
|
||||
bool headVisible = false, bool edit = false,
|
||||
bool stretchLast = true);
|
||||
//打开文件带提示框
|
||||
static void openFile(const QString &fileName, const QString &msg);
|
||||
//导出和打印数据提示框
|
||||
static bool checkRowCount(int rowCount, int maxCount, int warnCount);
|
||||
};
|
||||
|
||||
#endif // QUIHELPER_H
|
|
@ -0,0 +1,291 @@
|
|||
#include "quiinputbox.h"
|
||||
|
||||
QScopedPointer<QUIInputBox> QUIInputBox::self;
|
||||
QUIInputBox *QUIInputBox::Instance()
|
||||
{
|
||||
if (self.isNull()) {
|
||||
static QMutex mutex;
|
||||
QMutexLocker locker(&mutex);
|
||||
if (self.isNull()) {
|
||||
self.reset(new QUIInputBox);
|
||||
}
|
||||
}
|
||||
|
||||
return self.data();
|
||||
}
|
||||
|
||||
QUIInputBox::QUIInputBox(QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
this->initControl();
|
||||
this->initForm();
|
||||
}
|
||||
|
||||
QUIInputBox::~QUIInputBox()
|
||||
{
|
||||
delete widgetMain;
|
||||
}
|
||||
|
||||
void QUIInputBox::showEvent(QShowEvent *)
|
||||
{
|
||||
QUIHelper::setIconBtn(btnOk, ":/image/btn_ok.png", 0xf00c);
|
||||
QUIHelper::setIconBtn(btnCancel, ":/image/btn_close.png", 0xf00d);
|
||||
QUIHelper::setFormInCenter(this);
|
||||
txtValue->setFocus();
|
||||
this->activateWindow();
|
||||
}
|
||||
|
||||
void QUIInputBox::initControl()
|
||||
{
|
||||
this->setObjectName(QString::fromUtf8("QUIInputBox"));
|
||||
|
||||
verticalLayout1 = new QVBoxLayout(this);
|
||||
verticalLayout1->setSpacing(0);
|
||||
verticalLayout1->setObjectName(QString::fromUtf8("verticalLayout1"));
|
||||
verticalLayout1->setContentsMargins(1, 1, 1, 1);
|
||||
|
||||
widgetTitle = new QWidget(this);
|
||||
widgetTitle->setObjectName(QString::fromUtf8("widgetTitle"));
|
||||
QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
||||
sizePolicy.setHorizontalStretch(0);
|
||||
sizePolicy.setVerticalStretch(0);
|
||||
sizePolicy.setHeightForWidth(widgetTitle->sizePolicy().hasHeightForWidth());
|
||||
widgetTitle->setSizePolicy(sizePolicy);
|
||||
|
||||
horizontalLayout1 = new QHBoxLayout(widgetTitle);
|
||||
horizontalLayout1->setSpacing(0);
|
||||
horizontalLayout1->setObjectName(QString::fromUtf8("horizontalLayout1"));
|
||||
horizontalLayout1->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
labIco = new QLabel(widgetTitle);
|
||||
labIco->setObjectName(QString::fromUtf8("labIco"));
|
||||
QSizePolicy sizePolicy1(QSizePolicy::Minimum, QSizePolicy::Preferred);
|
||||
sizePolicy1.setHorizontalStretch(0);
|
||||
sizePolicy1.setVerticalStretch(0);
|
||||
sizePolicy1.setHeightForWidth(labIco->sizePolicy().hasHeightForWidth());
|
||||
labIco->setSizePolicy(sizePolicy1);
|
||||
labIco->setAlignment(Qt::AlignCenter);
|
||||
horizontalLayout1->addWidget(labIco);
|
||||
|
||||
labTitle = new QLabel(widgetTitle);
|
||||
labTitle->setObjectName(QString::fromUtf8("labTitle"));
|
||||
labTitle->setAlignment(Qt::AlignLeading | Qt::AlignLeft | Qt::AlignVCenter);
|
||||
horizontalLayout1->addWidget(labTitle);
|
||||
|
||||
labCountDown = new QLabel(widgetTitle);
|
||||
labCountDown->setObjectName(QString::fromUtf8("labCountDown"));
|
||||
QSizePolicy sizePolicy2(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
sizePolicy2.setHorizontalStretch(0);
|
||||
sizePolicy2.setVerticalStretch(0);
|
||||
sizePolicy2.setHeightForWidth(labCountDown->sizePolicy().hasHeightForWidth());
|
||||
labCountDown->setSizePolicy(sizePolicy2);
|
||||
labCountDown->setAlignment(Qt::AlignCenter);
|
||||
horizontalLayout1->addWidget(labCountDown);
|
||||
|
||||
widgetMenu = new QWidget(widgetTitle);
|
||||
widgetMenu->setObjectName(QString::fromUtf8("widgetMenu"));
|
||||
sizePolicy1.setHeightForWidth(widgetMenu->sizePolicy().hasHeightForWidth());
|
||||
widgetMenu->setSizePolicy(sizePolicy1);
|
||||
|
||||
horizontalLayout2 = new QHBoxLayout(widgetMenu);
|
||||
horizontalLayout2->setSpacing(0);
|
||||
horizontalLayout2->setObjectName(QString::fromUtf8("horizontalLayout2"));
|
||||
horizontalLayout2->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
btnMenu_Close = new QPushButton(widgetMenu);
|
||||
btnMenu_Close->setObjectName(QString::fromUtf8("btnMenu_Close"));
|
||||
QSizePolicy sizePolicy3(QSizePolicy::Minimum, QSizePolicy::Expanding);
|
||||
sizePolicy3.setHorizontalStretch(0);
|
||||
sizePolicy3.setVerticalStretch(0);
|
||||
sizePolicy3.setHeightForWidth(btnMenu_Close->sizePolicy().hasHeightForWidth());
|
||||
btnMenu_Close->setSizePolicy(sizePolicy3);
|
||||
btnMenu_Close->setCursor(QCursor(Qt::ArrowCursor));
|
||||
btnMenu_Close->setFocusPolicy(Qt::NoFocus);
|
||||
btnMenu_Close->setFlat(true);
|
||||
|
||||
horizontalLayout2->addWidget(btnMenu_Close);
|
||||
horizontalLayout1->addWidget(widgetMenu);
|
||||
verticalLayout1->addWidget(widgetTitle);
|
||||
|
||||
widgetMain = new QWidget(this);
|
||||
widgetMain->setObjectName(QString::fromUtf8("widgetMainQUI"));
|
||||
|
||||
verticalLayout2 = new QVBoxLayout(widgetMain);
|
||||
verticalLayout2->setSpacing(5);
|
||||
verticalLayout2->setObjectName(QString::fromUtf8("verticalLayout2"));
|
||||
verticalLayout2->setContentsMargins(5, 5, 5, 5);
|
||||
|
||||
frame = new QFrame(widgetMain);
|
||||
frame->setObjectName(QString::fromUtf8("frame"));
|
||||
frame->setFrameShape(QFrame::Box);
|
||||
frame->setFrameShadow(QFrame::Sunken);
|
||||
|
||||
labInfo = new QLabel(frame);
|
||||
labInfo->setObjectName(QString::fromUtf8("labInfo"));
|
||||
labInfo->setScaledContents(false);
|
||||
labInfo->setWordWrap(true);
|
||||
|
||||
verticalLayout3 = new QVBoxLayout(frame);
|
||||
verticalLayout3->setObjectName(QString::fromUtf8("verticalLayout3"));
|
||||
verticalLayout3->addWidget(labInfo);
|
||||
|
||||
txtValue = new QLineEdit(frame);
|
||||
txtValue->setObjectName(QString::fromUtf8("txtValue"));
|
||||
verticalLayout3->addWidget(txtValue);
|
||||
|
||||
cboxValue = new QComboBox(frame);
|
||||
cboxValue->setObjectName(QString::fromUtf8("cboxValue"));
|
||||
verticalLayout3->addWidget(cboxValue);
|
||||
|
||||
lay = new QHBoxLayout();
|
||||
lay->setObjectName(QString::fromUtf8("lay"));
|
||||
horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
||||
lay->addItem(horizontalSpacer);
|
||||
|
||||
btnOk = new QPushButton(frame);
|
||||
btnOk->setObjectName(QString::fromUtf8("btnOk"));
|
||||
btnOk->setMinimumSize(QSize(85, 0));
|
||||
lay->addWidget(btnOk);
|
||||
btnOk->setDefault(true);
|
||||
|
||||
btnCancel = new QPushButton(frame);
|
||||
btnCancel->setObjectName(QString::fromUtf8("btnCancel"));
|
||||
btnCancel->setMinimumSize(QSize(85, 0));
|
||||
lay->addWidget(btnCancel);
|
||||
|
||||
verticalLayout3->addLayout(lay);
|
||||
verticalLayout2->addWidget(frame);
|
||||
verticalLayout1->addWidget(widgetMain);
|
||||
|
||||
QWidget::setTabOrder(txtValue, btnOk);
|
||||
QWidget::setTabOrder(btnOk, btnCancel);
|
||||
|
||||
labTitle->setText("输入框");
|
||||
btnOk->setText("确定");
|
||||
btnCancel->setText("取消");
|
||||
|
||||
connect(btnOk, SIGNAL(clicked()), this, SLOT(on_btnOk_clicked()));
|
||||
connect(btnCancel, SIGNAL(clicked()), this, SLOT(on_btnMenu_Close_clicked()));
|
||||
connect(btnMenu_Close, SIGNAL(clicked()), this, SLOT(on_btnMenu_Close_clicked()));
|
||||
}
|
||||
|
||||
void QUIInputBox::initForm()
|
||||
{
|
||||
QUIHelper::setFramelessForm(this, widgetTitle, labIco, btnMenu_Close);
|
||||
this->setWindowTitle(this->labTitle->text());
|
||||
this->setFixedSize(QUIDialogMinWidth, QUIDialogMinHeight + 10);
|
||||
|
||||
QList<QPushButton *> btns = this->frame->findChildren<QPushButton *>();
|
||||
foreach (QPushButton *btn, btns) {
|
||||
btn->setMinimumWidth(QUIBtnMinWidth);
|
||||
btn->setIconSize(QSize(QUIIconWidth, QUIIconHeight));
|
||||
}
|
||||
|
||||
closeSec = 0;
|
||||
currentSec = 0;
|
||||
|
||||
QTimer *timer = new QTimer(this);
|
||||
timer->setInterval(1000);
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(checkSec()));
|
||||
timer->start();
|
||||
|
||||
this->installEventFilter(this);
|
||||
}
|
||||
|
||||
void QUIInputBox::checkSec()
|
||||
{
|
||||
if (closeSec == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentSec < closeSec) {
|
||||
currentSec++;
|
||||
} else {
|
||||
this->close();
|
||||
}
|
||||
|
||||
QString str = QString("关闭倒计时 %1 s").arg(closeSec - currentSec + 1);
|
||||
this->labCountDown->setText(str);
|
||||
}
|
||||
|
||||
void QUIInputBox::setParameter(const QString &title, int type, int closeSec,
|
||||
QString placeholderText, bool pwd,
|
||||
const QString &defaultValue)
|
||||
{
|
||||
this->closeSec = closeSec;
|
||||
this->currentSec = 0;
|
||||
this->labCountDown->clear();
|
||||
this->labInfo->setText(title);
|
||||
checkSec();
|
||||
|
||||
if (type == 0) {
|
||||
this->cboxValue->setVisible(false);
|
||||
this->txtValue->setPlaceholderText(placeholderText);
|
||||
this->txtValue->setText(defaultValue);
|
||||
|
||||
if (pwd) {
|
||||
this->txtValue->setEchoMode(QLineEdit::Password);
|
||||
}
|
||||
} else if (type == 1) {
|
||||
this->txtValue->setVisible(false);
|
||||
this->cboxValue->addItems(defaultValue.split("|"));
|
||||
}
|
||||
}
|
||||
|
||||
QString QUIInputBox::getValue() const
|
||||
{
|
||||
return this->value;
|
||||
}
|
||||
|
||||
void QUIInputBox::closeEvent(QCloseEvent *)
|
||||
{
|
||||
closeSec = 0;
|
||||
currentSec = 0;
|
||||
}
|
||||
|
||||
bool QUIInputBox::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
static QPoint mousePoint;
|
||||
static bool mousePressed = false;
|
||||
|
||||
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
|
||||
if (mouseEvent->type() == QEvent::MouseButtonPress) {
|
||||
if (mouseEvent->button() == Qt::LeftButton) {
|
||||
mousePressed = true;
|
||||
mousePoint = mouseEvent->globalPos() - this->pos();
|
||||
return true;
|
||||
}
|
||||
} else if (mouseEvent->type() == QEvent::MouseButtonRelease) {
|
||||
mousePressed = false;
|
||||
return true;
|
||||
} else if (mouseEvent->type() == QEvent::MouseMove) {
|
||||
if (mousePressed) {
|
||||
this->move(mouseEvent->globalPos() - mousePoint);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return QWidget::eventFilter(watched, event);
|
||||
}
|
||||
|
||||
void QUIInputBox::on_btnOk_clicked()
|
||||
{
|
||||
if (this->txtValue->isVisible()) {
|
||||
value = this->txtValue->text();
|
||||
} else if (this->cboxValue->isVisible()) {
|
||||
value = this->cboxValue->currentText();
|
||||
}
|
||||
|
||||
done(QMessageBox::Ok);
|
||||
close();
|
||||
}
|
||||
|
||||
void QUIInputBox::on_btnMenu_Close_clicked()
|
||||
{
|
||||
done(QMessageBox::Cancel);
|
||||
close();
|
||||
}
|
||||
|
||||
void QUIInputBox::setIconMain(const QChar &icon, quint32 size)
|
||||
{
|
||||
IconHelper::Instance()->setIcon(this->labIco, icon, size);
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
#ifndef QUIINPUTBOX_H
|
||||
#define QUIINPUTBOX_H
|
||||
|
||||
#include "quihead.h"
|
||||
|
||||
class QUIInputBox : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static QUIInputBox *Instance();
|
||||
explicit QUIInputBox(QWidget *parent = 0);
|
||||
~QUIInputBox();
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *);
|
||||
void closeEvent(QCloseEvent *);
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
static QScopedPointer<QUIInputBox> self;
|
||||
|
||||
QVBoxLayout *verticalLayout1;
|
||||
QWidget *widgetTitle;
|
||||
QHBoxLayout *horizontalLayout1;
|
||||
QLabel *labIco;
|
||||
QLabel *labTitle;
|
||||
QLabel *labCountDown;
|
||||
QWidget *widgetMenu;
|
||||
QHBoxLayout *horizontalLayout2;
|
||||
QPushButton *btnMenu_Close;
|
||||
QWidget *widgetMain;
|
||||
QVBoxLayout *verticalLayout2;
|
||||
QFrame *frame;
|
||||
QVBoxLayout *verticalLayout3;
|
||||
QLabel *labInfo;
|
||||
QLineEdit *txtValue;
|
||||
QComboBox *cboxValue;
|
||||
QHBoxLayout *lay;
|
||||
QSpacerItem *horizontalSpacer;
|
||||
QPushButton *btnOk;
|
||||
QPushButton *btnCancel;
|
||||
|
||||
private:
|
||||
int closeSec; //总显示时间
|
||||
int currentSec; //当前已显示时间
|
||||
QString value; //当前值
|
||||
|
||||
private slots:
|
||||
void initControl(); //初始化控件
|
||||
void initForm(); //初始化窗体
|
||||
void checkSec(); //校验倒计时
|
||||
|
||||
private slots:
|
||||
void on_btnOk_clicked();
|
||||
void on_btnMenu_Close_clicked();
|
||||
|
||||
public:
|
||||
QString getValue()const;
|
||||
|
||||
public Q_SLOTS:
|
||||
void setIconMain(const QChar &icon, quint32 size = 12);
|
||||
void setParameter(const QString &title, int type = 0, int closeSec = 0,
|
||||
QString placeholderText = QString(), bool pwd = false,
|
||||
const QString &defaultValue = QString());
|
||||
|
||||
};
|
||||
|
||||
#endif // QUIINPUTBOX_H
|
|
@ -0,0 +1,310 @@
|
|||
#include "quimessagebox.h"
|
||||
|
||||
QScopedPointer<QUIMessageBox> QUIMessageBox::self;
|
||||
QUIMessageBox *QUIMessageBox::Instance()
|
||||
{
|
||||
if (self.isNull()) {
|
||||
static QMutex mutex;
|
||||
QMutexLocker locker(&mutex);
|
||||
if (self.isNull()) {
|
||||
self.reset(new QUIMessageBox);
|
||||
}
|
||||
}
|
||||
|
||||
return self.data();
|
||||
}
|
||||
|
||||
QUIMessageBox::QUIMessageBox(QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
this->initControl();
|
||||
this->initForm();
|
||||
}
|
||||
|
||||
QUIMessageBox::~QUIMessageBox()
|
||||
{
|
||||
delete widgetMain;
|
||||
}
|
||||
|
||||
void QUIMessageBox::showEvent(QShowEvent *)
|
||||
{
|
||||
QUIHelper::setIconBtn(btnOk, ":/image/btn_ok.png", 0xf00c);
|
||||
QUIHelper::setIconBtn(btnCancel, ":/image/btn_close.png", 0xf00d);
|
||||
QUIHelper::setFormInCenter(this);
|
||||
this->activateWindow();
|
||||
}
|
||||
|
||||
void QUIMessageBox::closeEvent(QCloseEvent *)
|
||||
{
|
||||
closeSec = 0;
|
||||
currentSec = 0;
|
||||
}
|
||||
|
||||
bool QUIMessageBox::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
static QPoint mousePoint;
|
||||
static bool mousePressed = false;
|
||||
|
||||
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
|
||||
if (mouseEvent->type() == QEvent::MouseButtonPress) {
|
||||
if (mouseEvent->button() == Qt::LeftButton) {
|
||||
mousePressed = true;
|
||||
mousePoint = mouseEvent->globalPos() - this->pos();
|
||||
return true;
|
||||
}
|
||||
} else if (mouseEvent->type() == QEvent::MouseButtonRelease) {
|
||||
mousePressed = false;
|
||||
return true;
|
||||
} else if (mouseEvent->type() == QEvent::MouseMove) {
|
||||
if (mousePressed) {
|
||||
this->move(mouseEvent->globalPos() - mousePoint);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return QWidget::eventFilter(watched, event);
|
||||
}
|
||||
|
||||
void QUIMessageBox::initControl()
|
||||
{
|
||||
this->setObjectName(QString::fromUtf8("QUIMessageBox"));
|
||||
|
||||
verticalLayout1 = new QVBoxLayout(this);
|
||||
verticalLayout1->setSpacing(0);
|
||||
verticalLayout1->setObjectName(QString::fromUtf8("verticalLayout1"));
|
||||
verticalLayout1->setContentsMargins(1, 1, 1, 1);
|
||||
|
||||
widgetTitle = new QWidget(this);
|
||||
widgetTitle->setObjectName(QString::fromUtf8("widgetTitle"));
|
||||
QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
||||
sizePolicy.setHorizontalStretch(0);
|
||||
sizePolicy.setVerticalStretch(0);
|
||||
sizePolicy.setHeightForWidth(widgetTitle->sizePolicy().hasHeightForWidth());
|
||||
widgetTitle->setSizePolicy(sizePolicy);
|
||||
|
||||
horizontalLayout3 = new QHBoxLayout(widgetTitle);
|
||||
horizontalLayout3->setSpacing(0);
|
||||
horizontalLayout3->setObjectName(QString::fromUtf8("horizontalLayout3"));
|
||||
horizontalLayout3->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
labIco = new QLabel(widgetTitle);
|
||||
labIco->setObjectName(QString::fromUtf8("labIco"));
|
||||
QSizePolicy sizePolicy1(QSizePolicy::Minimum, QSizePolicy::Preferred);
|
||||
sizePolicy1.setHorizontalStretch(0);
|
||||
sizePolicy1.setVerticalStretch(0);
|
||||
sizePolicy1.setHeightForWidth(labIco->sizePolicy().hasHeightForWidth());
|
||||
labIco->setSizePolicy(sizePolicy1);
|
||||
labIco->setAlignment(Qt::AlignCenter);
|
||||
horizontalLayout3->addWidget(labIco);
|
||||
|
||||
labTitle = new QLabel(widgetTitle);
|
||||
labTitle->setObjectName(QString::fromUtf8("labTitle"));
|
||||
labTitle->setAlignment(Qt::AlignLeading | Qt::AlignLeft | Qt::AlignVCenter);
|
||||
horizontalLayout3->addWidget(labTitle);
|
||||
|
||||
labCountDown = new QLabel(widgetTitle);
|
||||
labCountDown->setObjectName(QString::fromUtf8("labCountDown"));
|
||||
QSizePolicy sizePolicy2(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
sizePolicy2.setHorizontalStretch(0);
|
||||
sizePolicy2.setVerticalStretch(0);
|
||||
sizePolicy2.setHeightForWidth(labCountDown->sizePolicy().hasHeightForWidth());
|
||||
labCountDown->setSizePolicy(sizePolicy2);
|
||||
labCountDown->setAlignment(Qt::AlignCenter);
|
||||
horizontalLayout3->addWidget(labCountDown);
|
||||
|
||||
widgetMenu = new QWidget(widgetTitle);
|
||||
widgetMenu->setObjectName(QString::fromUtf8("widgetMenu"));
|
||||
sizePolicy1.setHeightForWidth(widgetMenu->sizePolicy().hasHeightForWidth());
|
||||
widgetMenu->setSizePolicy(sizePolicy1);
|
||||
|
||||
horizontalLayout4 = new QHBoxLayout(widgetMenu);
|
||||
horizontalLayout4->setSpacing(0);
|
||||
horizontalLayout4->setObjectName(QString::fromUtf8("horizontalLayout4"));
|
||||
horizontalLayout4->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
btnMenu_Close = new QPushButton(widgetMenu);
|
||||
btnMenu_Close->setObjectName(QString::fromUtf8("btnMenu_Close"));
|
||||
QSizePolicy sizePolicy3(QSizePolicy::Minimum, QSizePolicy::Expanding);
|
||||
sizePolicy3.setHorizontalStretch(0);
|
||||
sizePolicy3.setVerticalStretch(0);
|
||||
sizePolicy3.setHeightForWidth(btnMenu_Close->sizePolicy().hasHeightForWidth());
|
||||
btnMenu_Close->setSizePolicy(sizePolicy3);
|
||||
btnMenu_Close->setCursor(QCursor(Qt::ArrowCursor));
|
||||
btnMenu_Close->setFocusPolicy(Qt::NoFocus);
|
||||
btnMenu_Close->setFlat(true);
|
||||
|
||||
horizontalLayout4->addWidget(btnMenu_Close);
|
||||
horizontalLayout3->addWidget(widgetMenu);
|
||||
verticalLayout1->addWidget(widgetTitle);
|
||||
|
||||
widgetMain = new QWidget(this);
|
||||
widgetMain->setObjectName(QString::fromUtf8("widgetMainQUI"));
|
||||
|
||||
verticalLayout2 = new QVBoxLayout(widgetMain);
|
||||
verticalLayout2->setSpacing(5);
|
||||
verticalLayout2->setObjectName(QString::fromUtf8("verticalLayout2"));
|
||||
verticalLayout2->setContentsMargins(5, 5, 5, 5);
|
||||
|
||||
frame = new QFrame(widgetMain);
|
||||
frame->setObjectName(QString::fromUtf8("frame"));
|
||||
frame->setFrameShape(QFrame::Box);
|
||||
frame->setFrameShadow(QFrame::Sunken);
|
||||
|
||||
labIcoMain = new QLabel(frame);
|
||||
labIcoMain->setObjectName(QString::fromUtf8("labIcoMain"));
|
||||
labIcoMain->setAlignment(Qt::AlignCenter);
|
||||
|
||||
verticalLayout4 = new QVBoxLayout(frame);
|
||||
verticalLayout4->setObjectName(QString::fromUtf8("verticalLayout4"));
|
||||
verticalLayout4->setContentsMargins(-1, 9, -1, -1);
|
||||
|
||||
horizontalLayout1 = new QHBoxLayout();
|
||||
horizontalLayout1->setObjectName(QString::fromUtf8("horizontalLayout1"));
|
||||
horizontalLayout1->addWidget(labIcoMain);
|
||||
horizontalSpacer1 = new QSpacerItem(5, 0, QSizePolicy::Minimum, QSizePolicy::Minimum);
|
||||
horizontalLayout1->addItem(horizontalSpacer1);
|
||||
|
||||
labInfo = new QLabel(frame);
|
||||
labInfo->setObjectName(QString::fromUtf8("labInfo"));
|
||||
QSizePolicy sizePolicy4(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
sizePolicy4.setHorizontalStretch(0);
|
||||
sizePolicy4.setVerticalStretch(0);
|
||||
sizePolicy4.setHeightForWidth(labInfo->sizePolicy().hasHeightForWidth());
|
||||
labInfo->setSizePolicy(sizePolicy4);
|
||||
labInfo->setMinimumSize(QSize(0, QUITitleMinSize));
|
||||
labInfo->setScaledContents(false);
|
||||
labInfo->setWordWrap(true);
|
||||
horizontalLayout1->addWidget(labInfo);
|
||||
verticalLayout4->addLayout(horizontalLayout1);
|
||||
|
||||
horizontalLayout2 = new QHBoxLayout();
|
||||
horizontalLayout2->setObjectName(QString::fromUtf8("horizontalLayout2"));
|
||||
horizontalSpacer2 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
||||
horizontalLayout2->addItem(horizontalSpacer2);
|
||||
|
||||
btnOk = new QPushButton(frame);
|
||||
btnOk->setObjectName(QString::fromUtf8("btnOk"));
|
||||
btnOk->setMinimumSize(QSize(85, 0));
|
||||
btnOk->setFocusPolicy(Qt::StrongFocus);
|
||||
horizontalLayout2->addWidget(btnOk);
|
||||
btnOk->setDefault(true);
|
||||
|
||||
btnCancel = new QPushButton(frame);
|
||||
btnCancel->setObjectName(QString::fromUtf8("btnCancel"));
|
||||
btnCancel->setMinimumSize(QSize(85, 0));
|
||||
btnCancel->setFocusPolicy(Qt::StrongFocus);
|
||||
horizontalLayout2->addWidget(btnCancel);
|
||||
|
||||
verticalLayout4->addLayout(horizontalLayout2);
|
||||
verticalLayout2->addWidget(frame);
|
||||
verticalLayout1->addWidget(widgetMain);
|
||||
|
||||
widgetTitle->raise();
|
||||
widgetMain->raise();
|
||||
frame->raise();
|
||||
|
||||
btnOk->setText("确定");
|
||||
btnCancel->setText("取消");
|
||||
|
||||
connect(btnOk, SIGNAL(clicked()), this, SLOT(on_btnOk_clicked()));
|
||||
connect(btnCancel, SIGNAL(clicked()), this, SLOT(on_btnMenu_Close_clicked()));
|
||||
connect(btnMenu_Close, SIGNAL(clicked()), this, SLOT(on_btnMenu_Close_clicked()));
|
||||
}
|
||||
|
||||
void QUIMessageBox::initForm()
|
||||
{
|
||||
QUIHelper::setFramelessForm(this, widgetTitle, labIco, btnMenu_Close);
|
||||
this->setWindowTitle(this->labTitle->text());
|
||||
this->setFixedSize(QUIDialogMinWidth, QUIDialogMinHeight);
|
||||
labIcoMain->setFixedSize(QUITitleMinSize, QUITitleMinSize);
|
||||
|
||||
QList<QPushButton *> btns = this->frame->findChildren<QPushButton *>();
|
||||
foreach (QPushButton *btn, btns) {
|
||||
btn->setMinimumWidth(QUIBtnMinWidth);
|
||||
btn->setIconSize(QSize(QUIIconWidth, QUIIconHeight));
|
||||
}
|
||||
|
||||
closeSec = 0;
|
||||
currentSec = 0;
|
||||
|
||||
QTimer *timer = new QTimer(this);
|
||||
timer->setInterval(1000);
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(checkSec()));
|
||||
timer->start();
|
||||
|
||||
this->installEventFilter(this);
|
||||
}
|
||||
|
||||
void QUIMessageBox::checkSec()
|
||||
{
|
||||
if (closeSec == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentSec < closeSec) {
|
||||
currentSec++;
|
||||
} else {
|
||||
this->close();
|
||||
}
|
||||
|
||||
QString str = QString("关闭倒计时 %1 s").arg(closeSec - currentSec + 1);
|
||||
this->labCountDown->setText(str);
|
||||
}
|
||||
|
||||
void QUIMessageBox::on_btnOk_clicked()
|
||||
{
|
||||
done(QMessageBox::Yes);
|
||||
close();
|
||||
}
|
||||
|
||||
void QUIMessageBox::on_btnMenu_Close_clicked()
|
||||
{
|
||||
done(QMessageBox::No);
|
||||
close();
|
||||
}
|
||||
|
||||
void QUIMessageBox::setIconMain(const QChar &icon, quint32 size)
|
||||
{
|
||||
IconHelper::Instance()->setIcon(this->labIco, icon, size);
|
||||
}
|
||||
|
||||
void QUIMessageBox::setIconMsg(const QString &png, const QChar &str)
|
||||
{
|
||||
//图片存在则取图片,不存在则取图形字体
|
||||
int size = this->labIcoMain->size().height();
|
||||
if (QImage(png).isNull()) {
|
||||
IconHelper::Instance()->setIcon(this->labIcoMain, str, size);
|
||||
} else {
|
||||
this->labIcoMain->setStyleSheet(QString("border-image:url(%1);").arg(png));
|
||||
}
|
||||
}
|
||||
|
||||
void QUIMessageBox::setMessage(const QString &msg, int type, int closeSec)
|
||||
{
|
||||
this->closeSec = closeSec;
|
||||
this->currentSec = 0;
|
||||
this->labCountDown->clear();
|
||||
checkSec();
|
||||
|
||||
if (type == 0) {
|
||||
setIconMsg(":/image/msg_info.png", 0xf05a);
|
||||
this->btnCancel->setVisible(false);
|
||||
this->labTitle->setText("提示");
|
||||
} else if (type == 1) {
|
||||
setIconMsg(":/image/msg_question.png", 0xf059);
|
||||
this->labTitle->setText("询问");
|
||||
} else if (type == 2) {
|
||||
setIconMsg(":/image/msg_error.png", 0xf057);
|
||||
this->btnCancel->setVisible(false);
|
||||
this->labTitle->setText("错误");
|
||||
}
|
||||
|
||||
this->labInfo->setText(msg);
|
||||
this->setWindowTitle(this->labTitle->text());
|
||||
//设置对话框的大小总以最合适的大小显示
|
||||
if (msg.length() < 70) {
|
||||
this->layout()->setSizeConstraint(QLayout::SetMinimumSize);
|
||||
this->setFixedSize(QUIDialogMinWidth, QUIDialogMinHeight);
|
||||
} else {
|
||||
this->layout()->setSizeConstraint(QLayout::SetFixedSize);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
#ifndef QUIMESSAGEBOX_H
|
||||
#define QUIMESSAGEBOX_H
|
||||
|
||||
#include "quihead.h"
|
||||
|
||||
class QUIMessageBox : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static QUIMessageBox *Instance();
|
||||
explicit QUIMessageBox(QWidget *parent = 0);
|
||||
~QUIMessageBox();
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *);
|
||||
void closeEvent(QCloseEvent *);
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
static QScopedPointer<QUIMessageBox> self;
|
||||
|
||||
QVBoxLayout *verticalLayout1;
|
||||
QWidget *widgetTitle;
|
||||
QHBoxLayout *horizontalLayout3;
|
||||
QLabel *labIco;
|
||||
QLabel *labTitle;
|
||||
QLabel *labCountDown;
|
||||
QWidget *widgetMenu;
|
||||
QHBoxLayout *horizontalLayout4;
|
||||
QPushButton *btnMenu_Close;
|
||||
QWidget *widgetMain;
|
||||
QVBoxLayout *verticalLayout2;
|
||||
QFrame *frame;
|
||||
QVBoxLayout *verticalLayout4;
|
||||
QHBoxLayout *horizontalLayout1;
|
||||
QLabel *labIcoMain;
|
||||
QSpacerItem *horizontalSpacer1;
|
||||
QLabel *labInfo;
|
||||
QHBoxLayout *horizontalLayout2;
|
||||
QSpacerItem *horizontalSpacer2;
|
||||
QPushButton *btnOk;
|
||||
QPushButton *btnCancel;
|
||||
|
||||
private:
|
||||
int closeSec; //总显示时间
|
||||
int currentSec; //当前已显示时间
|
||||
|
||||
private slots:
|
||||
void initControl(); //初始化控件
|
||||
void initForm(); //初始化窗体
|
||||
void checkSec(); //校验倒计时
|
||||
|
||||
private slots:
|
||||
void on_btnOk_clicked();
|
||||
void on_btnMenu_Close_clicked();
|
||||
|
||||
public Q_SLOTS:
|
||||
void setIconMain(const QChar &icon, quint32 size = 12);
|
||||
void setIconMsg(const QString &png, const QChar &str);
|
||||
void setMessage(const QString &msg, int type, int closeSec = 0);
|
||||
};
|
||||
|
||||
#endif // QUIMESSAGEBOX_H
|
|
@ -0,0 +1,192 @@
|
|||
#include "quistyle.h"
|
||||
|
||||
void QUIStyle::getStyle(QStringList &styleNames, QStringList &styleFiles)
|
||||
{
|
||||
static QStringList names;
|
||||
if (names.count() == 0) {
|
||||
names << "银色" << "蓝色" << "浅蓝色" << "深蓝色";
|
||||
names << "灰色" << "浅灰色" << "深灰色";
|
||||
names << "黑色" << "浅黑色" << "深黑色" << "PS黑色";
|
||||
names << "黑色扁平" << "白色扁平" << "蓝色扁平";
|
||||
names << "紫色" << "黑蓝色" << "视频黑";
|
||||
}
|
||||
|
||||
//中文皮肤名称对应样式表文件
|
||||
static QStringList files;
|
||||
if (files.count() == 0) {
|
||||
files << ":/qss/silvery.css" << ":/qss/blue.css" << ":/qss/lightblue.css" << ":/qss/darkblue.css";
|
||||
files << ":/qss/gray.css" << ":/qss/lightgray.css" << ":/qss/darkgray.css";
|
||||
files << ":/qss/black.css" << ":/qss/lightblack.css" << ":/qss/darkblack.css" << ":/qss/psblack.css";
|
||||
files << ":/qss/flatblack.css" << ":/qss/flatwhite.css" << ":/qss/flatblue.css";
|
||||
files << ":/qss/purple.css" << ":/qss/blackblue.css" << ":/qss/blackvideo.css";
|
||||
}
|
||||
|
||||
styleNames = names;
|
||||
styleFiles = files;
|
||||
}
|
||||
|
||||
void QUIStyle::setStyle(const QString &qss, const QString &paletteColor)
|
||||
{
|
||||
QUIHelper::isCustomUI = true;
|
||||
qApp->setPalette(QPalette(paletteColor));
|
||||
qApp->setStyleSheet(qss);
|
||||
}
|
||||
|
||||
void QUIStyle::setStyle(const QUIStyle::Style &style)
|
||||
{
|
||||
//取出所有的皮肤名称和对应样式文件
|
||||
QStringList styleNames, styleFiles;
|
||||
getStyle(styleNames, styleFiles);
|
||||
|
||||
//取出对应索引的样式文件
|
||||
QString qssFile = (styleFiles.at((int)style));
|
||||
|
||||
//设置全局样式
|
||||
QFile file(qssFile);
|
||||
if (file.open(QFile::ReadOnly)) {
|
||||
QString qss = QLatin1String(file.readAll());
|
||||
QString paletteColor = qss.mid(20, 7);
|
||||
getQssColor(qss, QUIConfig::TextColor, QUIConfig::PanelColor, QUIConfig::BorderColor, QUIConfig::NormalColorStart,
|
||||
QUIConfig::NormalColorEnd, QUIConfig::DarkColorStart, QUIConfig::DarkColorEnd, QUIConfig::HighColor);
|
||||
setStyle(qss, paletteColor);
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
void QUIStyle::setStyle(const QString &qssFile)
|
||||
{
|
||||
QString paletteColor, textColor;
|
||||
setStyle(qssFile, paletteColor, textColor);
|
||||
}
|
||||
|
||||
void QUIStyle::setStyle(const QString &qssFile, QString &paletteColor, QString &textColor)
|
||||
{
|
||||
QFile file(qssFile);
|
||||
if (file.open(QFile::ReadOnly)) {
|
||||
QString qss = QLatin1String(file.readAll());
|
||||
paletteColor = qss.mid(20, 7);
|
||||
textColor = qss.mid(49, 7);
|
||||
getQssColor(qss, QUIConfig::TextColor, QUIConfig::PanelColor, QUIConfig::BorderColor, QUIConfig::NormalColorStart,
|
||||
QUIConfig::NormalColorEnd, QUIConfig::DarkColorStart, QUIConfig::DarkColorEnd, QUIConfig::HighColor);
|
||||
setStyle(qss, paletteColor);
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
void QUIStyle::setStyle(const QString &qssFile, QString &textColor, QString &panelColor, QString &borderColor,
|
||||
QString &normalColorStart, QString &normalColorEnd,
|
||||
QString &darkColorStart, QString &darkColorEnd, QString &highColor)
|
||||
{
|
||||
QFile file(qssFile);
|
||||
if (file.open(QFile::ReadOnly)) {
|
||||
QString qss = QLatin1String(file.readAll());
|
||||
getQssColor(qss, textColor, panelColor, borderColor, normalColorStart, normalColorEnd, darkColorStart, darkColorEnd, highColor);
|
||||
setStyle(qss, panelColor);
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
void QUIStyle::getQssColor(const QString &qss, QString &textColor, QString &panelColor, QString &borderColor,
|
||||
QString &normalColorStart, QString &normalColorEnd,
|
||||
QString &darkColorStart, QString &darkColorEnd, QString &highColor)
|
||||
{
|
||||
QUIHelper::isCustomUI = true;
|
||||
|
||||
QString str = qss;
|
||||
QString flagTextColor = "TextColor:";
|
||||
int indexTextColor = str.indexOf(flagTextColor);
|
||||
if (indexTextColor >= 0) {
|
||||
textColor = str.mid(indexTextColor + flagTextColor.length(), 7);
|
||||
}
|
||||
|
||||
QString flagPanelColor = "PanelColor:";
|
||||
int indexPanelColor = str.indexOf(flagPanelColor);
|
||||
if (indexPanelColor >= 0) {
|
||||
panelColor = str.mid(indexPanelColor + flagPanelColor.length(), 7);
|
||||
}
|
||||
|
||||
QString flagBorderColor = "BorderColor:";
|
||||
int indexBorderColor = str.indexOf(flagBorderColor);
|
||||
if (indexBorderColor >= 0) {
|
||||
borderColor = str.mid(indexBorderColor + flagBorderColor.length(), 7);
|
||||
}
|
||||
|
||||
QString flagNormalColorStart = "NormalColorStart:";
|
||||
int indexNormalColorStart = str.indexOf(flagNormalColorStart);
|
||||
if (indexNormalColorStart >= 0) {
|
||||
normalColorStart = str.mid(indexNormalColorStart + flagNormalColorStart.length(), 7);
|
||||
}
|
||||
|
||||
QString flagNormalColorEnd = "NormalColorEnd:";
|
||||
int indexNormalColorEnd = str.indexOf(flagNormalColorEnd);
|
||||
if (indexNormalColorEnd >= 0) {
|
||||
normalColorEnd = str.mid(indexNormalColorEnd + flagNormalColorEnd.length(), 7);
|
||||
}
|
||||
|
||||
QString flagDarkColorStart = "DarkColorStart:";
|
||||
int indexDarkColorStart = str.indexOf(flagDarkColorStart);
|
||||
if (indexDarkColorStart >= 0) {
|
||||
darkColorStart = str.mid(indexDarkColorStart + flagDarkColorStart.length(), 7);
|
||||
}
|
||||
|
||||
QString flagDarkColorEnd = "DarkColorEnd:";
|
||||
int indexDarkColorEnd = str.indexOf(flagDarkColorEnd);
|
||||
if (indexDarkColorEnd >= 0) {
|
||||
darkColorEnd = str.mid(indexDarkColorEnd + flagDarkColorEnd.length(), 7);
|
||||
}
|
||||
|
||||
QString flagHighColor = "HighColor:";
|
||||
int indexHighColor = str.indexOf(flagHighColor);
|
||||
if (indexHighColor >= 0) {
|
||||
highColor = str.mid(indexHighColor + flagHighColor.length(), 7);
|
||||
}
|
||||
}
|
||||
|
||||
void QUIStyle::setLabStyle(QLabel *lab, quint8 type, const QString &bgColor, const QString &textColor)
|
||||
{
|
||||
QString colorBg = bgColor;
|
||||
QString colorText = textColor;
|
||||
|
||||
//如果设置了新颜色则启用新颜色
|
||||
if (bgColor.isEmpty() || textColor.isEmpty()) {
|
||||
if (type == 0) {
|
||||
colorBg = "#D64D54";
|
||||
colorText = "#FFFFFF";
|
||||
} else if (type == 1) {
|
||||
colorBg = "#17A086";
|
||||
colorText = "#FFFFFF";
|
||||
} else if (type == 2) {
|
||||
colorBg = "#47A4E9";
|
||||
colorText = "#FFFFFF";
|
||||
} else if (type == 3) {
|
||||
colorBg = "#282D30";
|
||||
colorText = "#FFFFFF";
|
||||
} else if (type == 4) {
|
||||
colorBg = "#0E99A0";
|
||||
colorText = "#FFFFFF";
|
||||
} else if (type == 5) {
|
||||
colorBg = "#A279C5";
|
||||
colorText = "#FFFFFF";
|
||||
} else if (type == 6) {
|
||||
colorBg = "#8C2957";
|
||||
colorText = "#FFFFFF";
|
||||
} else if (type == 7) {
|
||||
colorBg = "#04567E";
|
||||
colorText = "#FFFFFF";
|
||||
} else if (type == 8) {
|
||||
colorBg = "#FD8B28";
|
||||
colorText = "#FFFFFF";
|
||||
} else if (type == 9) {
|
||||
colorBg = "#5580A2";
|
||||
colorText = "#FFFFFF";
|
||||
}
|
||||
}
|
||||
|
||||
QStringList qss;
|
||||
//禁用颜色
|
||||
qss << QString("QLabel::disabled{background:none;color:%1;}").arg(QUIConfig::BorderColor);
|
||||
//正常颜色
|
||||
qss << QString("QLabel{border:none;background-color:%1;color:%2;}").arg(colorBg).arg(colorText);
|
||||
lab->setStyleSheet(qss.join(""));
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
#ifndef QUISTYLE_H
|
||||
#define QUISTYLE_H
|
||||
|
||||
#include "quihead.h"
|
||||
|
||||
class QUIStyle
|
||||
{
|
||||
public:
|
||||
//样式枚举
|
||||
enum Style {
|
||||
Style_Silvery = 0, //银色样式
|
||||
Style_Blue = 1, //蓝色样式
|
||||
Style_LightBlue = 2, //淡蓝色样式
|
||||
Style_DarkBlue = 3, //深蓝色样式
|
||||
Style_Gray = 4, //灰色样式
|
||||
Style_LightGray = 5, //浅灰色样式
|
||||
Style_DarkGray = 6, //深灰色样式
|
||||
Style_Black = 7, //黑色样式
|
||||
Style_LightBlack = 8, //浅黑色样式
|
||||
Style_DarkBlack = 9, //深黑色样式
|
||||
Style_PSBlack = 10, //PS黑色样式
|
||||
Style_FlatBlack = 11, //黑色扁平样式
|
||||
Style_FlatWhite = 12, //白色扁平样式
|
||||
Style_FlatBlue = 13, //蓝色扁平样式
|
||||
Style_Purple = 14, //紫色样式
|
||||
Style_BlackBlue = 15, //黑蓝色样式
|
||||
Style_BlackVideo = 16 //视频监控黑色样式
|
||||
};
|
||||
|
||||
//获取皮肤样式中文名称和对应的样式表文件
|
||||
static void getStyle(QStringList &styleNames, QStringList &styleFiles);
|
||||
//设置全局样式
|
||||
static void setStyle(const QString &qss, const QString &paletteColor);
|
||||
static void setStyle(const QUIStyle::Style &style);
|
||||
static void setStyle(const QString &qssFile);
|
||||
static void setStyle(const QString &qssFile, QString &paletteColor, QString &textColor);
|
||||
static void setStyle(const QString &qssFile, QString &textColor,
|
||||
QString &panelColor, QString &borderColor,
|
||||
QString &normalColorStart, QString &normalColorEnd,
|
||||
QString &darkColorStart, QString &darkColorEnd,
|
||||
QString &highColor);
|
||||
|
||||
//根据QSS样式获取对应颜色值
|
||||
static void getQssColor(const QString &qss, QString &textColor,
|
||||
QString &panelColor, QString &borderColor,
|
||||
QString &normalColorStart, QString &normalColorEnd,
|
||||
QString &darkColorStart, QString &darkColorEnd,
|
||||
QString &highColor);
|
||||
|
||||
//设置标签颜色
|
||||
static void setLabStyle(QLabel *lab, quint8 type, const QString &bgColor = "", const QString &textColor = "");
|
||||
};
|
||||
|
||||
#endif // QUISTYLE_H
|
|
@ -0,0 +1,251 @@
|
|||
#include "quitipbox.h"
|
||||
|
||||
QScopedPointer<QUITipBox> QUITipBox::self;
|
||||
QUITipBox *QUITipBox::Instance()
|
||||
{
|
||||
if (self.isNull()) {
|
||||
static QMutex mutex;
|
||||
QMutexLocker locker(&mutex);
|
||||
if (self.isNull()) {
|
||||
self.reset(new QUITipBox);
|
||||
}
|
||||
}
|
||||
|
||||
return self.data();
|
||||
}
|
||||
|
||||
QUITipBox::QUITipBox(QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
this->initControl();
|
||||
this->initForm();
|
||||
}
|
||||
|
||||
QUITipBox::~QUITipBox()
|
||||
{
|
||||
delete widgetMain;
|
||||
}
|
||||
|
||||
void QUITipBox::showEvent(QShowEvent *)
|
||||
{
|
||||
this->activateWindow();
|
||||
}
|
||||
|
||||
void QUITipBox::closeEvent(QCloseEvent *)
|
||||
{
|
||||
closeSec = 0;
|
||||
currentSec = 0;
|
||||
}
|
||||
|
||||
bool QUITipBox::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
static QPoint mousePoint;
|
||||
static bool mousePressed = false;
|
||||
|
||||
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
|
||||
if (mouseEvent->type() == QEvent::MouseButtonPress) {
|
||||
if (mouseEvent->button() == Qt::LeftButton) {
|
||||
mousePressed = true;
|
||||
mousePoint = mouseEvent->globalPos() - this->pos();
|
||||
return true;
|
||||
}
|
||||
} else if (mouseEvent->type() == QEvent::MouseButtonRelease) {
|
||||
mousePressed = false;
|
||||
return true;
|
||||
} else if (mouseEvent->type() == QEvent::MouseMove) {
|
||||
if (mousePressed) {
|
||||
this->move(mouseEvent->globalPos() - mousePoint);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return QWidget::eventFilter(watched, event);
|
||||
}
|
||||
|
||||
void QUITipBox::initControl()
|
||||
{
|
||||
this->setObjectName(QString::fromUtf8("QUITipBox"));
|
||||
|
||||
verticalLayout = new QVBoxLayout(this);
|
||||
verticalLayout->setSpacing(0);
|
||||
verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
|
||||
verticalLayout->setContentsMargins(1, 1, 1, 1);
|
||||
|
||||
widgetTitle = new QWidget(this);
|
||||
widgetTitle->setObjectName(QString::fromUtf8("widgetTitle"));
|
||||
QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
||||
sizePolicy.setHorizontalStretch(0);
|
||||
sizePolicy.setVerticalStretch(0);
|
||||
sizePolicy.setHeightForWidth(widgetTitle->sizePolicy().hasHeightForWidth());
|
||||
widgetTitle->setSizePolicy(sizePolicy);
|
||||
|
||||
horizontalLayout2 = new QHBoxLayout(widgetTitle);
|
||||
horizontalLayout2->setSpacing(0);
|
||||
horizontalLayout2->setObjectName(QString::fromUtf8("horizontalLayout2"));
|
||||
horizontalLayout2->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
labIco = new QLabel(widgetTitle);
|
||||
labIco->setObjectName(QString::fromUtf8("labIco"));
|
||||
labIco->setAlignment(Qt::AlignCenter);
|
||||
horizontalLayout2->addWidget(labIco);
|
||||
|
||||
labTitle = new QLabel(widgetTitle);
|
||||
labTitle->setObjectName(QString::fromUtf8("labTitle"));
|
||||
labTitle->setAlignment(Qt::AlignLeading | Qt::AlignLeft | Qt::AlignVCenter);
|
||||
horizontalLayout2->addWidget(labTitle);
|
||||
|
||||
labCountDown = new QLabel(widgetTitle);
|
||||
labCountDown->setObjectName(QString::fromUtf8("labCountDown"));
|
||||
QSizePolicy sizePolicy1(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
sizePolicy1.setHorizontalStretch(0);
|
||||
sizePolicy1.setVerticalStretch(0);
|
||||
sizePolicy1.setHeightForWidth(labCountDown->sizePolicy().hasHeightForWidth());
|
||||
labCountDown->setSizePolicy(sizePolicy1);
|
||||
labCountDown->setAlignment(Qt::AlignCenter);
|
||||
horizontalLayout2->addWidget(labCountDown);
|
||||
|
||||
widgetMenu = new QWidget(widgetTitle);
|
||||
widgetMenu->setObjectName(QString::fromUtf8("widgetMenu"));
|
||||
QSizePolicy sizePolicy2(QSizePolicy::Minimum, QSizePolicy::Preferred);
|
||||
sizePolicy2.setHorizontalStretch(0);
|
||||
sizePolicy2.setVerticalStretch(0);
|
||||
sizePolicy2.setHeightForWidth(widgetMenu->sizePolicy().hasHeightForWidth());
|
||||
widgetMenu->setSizePolicy(sizePolicy2);
|
||||
|
||||
horizontalLayout = new QHBoxLayout(widgetMenu);
|
||||
horizontalLayout->setSpacing(0);
|
||||
horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
|
||||
horizontalLayout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
btnMenu_Close = new QPushButton(widgetMenu);
|
||||
btnMenu_Close->setObjectName(QString::fromUtf8("btnMenu_Close"));
|
||||
QSizePolicy sizePolicy3(QSizePolicy::Minimum, QSizePolicy::Expanding);
|
||||
sizePolicy3.setHorizontalStretch(0);
|
||||
sizePolicy3.setVerticalStretch(0);
|
||||
sizePolicy3.setHeightForWidth(btnMenu_Close->sizePolicy().hasHeightForWidth());
|
||||
btnMenu_Close->setSizePolicy(sizePolicy3);
|
||||
btnMenu_Close->setCursor(QCursor(Qt::ArrowCursor));
|
||||
btnMenu_Close->setFocusPolicy(Qt::NoFocus);
|
||||
btnMenu_Close->setFlat(true);
|
||||
|
||||
horizontalLayout->addWidget(btnMenu_Close);
|
||||
horizontalLayout2->addWidget(widgetMenu);
|
||||
verticalLayout->addWidget(widgetTitle);
|
||||
|
||||
widgetMain = new QWidget(this);
|
||||
widgetMain->setObjectName(QString::fromUtf8("widgetMainQUI"));
|
||||
widgetMain->setAutoFillBackground(true);
|
||||
|
||||
labInfo = new QLabel(widgetMain);
|
||||
labInfo->setObjectName(QString::fromUtf8("labInfo"));
|
||||
labInfo->setScaledContents(true);
|
||||
labInfo->setWordWrap(true);
|
||||
|
||||
verticalLayout2 = new QVBoxLayout(widgetMain);
|
||||
verticalLayout2->setObjectName(QString::fromUtf8("verticalLayout2"));
|
||||
verticalLayout2->addWidget(labInfo);
|
||||
verticalLayout->addWidget(widgetMain);
|
||||
|
||||
connect(btnMenu_Close, SIGNAL(clicked()), this, SLOT(on_btnMenu_Close_clicked()));
|
||||
}
|
||||
|
||||
void QUITipBox::initForm()
|
||||
{
|
||||
QUIHelper::setFramelessForm(this, widgetTitle, labIco, btnMenu_Close);
|
||||
this->setWindowTitle(this->labTitle->text());
|
||||
this->setFixedSize(QUIDialogMinWidth, QUIDialogMinHeight);
|
||||
|
||||
closeSec = 0;
|
||||
currentSec = 0;
|
||||
|
||||
QTimer *timer = new QTimer(this);
|
||||
timer->setInterval(1000);
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(checkSec()));
|
||||
timer->start();
|
||||
|
||||
this->installEventFilter(this);
|
||||
|
||||
//字体加大
|
||||
QFont font;
|
||||
font.setPixelSize(QUIConfig::FontSize + 3);
|
||||
font.setBold(true);
|
||||
this->labInfo->setFont(font);
|
||||
|
||||
//显示和隐藏窗体动画效果
|
||||
animation = new QPropertyAnimation(this, "pos");
|
||||
animation->setDuration(500);
|
||||
animation->setEasingCurve(QEasingCurve::InOutQuad);
|
||||
}
|
||||
|
||||
void QUITipBox::checkSec()
|
||||
{
|
||||
if (closeSec == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentSec < closeSec) {
|
||||
currentSec++;
|
||||
} else {
|
||||
this->close();
|
||||
}
|
||||
|
||||
QString str = QString("关闭倒计时 %1 s").arg(closeSec - currentSec + 1);
|
||||
this->labCountDown->setText(str);
|
||||
}
|
||||
|
||||
void QUITipBox::on_btnMenu_Close_clicked()
|
||||
{
|
||||
done(QMessageBox::No);
|
||||
close();
|
||||
}
|
||||
|
||||
void QUITipBox::setIconMain(const QChar &icon, quint32 size)
|
||||
{
|
||||
IconHelper::Instance()->setIcon(this->labIco, icon, size);
|
||||
}
|
||||
|
||||
void QUITipBox::setTip(const QString &title, const QString &tip, bool fullScreen, bool center, int closeSec)
|
||||
{
|
||||
this->closeSec = closeSec;
|
||||
this->currentSec = 0;
|
||||
this->labCountDown->clear();
|
||||
checkSec();
|
||||
|
||||
this->fullScreen = fullScreen;
|
||||
this->labTitle->setText(title);
|
||||
this->labInfo->setText(tip);
|
||||
this->labInfo->setAlignment(center ? Qt::AlignCenter : Qt::AlignLeft);
|
||||
this->setWindowTitle(this->labTitle->text());
|
||||
|
||||
int screenIndex = QUIHelper::getScreenIndex();
|
||||
QRect rect = fullScreen ? qApp->desktop()->screenGeometry(screenIndex) : qApp->desktop()->availableGeometry(screenIndex);
|
||||
int width = rect.width();
|
||||
int height = rect.height();
|
||||
int x = width - this->width() + rect.x();
|
||||
int y = height - this->height();
|
||||
|
||||
//移到右下角
|
||||
this->move(x, y);
|
||||
|
||||
//启动动画
|
||||
animation->stop();
|
||||
animation->setStartValue(QPoint(x, height));
|
||||
animation->setEndValue(QPoint(x, y));
|
||||
animation->start();
|
||||
}
|
||||
|
||||
void QUITipBox::hide()
|
||||
{
|
||||
int screenIndex = QUIHelper::getScreenIndex();
|
||||
QRect rect = fullScreen ? qApp->desktop()->screenGeometry(screenIndex) : qApp->desktop()->availableGeometry(screenIndex);
|
||||
int width = rect.width();
|
||||
int height = rect.height();
|
||||
int x = width - this->width() + rect.x();
|
||||
int y = height - this->height();
|
||||
|
||||
//启动动画
|
||||
animation->stop();
|
||||
animation->setStartValue(QPoint(x, y));
|
||||
animation->setEndValue(QPoint(x, qApp->desktop()->geometry().height()));
|
||||
animation->start();
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
#ifndef QUITIPBOX_H
|
||||
#define QUITIPBOX_H
|
||||
|
||||
#include "quihead.h"
|
||||
|
||||
class QUITipBox : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static QUITipBox *Instance();
|
||||
explicit QUITipBox(QWidget *parent = 0);
|
||||
~QUITipBox();
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *);
|
||||
void closeEvent(QCloseEvent *);
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
static QScopedPointer<QUITipBox> self;
|
||||
|
||||
QVBoxLayout *verticalLayout;
|
||||
QWidget *widgetTitle;
|
||||
QHBoxLayout *horizontalLayout2;
|
||||
QLabel *labIco;
|
||||
QLabel *labTitle;
|
||||
QLabel *labCountDown;
|
||||
QWidget *widgetMenu;
|
||||
QHBoxLayout *horizontalLayout;
|
||||
QPushButton *btnMenu_Close;
|
||||
QWidget *widgetMain;
|
||||
QVBoxLayout *verticalLayout2;
|
||||
QLabel *labInfo;
|
||||
|
||||
QPropertyAnimation *animation;
|
||||
bool fullScreen;
|
||||
|
||||
private:
|
||||
int closeSec; //总显示时间
|
||||
int currentSec; //当前已显示时间
|
||||
|
||||
private slots:
|
||||
void initControl(); //初始化控件
|
||||
void initForm(); //初始化窗体
|
||||
void checkSec(); //校验倒计时
|
||||
|
||||
private slots:
|
||||
void on_btnMenu_Close_clicked();
|
||||
|
||||
public Q_SLOTS:
|
||||
void setIconMain(const QChar &icon, quint32 size = 12);
|
||||
void setTip(const QString &title, const QString &tip, bool fullScreen = false, bool center = true, int closeSec = 0);
|
||||
void hide();
|
||||
};
|
||||
|
||||
#endif // QUITIPBOX_H
|
|
@ -0,0 +1,438 @@
|
|||
#include "quiwidget.h"
|
||||
|
||||
QUIWidget::QUIWidget(QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
this->initControl();
|
||||
this->initForm();
|
||||
QUIHelper::setFormInCenter(this);
|
||||
}
|
||||
|
||||
QUIWidget::~QUIWidget()
|
||||
{
|
||||
}
|
||||
|
||||
bool QUIWidget::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
static QPoint mousePoint;
|
||||
static bool mousePressed = false;
|
||||
|
||||
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
|
||||
if (mouseEvent->type() == QEvent::MouseButtonPress) {
|
||||
if (mouseEvent->button() == Qt::LeftButton) {
|
||||
mousePressed = true;
|
||||
mousePoint = mouseEvent->globalPos() - this->pos();
|
||||
}
|
||||
} else if (mouseEvent->type() == QEvent::MouseButtonRelease) {
|
||||
mousePressed = false;
|
||||
} else if (mouseEvent->type() == QEvent::MouseMove) {
|
||||
if (mousePressed) {
|
||||
if (this->property("canMove").toBool()) {
|
||||
this->move(mouseEvent->globalPos() - mousePoint);
|
||||
}
|
||||
}
|
||||
} else if (mouseEvent->type() == QEvent::MouseButtonDblClick) {
|
||||
//以下写法可以将双击识别限定在标题栏
|
||||
if (this->btnMenu_Max->isVisible() && watched == this->widgetTitle) {
|
||||
//if (this->btnMenu_Max->isVisible()) {
|
||||
this->on_btnMenu_Max_clicked();
|
||||
}
|
||||
}
|
||||
|
||||
return QWidget::eventFilter(watched, event);
|
||||
}
|
||||
|
||||
QLabel *QUIWidget::getLabIco() const
|
||||
{
|
||||
return this->labIco;
|
||||
}
|
||||
|
||||
QLabel *QUIWidget::getLabTitle() const
|
||||
{
|
||||
return this->labTitle;
|
||||
}
|
||||
|
||||
QToolButton *QUIWidget::getBtnMenu() const
|
||||
{
|
||||
return this->btnMenu;
|
||||
}
|
||||
|
||||
QPushButton *QUIWidget::getBtnMenuMin() const
|
||||
{
|
||||
return this->btnMenu_Min;
|
||||
}
|
||||
|
||||
QPushButton *QUIWidget::getBtnMenuMax() const
|
||||
{
|
||||
return this->btnMenu_Max;
|
||||
}
|
||||
|
||||
QPushButton *QUIWidget::getBtnMenuMClose() const
|
||||
{
|
||||
return this->btnMenu_Close;
|
||||
}
|
||||
|
||||
QString QUIWidget::getTitle() const
|
||||
{
|
||||
return this->title;
|
||||
}
|
||||
|
||||
Qt::Alignment QUIWidget::getAlignment() const
|
||||
{
|
||||
return this->alignment;
|
||||
}
|
||||
|
||||
bool QUIWidget::getMinHide() const
|
||||
{
|
||||
return this->minHide;
|
||||
}
|
||||
|
||||
bool QUIWidget::getExitAll() const
|
||||
{
|
||||
return this->exitAll;
|
||||
}
|
||||
|
||||
QSize QUIWidget::sizeHint() const
|
||||
{
|
||||
return QSize(600, 450);
|
||||
}
|
||||
|
||||
QSize QUIWidget::minimumSizeHint() const
|
||||
{
|
||||
return QSize(200, 150);
|
||||
}
|
||||
|
||||
void QUIWidget::initControl()
|
||||
{
|
||||
this->setObjectName(QString::fromUtf8("QUIWidget"));
|
||||
this->resize(900, 750);
|
||||
verticalLayout1 = new QVBoxLayout(this);
|
||||
verticalLayout1->setSpacing(0);
|
||||
verticalLayout1->setContentsMargins(11, 11, 11, 11);
|
||||
verticalLayout1->setObjectName(QString::fromUtf8("verticalLayout1"));
|
||||
verticalLayout1->setContentsMargins(1, 1, 1, 1);
|
||||
widgetMain = new QWidget(this);
|
||||
widgetMain->setObjectName(QString::fromUtf8("widgetMainQUI"));
|
||||
verticalLayout2 = new QVBoxLayout(widgetMain);
|
||||
verticalLayout2->setSpacing(0);
|
||||
verticalLayout2->setContentsMargins(11, 11, 11, 11);
|
||||
verticalLayout2->setObjectName(QString::fromUtf8("verticalLayout2"));
|
||||
verticalLayout2->setContentsMargins(0, 0, 0, 0);
|
||||
widgetTitle = new QWidget(widgetMain);
|
||||
widgetTitle->setObjectName(QString::fromUtf8("widgetTitle"));
|
||||
QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
||||
sizePolicy.setHorizontalStretch(0);
|
||||
sizePolicy.setVerticalStretch(0);
|
||||
sizePolicy.setHeightForWidth(widgetTitle->sizePolicy().hasHeightForWidth());
|
||||
widgetTitle->setSizePolicy(sizePolicy);
|
||||
widgetTitle->setMinimumSize(QSize(0, 30));
|
||||
horizontalLayout4 = new QHBoxLayout(widgetTitle);
|
||||
horizontalLayout4->setSpacing(0);
|
||||
horizontalLayout4->setContentsMargins(11, 11, 11, 11);
|
||||
horizontalLayout4->setObjectName(QString::fromUtf8("horizontalLayout4"));
|
||||
horizontalLayout4->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
labIco = new QLabel(widgetTitle);
|
||||
labIco->setObjectName(QString::fromUtf8("labIco"));
|
||||
QSizePolicy sizePolicy1(QSizePolicy::Minimum, QSizePolicy::Preferred);
|
||||
sizePolicy1.setHorizontalStretch(0);
|
||||
sizePolicy1.setVerticalStretch(0);
|
||||
sizePolicy1.setHeightForWidth(labIco->sizePolicy().hasHeightForWidth());
|
||||
labIco->setSizePolicy(sizePolicy1);
|
||||
labIco->setMinimumSize(QSize(30, 0));
|
||||
labIco->setAlignment(Qt::AlignCenter);
|
||||
horizontalLayout4->addWidget(labIco);
|
||||
|
||||
labTitle = new QLabel(widgetTitle);
|
||||
labTitle->setObjectName(QString::fromUtf8("labTitle"));
|
||||
QSizePolicy sizePolicy2(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
sizePolicy2.setHorizontalStretch(0);
|
||||
sizePolicy2.setVerticalStretch(0);
|
||||
sizePolicy2.setHeightForWidth(labTitle->sizePolicy().hasHeightForWidth());
|
||||
labTitle->setSizePolicy(sizePolicy2);
|
||||
labTitle->setAlignment(Qt::AlignLeading | Qt::AlignLeft | Qt::AlignVCenter);
|
||||
horizontalLayout4->addWidget(labTitle);
|
||||
|
||||
widgetMenu = new QWidget(widgetTitle);
|
||||
widgetMenu->setObjectName(QString::fromUtf8("widgetMenu"));
|
||||
sizePolicy1.setHeightForWidth(widgetMenu->sizePolicy().hasHeightForWidth());
|
||||
widgetMenu->setSizePolicy(sizePolicy1);
|
||||
horizontalLayout = new QHBoxLayout(widgetMenu);
|
||||
horizontalLayout->setSpacing(0);
|
||||
horizontalLayout->setContentsMargins(11, 11, 11, 11);
|
||||
horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
|
||||
horizontalLayout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
btnMenu = new QToolButton(widgetMenu);
|
||||
btnMenu->setObjectName(QString::fromUtf8("btnMenu"));
|
||||
QSizePolicy sizePolicy3(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
||||
sizePolicy3.setHorizontalStretch(0);
|
||||
sizePolicy3.setVerticalStretch(0);
|
||||
sizePolicy3.setHeightForWidth(btnMenu->sizePolicy().hasHeightForWidth());
|
||||
btnMenu->setSizePolicy(sizePolicy3);
|
||||
btnMenu->setMinimumSize(QSize(30, 0));
|
||||
btnMenu->setMaximumSize(QSize(30, 16777215));
|
||||
btnMenu->setFocusPolicy(Qt::NoFocus);
|
||||
btnMenu->setPopupMode(QToolButton::InstantPopup);
|
||||
horizontalLayout->addWidget(btnMenu);
|
||||
|
||||
btnMenu_Min = new QPushButton(widgetMenu);
|
||||
btnMenu_Min->setObjectName(QString::fromUtf8("btnMenu_Min"));
|
||||
QSizePolicy sizePolicy4(QSizePolicy::Minimum, QSizePolicy::Expanding);
|
||||
sizePolicy4.setHorizontalStretch(0);
|
||||
sizePolicy4.setVerticalStretch(0);
|
||||
sizePolicy4.setHeightForWidth(btnMenu_Min->sizePolicy().hasHeightForWidth());
|
||||
btnMenu_Min->setSizePolicy(sizePolicy4);
|
||||
btnMenu_Min->setMinimumSize(QSize(30, 0));
|
||||
btnMenu_Min->setMaximumSize(QSize(30, 16777215));
|
||||
btnMenu_Min->setCursor(QCursor(Qt::ArrowCursor));
|
||||
btnMenu_Min->setFocusPolicy(Qt::NoFocus);
|
||||
horizontalLayout->addWidget(btnMenu_Min);
|
||||
|
||||
btnMenu_Max = new QPushButton(widgetMenu);
|
||||
btnMenu_Max->setObjectName(QString::fromUtf8("btnMenu_Max"));
|
||||
sizePolicy3.setHeightForWidth(btnMenu_Max->sizePolicy().hasHeightForWidth());
|
||||
btnMenu_Max->setSizePolicy(sizePolicy3);
|
||||
btnMenu_Max->setMinimumSize(QSize(30, 0));
|
||||
btnMenu_Max->setMaximumSize(QSize(30, 16777215));
|
||||
btnMenu_Max->setCursor(QCursor(Qt::ArrowCursor));
|
||||
btnMenu_Max->setFocusPolicy(Qt::NoFocus);
|
||||
horizontalLayout->addWidget(btnMenu_Max);
|
||||
|
||||
btnMenu_Close = new QPushButton(widgetMenu);
|
||||
btnMenu_Close->setObjectName(QString::fromUtf8("btnMenu_Close"));
|
||||
sizePolicy3.setHeightForWidth(btnMenu_Close->sizePolicy().hasHeightForWidth());
|
||||
btnMenu_Close->setSizePolicy(sizePolicy3);
|
||||
btnMenu_Close->setMinimumSize(QSize(30, 0));
|
||||
btnMenu_Close->setMaximumSize(QSize(30, 16777215));
|
||||
btnMenu_Close->setCursor(QCursor(Qt::ArrowCursor));
|
||||
btnMenu_Close->setFocusPolicy(Qt::NoFocus);
|
||||
horizontalLayout->addWidget(btnMenu_Close);
|
||||
horizontalLayout4->addWidget(widgetMenu);
|
||||
verticalLayout2->addWidget(widgetTitle);
|
||||
|
||||
widget = new QWidget(widgetMain);
|
||||
widget->setObjectName(QString::fromUtf8("widget"));
|
||||
verticalLayout3 = new QVBoxLayout(widget);
|
||||
verticalLayout3->setSpacing(0);
|
||||
verticalLayout3->setContentsMargins(11, 11, 11, 11);
|
||||
verticalLayout3->setObjectName(QString::fromUtf8("verticalLayout3"));
|
||||
verticalLayout3->setContentsMargins(0, 0, 0, 0);
|
||||
verticalLayout2->addWidget(widget);
|
||||
verticalLayout1->addWidget(widgetMain);
|
||||
|
||||
connect(this->btnMenu_Min, SIGNAL(clicked()), this, SLOT(on_btnMenu_Min_clicked()));
|
||||
connect(this->btnMenu_Max, SIGNAL(clicked()), this, SLOT(on_btnMenu_Max_clicked()));
|
||||
connect(this->btnMenu_Close, SIGNAL(clicked()), this, SLOT(on_btnMenu_Close_clicked()));
|
||||
}
|
||||
|
||||
void QUIWidget::initForm()
|
||||
{
|
||||
//设置图形字体
|
||||
setIcon(QUIWidget::Lab_Ico, QUIConfig::IconMain, QUIConfig::FontSize + 1);
|
||||
setIcon(QUIWidget::BtnMenu, QUIConfig::IconMenu);
|
||||
setIcon(QUIWidget::BtnMenu_Min, QUIConfig::IconMin);
|
||||
setIcon(QUIWidget::BtnMenu_Normal, QUIConfig::IconNormal);
|
||||
setIcon(QUIWidget::BtnMenu_Close, QUIConfig::IconClose);
|
||||
|
||||
this->widgetTitle->setProperty("form", "title");
|
||||
QUIHelper::setFramelessForm(this);
|
||||
|
||||
//设置标题及对齐方式
|
||||
title = "QUI Demo";
|
||||
alignment = Qt::AlignLeft | Qt::AlignVCenter;
|
||||
minHide = false;
|
||||
exitAll = true;
|
||||
mainWidget = 0;
|
||||
|
||||
setVisible(QUIWidget::BtnMenu, false);
|
||||
|
||||
//绑定事件过滤器监听鼠标移动
|
||||
this->installEventFilter(this);
|
||||
this->widgetTitle->installEventFilter(this);
|
||||
|
||||
//添加换肤菜单
|
||||
QStringList styleNames, styleFiles;
|
||||
QUIStyle::getStyle(styleNames, styleFiles);
|
||||
int count = styleNames.count();
|
||||
for (int i = 0; i < count; i++) {
|
||||
QAction *action = new QAction(this);
|
||||
action->setText(styleNames.at(i));
|
||||
action->setData(styleFiles.at(i));
|
||||
connect(action, SIGNAL(triggered(bool)), this, SLOT(changeStyle()));
|
||||
this->btnMenu->addAction(action);
|
||||
}
|
||||
}
|
||||
|
||||
void QUIWidget::changeStyle()
|
||||
{
|
||||
QAction *action = (QAction *)sender();
|
||||
QString qssFile = action->data().toString();
|
||||
QUIStyle::setStyle(qssFile);
|
||||
emit changeStyle(qssFile);
|
||||
}
|
||||
|
||||
void QUIWidget::setIcon(QUIWidget::Widget widget, const QChar &icon, quint32 size)
|
||||
{
|
||||
if (widget == QUIWidget::Lab_Ico) {
|
||||
setIconMain(icon, size);
|
||||
} else if (widget == QUIWidget::BtnMenu) {
|
||||
QUIConfig::IconMenu = icon;
|
||||
IconHelper::Instance()->setIcon(this->btnMenu, icon, size);
|
||||
} else if (widget == QUIWidget::BtnMenu_Min) {
|
||||
QUIConfig::IconMin = icon;
|
||||
IconHelper::Instance()->setIcon(this->btnMenu_Min, icon, size);
|
||||
} else if (widget == QUIWidget::BtnMenu_Max) {
|
||||
QUIConfig::IconMax = icon;
|
||||
IconHelper::Instance()->setIcon(this->btnMenu_Max, icon, size);
|
||||
} else if (widget == QUIWidget::BtnMenu_Normal) {
|
||||
QUIConfig::IconNormal = icon;
|
||||
IconHelper::Instance()->setIcon(this->btnMenu_Max, icon, size);
|
||||
} else if (widget == QUIWidget::BtnMenu_Close) {
|
||||
QUIConfig::IconClose = icon;
|
||||
IconHelper::Instance()->setIcon(this->btnMenu_Close, icon, size);
|
||||
}
|
||||
}
|
||||
|
||||
void QUIWidget::setIconMain(const QChar &icon, quint32 size)
|
||||
{
|
||||
QUIConfig::IconMain = icon;
|
||||
IconHelper::Instance()->setIcon(this->labIco, icon, size);
|
||||
QUIMessageBox::Instance()->setIconMain(icon, size);
|
||||
QUIInputBox::Instance()->setIconMain(icon, size);
|
||||
QUIDateSelect::Instance()->setIconMain(icon, size);
|
||||
}
|
||||
|
||||
void QUIWidget::setPixmap(QUIWidget::Widget widget, const QString &file, const QSize &size)
|
||||
{
|
||||
//按照宽高比自动缩放
|
||||
QPixmap pix = QPixmap(file);
|
||||
pix = pix.scaled(size, Qt::KeepAspectRatio);
|
||||
if (widget == QUIWidget::Lab_Ico) {
|
||||
this->labIco->setPixmap(pix);
|
||||
} else if (widget == QUIWidget::BtnMenu) {
|
||||
this->btnMenu->setIcon(QIcon(file));
|
||||
} else if (widget == QUIWidget::BtnMenu_Min) {
|
||||
this->btnMenu_Min->setIcon(QIcon(file));
|
||||
} else if (widget == QUIWidget::BtnMenu_Max) {
|
||||
this->btnMenu_Max->setIcon(QIcon(file));
|
||||
} else if (widget == QUIWidget::BtnMenu_Close) {
|
||||
this->btnMenu_Close->setIcon(QIcon(file));
|
||||
}
|
||||
}
|
||||
|
||||
void QUIWidget::setVisible(QUIWidget::Widget widget, bool visible)
|
||||
{
|
||||
if (widget == QUIWidget::Lab_Ico) {
|
||||
this->labIco->setVisible(visible);
|
||||
} else if (widget == QUIWidget::BtnMenu) {
|
||||
this->btnMenu->setVisible(visible);
|
||||
} else if (widget == QUIWidget::BtnMenu_Min) {
|
||||
this->btnMenu_Min->setVisible(visible);
|
||||
} else if (widget == QUIWidget::BtnMenu_Max) {
|
||||
this->btnMenu_Max->setVisible(visible);
|
||||
} else if (widget == QUIWidget::BtnMenu_Close) {
|
||||
this->btnMenu_Close->setVisible(visible);
|
||||
}
|
||||
}
|
||||
|
||||
void QUIWidget::setOnlyCloseBtn()
|
||||
{
|
||||
this->btnMenu->setVisible(false);
|
||||
this->btnMenu_Min->setVisible(false);
|
||||
this->btnMenu_Max->setVisible(false);
|
||||
}
|
||||
|
||||
void QUIWidget::setTitleHeight(int height)
|
||||
{
|
||||
this->widgetTitle->setFixedHeight(height);
|
||||
}
|
||||
|
||||
void QUIWidget::setBtnWidth(int width)
|
||||
{
|
||||
this->labIco->setFixedWidth(width);
|
||||
this->btnMenu->setFixedWidth(width);
|
||||
this->btnMenu_Min->setFixedWidth(width);
|
||||
this->btnMenu_Max->setFixedWidth(width);
|
||||
this->btnMenu_Close->setFixedWidth(width);
|
||||
}
|
||||
|
||||
void QUIWidget::setTitle(const QString &title)
|
||||
{
|
||||
if (this->title != title) {
|
||||
this->title = title;
|
||||
this->labTitle->setText(title);
|
||||
this->setWindowTitle(this->labTitle->text());
|
||||
}
|
||||
}
|
||||
|
||||
void QUIWidget::setAlignment(Qt::Alignment alignment)
|
||||
{
|
||||
if (this->alignment != alignment) {
|
||||
this->alignment = alignment;
|
||||
this->labTitle->setAlignment(alignment);
|
||||
}
|
||||
}
|
||||
|
||||
void QUIWidget::setMinHide(bool minHide)
|
||||
{
|
||||
if (this->minHide != minHide) {
|
||||
this->minHide = minHide;
|
||||
}
|
||||
}
|
||||
|
||||
void QUIWidget::setExitAll(bool exitAll)
|
||||
{
|
||||
if (this->exitAll != exitAll) {
|
||||
this->exitAll = exitAll;
|
||||
}
|
||||
}
|
||||
|
||||
void QUIWidget::setMainWidget(QWidget *mainWidget)
|
||||
{
|
||||
//一个QUI窗体对象只能设置一个主窗体
|
||||
if (this->mainWidget == 0) {
|
||||
//将子窗体添加到布局
|
||||
this->widget->layout()->addWidget(mainWidget);
|
||||
//自动设置大小
|
||||
resize(mainWidget->width(), mainWidget->height() + this->widgetTitle->height());
|
||||
this->mainWidget = mainWidget;
|
||||
}
|
||||
}
|
||||
|
||||
void QUIWidget::on_btnMenu_Min_clicked()
|
||||
{
|
||||
if (minHide) {
|
||||
hide();
|
||||
} else {
|
||||
showMinimized();
|
||||
}
|
||||
}
|
||||
|
||||
void QUIWidget::on_btnMenu_Max_clicked()
|
||||
{
|
||||
static bool max = false;
|
||||
static QRect location = this->geometry();
|
||||
|
||||
if (max) {
|
||||
this->setGeometry(location);
|
||||
setIcon(QUIWidget::BtnMenu_Normal, QUIConfig::IconNormal);
|
||||
} else {
|
||||
location = this->geometry();
|
||||
int screenIndex = QUIHelper::getScreenIndex();
|
||||
this->setGeometry(qApp->desktop()->availableGeometry(screenIndex));
|
||||
setIcon(QUIWidget::BtnMenu_Max, QUIConfig::IconMax);
|
||||
}
|
||||
|
||||
this->setProperty("canMove", max);
|
||||
max = !max;
|
||||
}
|
||||
|
||||
void QUIWidget::on_btnMenu_Close_clicked()
|
||||
{
|
||||
//先发送关闭信号
|
||||
emit closing();
|
||||
if (exitAll) {
|
||||
mainWidget->close();
|
||||
this->close();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
#ifndef QUIWIDGET_H
|
||||
#define QUIWIDGET_H
|
||||
|
||||
#include "quihead.h"
|
||||
|
||||
class QUIWidget : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//将部分对象作为枚举值暴露给外部
|
||||
enum Widget {
|
||||
Lab_Ico = 0, //左上角图标
|
||||
BtnMenu = 1, //下拉菜单按钮
|
||||
BtnMenu_Min = 2, //最小化按钮
|
||||
BtnMenu_Max = 3, //最大化按钮
|
||||
BtnMenu_Normal = 4, //还原按钮
|
||||
BtnMenu_Close = 5 //关闭按钮
|
||||
};
|
||||
|
||||
explicit QUIWidget(QWidget *parent = 0);
|
||||
~QUIWidget();
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
QVBoxLayout *verticalLayout1;
|
||||
QWidget *widgetMain;
|
||||
QVBoxLayout *verticalLayout2;
|
||||
QWidget *widgetTitle;
|
||||
QHBoxLayout *horizontalLayout4;
|
||||
QLabel *labIco;
|
||||
QLabel *labTitle;
|
||||
QWidget *widgetMenu;
|
||||
QHBoxLayout *horizontalLayout;
|
||||
QToolButton *btnMenu;
|
||||
QPushButton *btnMenu_Min;
|
||||
QPushButton *btnMenu_Max;
|
||||
QPushButton *btnMenu_Close;
|
||||
QWidget *widget;
|
||||
QVBoxLayout *verticalLayout3;
|
||||
|
||||
private:
|
||||
QString title; //标题
|
||||
Qt::Alignment alignment;//标题文本对齐
|
||||
bool minHide; //最小化隐藏
|
||||
bool exitAll; //退出整个程序
|
||||
QWidget *mainWidget; //主窗体对象
|
||||
|
||||
public:
|
||||
QLabel *getLabIco() const;
|
||||
QLabel *getLabTitle() const;
|
||||
|
||||
QToolButton *getBtnMenu() const;
|
||||
QPushButton *getBtnMenuMin() const;
|
||||
QPushButton *getBtnMenuMax() const;
|
||||
QPushButton *getBtnMenuMClose() const;
|
||||
|
||||
QString getTitle() const;
|
||||
Qt::Alignment getAlignment() const;
|
||||
bool getMinHide() const;
|
||||
bool getExitAll() const;
|
||||
|
||||
QSize sizeHint() const;
|
||||
QSize minimumSizeHint() const;
|
||||
|
||||
private slots:
|
||||
void initControl(); //初始化控件
|
||||
void initForm(); //初始化窗体
|
||||
void changeStyle(); //更换样式
|
||||
|
||||
private slots:
|
||||
void on_btnMenu_Min_clicked();
|
||||
void on_btnMenu_Max_clicked();
|
||||
void on_btnMenu_Close_clicked();
|
||||
|
||||
public Q_SLOTS:
|
||||
//设置部件图标
|
||||
void setIcon(QUIWidget::Widget widget, const QChar &icon, quint32 size = 12);
|
||||
void setIconMain(const QChar &icon, quint32 size = 12);
|
||||
//设置部件图片
|
||||
void setPixmap(QUIWidget::Widget widget, const QString &file, const QSize &size = QSize(16, 16));
|
||||
//设置部件是否可见
|
||||
void setVisible(QUIWidget::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 setMinHide(bool minHide);
|
||||
|
||||
//设置退出时候直接退出整个应用程序
|
||||
void setExitAll(bool exitAll);
|
||||
|
||||
//设置主窗体
|
||||
void setMainWidget(QWidget *mainWidget);
|
||||
|
||||
Q_SIGNALS:
|
||||
void changeStyle(const QString &qssFile);
|
||||
void closing();
|
||||
};
|
||||
|
||||
#endif // QUIWIDGET_H
|
|
@ -16,8 +16,10 @@ CONFIG += warn_off
|
|||
SOURCES += main.cpp
|
||||
SOURCES += frmframelesswidget.cpp
|
||||
SOURCES += framelesswidget.cpp
|
||||
SOURCES += framelesswidget2.cpp
|
||||
|
||||
HEADERS += frmframelesswidget.h
|
||||
HEADERS += framelesswidget.h
|
||||
HEADERS += framelesswidget2.h
|
||||
|
||||
FORMS += frmframelesswidget.ui
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
#include "framelesswidget2.h"
|
||||
#include "qevent.h"
|
||||
#include "qdebug.h"
|
||||
#ifdef Q_OS_WIN
|
||||
#include "windows.h"
|
||||
#endif
|
||||
|
||||
FramelessWidget2::FramelessWidget2(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
padding = 5;
|
||||
this->installEventFilter(this);
|
||||
}
|
||||
|
||||
bool FramelessWidget2::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
if (watched == this) {
|
||||
static QPoint mousePoint;
|
||||
static bool mousePressed = false;
|
||||
|
||||
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
|
||||
if (mouseEvent->type() == QEvent::MouseButtonPress) {
|
||||
if (mouseEvent->button() == Qt::LeftButton) {
|
||||
mousePressed = true;
|
||||
mousePoint = mouseEvent->globalPos() - this->pos();
|
||||
}
|
||||
} else if (mouseEvent->type() == QEvent::MouseButtonRelease) {
|
||||
mousePressed = false;
|
||||
} else if (mouseEvent->type() == QEvent::MouseMove) {
|
||||
if (mousePressed) {
|
||||
this->move(mouseEvent->globalPos() - mousePoint);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return QWidget::eventFilter(watched, event);
|
||||
}
|
||||
|
||||
bool FramelessWidget2::nativeEvent(const QByteArray &eventType, void *message, long *result)
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
MSG *msg = (MSG *)message;
|
||||
switch (msg->message) {
|
||||
case WM_NCHITTEST: {
|
||||
QPoint pos = mapFromGlobal(QPoint(LOWORD(msg->lParam), HIWORD(msg->lParam)));
|
||||
bool left = pos.x() < padding;
|
||||
bool right = pos.x() > width() - padding;
|
||||
bool top = pos.y() < padding;
|
||||
bool bottom = pos.y() > height() - padding;
|
||||
if (left && top) {
|
||||
*result = HTTOPLEFT;
|
||||
} else if (left && bottom) {
|
||||
*result = HTBOTTOMLEFT;
|
||||
} else if (right && top) {
|
||||
*result = HTTOPRIGHT;
|
||||
} else if (right && bottom) {
|
||||
*result = HTBOTTOMRIGHT;
|
||||
} else if (left) {
|
||||
*result = HTLEFT;
|
||||
} else if (right) {
|
||||
*result = HTRIGHT;
|
||||
} else if (top) {
|
||||
*result = HTTOP;
|
||||
} else if (bottom) {
|
||||
*result = HTBOTTOM;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
bool FramelessWidget2::winEvent(MSG *message, long *result)
|
||||
{
|
||||
return nativeEvent("windows_generic_MSG", message, result);
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,28 @@
|
|||
#ifndef FRAMELESSWIDGET2_H
|
||||
#define FRAMELESSWIDGET2_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#ifdef quc
|
||||
class Q_DECL_EXPORT FramelessWidget2 : public QWidget
|
||||
#else
|
||||
class FramelessWidget2 : public QWidget
|
||||
#endif
|
||||
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FramelessWidget2(QWidget *parent = 0);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
bool nativeEvent(const QByteArray &eventType, void *message, long *result);
|
||||
#ifdef Q_OS_WIN
|
||||
bool winEvent(MSG *message, long *result);
|
||||
#endif
|
||||
|
||||
private:
|
||||
int padding;
|
||||
};
|
||||
|
||||
#endif // FRAMELESSWIDGET2_H
|
|
@ -5,11 +5,14 @@
|
|||
#include "qpushbutton.h"
|
||||
#include "qcheckbox.h"
|
||||
#include "framelesswidget.h"
|
||||
#include "framelesswidget2.h"
|
||||
|
||||
frmFramelessWidget::frmFramelessWidget(QWidget *parent) : QWidget(parent), ui(new Ui::frmFramelessWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
w = 0;
|
||||
widget1 = 0;
|
||||
widget2 = 0;
|
||||
frameless = 0;
|
||||
}
|
||||
|
||||
frmFramelessWidget::~frmFramelessWidget()
|
||||
|
@ -22,52 +25,70 @@ void frmFramelessWidget::closeEvent(QCloseEvent *)
|
|||
exit(0);
|
||||
}
|
||||
|
||||
void frmFramelessWidget::initWidget(QWidget *w)
|
||||
{
|
||||
//设置无边框属性
|
||||
w->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
|
||||
//w->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
|
||||
w->setWindowTitle("自由拉伸无边框窗体");
|
||||
w->setMinimumSize(200, 120);
|
||||
w->resize(480, 320);
|
||||
|
||||
//设置下背景颜色区别看
|
||||
QPalette palette = w->palette();
|
||||
palette.setBrush(QPalette::Background, QColor(162, 121, 197));
|
||||
w->setPalette(palette);
|
||||
|
||||
QPushButton *btn = new QPushButton(w);
|
||||
btn->setText("关闭");
|
||||
btn->setGeometry(10, 10, 130, 25);
|
||||
connect(btn, SIGNAL(clicked(bool)), w, SLOT(close()));
|
||||
|
||||
QCheckBox *cboxMove = new QCheckBox(w);
|
||||
cboxMove->setText("可移动");
|
||||
cboxMove->setChecked(true);
|
||||
cboxMove->setGeometry(10, 40, 70, 25);
|
||||
connect(cboxMove, SIGNAL(stateChanged(int)), this, SLOT(stateChanged1(int)));
|
||||
|
||||
QCheckBox *cboxResize = new QCheckBox(w);
|
||||
cboxResize->setText("可拉伸");
|
||||
cboxResize->setChecked(true);
|
||||
cboxResize->setGeometry(80, 40, 70, 25);
|
||||
connect(cboxResize, SIGNAL(stateChanged(int)), this, SLOT(stateChanged2(int)));
|
||||
}
|
||||
|
||||
void frmFramelessWidget::on_pushButton_clicked()
|
||||
{
|
||||
if (w == 0) {
|
||||
w = new QWidget;
|
||||
//设置无边框属性
|
||||
w->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
|
||||
//w->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
|
||||
w->setWindowTitle("自由拉伸无边框窗体");
|
||||
w->setMinimumSize(200, 120);
|
||||
w->resize(480, 320);
|
||||
|
||||
//设置下背景颜色区别看
|
||||
QPalette palette = w->palette();
|
||||
palette.setBrush(QPalette::Background, QColor(162, 121, 197));
|
||||
w->setPalette(palette);
|
||||
|
||||
QPushButton *btn = new QPushButton(w);
|
||||
btn->setText("关闭");
|
||||
btn->setGeometry(10, 10, 130, 25);
|
||||
connect(btn, SIGNAL(clicked(bool)), w, SLOT(close()));
|
||||
|
||||
QCheckBox *cboxMove = new QCheckBox(w);
|
||||
cboxMove->setText("可移动");
|
||||
cboxMove->setChecked(true);
|
||||
cboxMove->setGeometry(10, 40, 70, 25);
|
||||
connect(cboxMove, SIGNAL(stateChanged(int)), this, SLOT(stateChanged1(int)));
|
||||
|
||||
QCheckBox *cboxResize = new QCheckBox(w);
|
||||
cboxResize->setText("可拉伸");
|
||||
cboxResize->setChecked(true);
|
||||
cboxResize->setGeometry(80, 40, 70, 25);
|
||||
connect(cboxResize, SIGNAL(stateChanged(int)), this, SLOT(stateChanged2(int)));
|
||||
|
||||
frameless = new FramelessWidget(w);
|
||||
frameless->setWidget(w);
|
||||
if (widget1 == 0) {
|
||||
widget1 = new QWidget;
|
||||
this->initWidget(widget1);
|
||||
frameless = new FramelessWidget(widget1);
|
||||
frameless->setWidget(widget1);
|
||||
}
|
||||
|
||||
w->show();
|
||||
widget1->show();
|
||||
}
|
||||
|
||||
void frmFramelessWidget::stateChanged1(int arg1)
|
||||
{
|
||||
frameless->setMoveEnable(arg1 != 0);
|
||||
if (frameless != 0) {
|
||||
frameless->setMoveEnable(arg1 != 0);
|
||||
}
|
||||
}
|
||||
|
||||
void frmFramelessWidget::stateChanged2(int arg1)
|
||||
{
|
||||
frameless->setResizeEnable(arg1 != 0);
|
||||
if (frameless != 0) {
|
||||
frameless->setResizeEnable(arg1 != 0);
|
||||
}
|
||||
}
|
||||
|
||||
void frmFramelessWidget::on_pushButton_2_clicked()
|
||||
{
|
||||
if (widget2 == 0) {
|
||||
widget2 = new FramelessWidget2;
|
||||
this->initWidget(widget2);
|
||||
}
|
||||
|
||||
widget2->show();
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <QWidget>
|
||||
class FramelessWidget;
|
||||
class FramelessWidget2;
|
||||
|
||||
namespace Ui {
|
||||
class frmFramelessWidget;
|
||||
|
@ -21,13 +22,16 @@ protected:
|
|||
|
||||
private:
|
||||
Ui::frmFramelessWidget *ui;
|
||||
QWidget *w;
|
||||
QWidget *widget1;
|
||||
FramelessWidget2 *widget2;
|
||||
FramelessWidget *frameless;
|
||||
|
||||
private slots:
|
||||
void initWidget(QWidget *w);
|
||||
void on_pushButton_clicked();
|
||||
void stateChanged1(int arg1);
|
||||
void stateChanged2(int arg1);
|
||||
void on_pushButton_2_clicked();
|
||||
};
|
||||
|
||||
#endif // FRMFRAMELESSWIDGET_H
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>600</width>
|
||||
<height>480</height>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -26,6 +26,19 @@
|
|||
<string>弹出</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="pushButton_2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>110</x>
|
||||
<y>10</y>
|
||||
<width>92</width>
|
||||
<height>28</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>无边框2</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
HEADERS += \
|
||||
$$PWD/appconfig.h \
|
||||
$$PWD/quiwidget.h \
|
||||
$$PWD/tcpserver1.h \
|
||||
$$PWD/tcpserver2.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/appconfig.cpp \
|
||||
$$PWD/quiwidget.cpp \
|
||||
$$PWD/tcpserver1.cpp \
|
||||
$$PWD/tcpserver2.cpp
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,875 +0,0 @@
|
|||
#ifndef QUIWIDGET_H
|
||||
#define QUIWIDGET_H
|
||||
|
||||
#define TIMEMS qPrintable(QTime::currentTime().toString("HH:mm:ss zzz"))
|
||||
#define TIME qPrintable(QTime::currentTime().toString("HH:mm:ss"))
|
||||
#define QDATE qPrintable(QDate::currentDate().toString("yyyy-MM-dd"))
|
||||
#define QTIME qPrintable(QTime::currentTime().toString("HH-mm-ss"))
|
||||
#define DATETIME qPrintable(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss"))
|
||||
#define STRDATETIME qPrintable(QDateTime::currentDateTime().toString("yyyy-MM-dd-HH-mm-ss"))
|
||||
#define STRDATETIMEMS qPrintable(QDateTime::currentDateTime().toString("yyyy-MM-dd-HH-mm-ss-zzz"))
|
||||
|
||||
//定义换行符
|
||||
#ifdef Q_OS_WIN
|
||||
#define NEWLINE "\r\n"
|
||||
#else
|
||||
#define NEWLINE "\n"
|
||||
#endif
|
||||
|
||||
//定义无边框标题栏高度+对话框最小宽高
|
||||
#ifdef __arm__
|
||||
#define TitleMinSize 40
|
||||
#define DialogMinWidth 350
|
||||
#define DialogMinHeight 180
|
||||
#else
|
||||
#define TitleMinSize 30
|
||||
#define DialogMinWidth 280
|
||||
#define DialogMinHeight 150
|
||||
#endif
|
||||
|
||||
/**
|
||||
* QUI无边框窗体控件 作者:feiyangqingyun(QQ:517216493)
|
||||
* 1:内置 N >= 17 套精美样式,可直接切换,也可自定义样式路径
|
||||
* 2:可设置部件(左上角图标/最小化按钮/最大化按钮/关闭按钮)的图标或者图片及是否可见
|
||||
* 3:可集成设计师插件,直接拖曳使用,所见即所得
|
||||
* 4:如果需要窗体可拖动大小,设置 setSizeGripEnabled(true);
|
||||
* 5:可设置全局样式 setStyle
|
||||
* 6:可弹出消息框,可选阻塞模式和不阻塞,默认不阻塞 showMessageBoxInfo
|
||||
* 7:可弹出错误框,可选阻塞模式和不阻塞,默认不阻塞 showMessageBoxError
|
||||
* 8:可弹出询问框 showMessageBoxError
|
||||
* 9:可弹出右下角信息框 showTipBox
|
||||
* 10:可弹出输入框 showInputBox
|
||||
* 11:可弹出时间范围选择框 showDateSelect
|
||||
* 12:消息框支持设置倒计时关闭
|
||||
* 13:集成图形字体设置方法及根据指定文字获取图片
|
||||
* 14:集成设置窗体居中显示/设置翻译文件/设置编码/设置延时/设置系统时间等静态方法
|
||||
* 15:集成获取应用程序文件名/文件路径 等方法
|
||||
*/
|
||||
|
||||
#include "head.h"
|
||||
|
||||
#ifdef quc
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(5,7,0))
|
||||
#include <QtDesigner/QDesignerExportWidget>
|
||||
#else
|
||||
#include <QtUiPlugin/QDesignerExportWidget>
|
||||
#endif
|
||||
|
||||
class QDESIGNER_WIDGET_EXPORT QUIWidget : public QDialog
|
||||
#else
|
||||
class QUIWidget : public QDialog
|
||||
#endif
|
||||
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_ENUMS(Style)
|
||||
Q_PROPERTY(QString title READ getTitle WRITE setTitle)
|
||||
Q_PROPERTY(Qt::Alignment alignment READ getAlignment WRITE setAlignment)
|
||||
Q_PROPERTY(bool minHide READ getMinHide WRITE setMinHide)
|
||||
Q_PROPERTY(bool exitAll READ getExitAll WRITE setExitAll)
|
||||
|
||||
public:
|
||||
//将部分对象作为枚举值暴露给外部
|
||||
enum Widget {
|
||||
Lab_Ico = 0, //左上角图标
|
||||
BtnMenu = 1, //下拉菜单按钮
|
||||
BtnMenu_Min = 2, //最小化按钮
|
||||
BtnMenu_Max = 3, //最大化按钮
|
||||
BtnMenu_Normal = 4, //还原按钮
|
||||
BtnMenu_Close = 5 //关闭按钮
|
||||
};
|
||||
|
||||
//样式枚举
|
||||
enum Style {
|
||||
Style_Silvery = 0, //银色样式
|
||||
Style_Blue = 1, //蓝色样式
|
||||
Style_LightBlue = 2, //淡蓝色样式
|
||||
Style_DarkBlue = 3, //深蓝色样式
|
||||
Style_Gray = 4, //灰色样式
|
||||
Style_LightGray = 5, //浅灰色样式
|
||||
Style_DarkGray = 6, //深灰色样式
|
||||
Style_Black = 7, //黑色样式
|
||||
Style_LightBlack = 8, //浅黑色样式
|
||||
Style_DarkBlack = 9, //深黑色样式
|
||||
Style_PSBlack = 10, //PS黑色样式
|
||||
Style_FlatBlack = 11, //黑色扁平样式
|
||||
Style_FlatWhite = 12, //白色扁平样式
|
||||
Style_FlatBlue = 13, //蓝色扁平样式
|
||||
Style_Purple = 14, //紫色样式
|
||||
Style_BlackBlue = 15, //黑蓝色样式
|
||||
Style_BlackVideo = 16 //视频监控黑色样式
|
||||
};
|
||||
|
||||
public:
|
||||
explicit QUIWidget(QWidget *parent = 0);
|
||||
~QUIWidget();
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
QVBoxLayout *verticalLayout1;
|
||||
QWidget *widgetMain;
|
||||
QVBoxLayout *verticalLayout2;
|
||||
QWidget *widgetTitle;
|
||||
QHBoxLayout *horizontalLayout4;
|
||||
QLabel *labIco;
|
||||
QLabel *labTitle;
|
||||
QWidget *widgetMenu;
|
||||
QHBoxLayout *horizontalLayout;
|
||||
QToolButton *btnMenu;
|
||||
QPushButton *btnMenu_Min;
|
||||
QPushButton *btnMenu_Max;
|
||||
QPushButton *btnMenu_Close;
|
||||
QWidget *widget;
|
||||
QVBoxLayout *verticalLayout3;
|
||||
|
||||
private:
|
||||
QString title; //标题
|
||||
Qt::Alignment alignment;//标题文本对齐
|
||||
bool minHide; //最小化隐藏
|
||||
bool exitAll; //退出整个程序
|
||||
QWidget *mainWidget; //主窗体对象
|
||||
|
||||
public:
|
||||
QLabel *getLabIco() const;
|
||||
QLabel *getLabTitle() const;
|
||||
QToolButton *getBtnMenu() const;
|
||||
QPushButton *getBtnMenuMin() const;
|
||||
QPushButton *getBtnMenuMax() const;
|
||||
QPushButton *getBtnMenuMClose() const;
|
||||
|
||||
QString getTitle() const;
|
||||
Qt::Alignment getAlignment() const;
|
||||
bool getMinHide() const;
|
||||
bool getExitAll() const;
|
||||
|
||||
QSize sizeHint() const;
|
||||
QSize minimumSizeHint() const;
|
||||
|
||||
private slots:
|
||||
void initControl(); //初始化控件
|
||||
void initForm(); //初始化窗体
|
||||
void changeStyle(); //更换样式
|
||||
|
||||
private slots:
|
||||
void on_btnMenu_Min_clicked();
|
||||
void on_btnMenu_Max_clicked();
|
||||
void on_btnMenu_Close_clicked();
|
||||
|
||||
public Q_SLOTS:
|
||||
//设置部件图标
|
||||
void setIcon(QUIWidget::Widget widget, const QChar &str, quint32 size = 12);
|
||||
void setIconMain(const QChar &str, quint32 size = 12);
|
||||
//设置部件图片
|
||||
void setPixmap(QUIWidget::Widget widget, const QString &file, const QSize &size = QSize(16, 16));
|
||||
//设置部件是否可见
|
||||
void setVisible(QUIWidget::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 setMinHide(bool minHide);
|
||||
|
||||
//设置退出时候直接退出整个应用程序
|
||||
void setExitAll(bool exitAll);
|
||||
|
||||
//设置主窗体
|
||||
void setMainWidget(QWidget *mainWidget);
|
||||
|
||||
Q_SIGNALS:
|
||||
void changeStyle(const QString &qssFile);
|
||||
void closing();
|
||||
};
|
||||
|
||||
//弹出信息框类
|
||||
class QUIMessageBox : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static QUIMessageBox *Instance();
|
||||
explicit QUIMessageBox(QWidget *parent = 0);
|
||||
~QUIMessageBox();
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *);
|
||||
void closeEvent(QCloseEvent *);
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
static QScopedPointer<QUIMessageBox> self;
|
||||
|
||||
QVBoxLayout *verticalLayout1;
|
||||
QWidget *widgetTitle;
|
||||
QHBoxLayout *horizontalLayout3;
|
||||
QLabel *labIco;
|
||||
QLabel *labTitle;
|
||||
QLabel *labCountDown;
|
||||
QWidget *widgetMenu;
|
||||
QHBoxLayout *horizontalLayout4;
|
||||
QPushButton *btnMenu_Close;
|
||||
QWidget *widgetMain;
|
||||
QVBoxLayout *verticalLayout2;
|
||||
QFrame *frame;
|
||||
QVBoxLayout *verticalLayout4;
|
||||
QHBoxLayout *horizontalLayout1;
|
||||
QLabel *labIcoMain;
|
||||
QSpacerItem *horizontalSpacer1;
|
||||
QLabel *labInfo;
|
||||
QHBoxLayout *horizontalLayout2;
|
||||
QSpacerItem *horizontalSpacer2;
|
||||
QPushButton *btnOk;
|
||||
QPushButton *btnCancel;
|
||||
|
||||
private:
|
||||
int closeSec; //总显示时间
|
||||
int currentSec; //当前已显示时间
|
||||
|
||||
private slots:
|
||||
void initControl(); //初始化控件
|
||||
void initForm(); //初始化窗体
|
||||
void checkSec(); //校验倒计时
|
||||
|
||||
private slots:
|
||||
void on_btnOk_clicked();
|
||||
void on_btnMenu_Close_clicked();
|
||||
|
||||
public Q_SLOTS:
|
||||
void setIconMain(const QChar &str, quint32 size = 12);
|
||||
void setIconMsg(const QString &png, const QChar &str);
|
||||
void setMessage(const QString &msg, int type, int closeSec = 0);
|
||||
};
|
||||
|
||||
//右下角弹出框类
|
||||
class QUITipBox : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static QUITipBox *Instance();
|
||||
explicit QUITipBox(QWidget *parent = 0);
|
||||
~QUITipBox();
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *);
|
||||
void closeEvent(QCloseEvent *);
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
static QScopedPointer<QUITipBox> self;
|
||||
|
||||
QVBoxLayout *verticalLayout;
|
||||
QWidget *widgetTitle;
|
||||
QHBoxLayout *horizontalLayout2;
|
||||
QLabel *labIco;
|
||||
QLabel *labTitle;
|
||||
QLabel *labCountDown;
|
||||
QWidget *widgetMenu;
|
||||
QHBoxLayout *horizontalLayout;
|
||||
QPushButton *btnMenu_Close;
|
||||
QWidget *widgetMain;
|
||||
QVBoxLayout *verticalLayout2;
|
||||
QLabel *labInfo;
|
||||
|
||||
QPropertyAnimation *animation;
|
||||
bool fullScreen;
|
||||
|
||||
private:
|
||||
int closeSec; //总显示时间
|
||||
int currentSec; //当前已显示时间
|
||||
|
||||
private slots:
|
||||
void initControl(); //初始化控件
|
||||
void initForm(); //初始化窗体
|
||||
void checkSec(); //校验倒计时
|
||||
|
||||
private slots:
|
||||
void on_btnMenu_Close_clicked();
|
||||
|
||||
public Q_SLOTS:
|
||||
void setIconMain(const QChar &str, quint32 size = 12);
|
||||
void setTip(const QString &title, const QString &tip, bool fullScreen = false, bool center = true, int closeSec = 0);
|
||||
void hide();
|
||||
};
|
||||
|
||||
|
||||
//弹出输入框类
|
||||
class QUIInputBox : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static QUIInputBox *Instance();
|
||||
explicit QUIInputBox(QWidget *parent = 0);
|
||||
~QUIInputBox();
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *);
|
||||
void closeEvent(QCloseEvent *);
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
static QScopedPointer<QUIInputBox> self;
|
||||
|
||||
QVBoxLayout *verticalLayout1;
|
||||
QWidget *widgetTitle;
|
||||
QHBoxLayout *horizontalLayout1;
|
||||
QLabel *labIco;
|
||||
QLabel *labTitle;
|
||||
QLabel *labCountDown;
|
||||
QWidget *widgetMenu;
|
||||
QHBoxLayout *horizontalLayout2;
|
||||
QPushButton *btnMenu_Close;
|
||||
QWidget *widgetMain;
|
||||
QVBoxLayout *verticalLayout2;
|
||||
QFrame *frame;
|
||||
QVBoxLayout *verticalLayout3;
|
||||
QLabel *labInfo;
|
||||
QLineEdit *txtValue;
|
||||
QComboBox *cboxValue;
|
||||
QHBoxLayout *lay;
|
||||
QSpacerItem *horizontalSpacer;
|
||||
QPushButton *btnOk;
|
||||
QPushButton *btnCancel;
|
||||
|
||||
private:
|
||||
int closeSec; //总显示时间
|
||||
int currentSec; //当前已显示时间
|
||||
QString value; //当前值
|
||||
|
||||
private slots:
|
||||
void initControl(); //初始化控件
|
||||
void initForm(); //初始化窗体
|
||||
void checkSec(); //校验倒计时
|
||||
|
||||
private slots:
|
||||
void on_btnOk_clicked();
|
||||
void on_btnMenu_Close_clicked();
|
||||
|
||||
public:
|
||||
QString getValue()const;
|
||||
|
||||
public Q_SLOTS:
|
||||
void setIconMain(const QChar &str, quint32 size = 12);
|
||||
void setParameter(const QString &title, int type = 0, int closeSec = 0,
|
||||
QString placeholderText = QString(), bool pwd = false,
|
||||
const QString &defaultValue = QString());
|
||||
|
||||
};
|
||||
|
||||
//弹出日期选择对话框
|
||||
class QUIDateSelect : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static QUIDateSelect *Instance();
|
||||
explicit QUIDateSelect(QWidget *parent = 0);
|
||||
~QUIDateSelect();
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *);
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
static QScopedPointer<QUIDateSelect> self;
|
||||
|
||||
QVBoxLayout *verticalLayout;
|
||||
QWidget *widgetTitle;
|
||||
QHBoxLayout *horizontalLayout1;
|
||||
QLabel *labIco;
|
||||
QLabel *labTitle;
|
||||
QWidget *widgetMenu;
|
||||
QHBoxLayout *horizontalLayout;
|
||||
QPushButton *btnMenu_Close;
|
||||
QWidget *widgetMain;
|
||||
QVBoxLayout *verticalLayout1;
|
||||
QFrame *frame;
|
||||
QGridLayout *gridLayout;
|
||||
QLabel *labStart;
|
||||
QPushButton *btnOk;
|
||||
QLabel *labEnd;
|
||||
QPushButton *btnClose;
|
||||
QDateTimeEdit *dateStart;
|
||||
QDateTimeEdit *dateEnd;
|
||||
|
||||
private:
|
||||
QString startDateTime; //开始时间
|
||||
QString endDateTime; //结束时间
|
||||
QString format; //日期时间格式
|
||||
|
||||
private slots:
|
||||
void initControl(); //初始化控件
|
||||
void initForm(); //初始化窗体
|
||||
|
||||
private slots:
|
||||
void on_btnOk_clicked();
|
||||
void on_btnMenu_Close_clicked();
|
||||
|
||||
public:
|
||||
//获取当前选择的开始时间和结束时间
|
||||
QString getStartDateTime() const;
|
||||
QString getEndDateTime() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
void setIconMain(const QChar &str, quint32 size = 12);
|
||||
void setFormat(const QString &format);
|
||||
|
||||
};
|
||||
|
||||
//图形字体处理类
|
||||
class IconHelper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static IconHelper *Instance();
|
||||
explicit IconHelper(QObject *parent = 0);
|
||||
|
||||
//获取图形字体
|
||||
QFont getIconFont();
|
||||
|
||||
//设置图形字体到标签
|
||||
void setIcon(QLabel *lab, const QChar &str, quint32 size = 12);
|
||||
//设置图形字体到按钮
|
||||
void setIcon(QAbstractButton *btn, const QChar &str, quint32 size = 12);
|
||||
|
||||
//获取指定图形字体,可以指定文字大小,图片宽高,文字对齐
|
||||
QPixmap getPixmap(const QColor &color, const QChar &str, quint32 size = 12,
|
||||
quint32 pixWidth = 15, quint32 pixHeight = 15,
|
||||
int flags = Qt::AlignCenter);
|
||||
|
||||
//根据按钮获取该按钮对应的图标
|
||||
QPixmap getPixmap(QToolButton *btn, bool normal);
|
||||
QPixmap getPixmap(QToolButton *btn, int type);
|
||||
|
||||
//指定QFrame导航按钮样式,带图标
|
||||
void setStyle(QFrame *frame, QList<QToolButton *> btns, QList<int> pixChar,
|
||||
quint32 iconSize = 12, quint32 iconWidth = 15, quint32 iconHeight = 15,
|
||||
const QString &normalBgColor = "#2FC5A2",
|
||||
const QString &darkBgColor = "#3EA7E9",
|
||||
const QString &normalTextColor = "#EEEEEE",
|
||||
const QString &darkTextColor = "#FFFFFF");
|
||||
|
||||
//指定导航面板样式,不带图标
|
||||
static void setStyle(QWidget *widget, const QString &type = "left", int borderWidth = 3,
|
||||
const QString &borderColor = "#029FEA",
|
||||
const QString &normalBgColor = "#292F38",
|
||||
const QString &darkBgColor = "#1D2025",
|
||||
const QString &normalTextColor = "#54626F",
|
||||
const QString &darkTextColor = "#FDFDFD");
|
||||
|
||||
//移除导航面板样式,防止重复
|
||||
void removeStyle(QList<QToolButton *> btns);
|
||||
|
||||
//指定QWidget导航面板样式,带图标和效果切换
|
||||
void setStyle(QWidget *widget, QList<QToolButton *> btns, QList<int> pixChar,
|
||||
quint32 iconSize = 12, quint32 iconWidth = 15, quint32 iconHeight = 15,
|
||||
const QString &type = "left", int borderWidth = 3,
|
||||
const QString &borderColor = "#029FEA",
|
||||
const QString &normalBgColor = "#292F38",
|
||||
const QString &darkBgColor = "#1D2025",
|
||||
const QString &normalTextColor = "#54626F",
|
||||
const QString &darkTextColor = "#FDFDFD");
|
||||
|
||||
struct StyleColor {
|
||||
quint32 iconSize;
|
||||
quint32 iconWidth;
|
||||
quint32 iconHeight;
|
||||
quint32 borderWidth;
|
||||
QString type;
|
||||
QString borderColor;
|
||||
QString normalBgColor;
|
||||
QString normalTextColor;
|
||||
QString hoverBgColor;
|
||||
QString hoverTextColor;
|
||||
QString pressedBgColor;
|
||||
QString pressedTextColor;
|
||||
QString checkedBgColor;
|
||||
QString checkedTextColor;
|
||||
|
||||
StyleColor() {
|
||||
iconSize = 12;
|
||||
iconWidth = 15;
|
||||
iconHeight = 15;
|
||||
borderWidth = 3;
|
||||
type = "left";
|
||||
borderColor = "#029FEA";
|
||||
normalBgColor = "#292F38";
|
||||
normalTextColor = "#54626F";
|
||||
hoverBgColor = "#40444D";
|
||||
hoverTextColor = "#FDFDFD";
|
||||
pressedBgColor = "#404244";
|
||||
pressedTextColor = "#FDFDFD";
|
||||
checkedBgColor = "#44494F";
|
||||
checkedTextColor = "#FDFDFD";
|
||||
}
|
||||
};
|
||||
|
||||
//指定QWidget导航面板样式,带图标和效果切换+悬停颜色+按下颜色+选中颜色
|
||||
void setStyle(QWidget *widget, QList<QToolButton *> btns, QList<int> pixChar, const StyleColor &styleColor);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
static QScopedPointer<IconHelper> self;
|
||||
|
||||
QFont iconFont; //图形字体
|
||||
QList<QToolButton *> btns; //按钮队列
|
||||
QList<QPixmap> pixNormal; //正常图片队列
|
||||
QList<QPixmap> pixDark; //加深图片队列
|
||||
QList<QPixmap> pixHover; //悬停图片队列
|
||||
QList<QPixmap> pixPressed; //按下图片队列
|
||||
QList<QPixmap> pixChecked; //选中图片队列
|
||||
};
|
||||
|
||||
//托盘图标类
|
||||
class TrayIcon : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static TrayIcon *Instance();
|
||||
explicit TrayIcon(QObject *parent = 0);
|
||||
|
||||
private:
|
||||
static QScopedPointer<TrayIcon> self;
|
||||
|
||||
QWidget *mainWidget; //对应所属主窗体
|
||||
QSystemTrayIcon *trayIcon; //托盘对象
|
||||
QMenu *menu; //右键菜单
|
||||
bool exitDirect; //是否直接退出
|
||||
|
||||
private slots:
|
||||
void iconIsActived(QSystemTrayIcon::ActivationReason reason);
|
||||
|
||||
public Q_SLOTS:
|
||||
//设置是否直接退出,如果不是直接退出则发送信号给主界面
|
||||
void setExitDirect(bool exitDirect);
|
||||
|
||||
//设置所属主窗体
|
||||
void setMainWidget(QWidget *mainWidget);
|
||||
|
||||
//显示消息
|
||||
void showMessage(const QString &title, const QString &msg,
|
||||
QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information, int msecs = 5000);
|
||||
|
||||
//设置图标
|
||||
void setIcon(const QString &strIcon);
|
||||
//设置提示信息
|
||||
void setToolTip(const QString &tip);
|
||||
//设置是否可见
|
||||
void setVisible(bool visible);
|
||||
//退出所有
|
||||
void closeAll();
|
||||
|
||||
Q_SIGNALS:
|
||||
void trayIconExit();
|
||||
};
|
||||
|
||||
|
||||
//全局静态方法类
|
||||
class QUIHelper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
//桌面宽度高度
|
||||
static int deskWidth();
|
||||
static int deskHeight();
|
||||
|
||||
//程序文件名称+当前所在路径
|
||||
static QString appName();
|
||||
static QString appPath();
|
||||
|
||||
//初始化随机数种子
|
||||
static void initRand();
|
||||
//获取uuid
|
||||
static QString getUuid();
|
||||
|
||||
//初始化数据库
|
||||
static void initDb(const QString &dbName);
|
||||
//初始化文件,不存在则拷贝
|
||||
static void initFile(const QString &sourceName, const QString &targetName);
|
||||
|
||||
//检查ini配置文件
|
||||
static bool checkIniFile(const QString &iniFile);
|
||||
|
||||
//设置图标到按钮
|
||||
static void setIconBtn(QAbstractButton *btn, const QString &png, const QChar &str);
|
||||
|
||||
//新建目录
|
||||
static void newDir(const QString &dirName);
|
||||
|
||||
//写入消息到额外的的消息日志文件
|
||||
static void writeInfo(const QString &info, bool needWrite = false, const QString &filePath = "log");
|
||||
static void writeError(const QString &info, bool needWrite = false, const QString &filePath = "log");
|
||||
|
||||
//设置无边框窗体
|
||||
static void setFramelessForm(QWidget *widgetMain, QWidget *widgetTitle, QLabel *labIco, QPushButton *btnClose, bool tool = true);
|
||||
|
||||
//设置全局样式
|
||||
static void setStyle(QUIWidget::Style style);
|
||||
static void setStyle(const QString &qssFile, QString &paletteColor, QString &textColor);
|
||||
static void setStyle(const QString &qssFile, QString &textColor,
|
||||
QString &panelColor, QString &borderColor,
|
||||
QString &normalColorStart, QString &normalColorEnd,
|
||||
QString &darkColorStart, QString &darkColorEnd,
|
||||
QString &highColor);
|
||||
|
||||
//根据QSS样式获取对应颜色值
|
||||
static void getQssColor(const QString &qss, QString &textColor,
|
||||
QString &panelColor, QString &borderColor,
|
||||
QString &normalColorStart, QString &normalColorEnd,
|
||||
QString &darkColorStart, QString &darkColorEnd,
|
||||
QString &highColor);
|
||||
|
||||
//九宫格图片 horzSplit-宫格1/3/7/9宽度 vertSplit-宫格1/3/7/9高度 dstWidth-目标图片宽度 dstHeight-目标图片高度
|
||||
static QPixmap ninePatch(const QString &picName, int horzSplit, int vertSplit, int dstWidth, int dstHeight);
|
||||
static QPixmap ninePatch(const QPixmap &pix, int horzSplit, int vertSplit, int dstWidth, int dstHeight);
|
||||
|
||||
//设置标签颜色
|
||||
static void setLabStyle(QLabel *lab, quint8 type, const QString &bgColor = "", const QString &textColor = "");
|
||||
|
||||
//设置窗体居中显示
|
||||
static void setFormInCenter(QWidget *frm);
|
||||
//设置翻译文件
|
||||
static void setTranslator(const QString &qmFile = ":/image/qt_zh_CN.qm");
|
||||
//设置编码
|
||||
static void setCode();
|
||||
//设置字体
|
||||
static void setFont(const QString &ttfFile = ":/image/DroidSansFallback.ttf",
|
||||
const QString &fontName = "Microsoft Yahei", int fontSize = 12);
|
||||
//设置延时
|
||||
static void sleep(int msec);
|
||||
//设置系统时间
|
||||
static void setSystemDateTime(const QString &year, const QString &month, const QString &day,
|
||||
const QString &hour, const QString &min, const QString &sec);
|
||||
//设置开机自启动
|
||||
static void runWithSystem(const QString &strName, const QString &strPath, bool autoRun = true);
|
||||
|
||||
//从字符串获取IP地址
|
||||
static QString getIP(const QString &url);
|
||||
//判断是否是IP地址
|
||||
static bool isIP(const QString &ip);
|
||||
//判断是否是MAC地址
|
||||
static bool isMac(const QString &mac);
|
||||
//判断是否是合法的电话号码
|
||||
static bool isTel(const QString &tel);
|
||||
//判断是否是合法的邮箱地址
|
||||
static bool isEmail(const QString &email);
|
||||
|
||||
//IP地址字符串与整型转换
|
||||
static QString ipv4IntToString(quint32 ip);
|
||||
static quint32 ipv4StringToInt(const QString &ip);
|
||||
|
||||
//16进制字符串转10进制
|
||||
static int strHexToDecimal(const QString &strHex);
|
||||
//10进制字符串转10进制
|
||||
static int strDecimalToDecimal(const QString &strDecimal);
|
||||
//2进制字符串转10进制
|
||||
static int strBinToDecimal(const QString &strBin);
|
||||
|
||||
//16进制字符串转2进制字符串
|
||||
static QString strHexToStrBin(const QString &strHex);
|
||||
//10进制转2进制字符串一个字节
|
||||
static QString decimalToStrBin1(int decimal);
|
||||
//10进制转2进制字符串两个字节
|
||||
static QString decimalToStrBin2(int decimal);
|
||||
//10进制转16进制字符串,补零.
|
||||
static QString decimalToStrHex(int decimal);
|
||||
|
||||
//int转字节数组
|
||||
static QByteArray intToByte(int i);
|
||||
static QByteArray intToByteRec(int i);
|
||||
|
||||
//字节数组转int
|
||||
static int byteToInt(const QByteArray &data);
|
||||
static int byteToIntRec(const QByteArray &data);
|
||||
static quint32 byteToUInt(const QByteArray &data);
|
||||
static quint32 byteToUIntRec(const QByteArray &data);
|
||||
|
||||
//ushort转字节数组
|
||||
static QByteArray ushortToByte(ushort i);
|
||||
static QByteArray ushortToByteRec(ushort i);
|
||||
|
||||
//字节数组转ushort
|
||||
static int byteToUShort(const QByteArray &data);
|
||||
static int byteToUShortRec(const QByteArray &data);
|
||||
|
||||
//异或加密算法
|
||||
static QString getXorEncryptDecrypt(const QString &str, char key);
|
||||
//异或校验
|
||||
static uchar getOrCode(const QByteArray &data);
|
||||
//计算校验码
|
||||
static uchar getCheckCode(const QByteArray &data);
|
||||
|
||||
//CRC校验
|
||||
static quint16 getRevCrc_16(quint8 *data, int len, quint16 init, const quint16 *table);
|
||||
static quint16 getCrc_16(quint8 *data, int len, quint16 init, const quint16 *table);
|
||||
static quint16 getModbus16(quint8 *data, int len);
|
||||
static QByteArray getCRCCode(const QByteArray &data);
|
||||
|
||||
//字节数组与Ascii字符串互转
|
||||
static void initAsciiStr();
|
||||
static QString byteArrayToAsciiStr(const QByteArray &data);
|
||||
static QByteArray asciiStrToByteArray(const QString &data);
|
||||
|
||||
//16进制字符串与字节数组互转
|
||||
static char hexStrToChar(char data);
|
||||
static QByteArray hexStrToByteArray(const QString &data);
|
||||
static QString byteArrayToHexStr(const QByteArray &data);
|
||||
|
||||
//获取保存的文件
|
||||
static QString getSaveName(const QString &filter, QString defaultDir = QCoreApplication::applicationDirPath());
|
||||
//获取选择的文件
|
||||
static QString getFileName(const QString &filter, QString defaultDir = QCoreApplication::applicationDirPath());
|
||||
//非阻塞保存文件对话框
|
||||
static QString saveFileName(const QString &filter, const QString &defaultDir = "", const QString &fileName = "");
|
||||
//获取选择的文件集合
|
||||
static QStringList getFileNames(const QString &filter, QString defaultDir = QCoreApplication::applicationDirPath());
|
||||
//获取选择的目录
|
||||
static QString getFolderName();
|
||||
|
||||
//获取文件名,含拓展名
|
||||
static QString getFileNameWithExtension(const QString &strFilePath);
|
||||
//获取选择文件夹中的文件
|
||||
static QStringList getFolderFileNames(const QStringList &filter);
|
||||
|
||||
//文件夹是否存在
|
||||
static bool folderIsExist(const QString &strFolder);
|
||||
//文件是否存在
|
||||
static bool fileIsExist(const QString &strFile);
|
||||
//复制文件
|
||||
static bool copyFile(const QString &sourceFile, const QString &targetFile);
|
||||
//删除文件夹下所有文件
|
||||
static void deleteDirectory(const QString &path);
|
||||
|
||||
//判断IP地址及端口是否在线
|
||||
static bool ipLive(const QString &ip, int port, int timeout = 1000);
|
||||
//获取网页所有源代码
|
||||
static QString getHtml(const QString &url);
|
||||
//获取本机公网IP地址
|
||||
static QString getNetIP(const QString &html);
|
||||
//获取本机IP
|
||||
static QString getLocalIP();
|
||||
//获取本机IP地址集合
|
||||
static QStringList getLocalIPs();
|
||||
//Url地址转为IP地址
|
||||
static QString urlToIP(const QString &url);
|
||||
|
||||
//字符串补全
|
||||
static QString getValue(quint8 value);
|
||||
//判断是否通外网
|
||||
static bool isWebOk();
|
||||
|
||||
//初始化表格
|
||||
static void initTableView(QTableView *tableView, int rowHeight = 25,
|
||||
bool headVisible = false, bool edit = false,
|
||||
bool stretchLast = true);
|
||||
|
||||
//弹出框
|
||||
static int showMessageBox(const QString &info, int type = 0, int closeSec = 0, bool exec = false);
|
||||
//弹出消息框
|
||||
static void showMessageBoxInfo(const QString &info, int closeSec = 0, bool exec = false);
|
||||
//弹出错误框
|
||||
static void showMessageBoxError(const QString &info, int closeSec = 0, bool exec = false);
|
||||
//弹出询问框
|
||||
static int showMessageBoxQuestion(const QString &info);
|
||||
|
||||
//弹出+隐藏右下角信息框
|
||||
static void showTipBox(const QString &title, const QString &tip, bool fullScreen = false,
|
||||
bool center = true, int closeSec = 0);
|
||||
static void hideTipBox();
|
||||
|
||||
//弹出输入框
|
||||
static QString showInputBox(const QString &title, int type = 0, int closeSec = 0,
|
||||
const QString &placeholderText = QString(), bool pwd = false,
|
||||
const QString &defaultValue = QString());
|
||||
//弹出日期选择框
|
||||
static void showDateSelect(QString &dateStart, QString &dateEnd, const QString &format = "yyyy-MM-dd");
|
||||
|
||||
|
||||
//设置按钮样式
|
||||
static QString setPushButtonQss(QPushButton *btn, //按钮对象
|
||||
int radius = 5, //圆角半径
|
||||
int padding = 8, //间距
|
||||
const QString &normalColor = "#34495E", //正常颜色
|
||||
const QString &normalTextColor = "#FFFFFF", //文字颜色
|
||||
const QString &hoverColor = "#4E6D8C", //悬停颜色
|
||||
const QString &hoverTextColor = "#F0F0F0", //悬停文字颜色
|
||||
const QString &pressedColor = "#2D3E50", //按下颜色
|
||||
const QString &pressedTextColor = "#B8C6D1"); //按下文字颜色
|
||||
//设置文本框样式
|
||||
static QString setLineEditQss(QLineEdit *txt, //文本框对象
|
||||
int radius = 3, //圆角半径
|
||||
int borderWidth = 2, //边框大小
|
||||
const QString &normalColor = "#DCE4EC", //正常颜色
|
||||
const QString &focusColor = "#34495E"); //选中颜色
|
||||
//设置进度条样式
|
||||
static QString setProgressBarQss(QProgressBar *bar,
|
||||
int barHeight = 8, //进度条高度
|
||||
int barRadius = 5, //进度条半径
|
||||
int fontSize = 9, //文字字号
|
||||
const QString &normalColor = "#E8EDF2", //正常颜色
|
||||
const QString &chunkColor = "#E74C3C"); //进度颜色
|
||||
//设置滑块条样式
|
||||
static QString setSliderQss(QSlider *slider, //滑动条对象
|
||||
int sliderHeight = 8, //滑动条高度
|
||||
const QString &normalColor = "#E8EDF2", //正常颜色
|
||||
const QString &grooveColor = "#1ABC9C", //滑块颜色
|
||||
const QString &handleBorderColor = "#1ABC9C", //指示器边框颜色
|
||||
const QString &handleColor = "#FFFFFF", //指示器颜色
|
||||
const QString &textColor = "#000000"); //文字颜色
|
||||
//设置单选框样式
|
||||
static QString setRadioButtonQss(QRadioButton *rbtn, //单选框对象
|
||||
int indicatorRadius = 8, //指示器圆角角度
|
||||
const QString &normalColor = "#D7DBDE", //正常颜色
|
||||
const QString &checkColor = "#34495E"); //选中颜色
|
||||
//设置滚动条样式
|
||||
static QString setScrollBarQss(QWidget *scroll, //滚动条对象
|
||||
int radius = 6, //圆角角度
|
||||
int min = 120, //指示器最小长度
|
||||
int max = 12, //滚动条最大长度
|
||||
const QString &bgColor = "#606060", //背景色
|
||||
const QString &handleNormalColor = "#34495E", //指示器正常颜色
|
||||
const QString &handleHoverColor = "#1ABC9C", //指示器悬停颜色
|
||||
const QString &handlePressedColor = "#E74C3C"); //指示器按下颜色
|
||||
};
|
||||
|
||||
//全局变量控制
|
||||
class QUIConfig
|
||||
{
|
||||
public:
|
||||
//全局图标
|
||||
static QChar IconMain; //标题栏左上角图标
|
||||
static QChar IconMenu; //下拉菜单图标
|
||||
static QChar IconMin; //最小化图标
|
||||
static QChar IconMax; //最大化图标
|
||||
static QChar IconNormal; //还原图标
|
||||
static QChar IconClose; //关闭图标
|
||||
|
||||
static QString FontName; //全局字体名称
|
||||
static int FontSize; //全局字体大小
|
||||
|
||||
//样式表颜色值
|
||||
static QString TextColor; //文字颜色
|
||||
static QString PanelColor; //面板颜色
|
||||
static QString BorderColor; //边框颜色
|
||||
static QString NormalColorStart;//正常状态开始颜色
|
||||
static QString NormalColorEnd; //正常状态结束颜色
|
||||
static QString DarkColorStart; //加深状态开始颜色
|
||||
static QString DarkColorEnd; //加深状态结束颜色
|
||||
static QString HighColor; //高亮颜色
|
||||
};
|
||||
|
||||
#endif // QUIWIDGET_H
|
|
@ -31,9 +31,6 @@ void frmMain::initForm()
|
|||
connect(tcpServer2, SIGNAL(sendData(QString, int, QString, QString)), this, SLOT(sendData2(QString, int, QString, QString)));
|
||||
connect(tcpServer2, SIGNAL(receiveData(QString, int, QString, QString)), this, SLOT(receiveData2(QString, int, QString, QString)));
|
||||
connect(tcpServer2, SIGNAL(receiveDeviceID(QString, int, QString)), this, SLOT(receiveDeviceID2(QString, int, QString)));
|
||||
|
||||
QUIHelper::setLabStyle(ui->labCount1, 3);
|
||||
QUIHelper::setLabStyle(ui->labCount2, 3);
|
||||
}
|
||||
|
||||
void frmMain::initConfig()
|
||||
|
|
|
@ -18,9 +18,12 @@ HEADERS += head.h
|
|||
RESOURCES += other/main.qrc
|
||||
CONFIG += warn_off
|
||||
|
||||
include ($$PWD/api/api.pri)
|
||||
include ($$PWD/form/form.pri)
|
||||
|
||||
INCLUDEPATH += $$PWD
|
||||
INCLUDEPATH += $$PWD/api
|
||||
INCLUDEPATH += $$PWD/form
|
||||
|
||||
include ($$PWD/api/api.pri)
|
||||
include ($$PWD/form/form.pri)
|
||||
|
||||
INCLUDEPATH += $$PWD/../core_qui
|
||||
include ($$PWD/../core_qui/core_qui.pri)
|
||||
|
|
|
@ -1,12 +1,8 @@
|
|||
HEADERS += \
|
||||
$$PWD/appconfig.h
|
||||
HEADERS += $$PWD/quiwidget.h
|
||||
HEADERS += $$PWD/appconfig.h
|
||||
HEADERS += $$PWD/tcpclient.h
|
||||
HEADERS += $$PWD/tcpserver.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/appconfig.cpp
|
||||
SOURCES += $$PWD/quiwidget.cpp
|
||||
SOURCES += $$PWD/appconfig.cpp
|
||||
SOURCES += $$PWD/tcpclient.cpp
|
||||
SOURCES += $$PWD/tcpserver.cpp
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,875 +0,0 @@
|
|||
#ifndef QUIWIDGET_H
|
||||
#define QUIWIDGET_H
|
||||
|
||||
#define TIMEMS qPrintable(QTime::currentTime().toString("HH:mm:ss zzz"))
|
||||
#define TIME qPrintable(QTime::currentTime().toString("HH:mm:ss"))
|
||||
#define QDATE qPrintable(QDate::currentDate().toString("yyyy-MM-dd"))
|
||||
#define QTIME qPrintable(QTime::currentTime().toString("HH-mm-ss"))
|
||||
#define DATETIME qPrintable(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss"))
|
||||
#define STRDATETIME qPrintable(QDateTime::currentDateTime().toString("yyyy-MM-dd-HH-mm-ss"))
|
||||
#define STRDATETIMEMS qPrintable(QDateTime::currentDateTime().toString("yyyy-MM-dd-HH-mm-ss-zzz"))
|
||||
|
||||
//定义换行符
|
||||
#ifdef Q_OS_WIN
|
||||
#define NEWLINE "\r\n"
|
||||
#else
|
||||
#define NEWLINE "\n"
|
||||
#endif
|
||||
|
||||
//定义无边框标题栏高度+对话框最小宽高
|
||||
#ifdef __arm__
|
||||
#define TitleMinSize 40
|
||||
#define DialogMinWidth 350
|
||||
#define DialogMinHeight 180
|
||||
#else
|
||||
#define TitleMinSize 30
|
||||
#define DialogMinWidth 280
|
||||
#define DialogMinHeight 150
|
||||
#endif
|
||||
|
||||
/**
|
||||
* QUI无边框窗体控件 作者:feiyangqingyun(QQ:517216493)
|
||||
* 1:内置 N >= 17 套精美样式,可直接切换,也可自定义样式路径
|
||||
* 2:可设置部件(左上角图标/最小化按钮/最大化按钮/关闭按钮)的图标或者图片及是否可见
|
||||
* 3:可集成设计师插件,直接拖曳使用,所见即所得
|
||||
* 4:如果需要窗体可拖动大小,设置 setSizeGripEnabled(true);
|
||||
* 5:可设置全局样式 setStyle
|
||||
* 6:可弹出消息框,可选阻塞模式和不阻塞,默认不阻塞 showMessageBoxInfo
|
||||
* 7:可弹出错误框,可选阻塞模式和不阻塞,默认不阻塞 showMessageBoxError
|
||||
* 8:可弹出询问框 showMessageBoxError
|
||||
* 9:可弹出右下角信息框 showTipBox
|
||||
* 10:可弹出输入框 showInputBox
|
||||
* 11:可弹出时间范围选择框 showDateSelect
|
||||
* 12:消息框支持设置倒计时关闭
|
||||
* 13:集成图形字体设置方法及根据指定文字获取图片
|
||||
* 14:集成设置窗体居中显示/设置翻译文件/设置编码/设置延时/设置系统时间等静态方法
|
||||
* 15:集成获取应用程序文件名/文件路径 等方法
|
||||
*/
|
||||
|
||||
#include "head.h"
|
||||
|
||||
#ifdef quc
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(5,7,0))
|
||||
#include <QtDesigner/QDesignerExportWidget>
|
||||
#else
|
||||
#include <QtUiPlugin/QDesignerExportWidget>
|
||||
#endif
|
||||
|
||||
class QDESIGNER_WIDGET_EXPORT QUIWidget : public QDialog
|
||||
#else
|
||||
class QUIWidget : public QDialog
|
||||
#endif
|
||||
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_ENUMS(Style)
|
||||
Q_PROPERTY(QString title READ getTitle WRITE setTitle)
|
||||
Q_PROPERTY(Qt::Alignment alignment READ getAlignment WRITE setAlignment)
|
||||
Q_PROPERTY(bool minHide READ getMinHide WRITE setMinHide)
|
||||
Q_PROPERTY(bool exitAll READ getExitAll WRITE setExitAll)
|
||||
|
||||
public:
|
||||
//将部分对象作为枚举值暴露给外部
|
||||
enum Widget {
|
||||
Lab_Ico = 0, //左上角图标
|
||||
BtnMenu = 1, //下拉菜单按钮
|
||||
BtnMenu_Min = 2, //最小化按钮
|
||||
BtnMenu_Max = 3, //最大化按钮
|
||||
BtnMenu_Normal = 4, //还原按钮
|
||||
BtnMenu_Close = 5 //关闭按钮
|
||||
};
|
||||
|
||||
//样式枚举
|
||||
enum Style {
|
||||
Style_Silvery = 0, //银色样式
|
||||
Style_Blue = 1, //蓝色样式
|
||||
Style_LightBlue = 2, //淡蓝色样式
|
||||
Style_DarkBlue = 3, //深蓝色样式
|
||||
Style_Gray = 4, //灰色样式
|
||||
Style_LightGray = 5, //浅灰色样式
|
||||
Style_DarkGray = 6, //深灰色样式
|
||||
Style_Black = 7, //黑色样式
|
||||
Style_LightBlack = 8, //浅黑色样式
|
||||
Style_DarkBlack = 9, //深黑色样式
|
||||
Style_PSBlack = 10, //PS黑色样式
|
||||
Style_FlatBlack = 11, //黑色扁平样式
|
||||
Style_FlatWhite = 12, //白色扁平样式
|
||||
Style_FlatBlue = 13, //蓝色扁平样式
|
||||
Style_Purple = 14, //紫色样式
|
||||
Style_BlackBlue = 15, //黑蓝色样式
|
||||
Style_BlackVideo = 16 //视频监控黑色样式
|
||||
};
|
||||
|
||||
public:
|
||||
explicit QUIWidget(QWidget *parent = 0);
|
||||
~QUIWidget();
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
QVBoxLayout *verticalLayout1;
|
||||
QWidget *widgetMain;
|
||||
QVBoxLayout *verticalLayout2;
|
||||
QWidget *widgetTitle;
|
||||
QHBoxLayout *horizontalLayout4;
|
||||
QLabel *labIco;
|
||||
QLabel *labTitle;
|
||||
QWidget *widgetMenu;
|
||||
QHBoxLayout *horizontalLayout;
|
||||
QToolButton *btnMenu;
|
||||
QPushButton *btnMenu_Min;
|
||||
QPushButton *btnMenu_Max;
|
||||
QPushButton *btnMenu_Close;
|
||||
QWidget *widget;
|
||||
QVBoxLayout *verticalLayout3;
|
||||
|
||||
private:
|
||||
QString title; //标题
|
||||
Qt::Alignment alignment;//标题文本对齐
|
||||
bool minHide; //最小化隐藏
|
||||
bool exitAll; //退出整个程序
|
||||
QWidget *mainWidget; //主窗体对象
|
||||
|
||||
public:
|
||||
QLabel *getLabIco() const;
|
||||
QLabel *getLabTitle() const;
|
||||
QToolButton *getBtnMenu() const;
|
||||
QPushButton *getBtnMenuMin() const;
|
||||
QPushButton *getBtnMenuMax() const;
|
||||
QPushButton *getBtnMenuMClose() const;
|
||||
|
||||
QString getTitle() const;
|
||||
Qt::Alignment getAlignment() const;
|
||||
bool getMinHide() const;
|
||||
bool getExitAll() const;
|
||||
|
||||
QSize sizeHint() const;
|
||||
QSize minimumSizeHint() const;
|
||||
|
||||
private slots:
|
||||
void initControl(); //初始化控件
|
||||
void initForm(); //初始化窗体
|
||||
void changeStyle(); //更换样式
|
||||
|
||||
private slots:
|
||||
void on_btnMenu_Min_clicked();
|
||||
void on_btnMenu_Max_clicked();
|
||||
void on_btnMenu_Close_clicked();
|
||||
|
||||
public Q_SLOTS:
|
||||
//设置部件图标
|
||||
void setIcon(QUIWidget::Widget widget, const QChar &str, quint32 size = 12);
|
||||
void setIconMain(const QChar &str, quint32 size = 12);
|
||||
//设置部件图片
|
||||
void setPixmap(QUIWidget::Widget widget, const QString &file, const QSize &size = QSize(16, 16));
|
||||
//设置部件是否可见
|
||||
void setVisible(QUIWidget::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 setMinHide(bool minHide);
|
||||
|
||||
//设置退出时候直接退出整个应用程序
|
||||
void setExitAll(bool exitAll);
|
||||
|
||||
//设置主窗体
|
||||
void setMainWidget(QWidget *mainWidget);
|
||||
|
||||
Q_SIGNALS:
|
||||
void changeStyle(const QString &qssFile);
|
||||
void closing();
|
||||
};
|
||||
|
||||
//弹出信息框类
|
||||
class QUIMessageBox : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static QUIMessageBox *Instance();
|
||||
explicit QUIMessageBox(QWidget *parent = 0);
|
||||
~QUIMessageBox();
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *);
|
||||
void closeEvent(QCloseEvent *);
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
static QScopedPointer<QUIMessageBox> self;
|
||||
|
||||
QVBoxLayout *verticalLayout1;
|
||||
QWidget *widgetTitle;
|
||||
QHBoxLayout *horizontalLayout3;
|
||||
QLabel *labIco;
|
||||
QLabel *labTitle;
|
||||
QLabel *labCountDown;
|
||||
QWidget *widgetMenu;
|
||||
QHBoxLayout *horizontalLayout4;
|
||||
QPushButton *btnMenu_Close;
|
||||
QWidget *widgetMain;
|
||||
QVBoxLayout *verticalLayout2;
|
||||
QFrame *frame;
|
||||
QVBoxLayout *verticalLayout4;
|
||||
QHBoxLayout *horizontalLayout1;
|
||||
QLabel *labIcoMain;
|
||||
QSpacerItem *horizontalSpacer1;
|
||||
QLabel *labInfo;
|
||||
QHBoxLayout *horizontalLayout2;
|
||||
QSpacerItem *horizontalSpacer2;
|
||||
QPushButton *btnOk;
|
||||
QPushButton *btnCancel;
|
||||
|
||||
private:
|
||||
int closeSec; //总显示时间
|
||||
int currentSec; //当前已显示时间
|
||||
|
||||
private slots:
|
||||
void initControl(); //初始化控件
|
||||
void initForm(); //初始化窗体
|
||||
void checkSec(); //校验倒计时
|
||||
|
||||
private slots:
|
||||
void on_btnOk_clicked();
|
||||
void on_btnMenu_Close_clicked();
|
||||
|
||||
public Q_SLOTS:
|
||||
void setIconMain(const QChar &str, quint32 size = 12);
|
||||
void setIconMsg(const QString &png, const QChar &str);
|
||||
void setMessage(const QString &msg, int type, int closeSec = 0);
|
||||
};
|
||||
|
||||
//右下角弹出框类
|
||||
class QUITipBox : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static QUITipBox *Instance();
|
||||
explicit QUITipBox(QWidget *parent = 0);
|
||||
~QUITipBox();
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *);
|
||||
void closeEvent(QCloseEvent *);
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
static QScopedPointer<QUITipBox> self;
|
||||
|
||||
QVBoxLayout *verticalLayout;
|
||||
QWidget *widgetTitle;
|
||||
QHBoxLayout *horizontalLayout2;
|
||||
QLabel *labIco;
|
||||
QLabel *labTitle;
|
||||
QLabel *labCountDown;
|
||||
QWidget *widgetMenu;
|
||||
QHBoxLayout *horizontalLayout;
|
||||
QPushButton *btnMenu_Close;
|
||||
QWidget *widgetMain;
|
||||
QVBoxLayout *verticalLayout2;
|
||||
QLabel *labInfo;
|
||||
|
||||
QPropertyAnimation *animation;
|
||||
bool fullScreen;
|
||||
|
||||
private:
|
||||
int closeSec; //总显示时间
|
||||
int currentSec; //当前已显示时间
|
||||
|
||||
private slots:
|
||||
void initControl(); //初始化控件
|
||||
void initForm(); //初始化窗体
|
||||
void checkSec(); //校验倒计时
|
||||
|
||||
private slots:
|
||||
void on_btnMenu_Close_clicked();
|
||||
|
||||
public Q_SLOTS:
|
||||
void setIconMain(const QChar &str, quint32 size = 12);
|
||||
void setTip(const QString &title, const QString &tip, bool fullScreen = false, bool center = true, int closeSec = 0);
|
||||
void hide();
|
||||
};
|
||||
|
||||
|
||||
//弹出输入框类
|
||||
class QUIInputBox : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static QUIInputBox *Instance();
|
||||
explicit QUIInputBox(QWidget *parent = 0);
|
||||
~QUIInputBox();
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *);
|
||||
void closeEvent(QCloseEvent *);
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
static QScopedPointer<QUIInputBox> self;
|
||||
|
||||
QVBoxLayout *verticalLayout1;
|
||||
QWidget *widgetTitle;
|
||||
QHBoxLayout *horizontalLayout1;
|
||||
QLabel *labIco;
|
||||
QLabel *labTitle;
|
||||
QLabel *labCountDown;
|
||||
QWidget *widgetMenu;
|
||||
QHBoxLayout *horizontalLayout2;
|
||||
QPushButton *btnMenu_Close;
|
||||
QWidget *widgetMain;
|
||||
QVBoxLayout *verticalLayout2;
|
||||
QFrame *frame;
|
||||
QVBoxLayout *verticalLayout3;
|
||||
QLabel *labInfo;
|
||||
QLineEdit *txtValue;
|
||||
QComboBox *cboxValue;
|
||||
QHBoxLayout *lay;
|
||||
QSpacerItem *horizontalSpacer;
|
||||
QPushButton *btnOk;
|
||||
QPushButton *btnCancel;
|
||||
|
||||
private:
|
||||
int closeSec; //总显示时间
|
||||
int currentSec; //当前已显示时间
|
||||
QString value; //当前值
|
||||
|
||||
private slots:
|
||||
void initControl(); //初始化控件
|
||||
void initForm(); //初始化窗体
|
||||
void checkSec(); //校验倒计时
|
||||
|
||||
private slots:
|
||||
void on_btnOk_clicked();
|
||||
void on_btnMenu_Close_clicked();
|
||||
|
||||
public:
|
||||
QString getValue()const;
|
||||
|
||||
public Q_SLOTS:
|
||||
void setIconMain(const QChar &str, quint32 size = 12);
|
||||
void setParameter(const QString &title, int type = 0, int closeSec = 0,
|
||||
QString placeholderText = QString(), bool pwd = false,
|
||||
const QString &defaultValue = QString());
|
||||
|
||||
};
|
||||
|
||||
//弹出日期选择对话框
|
||||
class QUIDateSelect : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static QUIDateSelect *Instance();
|
||||
explicit QUIDateSelect(QWidget *parent = 0);
|
||||
~QUIDateSelect();
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *);
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
static QScopedPointer<QUIDateSelect> self;
|
||||
|
||||
QVBoxLayout *verticalLayout;
|
||||
QWidget *widgetTitle;
|
||||
QHBoxLayout *horizontalLayout1;
|
||||
QLabel *labIco;
|
||||
QLabel *labTitle;
|
||||
QWidget *widgetMenu;
|
||||
QHBoxLayout *horizontalLayout;
|
||||
QPushButton *btnMenu_Close;
|
||||
QWidget *widgetMain;
|
||||
QVBoxLayout *verticalLayout1;
|
||||
QFrame *frame;
|
||||
QGridLayout *gridLayout;
|
||||
QLabel *labStart;
|
||||
QPushButton *btnOk;
|
||||
QLabel *labEnd;
|
||||
QPushButton *btnClose;
|
||||
QDateTimeEdit *dateStart;
|
||||
QDateTimeEdit *dateEnd;
|
||||
|
||||
private:
|
||||
QString startDateTime; //开始时间
|
||||
QString endDateTime; //结束时间
|
||||
QString format; //日期时间格式
|
||||
|
||||
private slots:
|
||||
void initControl(); //初始化控件
|
||||
void initForm(); //初始化窗体
|
||||
|
||||
private slots:
|
||||
void on_btnOk_clicked();
|
||||
void on_btnMenu_Close_clicked();
|
||||
|
||||
public:
|
||||
//获取当前选择的开始时间和结束时间
|
||||
QString getStartDateTime() const;
|
||||
QString getEndDateTime() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
void setIconMain(const QChar &str, quint32 size = 12);
|
||||
void setFormat(const QString &format);
|
||||
|
||||
};
|
||||
|
||||
//图形字体处理类
|
||||
class IconHelper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static IconHelper *Instance();
|
||||
explicit IconHelper(QObject *parent = 0);
|
||||
|
||||
//获取图形字体
|
||||
QFont getIconFont();
|
||||
|
||||
//设置图形字体到标签
|
||||
void setIcon(QLabel *lab, const QChar &str, quint32 size = 12);
|
||||
//设置图形字体到按钮
|
||||
void setIcon(QAbstractButton *btn, const QChar &str, quint32 size = 12);
|
||||
|
||||
//获取指定图形字体,可以指定文字大小,图片宽高,文字对齐
|
||||
QPixmap getPixmap(const QColor &color, const QChar &str, quint32 size = 12,
|
||||
quint32 pixWidth = 15, quint32 pixHeight = 15,
|
||||
int flags = Qt::AlignCenter);
|
||||
|
||||
//根据按钮获取该按钮对应的图标
|
||||
QPixmap getPixmap(QToolButton *btn, bool normal);
|
||||
QPixmap getPixmap(QToolButton *btn, int type);
|
||||
|
||||
//指定QFrame导航按钮样式,带图标
|
||||
void setStyle(QFrame *frame, QList<QToolButton *> btns, QList<int> pixChar,
|
||||
quint32 iconSize = 12, quint32 iconWidth = 15, quint32 iconHeight = 15,
|
||||
const QString &normalBgColor = "#2FC5A2",
|
||||
const QString &darkBgColor = "#3EA7E9",
|
||||
const QString &normalTextColor = "#EEEEEE",
|
||||
const QString &darkTextColor = "#FFFFFF");
|
||||
|
||||
//指定导航面板样式,不带图标
|
||||
static void setStyle(QWidget *widget, const QString &type = "left", int borderWidth = 3,
|
||||
const QString &borderColor = "#029FEA",
|
||||
const QString &normalBgColor = "#292F38",
|
||||
const QString &darkBgColor = "#1D2025",
|
||||
const QString &normalTextColor = "#54626F",
|
||||
const QString &darkTextColor = "#FDFDFD");
|
||||
|
||||
//移除导航面板样式,防止重复
|
||||
void removeStyle(QList<QToolButton *> btns);
|
||||
|
||||
//指定QWidget导航面板样式,带图标和效果切换
|
||||
void setStyle(QWidget *widget, QList<QToolButton *> btns, QList<int> pixChar,
|
||||
quint32 iconSize = 12, quint32 iconWidth = 15, quint32 iconHeight = 15,
|
||||
const QString &type = "left", int borderWidth = 3,
|
||||
const QString &borderColor = "#029FEA",
|
||||
const QString &normalBgColor = "#292F38",
|
||||
const QString &darkBgColor = "#1D2025",
|
||||
const QString &normalTextColor = "#54626F",
|
||||
const QString &darkTextColor = "#FDFDFD");
|
||||
|
||||
struct StyleColor {
|
||||
quint32 iconSize;
|
||||
quint32 iconWidth;
|
||||
quint32 iconHeight;
|
||||
quint32 borderWidth;
|
||||
QString type;
|
||||
QString borderColor;
|
||||
QString normalBgColor;
|
||||
QString normalTextColor;
|
||||
QString hoverBgColor;
|
||||
QString hoverTextColor;
|
||||
QString pressedBgColor;
|
||||
QString pressedTextColor;
|
||||
QString checkedBgColor;
|
||||
QString checkedTextColor;
|
||||
|
||||
StyleColor() {
|
||||
iconSize = 12;
|
||||
iconWidth = 15;
|
||||
iconHeight = 15;
|
||||
borderWidth = 3;
|
||||
type = "left";
|
||||
borderColor = "#029FEA";
|
||||
normalBgColor = "#292F38";
|
||||
normalTextColor = "#54626F";
|
||||
hoverBgColor = "#40444D";
|
||||
hoverTextColor = "#FDFDFD";
|
||||
pressedBgColor = "#404244";
|
||||
pressedTextColor = "#FDFDFD";
|
||||
checkedBgColor = "#44494F";
|
||||
checkedTextColor = "#FDFDFD";
|
||||
}
|
||||
};
|
||||
|
||||
//指定QWidget导航面板样式,带图标和效果切换+悬停颜色+按下颜色+选中颜色
|
||||
void setStyle(QWidget *widget, QList<QToolButton *> btns, QList<int> pixChar, const StyleColor &styleColor);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
static QScopedPointer<IconHelper> self;
|
||||
|
||||
QFont iconFont; //图形字体
|
||||
QList<QToolButton *> btns; //按钮队列
|
||||
QList<QPixmap> pixNormal; //正常图片队列
|
||||
QList<QPixmap> pixDark; //加深图片队列
|
||||
QList<QPixmap> pixHover; //悬停图片队列
|
||||
QList<QPixmap> pixPressed; //按下图片队列
|
||||
QList<QPixmap> pixChecked; //选中图片队列
|
||||
};
|
||||
|
||||
//托盘图标类
|
||||
class TrayIcon : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static TrayIcon *Instance();
|
||||
explicit TrayIcon(QObject *parent = 0);
|
||||
|
||||
private:
|
||||
static QScopedPointer<TrayIcon> self;
|
||||
|
||||
QWidget *mainWidget; //对应所属主窗体
|
||||
QSystemTrayIcon *trayIcon; //托盘对象
|
||||
QMenu *menu; //右键菜单
|
||||
bool exitDirect; //是否直接退出
|
||||
|
||||
private slots:
|
||||
void iconIsActived(QSystemTrayIcon::ActivationReason reason);
|
||||
|
||||
public Q_SLOTS:
|
||||
//设置是否直接退出,如果不是直接退出则发送信号给主界面
|
||||
void setExitDirect(bool exitDirect);
|
||||
|
||||
//设置所属主窗体
|
||||
void setMainWidget(QWidget *mainWidget);
|
||||
|
||||
//显示消息
|
||||
void showMessage(const QString &title, const QString &msg,
|
||||
QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information, int msecs = 5000);
|
||||
|
||||
//设置图标
|
||||
void setIcon(const QString &strIcon);
|
||||
//设置提示信息
|
||||
void setToolTip(const QString &tip);
|
||||
//设置是否可见
|
||||
void setVisible(bool visible);
|
||||
//退出所有
|
||||
void closeAll();
|
||||
|
||||
Q_SIGNALS:
|
||||
void trayIconExit();
|
||||
};
|
||||
|
||||
|
||||
//全局静态方法类
|
||||
class QUIHelper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
//桌面宽度高度
|
||||
static int deskWidth();
|
||||
static int deskHeight();
|
||||
|
||||
//程序文件名称+当前所在路径
|
||||
static QString appName();
|
||||
static QString appPath();
|
||||
|
||||
//初始化随机数种子
|
||||
static void initRand();
|
||||
//获取uuid
|
||||
static QString getUuid();
|
||||
|
||||
//初始化数据库
|
||||
static void initDb(const QString &dbName);
|
||||
//初始化文件,不存在则拷贝
|
||||
static void initFile(const QString &sourceName, const QString &targetName);
|
||||
|
||||
//检查ini配置文件
|
||||
static bool checkIniFile(const QString &iniFile);
|
||||
|
||||
//设置图标到按钮
|
||||
static void setIconBtn(QAbstractButton *btn, const QString &png, const QChar &str);
|
||||
|
||||
//新建目录
|
||||
static void newDir(const QString &dirName);
|
||||
|
||||
//写入消息到额外的的消息日志文件
|
||||
static void writeInfo(const QString &info, bool needWrite = false, const QString &filePath = "log");
|
||||
static void writeError(const QString &info, bool needWrite = false, const QString &filePath = "log");
|
||||
|
||||
//设置无边框窗体
|
||||
static void setFramelessForm(QWidget *widgetMain, QWidget *widgetTitle, QLabel *labIco, QPushButton *btnClose, bool tool = true);
|
||||
|
||||
//设置全局样式
|
||||
static void setStyle(QUIWidget::Style style);
|
||||
static void setStyle(const QString &qssFile, QString &paletteColor, QString &textColor);
|
||||
static void setStyle(const QString &qssFile, QString &textColor,
|
||||
QString &panelColor, QString &borderColor,
|
||||
QString &normalColorStart, QString &normalColorEnd,
|
||||
QString &darkColorStart, QString &darkColorEnd,
|
||||
QString &highColor);
|
||||
|
||||
//根据QSS样式获取对应颜色值
|
||||
static void getQssColor(const QString &qss, QString &textColor,
|
||||
QString &panelColor, QString &borderColor,
|
||||
QString &normalColorStart, QString &normalColorEnd,
|
||||
QString &darkColorStart, QString &darkColorEnd,
|
||||
QString &highColor);
|
||||
|
||||
//九宫格图片 horzSplit-宫格1/3/7/9宽度 vertSplit-宫格1/3/7/9高度 dstWidth-目标图片宽度 dstHeight-目标图片高度
|
||||
static QPixmap ninePatch(const QString &picName, int horzSplit, int vertSplit, int dstWidth, int dstHeight);
|
||||
static QPixmap ninePatch(const QPixmap &pix, int horzSplit, int vertSplit, int dstWidth, int dstHeight);
|
||||
|
||||
//设置标签颜色
|
||||
static void setLabStyle(QLabel *lab, quint8 type, const QString &bgColor = "", const QString &textColor = "");
|
||||
|
||||
//设置窗体居中显示
|
||||
static void setFormInCenter(QWidget *frm);
|
||||
//设置翻译文件
|
||||
static void setTranslator(const QString &qmFile = ":/image/qt_zh_CN.qm");
|
||||
//设置编码
|
||||
static void setCode();
|
||||
//设置字体
|
||||
static void setFont(const QString &ttfFile = ":/image/DroidSansFallback.ttf",
|
||||
const QString &fontName = "Microsoft Yahei", int fontSize = 12);
|
||||
//设置延时
|
||||
static void sleep(int msec);
|
||||
//设置系统时间
|
||||
static void setSystemDateTime(const QString &year, const QString &month, const QString &day,
|
||||
const QString &hour, const QString &min, const QString &sec);
|
||||
//设置开机自启动
|
||||
static void runWithSystem(const QString &strName, const QString &strPath, bool autoRun = true);
|
||||
|
||||
//从字符串获取IP地址
|
||||
static QString getIP(const QString &url);
|
||||
//判断是否是IP地址
|
||||
static bool isIP(const QString &ip);
|
||||
//判断是否是MAC地址
|
||||
static bool isMac(const QString &mac);
|
||||
//判断是否是合法的电话号码
|
||||
static bool isTel(const QString &tel);
|
||||
//判断是否是合法的邮箱地址
|
||||
static bool isEmail(const QString &email);
|
||||
|
||||
//IP地址字符串与整型转换
|
||||
static QString ipv4IntToString(quint32 ip);
|
||||
static quint32 ipv4StringToInt(const QString &ip);
|
||||
|
||||
//16进制字符串转10进制
|
||||
static int strHexToDecimal(const QString &strHex);
|
||||
//10进制字符串转10进制
|
||||
static int strDecimalToDecimal(const QString &strDecimal);
|
||||
//2进制字符串转10进制
|
||||
static int strBinToDecimal(const QString &strBin);
|
||||
|
||||
//16进制字符串转2进制字符串
|
||||
static QString strHexToStrBin(const QString &strHex);
|
||||
//10进制转2进制字符串一个字节
|
||||
static QString decimalToStrBin1(int decimal);
|
||||
//10进制转2进制字符串两个字节
|
||||
static QString decimalToStrBin2(int decimal);
|
||||
//10进制转16进制字符串,补零.
|
||||
static QString decimalToStrHex(int decimal);
|
||||
|
||||
//int转字节数组
|
||||
static QByteArray intToByte(int i);
|
||||
static QByteArray intToByteRec(int i);
|
||||
|
||||
//字节数组转int
|
||||
static int byteToInt(const QByteArray &data);
|
||||
static int byteToIntRec(const QByteArray &data);
|
||||
static quint32 byteToUInt(const QByteArray &data);
|
||||
static quint32 byteToUIntRec(const QByteArray &data);
|
||||
|
||||
//ushort转字节数组
|
||||
static QByteArray ushortToByte(ushort i);
|
||||
static QByteArray ushortToByteRec(ushort i);
|
||||
|
||||
//字节数组转ushort
|
||||
static int byteToUShort(const QByteArray &data);
|
||||
static int byteToUShortRec(const QByteArray &data);
|
||||
|
||||
//异或加密算法
|
||||
static QString getXorEncryptDecrypt(const QString &str, char key);
|
||||
//异或校验
|
||||
static uchar getOrCode(const QByteArray &data);
|
||||
//计算校验码
|
||||
static uchar getCheckCode(const QByteArray &data);
|
||||
|
||||
//CRC校验
|
||||
static quint16 getRevCrc_16(quint8 *data, int len, quint16 init, const quint16 *table);
|
||||
static quint16 getCrc_16(quint8 *data, int len, quint16 init, const quint16 *table);
|
||||
static quint16 getModbus16(quint8 *data, int len);
|
||||
static QByteArray getCRCCode(const QByteArray &data);
|
||||
|
||||
//字节数组与Ascii字符串互转
|
||||
static void initAsciiStr();
|
||||
static QString byteArrayToAsciiStr(const QByteArray &data);
|
||||
static QByteArray asciiStrToByteArray(const QString &data);
|
||||
|
||||
//16进制字符串与字节数组互转
|
||||
static char hexStrToChar(char data);
|
||||
static QByteArray hexStrToByteArray(const QString &data);
|
||||
static QString byteArrayToHexStr(const QByteArray &data);
|
||||
|
||||
//获取保存的文件
|
||||
static QString getSaveName(const QString &filter, QString defaultDir = QCoreApplication::applicationDirPath());
|
||||
//获取选择的文件
|
||||
static QString getFileName(const QString &filter, QString defaultDir = QCoreApplication::applicationDirPath());
|
||||
//非阻塞保存文件对话框
|
||||
static QString saveFileName(const QString &filter, const QString &defaultDir = "", const QString &fileName = "");
|
||||
//获取选择的文件集合
|
||||
static QStringList getFileNames(const QString &filter, QString defaultDir = QCoreApplication::applicationDirPath());
|
||||
//获取选择的目录
|
||||
static QString getFolderName();
|
||||
|
||||
//获取文件名,含拓展名
|
||||
static QString getFileNameWithExtension(const QString &strFilePath);
|
||||
//获取选择文件夹中的文件
|
||||
static QStringList getFolderFileNames(const QStringList &filter);
|
||||
|
||||
//文件夹是否存在
|
||||
static bool folderIsExist(const QString &strFolder);
|
||||
//文件是否存在
|
||||
static bool fileIsExist(const QString &strFile);
|
||||
//复制文件
|
||||
static bool copyFile(const QString &sourceFile, const QString &targetFile);
|
||||
//删除文件夹下所有文件
|
||||
static void deleteDirectory(const QString &path);
|
||||
|
||||
//判断IP地址及端口是否在线
|
||||
static bool ipLive(const QString &ip, int port, int timeout = 1000);
|
||||
//获取网页所有源代码
|
||||
static QString getHtml(const QString &url);
|
||||
//获取本机公网IP地址
|
||||
static QString getNetIP(const QString &html);
|
||||
//获取本机IP
|
||||
static QString getLocalIP();
|
||||
//获取本机IP地址集合
|
||||
static QStringList getLocalIPs();
|
||||
//Url地址转为IP地址
|
||||
static QString urlToIP(const QString &url);
|
||||
|
||||
//字符串补全
|
||||
static QString getValue(quint8 value);
|
||||
//判断是否通外网
|
||||
static bool isWebOk();
|
||||
|
||||
//初始化表格
|
||||
static void initTableView(QTableView *tableView, int rowHeight = 25,
|
||||
bool headVisible = false, bool edit = false,
|
||||
bool stretchLast = true);
|
||||
|
||||
//弹出框
|
||||
static int showMessageBox(const QString &info, int type = 0, int closeSec = 0, bool exec = false);
|
||||
//弹出消息框
|
||||
static void showMessageBoxInfo(const QString &info, int closeSec = 0, bool exec = false);
|
||||
//弹出错误框
|
||||
static void showMessageBoxError(const QString &info, int closeSec = 0, bool exec = false);
|
||||
//弹出询问框
|
||||
static int showMessageBoxQuestion(const QString &info);
|
||||
|
||||
//弹出+隐藏右下角信息框
|
||||
static void showTipBox(const QString &title, const QString &tip, bool fullScreen = false,
|
||||
bool center = true, int closeSec = 0);
|
||||
static void hideTipBox();
|
||||
|
||||
//弹出输入框
|
||||
static QString showInputBox(const QString &title, int type = 0, int closeSec = 0,
|
||||
const QString &placeholderText = QString(), bool pwd = false,
|
||||
const QString &defaultValue = QString());
|
||||
//弹出日期选择框
|
||||
static void showDateSelect(QString &dateStart, QString &dateEnd, const QString &format = "yyyy-MM-dd");
|
||||
|
||||
|
||||
//设置按钮样式
|
||||
static QString setPushButtonQss(QPushButton *btn, //按钮对象
|
||||
int radius = 5, //圆角半径
|
||||
int padding = 8, //间距
|
||||
const QString &normalColor = "#34495E", //正常颜色
|
||||
const QString &normalTextColor = "#FFFFFF", //文字颜色
|
||||
const QString &hoverColor = "#4E6D8C", //悬停颜色
|
||||
const QString &hoverTextColor = "#F0F0F0", //悬停文字颜色
|
||||
const QString &pressedColor = "#2D3E50", //按下颜色
|
||||
const QString &pressedTextColor = "#B8C6D1"); //按下文字颜色
|
||||
//设置文本框样式
|
||||
static QString setLineEditQss(QLineEdit *txt, //文本框对象
|
||||
int radius = 3, //圆角半径
|
||||
int borderWidth = 2, //边框大小
|
||||
const QString &normalColor = "#DCE4EC", //正常颜色
|
||||
const QString &focusColor = "#34495E"); //选中颜色
|
||||
//设置进度条样式
|
||||
static QString setProgressBarQss(QProgressBar *bar,
|
||||
int barHeight = 8, //进度条高度
|
||||
int barRadius = 5, //进度条半径
|
||||
int fontSize = 9, //文字字号
|
||||
const QString &normalColor = "#E8EDF2", //正常颜色
|
||||
const QString &chunkColor = "#E74C3C"); //进度颜色
|
||||
//设置滑块条样式
|
||||
static QString setSliderQss(QSlider *slider, //滑动条对象
|
||||
int sliderHeight = 8, //滑动条高度
|
||||
const QString &normalColor = "#E8EDF2", //正常颜色
|
||||
const QString &grooveColor = "#1ABC9C", //滑块颜色
|
||||
const QString &handleBorderColor = "#1ABC9C", //指示器边框颜色
|
||||
const QString &handleColor = "#FFFFFF", //指示器颜色
|
||||
const QString &textColor = "#000000"); //文字颜色
|
||||
//设置单选框样式
|
||||
static QString setRadioButtonQss(QRadioButton *rbtn, //单选框对象
|
||||
int indicatorRadius = 8, //指示器圆角角度
|
||||
const QString &normalColor = "#D7DBDE", //正常颜色
|
||||
const QString &checkColor = "#34495E"); //选中颜色
|
||||
//设置滚动条样式
|
||||
static QString setScrollBarQss(QWidget *scroll, //滚动条对象
|
||||
int radius = 6, //圆角角度
|
||||
int min = 120, //指示器最小长度
|
||||
int max = 12, //滚动条最大长度
|
||||
const QString &bgColor = "#606060", //背景色
|
||||
const QString &handleNormalColor = "#34495E", //指示器正常颜色
|
||||
const QString &handleHoverColor = "#1ABC9C", //指示器悬停颜色
|
||||
const QString &handlePressedColor = "#E74C3C"); //指示器按下颜色
|
||||
};
|
||||
|
||||
//全局变量控制
|
||||
class QUIConfig
|
||||
{
|
||||
public:
|
||||
//全局图标
|
||||
static QChar IconMain; //标题栏左上角图标
|
||||
static QChar IconMenu; //下拉菜单图标
|
||||
static QChar IconMin; //最小化图标
|
||||
static QChar IconMax; //最大化图标
|
||||
static QChar IconNormal; //还原图标
|
||||
static QChar IconClose; //关闭图标
|
||||
|
||||
static QString FontName; //全局字体名称
|
||||
static int FontSize; //全局字体大小
|
||||
|
||||
//样式表颜色值
|
||||
static QString TextColor; //文字颜色
|
||||
static QString PanelColor; //面板颜色
|
||||
static QString BorderColor; //边框颜色
|
||||
static QString NormalColorStart;//正常状态开始颜色
|
||||
static QString NormalColorEnd; //正常状态结束颜色
|
||||
static QString DarkColorStart; //加深状态开始颜色
|
||||
static QString DarkColorEnd; //加深状态结束颜色
|
||||
static QString HighColor; //高亮颜色
|
||||
};
|
||||
|
||||
#endif // QUIWIDGET_H
|
|
@ -35,3 +35,6 @@ INCLUDEPATH += $$PWD/form
|
|||
|
||||
include ($$PWD/api/api.pri)
|
||||
include ($$PWD/form/form.pri)
|
||||
|
||||
INCLUDEPATH += $$PWD/../core_qui
|
||||
include ($$PWD/../core_qui/core_qui.pri)
|
||||
|
|
Loading…
Reference in New Issue