|
|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
#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"))
|
|
|
|
|
@ -9,6 +10,7 @@
|
|
|
|
|
#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"))
|
|
|
|
|
|
|
|
|
|
// 根据操作系统类型定义换行符,在Windows系统下为 "\r\n",其他系统下为 "\n",方便后续文本处理时统一使用
|
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
|
#define NEWLINE "\r\n"
|
|
|
|
|
#else
|
|
|
|
|
@ -31,8 +33,10 @@
|
|
|
|
|
* 12:集成获取应用程序文件名/ 等方法
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
// 包含头文件,可能包含了一些基础的类型定义、函数声明等,是当前类实现所依赖的其他定义
|
|
|
|
|
#include "head.h"
|
|
|
|
|
|
|
|
|
|
// 根据是否定义了quc宏来决定使用不同的导出宏定义,用于在作为插件等情况下正确导出类,使其能被外部使用
|
|
|
|
|
#ifdef quc
|
|
|
|
|
#if (QT_VERSION < QT_VERSION_CHECK(5,7,0))
|
|
|
|
|
#include <QtDesigner/QDesignerExportWidget>
|
|
|
|
|
@ -40,19 +44,23 @@
|
|
|
|
|
#include <QtUiPlugin/QDesignerExportWidget>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// 定义QUIWidget类,继承自QDialog,在定义quc宏的情况下使用QDESIGNER_WIDGET_EXPORT导出该类,使其可在Qt设计师等环境中使用
|
|
|
|
|
class QDESIGNER_WIDGET_EXPORT QUIWidget : public QDialog
|
|
|
|
|
#else
|
|
|
|
|
#else
|
|
|
|
|
// 定义QUIWidget类,继承自QDialog,在未定义quc宏的情况下普通定义该类
|
|
|
|
|
class QUIWidget : public QDialog
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
// 将Style枚举类型暴露给Qt的元对象系统,以便能在信号槽机制等场景中使用
|
|
|
|
|
Q_ENUMS(Style)
|
|
|
|
|
// 定义属性title,可读可写,用于获取和设置窗口标题相关操作
|
|
|
|
|
Q_PROPERTY(QString title READ getTitle WRITE setTitle)
|
|
|
|
|
// 定义属性alignment,可读可写,用于获取和设置标题文本的对齐方式相关操作
|
|
|
|
|
Q_PROPERTY(Qt::Alignment alignment READ getAlignment WRITE setAlignment)
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
//将部分对象作为枚举值暴露给外部
|
|
|
|
|
// 将部分对象作为枚举值暴露给外部,方便代码中通过这些枚举值来指代对应的部件,增强代码可读性
|
|
|
|
|
enum Widget {
|
|
|
|
|
Lab_Ico = 0, //左上角图标
|
|
|
|
|
BtnMenu = 1, //下拉菜单按钮
|
|
|
|
|
@ -62,7 +70,7 @@ public:
|
|
|
|
|
BtnMenu_Close = 5 //关闭按钮
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//样式枚举
|
|
|
|
|
// 样式枚举,定义了一系列可供选择的窗口样式类型,方便后续切换和设置窗口的外观风格
|
|
|
|
|
enum Style {
|
|
|
|
|
Style_Silvery = 0, //银色样式
|
|
|
|
|
Style_Blue = 1, //蓝色样式
|
|
|
|
|
@ -79,515 +87,152 @@ public:
|
|
|
|
|
Style_FlatWhite = 12 //白色扁平样式
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//全局静态方法集合开始--------------------------------
|
|
|
|
|
// 全局静态方法集合开始--------------------------------
|
|
|
|
|
public:
|
|
|
|
|
//桌面宽度高度
|
|
|
|
|
// 获取桌面的宽度,以像素为单位,用于在需要根据桌面尺寸进行布局等操作时获取相关信息
|
|
|
|
|
static int deskWidth();
|
|
|
|
|
// 获取桌面的高度,以像素为单位,同理用于基于桌面尺寸的相关操作
|
|
|
|
|
static int deskHeight();
|
|
|
|
|
|
|
|
|
|
//程序本身文件名称
|
|
|
|
|
// 获取程序本身的文件名称(不包含路径),方便在需要显示程序名等场景使用
|
|
|
|
|
static QString appName();
|
|
|
|
|
//程序当前所在路径
|
|
|
|
|
// 获取程序当前所在的路径,对于文件操作、资源加载等操作可以基于此路径来进行
|
|
|
|
|
static QString appPath();
|
|
|
|
|
|
|
|
|
|
//新建目录
|
|
|
|
|
// 创建一个新的目录,参数为要创建的目录名称,用于在程序运行时动态创建文件夹来存储数据等
|
|
|
|
|
static void newDir(const QString &dirName);
|
|
|
|
|
|
|
|
|
|
//写入消息到额外的的消息日志文件
|
|
|
|
|
// 将指定的信息写入额外的消息日志文件中,可指定文件路径(默认路径为"log"),方便记录程序运行中的一些关键信息用于调试或记录操作历史
|
|
|
|
|
static void writeInfo(const QString &info, const QString &filePath = "log");
|
|
|
|
|
|
|
|
|
|
//设置全局样式
|
|
|
|
|
// 设置全局的样式,通过传入Style枚举类型的值来选择内置的样式,用于统一改变程序界面的整体风格
|
|
|
|
|
static void setStyle(QUIWidget::Style style);
|
|
|
|
|
// 设置全局样式,通过传入QSS样式文件路径以及相关颜色参数来定制样式,实现更灵活的界面外观设置
|
|
|
|
|
static void setStyle(const QString &qssFile, QString &paletteColor, QString &textColor);
|
|
|
|
|
// 设置全局样式,传入详细的QSS样式文件路径以及多个颜色相关参数,用于更精细地控制界面各部分的颜色表现
|
|
|
|
|
static void setStyle(const QString &qssFile, QString &textColor,
|
|
|
|
|
QString &panelColor, QString &borderColor,
|
|
|
|
|
QString &normalColorStart, QString &normalColorEnd,
|
|
|
|
|
QString &darkColorStart, QString &darkColorEnd,
|
|
|
|
|
QString &highColor);
|
|
|
|
|
|
|
|
|
|
//根据QSS样式获取对应颜色值
|
|
|
|
|
// 根据给定的QSS样式字符串,提取出其中对应的各种颜色值,存储到相应的输出参数中,用于分析和获取已有样式中的颜色设置情况
|
|
|
|
|
static void getQssColor(const QString &qss, QString &textColor,
|
|
|
|
|
QString &panelColor, QString &borderColor,
|
|
|
|
|
QString &normalColorStart, QString &normalColorEnd,
|
|
|
|
|
QString &darkColorStart, QString &darkColorEnd,
|
|
|
|
|
QString &highColor);
|
|
|
|
|
|
|
|
|
|
//设置窗体居中显示
|
|
|
|
|
// 将指定的窗口(QWidget类型的对象)设置为在屏幕居中显示,使界面布局更加美观、合理
|
|
|
|
|
static void setFormInCenter(QWidget *frm);
|
|
|
|
|
//设置翻译文件
|
|
|
|
|
// 设置翻译文件,用于实现程序的多语言支持,默认使用指定的翻译文件路径(":/image/qt_zh_CN.qm")
|
|
|
|
|
static void setTranslator(const QString &qmFile = ":/image/qt_zh_CN.qm");
|
|
|
|
|
//设置编码
|
|
|
|
|
// 设置编码相关内容,可能用于处理文本编码转换等情况,确保程序在不同编码环境下正确处理文本数据
|
|
|
|
|
static void setCode();
|
|
|
|
|
//设置延时
|
|
|
|
|
// 设置延时,让程序暂停执行指定的秒数,常用于需要等待一段时间再进行后续操作的场景,比如等待某个操作完成后再继续下一步
|
|
|
|
|
static void sleep(int sec);
|
|
|
|
|
//设置系统时间
|
|
|
|
|
// 设置系统时间,传入年、月、日、时、分、秒等参数来更改系统的当前时间,可能用于特定的时间同步或测试需求
|
|
|
|
|
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地址
|
|
|
|
|
// 判断给定的字符串是否是合法的IP地址格式,用于网络相关操作前对输入的IP地址进行合法性校验
|
|
|
|
|
static bool isIP(const QString &ip);
|
|
|
|
|
|
|
|
|
|
//判断是否是MAC地址
|
|
|
|
|
// 判断给定的字符串是否是合法的MAC地址格式,同样用于网络相关配置等场景下对MAC地址的合法性检查
|
|
|
|
|
static bool isMac(const QString &mac);
|
|
|
|
|
|
|
|
|
|
//判断是否是合法的电话号码
|
|
|
|
|
// 判断给定的字符串是否是合法的电话号码格式,用于涉及电话号码输入和验证的业务逻辑中
|
|
|
|
|
static bool isTel(const QString &tel);
|
|
|
|
|
|
|
|
|
|
//判断是否是合法的邮箱地址
|
|
|
|
|
// 判断给定的字符串是否是合法的邮箱地址格式,常用于用户注册、信息填写等场景下对邮箱输入的有效性验证
|
|
|
|
|
static bool isEmail(const QString &email);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//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进制字符串一个字节
|
|
|
|
|
// 将十进制整数转换为二进制表示的字符串,且长度为一个字节(8位),常用于字节级别的数据处理和转换
|
|
|
|
|
static QString decimalToStrBin1(int decimal);
|
|
|
|
|
|
|
|
|
|
//10进制转2进制字符串两个字节
|
|
|
|
|
// 将十进制整数转换为二进制表示的字符串,且长度为两个字节(16位),同样用于特定字节长度要求的数据转换场景
|
|
|
|
|
static QString decimalToStrBin2(int decimal);
|
|
|
|
|
|
|
|
|
|
//10进制转16进制字符串,补零.
|
|
|
|
|
// 将十进制整数转换为十六进制表示的字符串,并在必要时补零,保证十六进制表示的格式规范,常用于数据显示、存储等场景下的十六进制转换
|
|
|
|
|
static QString decimalToStrHex(int decimal);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//int转字节数组
|
|
|
|
|
// 将整数转换为字节数组,用于将数值类型的数据按照字节形式进行处理,比如网络传输、文件存储等需要按字节操作的情况
|
|
|
|
|
static QByteArray intToByte(int i);
|
|
|
|
|
|
|
|
|
|
//字节数组转int
|
|
|
|
|
// 将字节数组转换为整数,与intToByte相对应,用于从字节数据中还原出整数值,常用于接收网络数据或读取文件中存储的数值信息等情况
|
|
|
|
|
static int byteToInt(const QByteArray &data);
|
|
|
|
|
|
|
|
|
|
//ushort转字节数组
|
|
|
|
|
// 将无符号短整数(ushort)转换为字节数组,同样是为了便于在字节层面操作数据,适用于特定的数据格式要求场景
|
|
|
|
|
static QByteArray ushortToByte(ushort i);
|
|
|
|
|
|
|
|
|
|
//字节数组转ushort
|
|
|
|
|
// 将字节数组转换为无符号短整数,与ushortToByte相对应,用于从字节数据中获取无符号短整数值
|
|
|
|
|
static int byteToUShort(const QByteArray &data);
|
|
|
|
|
|
|
|
|
|
//异或加密算法
|
|
|
|
|
// 使用异或加密/解密算法对给定的字符串进行处理,传入字符串和密钥字符,可用于简单的数据加密和解密需求,保障数据的一定安全性
|
|
|
|
|
static QString getXorEncryptDecrypt(const QString &str, char key);
|
|
|
|
|
|
|
|
|
|
//异或校验
|
|
|
|
|
// 对给定的字节数组数据进行异或校验操作,返回校验结果(uchar类型),常用于数据完整性校验等场景
|
|
|
|
|
static uchar getOrCode(const QByteArray &data);
|
|
|
|
|
|
|
|
|
|
//计算校验码
|
|
|
|
|
// 计算给定字节数组数据的校验码(uchar类型),用于验证数据在传输或存储过程中是否发生错误等情况
|
|
|
|
|
static uchar getCheckCode(const QByteArray &data);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//字节数组转Ascii字符串
|
|
|
|
|
// 将字节数组转换为ASCII字符串表示,方便在需要以文本形式展示字节数据内容或者进行文本处理时使用
|
|
|
|
|
static QString byteArrayToAsciiStr(const QByteArray &data);
|
|
|
|
|
|
|
|
|
|
//16进制字符串转字节数组
|
|
|
|
|
// 将十六进制表示的字符串转换为字节数组,用于将十六进制格式的数据转换为字节形式进行后续处理,比如解析十六进制编码的文件内容等
|
|
|
|
|
static QByteArray hexStrToByteArray(const QString &str);
|
|
|
|
|
// 辅助函数,用于将十六进制字符(单个字符)转换为对应的字节值,供hexStrToByteArray等函数内部使用
|
|
|
|
|
static char convertHexChar(char ch);
|
|
|
|
|
|
|
|
|
|
//Ascii字符串转字节数组
|
|
|
|
|
// 将ASCII字符串转换为字节数组,与byteArrayToAsciiStr相对应,用于将文本形式的ASCII数据转换为字节形式进行处理
|
|
|
|
|
static QByteArray asciiStrToByteArray(const QString &str);
|
|
|
|
|
|
|
|
|
|
//字节数组转16进制字符串
|
|
|
|
|
// 将字节数组转换为十六进制表示的字符串,用于将字节数据以十六进制格式展示出来,比如在调试、数据查看等场景下方便查看字节数据内容
|
|
|
|
|
static QString byteArrayToHexStr(const QByteArray &data);
|
|
|
|
|
|
|
|
|
|
//获取选择的文件
|
|
|
|
|
// 弹出文件选择对话框,根据给定的文件过滤器(指定文件类型等筛选条件)来获取用户选择的单个文件路径,默认从应用程序所在目录开始选择
|
|
|
|
|
static QString getFileName(const QString &filter, QString defaultDir = QCoreApplication::applicationDirPath());
|
|
|
|
|
|
|
|
|
|
//获取选择的文件集合
|
|
|
|
|
// 弹出文件选择对话框,根据给定的文件过滤器获取用户选择的多个文件路径,默认从应用程序所在目录开始选择,返回文件路径列表
|
|
|
|
|
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地址及端口是否在线
|
|
|
|
|
// 判断指定的IP地址及端口是否在线(是否可连接),传入IP地址、端口号以及超时时间(默认1000毫秒),常用于网络检测相关功能
|
|
|
|
|
static bool ipLive(const QString &ip, int port, int timeout = 1000);
|
|
|
|
|
|
|
|
|
|
//获取网页所有源代码
|
|
|
|
|
// 获取指定网页的所有源代码内容,传入网页的URL地址,可用于网页数据抓取、分析等需求
|
|
|
|
|
static QString getHtml(const QString &url);
|
|
|
|
|
|
|
|
|
|
//获取本机公网IP地址
|
|
|
|
|
// 从给定的网页源代码(字符串形式)中获取本机的公网IP地址,用于获取网络相关信息,比如显示本机在网络中的公网IP情况
|
|
|
|
|
static QString getNetIP(const QString &webCode);
|
|
|
|
|
|
|
|
|
|
//获取本机IP
|
|
|
|
|
// 获取本机的IP地址(本地局域网IP等情况),用于在本地网络环境中确定本机的网络标识
|
|
|
|
|
static QString getLocalIP();
|
|
|
|
|
|
|
|
|
|
//Url地址转为IP地址
|
|
|
|
|
// 将给定的URL地址转换为对应的IP地址,用于网络地址转换相关的操作,比如某些网络配置、解析场景
|
|
|
|
|
static QString urlToIP(const QString &url);
|
|
|
|
|
|
|
|
|
|
//判断是否通外网
|
|
|
|
|
// 判断本机是否能连通外网,返回布尔值,常用于网络连接状态检测等功能,比如判断程序是否能正常访问互联网资源
|
|
|
|
|
static bool isWebOk();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//弹出消息框
|
|
|
|
|
// 弹出一个消息提示框,显示给定的信息内容,可指定自动关闭的时间(默认不自动关闭),用于向用户展示一些提示性信息
|
|
|
|
|
static void showMessageBoxInfo(const QString &info, int closeSec = 0);
|
|
|
|
|
//弹出错误框
|
|
|
|
|
// 弹出一个错误提示框,显示给定的错误信息内容,可指定自动关闭的时间(默认不自动关闭),用于在出现错误情况时告知用户
|
|
|
|
|
static void showMessageBoxError(const QString &info, int closeSec = 0);
|
|
|
|
|
//弹出询问框
|
|
|
|
|
// 弹出一个询问框,显示给定的询问信息内容,返回用户的选择结果(比如确定、取消等对应的整数值),用于获取用户在某些操作上的确认情况
|
|
|
|
|
static int showMessageBoxQuestion(const QString &info);
|
|
|
|
|
|
|
|
|
|
//弹出输入框
|
|
|
|
|
// 弹出一个输入框,让用户输入内容,返回用户输入的字符串,同时通过引用参数返回输入是否成功的布尔值,可设置标题、输入框类型、自动关闭时间、默认值以及是否为密码框等属性
|
|
|
|
|
static QString showInputBox(bool &ok, const QString &title, int type = 0, int closeSec = 0,
|
|
|
|
|
QString defaultValue = QString(), bool pwd = false);
|
|
|
|
|
|
|
|
|
|
//全局静态方法集合结束--------------------------------
|
|
|
|
|
// 全局静态方法集合结束--------------------------------
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
// 显式构造函数,传入父窗口指针(默认值为0,即无父窗口),用于创建QUIWidget类的实例对象
|
|
|
|
|
explicit QUIWidget(QWidget *parent = 0);
|
|
|
|
|
~QUIWidget();
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
bool eventFilter(QObject *obj, QEvent *evt);
|
|
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
bool max; //是否处于最大化状态
|
|
|
|
|
QRect location; //鼠标移动窗体后的坐标位置
|
|
|
|
|
|
|
|
|
|
QString title; //标题
|
|
|
|
|
Qt::Alignment alignment; //标题文本对齐
|
|
|
|
|
bool minHide; //最小化隐藏
|
|
|
|
|
QWidget *mainWidget; //主窗体对象
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
QLabel *getLabIco() const;
|
|
|
|
|
QLabel *getLabTitle() const;
|
|
|
|
|
QToolButton *getBtnMenu() const;
|
|
|
|
|
QPushButton *getBtnMenuMin() const;
|
|
|
|
|
QPushButton *getBtnMenuMax() const;
|
|
|
|
|
QPushButton *getBtnMenuMClose() const;
|
|
|
|
|
|
|
|
|
|
Style getStyle() const;
|
|
|
|
|
QString getTitle() const;
|
|
|
|
|
Qt::Alignment getAlignment() 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, QChar str, quint32 size = 9);
|
|
|
|
|
void setIconMain(QChar str, quint32 size = 9);
|
|
|
|
|
//设置部件图片
|
|
|
|
|
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 setMainWidget(QWidget *mainWidget);
|
|
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
|
void changeStyle(const QString &qssFile);
|
|
|
|
|
void closing();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//弹出信息框类
|
|
|
|
|
class QUIMessageBox : public QDialog
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
explicit QUIMessageBox(QWidget *parent = 0);
|
|
|
|
|
~QUIMessageBox();
|
|
|
|
|
|
|
|
|
|
static QUIMessageBox *Instance()
|
|
|
|
|
{
|
|
|
|
|
static QMutex mutex;
|
|
|
|
|
|
|
|
|
|
if (!self) {
|
|
|
|
|
QMutexLocker locker(&mutex);
|
|
|
|
|
|
|
|
|
|
if (!self) {
|
|
|
|
|
self = new QUIMessageBox;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
void closeEvent(QCloseEvent *);
|
|
|
|
|
bool eventFilter(QObject *obj, QEvent *evt);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
static QUIMessageBox *self;
|
|
|
|
|
|
|
|
|
|
QVBoxLayout *verticalLayout1;
|
|
|
|
|
QWidget *widgetTitle;
|
|
|
|
|
QHBoxLayout *horizontalLayout3;
|
|
|
|
|
QLabel *labIco;
|
|
|
|
|
QLabel *labTitle;
|
|
|
|
|
QLabel *labTime;
|
|
|
|
|
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(QChar str, quint32 size = 9);
|
|
|
|
|
void setMessage(const QString &msg, int type, int closeSec = 0);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//弹出输入框类
|
|
|
|
|
class QUIInputBox : public QDialog
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
explicit QUIInputBox(QWidget *parent = 0);
|
|
|
|
|
~QUIInputBox();
|
|
|
|
|
|
|
|
|
|
static QUIInputBox *Instance()
|
|
|
|
|
{
|
|
|
|
|
static QMutex mutex;
|
|
|
|
|
|
|
|
|
|
if (!self) {
|
|
|
|
|
QMutexLocker locker(&mutex);
|
|
|
|
|
|
|
|
|
|
if (!self) {
|
|
|
|
|
self = new QUIInputBox;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
void closeEvent(QCloseEvent *);
|
|
|
|
|
bool eventFilter(QObject *obj, QEvent *evt);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
static QUIInputBox *self;
|
|
|
|
|
|
|
|
|
|
QVBoxLayout *verticalLayout1;
|
|
|
|
|
QWidget *widgetTitle;
|
|
|
|
|
QHBoxLayout *horizontalLayout1;
|
|
|
|
|
QLabel *labIco;
|
|
|
|
|
QLabel *labTitle;
|
|
|
|
|
QLabel *labTime;
|
|
|
|
|
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(QChar str, quint32 size = 9);
|
|
|
|
|
void setParameter(const QString &title, int type = 0, int closeSec = 0,
|
|
|
|
|
QString defaultValue = QString(), bool pwd = false);
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//图形字体处理类
|
|
|
|
|
class IconHelper : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
explicit IconHelper(QObject *parent = 0);
|
|
|
|
|
static IconHelper *Instance()
|
|
|
|
|
{
|
|
|
|
|
static QMutex mutex;
|
|
|
|
|
|
|
|
|
|
if (!self) {
|
|
|
|
|
QMutexLocker locker(&mutex);
|
|
|
|
|
|
|
|
|
|
if (!self) {
|
|
|
|
|
self = new IconHelper;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setIcon(QLabel *lab, QChar c, quint32 size = 9);
|
|
|
|
|
void setIcon(QAbstractButton *btn, QChar c, quint32 size = 9);
|
|
|
|
|
QPixmap getPixmap(const QString &color, QChar c, quint32 size = 9,
|
|
|
|
|
quint32 pixWidth = 10, quint32 pixHeight = 10);
|
|
|
|
|
|
|
|
|
|
//根据按钮获取该按钮对应的图标
|
|
|
|
|
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<int> pixChar,
|
|
|
|
|
quint32 iconSize = 9, quint32 iconWidth = 10, quint32 iconHeight = 10,
|
|
|
|
|
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<int> pixChar,
|
|
|
|
|
quint32 iconSize = 9, quint32 iconWidth = 10, quint32 iconHeight = 10,
|
|
|
|
|
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 IconHelper *self; //对象自身
|
|
|
|
|
QFont iconFont; //图形字体
|
|
|
|
|
QList<QToolButton *> btns; //按钮队列
|
|
|
|
|
QList<QPixmap> pixNormal; //正常图片队列
|
|
|
|
|
QList<QPixmap> pixDark; //加深图片队列
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//全局变量控制
|
|
|
|
|
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 ConfigFile; //配置文件文件路径及名称
|
|
|
|
|
|
|
|
|
|
//样式表颜色值
|
|
|
|
|
static QString TextColor; //文字颜色
|
|
|
|
|
static QString PanelColor; //面板颜色
|
|
|
|
|
static QString BorderColor; //边框颜色
|
|
|
|
|
static QString NormalColorStart;//正常状态开始颜色
|
|
|
|
|
static QString NormalColorEnd; //正常状态结束颜色
|
|
|
|
|
static QString DarkColorStart; //加深状态开始颜色
|
|
|
|
|
static QString DarkColorEnd; //加深状态结束颜色
|
|
|
|
|
static QString HighColor; //高亮颜色
|
|
|
|
|
|
|
|
|
|
static void ReadConfig(); //读取配置文件,在main函数最开始加载程序载入
|
|
|
|
|
static void WriteConfig(); //写入配置文件,在更改配置文件程序关闭时调用
|
|
|
|
|
static void NewConfig(); //以初始值新建配置文件
|
|
|
|
|
static bool CheckConfig(); //校验配置文件
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // QUIWIDGET_H
|
|
|
|
|
// 析构函数,用于释放
|