改进部分代码
parent
a022df2d06
commit
ac85752894
|
@ -30,7 +30,8 @@ bool App::AutoConnect = false;
|
||||||
|
|
||||||
void App::readConfig()
|
void App::readConfig()
|
||||||
{
|
{
|
||||||
if (!checkConfig()) {
|
if (!QUIHelper::checkIniFile(App::ConfigFile)) {
|
||||||
|
writeConfig();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,43 +97,6 @@ void App::writeConfig()
|
||||||
set.endGroup();
|
set.endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool App::checkConfig()
|
|
||||||
{
|
|
||||||
//如果配置文件大小为0,则以初始值继续运行,并生成配置文件
|
|
||||||
QFile file(App::ConfigFile);
|
|
||||||
if (file.size() == 0) {
|
|
||||||
writeConfig();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//如果配置文件不完整,则以初始值继续运行,并生成配置文件
|
|
||||||
if (file.open(QFile::ReadOnly)) {
|
|
||||||
bool ok = true;
|
|
||||||
while (!file.atEnd()) {
|
|
||||||
QString line = file.readLine();
|
|
||||||
line = line.replace("\r", "");
|
|
||||||
line = line.replace("\n", "");
|
|
||||||
QStringList list = line.split("=");
|
|
||||||
if (list.count() == 2) {
|
|
||||||
if (list.at(1) == "") {
|
|
||||||
ok = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ok) {
|
|
||||||
writeConfig();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
writeConfig();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList App::Intervals = QStringList();
|
QStringList App::Intervals = QStringList();
|
||||||
QStringList App::Datas = QStringList();
|
QStringList App::Datas = QStringList();
|
||||||
QStringList App::Keys = QStringList();
|
QStringList App::Keys = QStringList();
|
||||||
|
|
|
@ -36,7 +36,6 @@ public:
|
||||||
//读写配置参数及其他操作
|
//读写配置参数及其他操作
|
||||||
static void readConfig(); //读取配置参数
|
static void readConfig(); //读取配置参数
|
||||||
static void writeConfig(); //写入配置参数
|
static void writeConfig(); //写入配置参数
|
||||||
static bool checkConfig(); //校验配置文件
|
|
||||||
|
|
||||||
static QStringList Intervals;
|
static QStringList Intervals;
|
||||||
static QStringList Datas;
|
static QStringList Datas;
|
||||||
|
|
|
@ -2186,6 +2186,42 @@ void QUIHelper::initFile(const QString &sourceName, const QString &targetName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool QUIHelper::checkIniFile(const QString &iniFile)
|
||||||
|
{
|
||||||
|
//如果配置文件大小为0,则以初始值继续运行,并生成配置文件
|
||||||
|
QFile file(iniFile);
|
||||||
|
if (file.size() == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//如果配置文件不完整,则以初始值继续运行,并生成配置文件
|
||||||
|
if (file.open(QFile::ReadOnly)) {
|
||||||
|
bool ok = true;
|
||||||
|
while (!file.atEnd()) {
|
||||||
|
QString line = file.readLine();
|
||||||
|
line = line.replace("\r", "");
|
||||||
|
line = line.replace("\n", "");
|
||||||
|
QStringList list = line.split("=");
|
||||||
|
|
||||||
|
if (list.count() == 2) {
|
||||||
|
if (list.at(1) == "") {
|
||||||
|
qDebug() << TIMEMS << "ini node no value" << list.at(0);
|
||||||
|
ok = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ok) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void QUIHelper::setIconBtn(QAbstractButton *btn, const QString &png, const QChar &str)
|
void QUIHelper::setIconBtn(QAbstractButton *btn, const QString &png, const QChar &str)
|
||||||
{
|
{
|
||||||
int size = 16;
|
int size = 16;
|
||||||
|
|
|
@ -601,6 +601,9 @@ public:
|
||||||
//初始化文件,不存在则拷贝
|
//初始化文件,不存在则拷贝
|
||||||
static void initFile(const QString &sourceName, const QString &targetName);
|
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 setIconBtn(QAbstractButton *btn, const QString &png, const QChar &str);
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,8 @@ bool App::HexData2 = false;
|
||||||
|
|
||||||
void App::readConfig()
|
void App::readConfig()
|
||||||
{
|
{
|
||||||
if (!checkConfig()) {
|
if (!QUIHelper::checkIniFile(App::ConfigFile)) {
|
||||||
|
writeConfig();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,48 +48,3 @@ void App::writeConfig()
|
||||||
set.setValue("HexData2", App::HexData2);
|
set.setValue("HexData2", App::HexData2);
|
||||||
set.endGroup();
|
set.endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::newConfig()
|
|
||||||
{
|
|
||||||
#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0))
|
|
||||||
#endif
|
|
||||||
writeConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool App::checkConfig()
|
|
||||||
{
|
|
||||||
//如果配置文件大小为0,则以初始值继续运行,并生成配置文件
|
|
||||||
QFile file(App::ConfigFile);
|
|
||||||
if (file.size() == 0) {
|
|
||||||
newConfig();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//如果配置文件不完整,则以初始值继续运行,并生成配置文件
|
|
||||||
if (file.open(QFile::ReadOnly)) {
|
|
||||||
bool ok = true;
|
|
||||||
while (!file.atEnd()) {
|
|
||||||
QString line = file.readLine();
|
|
||||||
line = line.replace("\r", "");
|
|
||||||
line = line.replace("\n", "");
|
|
||||||
QStringList list = line.split("=");
|
|
||||||
|
|
||||||
if (list.count() == 2) {
|
|
||||||
if (list.at(1) == "") {
|
|
||||||
ok = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ok) {
|
|
||||||
newConfig();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
newConfig();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
|
@ -21,9 +21,6 @@ public:
|
||||||
//读写配置参数及其他操作
|
//读写配置参数及其他操作
|
||||||
static void readConfig(); //读取配置参数
|
static void readConfig(); //读取配置参数
|
||||||
static void writeConfig(); //写入配置参数
|
static void writeConfig(); //写入配置参数
|
||||||
static void newConfig(); //以初始值新建配置文件
|
|
||||||
static bool checkConfig(); //校验配置文件
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // APP_H
|
#endif // APP_H
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -9,21 +9,27 @@
|
||||||
#define STRDATETIME 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"))
|
#define STRDATETIMEMS qPrintable(QDateTime::currentDateTime().toString("yyyy-MM-dd-HH-mm-ss-zzz"))
|
||||||
|
|
||||||
|
//定义换行符
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
#define NEWLINE "\r\n"
|
#define NEWLINE "\r\n"
|
||||||
#else
|
#else
|
||||||
#define NEWLINE "\n"
|
#define NEWLINE "\n"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//定义无边框标题栏高度+对话框最小宽高
|
||||||
#ifdef __arm__
|
#ifdef __arm__
|
||||||
#define TitleMinSize 40
|
#define TitleMinSize 40
|
||||||
|
#define DialogMinWidth 350
|
||||||
|
#define DialogMinHeight 180
|
||||||
#else
|
#else
|
||||||
#define TitleMinSize 30
|
#define TitleMinSize 30
|
||||||
|
#define DialogMinWidth 280
|
||||||
|
#define DialogMinHeight 150
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* QUI无边框窗体控件 作者:feiyangqingyun(QQ:517216493)
|
* QUI无边框窗体控件 作者:feiyangqingyun(QQ:517216493)
|
||||||
* 1:内置 N >= 12 套精美样式,可直接切换,也可自定义样式路径
|
* 1:内置 N >= 17 套精美样式,可直接切换,也可自定义样式路径
|
||||||
* 2:可设置部件(左上角图标/最小化按钮/最大化按钮/关闭按钮)的图标或者图片及是否可见
|
* 2:可设置部件(左上角图标/最小化按钮/最大化按钮/关闭按钮)的图标或者图片及是否可见
|
||||||
* 3:可集成设计师插件,直接拖曳使用,所见即所得
|
* 3:可集成设计师插件,直接拖曳使用,所见即所得
|
||||||
* 4:如果需要窗体可拖动大小,设置 setSizeGripEnabled(true);
|
* 4:如果需要窗体可拖动大小,设置 setSizeGripEnabled(true);
|
||||||
|
@ -31,15 +37,16 @@
|
||||||
* 6:可弹出消息框,可选阻塞模式和不阻塞,默认不阻塞 showMessageBoxInfo
|
* 6:可弹出消息框,可选阻塞模式和不阻塞,默认不阻塞 showMessageBoxInfo
|
||||||
* 7:可弹出错误框,可选阻塞模式和不阻塞,默认不阻塞 showMessageBoxError
|
* 7:可弹出错误框,可选阻塞模式和不阻塞,默认不阻塞 showMessageBoxError
|
||||||
* 8:可弹出询问框 showMessageBoxError
|
* 8:可弹出询问框 showMessageBoxError
|
||||||
* 9:可弹出输入框 showInputBox
|
* 9:可弹出右下角信息框 showTipBox
|
||||||
* 10:消息框支持设置倒计时关闭
|
* 10:可弹出输入框 showInputBox
|
||||||
* 11:集成图形字体设置方法及根据指定文字获取图片
|
* 11:可弹出时间范围选择框 showDateSelect
|
||||||
* 12:集成设置窗体居中显示/设置翻译文件/设置编码/设置延时/设置系统时间等静态方法
|
* 12:消息框支持设置倒计时关闭
|
||||||
* 13:集成获取应用程序文件名/文件路径 等方法
|
* 13:集成图形字体设置方法及根据指定文字获取图片
|
||||||
|
* 14:集成设置窗体居中显示/设置翻译文件/设置编码/设置延时/设置系统时间等静态方法
|
||||||
|
* 15:集成获取应用程序文件名/文件路径 等方法
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "head.h"
|
#include "head.h"
|
||||||
#include "app.h"
|
|
||||||
|
|
||||||
#ifdef quc
|
#ifdef quc
|
||||||
#if (QT_VERSION < QT_VERSION_CHECK(5,7,0))
|
#if (QT_VERSION < QT_VERSION_CHECK(5,7,0))
|
||||||
|
@ -58,6 +65,8 @@ class QUIWidget : public QDialog
|
||||||
Q_ENUMS(Style)
|
Q_ENUMS(Style)
|
||||||
Q_PROPERTY(QString title READ getTitle WRITE setTitle)
|
Q_PROPERTY(QString title READ getTitle WRITE setTitle)
|
||||||
Q_PROPERTY(Qt::Alignment alignment READ getAlignment WRITE setAlignment)
|
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:
|
public:
|
||||||
//将部分对象作为枚举值暴露给外部
|
//将部分对象作为枚举值暴露给外部
|
||||||
|
@ -81,10 +90,14 @@ public:
|
||||||
Style_DarkGray = 6, //深灰色样式
|
Style_DarkGray = 6, //深灰色样式
|
||||||
Style_Black = 7, //黑色样式
|
Style_Black = 7, //黑色样式
|
||||||
Style_LightBlack = 8, //浅黑色样式
|
Style_LightBlack = 8, //浅黑色样式
|
||||||
Style_DarkBlack = 12, //深黑色样式
|
Style_DarkBlack = 9, //深黑色样式
|
||||||
Style_PSBlack = 10, //PS黑色样式
|
Style_PSBlack = 10, //PS黑色样式
|
||||||
Style_FlatBlack = 11, //黑色扁平样式
|
Style_FlatBlack = 11, //黑色扁平样式
|
||||||
Style_FlatWhite = 12 //白色扁平样式
|
Style_FlatWhite = 12, //白色扁平样式
|
||||||
|
Style_FlatBlue = 13, //蓝色扁平样式
|
||||||
|
Style_Purple = 14, //紫色样式
|
||||||
|
Style_BlackBlue = 15, //黑蓝色样式
|
||||||
|
Style_BlackVideo = 16 //视频监控黑色样式
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -92,7 +105,7 @@ public:
|
||||||
~QUIWidget();
|
~QUIWidget();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool eventFilter(QObject *obj, QEvent *evt);
|
bool eventFilter(QObject *watched, QEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVBoxLayout *verticalLayout1;
|
QVBoxLayout *verticalLayout1;
|
||||||
|
@ -115,6 +128,7 @@ private:
|
||||||
QString title; //标题
|
QString title; //标题
|
||||||
Qt::Alignment alignment;//标题文本对齐
|
Qt::Alignment alignment;//标题文本对齐
|
||||||
bool minHide; //最小化隐藏
|
bool minHide; //最小化隐藏
|
||||||
|
bool exitAll; //退出整个程序
|
||||||
QWidget *mainWidget; //主窗体对象
|
QWidget *mainWidget; //主窗体对象
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -125,9 +139,10 @@ public:
|
||||||
QPushButton *getBtnMenuMax() const;
|
QPushButton *getBtnMenuMax() const;
|
||||||
QPushButton *getBtnMenuMClose() const;
|
QPushButton *getBtnMenuMClose() const;
|
||||||
|
|
||||||
Style getStyle() const;
|
|
||||||
QString getTitle() const;
|
QString getTitle() const;
|
||||||
Qt::Alignment getAlignment() const;
|
Qt::Alignment getAlignment() const;
|
||||||
|
bool getMinHide() const;
|
||||||
|
bool getExitAll() const;
|
||||||
|
|
||||||
QSize sizeHint() const;
|
QSize sizeHint() const;
|
||||||
QSize minimumSizeHint() const;
|
QSize minimumSizeHint() const;
|
||||||
|
@ -144,8 +159,8 @@ private slots:
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
//设置部件图标
|
//设置部件图标
|
||||||
void setIcon(QUIWidget::Widget widget, QChar str, quint32 size = 12);
|
void setIcon(QUIWidget::Widget widget, const QChar &str, quint32 size = 12);
|
||||||
void setIconMain(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 setPixmap(QUIWidget::Widget widget, const QString &file, const QSize &size = QSize(16, 16));
|
||||||
//设置部件是否可见
|
//设置部件是否可见
|
||||||
|
@ -165,6 +180,9 @@ public Q_SLOTS:
|
||||||
//设置最小化隐藏
|
//设置最小化隐藏
|
||||||
void setMinHide(bool minHide);
|
void setMinHide(bool minHide);
|
||||||
|
|
||||||
|
//设置退出时候直接退出整个应用程序
|
||||||
|
void setExitAll(bool exitAll);
|
||||||
|
|
||||||
//设置主窗体
|
//设置主窗体
|
||||||
void setMainWidget(QWidget *mainWidget);
|
void setMainWidget(QWidget *mainWidget);
|
||||||
|
|
||||||
|
@ -184,18 +202,19 @@ public:
|
||||||
~QUIMessageBox();
|
~QUIMessageBox();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void showEvent(QShowEvent *);
|
||||||
void closeEvent(QCloseEvent *);
|
void closeEvent(QCloseEvent *);
|
||||||
bool eventFilter(QObject *obj, QEvent *evt);
|
bool eventFilter(QObject *watched, QEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static QUIMessageBox *self;
|
static QScopedPointer<QUIMessageBox> self;
|
||||||
|
|
||||||
QVBoxLayout *verticalLayout1;
|
QVBoxLayout *verticalLayout1;
|
||||||
QWidget *widgetTitle;
|
QWidget *widgetTitle;
|
||||||
QHBoxLayout *horizontalLayout3;
|
QHBoxLayout *horizontalLayout3;
|
||||||
QLabel *labIco;
|
QLabel *labIco;
|
||||||
QLabel *labTitle;
|
QLabel *labTitle;
|
||||||
QLabel *labTime;
|
QLabel *labCountDown;
|
||||||
QWidget *widgetMenu;
|
QWidget *widgetMenu;
|
||||||
QHBoxLayout *horizontalLayout4;
|
QHBoxLayout *horizontalLayout4;
|
||||||
QPushButton *btnMenu_Close;
|
QPushButton *btnMenu_Close;
|
||||||
|
@ -226,10 +245,64 @@ private slots:
|
||||||
void on_btnMenu_Close_clicked();
|
void on_btnMenu_Close_clicked();
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void setIconMain(QChar str, quint32 size = 12);
|
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);
|
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
|
class QUIInputBox : public QDialog
|
||||||
{
|
{
|
||||||
|
@ -241,18 +314,19 @@ public:
|
||||||
~QUIInputBox();
|
~QUIInputBox();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void showEvent(QShowEvent *);
|
||||||
void closeEvent(QCloseEvent *);
|
void closeEvent(QCloseEvent *);
|
||||||
bool eventFilter(QObject *obj, QEvent *evt);
|
bool eventFilter(QObject *watched, QEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static QUIInputBox *self;
|
static QScopedPointer<QUIInputBox> self;
|
||||||
|
|
||||||
QVBoxLayout *verticalLayout1;
|
QVBoxLayout *verticalLayout1;
|
||||||
QWidget *widgetTitle;
|
QWidget *widgetTitle;
|
||||||
QHBoxLayout *horizontalLayout1;
|
QHBoxLayout *horizontalLayout1;
|
||||||
QLabel *labIco;
|
QLabel *labIco;
|
||||||
QLabel *labTitle;
|
QLabel *labTitle;
|
||||||
QLabel *labTime;
|
QLabel *labCountDown;
|
||||||
QWidget *widgetMenu;
|
QWidget *widgetMenu;
|
||||||
QHBoxLayout *horizontalLayout2;
|
QHBoxLayout *horizontalLayout2;
|
||||||
QPushButton *btnMenu_Close;
|
QPushButton *btnMenu_Close;
|
||||||
|
@ -286,9 +360,10 @@ public:
|
||||||
QString getValue()const;
|
QString getValue()const;
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void setIconMain(QChar str, quint32 size = 12);
|
void setIconMain(const QChar &str, quint32 size = 12);
|
||||||
void setParameter(const QString &title, int type = 0, int closeSec = 0,
|
void setParameter(const QString &title, int type = 0, int closeSec = 0,
|
||||||
QString defaultValue = QString(), bool pwd = false);
|
QString placeholderText = QString(), bool pwd = false,
|
||||||
|
const QString &defaultValue = QString());
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -303,10 +378,11 @@ public:
|
||||||
~QUIDateSelect();
|
~QUIDateSelect();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool eventFilter(QObject *obj, QEvent *evt);
|
void showEvent(QShowEvent *);
|
||||||
|
bool eventFilter(QObject *watched, QEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static QUIDateSelect *self;
|
static QScopedPointer<QUIDateSelect> self;
|
||||||
|
|
||||||
QVBoxLayout *verticalLayout;
|
QVBoxLayout *verticalLayout;
|
||||||
QWidget *widgetTitle;
|
QWidget *widgetTitle;
|
||||||
|
@ -346,11 +422,162 @@ public:
|
||||||
QString getEndDateTime() const;
|
QString getEndDateTime() const;
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void setIconMain(QChar str, quint32 size = 12);
|
void setIconMain(const QChar &str, quint32 size = 12);
|
||||||
void setFormat(const QString &format);
|
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
|
class QUIHelper : public QObject
|
||||||
{
|
{
|
||||||
|
@ -360,20 +587,35 @@ public:
|
||||||
static int deskWidth();
|
static int deskWidth();
|
||||||
static int deskHeight();
|
static int deskHeight();
|
||||||
|
|
||||||
//程序本身文件名称
|
//程序文件名称+当前所在路径
|
||||||
static QString appName();
|
static QString appName();
|
||||||
//程序当前所在路径
|
|
||||||
static QString appPath();
|
static QString appPath();
|
||||||
|
|
||||||
//初始化随机数种子
|
//初始化随机数种子
|
||||||
static void initRand();
|
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 newDir(const QString &dirName);
|
||||||
|
|
||||||
//写入消息到额外的的消息日志文件
|
//写入消息到额外的的消息日志文件
|
||||||
static void writeInfo(const QString &info, const QString &filePath = "log");
|
static void writeInfo(const QString &info, bool needWrite = false, const QString &filePath = "log");
|
||||||
static void writeError(const QString &info, 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(QUIWidget::Style style);
|
||||||
|
@ -396,7 +638,7 @@ public:
|
||||||
static QPixmap ninePatch(const QPixmap &pix, 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);
|
static void setLabStyle(QLabel *lab, quint8 type, const QString &bgColor = "", const QString &textColor = "");
|
||||||
|
|
||||||
//设置窗体居中显示
|
//设置窗体居中显示
|
||||||
static void setFormInCenter(QWidget *frm);
|
static void setFormInCenter(QWidget *frm);
|
||||||
|
@ -404,49 +646,48 @@ public:
|
||||||
static void setTranslator(const QString &qmFile = ":/image/qt_zh_CN.qm");
|
static void setTranslator(const QString &qmFile = ":/image/qt_zh_CN.qm");
|
||||||
//设置编码
|
//设置编码
|
||||||
static void setCode();
|
static void setCode();
|
||||||
|
//设置字体
|
||||||
|
static void setFont(const QString &ttfFile = ":/image/DroidSansFallback.ttf",
|
||||||
|
const QString &fontName = "Microsoft Yahei", int fontSize = 12);
|
||||||
//设置延时
|
//设置延时
|
||||||
static void sleep(int sec);
|
static void sleep(int msec);
|
||||||
//设置系统时间
|
//设置系统时间
|
||||||
static void setSystemDateTime(const QString &year, const QString &month, const QString &day,
|
static void setSystemDateTime(const QString &year, const QString &month, const QString &day,
|
||||||
const QString &hour, const QString &min, const QString &sec);
|
const QString &hour, const QString &min, const QString &sec);
|
||||||
//设置开机自启动
|
//设置开机自启动
|
||||||
static void runWithSystem(const QString &strName, const QString &strPath, bool autoRun = true);
|
static void runWithSystem(const QString &strName, const QString &strPath, bool autoRun = true);
|
||||||
|
|
||||||
|
//从字符串获取IP地址
|
||||||
|
static QString getIP(const QString &url);
|
||||||
//判断是否是IP地址
|
//判断是否是IP地址
|
||||||
static bool isIP(const QString &ip);
|
static bool isIP(const QString &ip);
|
||||||
|
|
||||||
//判断是否是MAC地址
|
//判断是否是MAC地址
|
||||||
static bool isMac(const QString &mac);
|
static bool isMac(const QString &mac);
|
||||||
|
|
||||||
//判断是否是合法的电话号码
|
//判断是否是合法的电话号码
|
||||||
static bool isTel(const QString &tel);
|
static bool isTel(const QString &tel);
|
||||||
|
|
||||||
//判断是否是合法的邮箱地址
|
//判断是否是合法的邮箱地址
|
||||||
static bool isEmail(const QString &email);
|
static bool isEmail(const QString &email);
|
||||||
|
|
||||||
|
//IP地址字符串与整型转换
|
||||||
|
static QString ipv4IntToString(quint32 ip);
|
||||||
|
static quint32 ipv4StringToInt(const QString &ip);
|
||||||
|
|
||||||
//16进制字符串转10进制
|
//16进制字符串转10进制
|
||||||
static int strHexToDecimal(const QString &strHex);
|
static int strHexToDecimal(const QString &strHex);
|
||||||
|
|
||||||
//10进制字符串转10进制
|
//10进制字符串转10进制
|
||||||
static int strDecimalToDecimal(const QString &strDecimal);
|
static int strDecimalToDecimal(const QString &strDecimal);
|
||||||
|
|
||||||
//2进制字符串转10进制
|
//2进制字符串转10进制
|
||||||
static int strBinToDecimal(const QString &strBin);
|
static int strBinToDecimal(const QString &strBin);
|
||||||
|
|
||||||
//16进制字符串转2进制字符串
|
//16进制字符串转2进制字符串
|
||||||
static QString strHexToStrBin(const QString &strHex);
|
static QString strHexToStrBin(const QString &strHex);
|
||||||
|
|
||||||
//10进制转2进制字符串一个字节
|
//10进制转2进制字符串一个字节
|
||||||
static QString decimalToStrBin1(int decimal);
|
static QString decimalToStrBin1(int decimal);
|
||||||
|
|
||||||
//10进制转2进制字符串两个字节
|
//10进制转2进制字符串两个字节
|
||||||
static QString decimalToStrBin2(int decimal);
|
static QString decimalToStrBin2(int decimal);
|
||||||
|
|
||||||
//10进制转16进制字符串,补零.
|
//10进制转16进制字符串,补零.
|
||||||
static QString decimalToStrHex(int decimal);
|
static QString decimalToStrHex(int decimal);
|
||||||
|
|
||||||
|
|
||||||
//int转字节数组
|
//int转字节数组
|
||||||
static QByteArray intToByte(int i);
|
static QByteArray intToByte(int i);
|
||||||
static QByteArray intToByteRec(int i);
|
static QByteArray intToByteRec(int i);
|
||||||
|
@ -454,6 +695,8 @@ public:
|
||||||
//字节数组转int
|
//字节数组转int
|
||||||
static int byteToInt(const QByteArray &data);
|
static int byteToInt(const QByteArray &data);
|
||||||
static int byteToIntRec(const QByteArray &data);
|
static int byteToIntRec(const QByteArray &data);
|
||||||
|
static quint32 byteToUInt(const QByteArray &data);
|
||||||
|
static quint32 byteToUIntRec(const QByteArray &data);
|
||||||
|
|
||||||
//ushort转字节数组
|
//ushort转字节数组
|
||||||
static QByteArray ushortToByte(ushort i);
|
static QByteArray ushortToByte(ushort i);
|
||||||
|
@ -465,85 +708,77 @@ public:
|
||||||
|
|
||||||
//异或加密算法
|
//异或加密算法
|
||||||
static QString getXorEncryptDecrypt(const QString &str, char key);
|
static QString getXorEncryptDecrypt(const QString &str, char key);
|
||||||
|
|
||||||
//异或校验
|
//异或校验
|
||||||
static uchar getOrCode(const QByteArray &data);
|
static uchar getOrCode(const QByteArray &data);
|
||||||
|
|
||||||
//计算校验码
|
//计算校验码
|
||||||
static uchar getCheckCode(const QByteArray &data);
|
static uchar getCheckCode(const QByteArray &data);
|
||||||
|
|
||||||
//字符串补全
|
|
||||||
static QString getValue(quint8 value);
|
|
||||||
|
|
||||||
//CRC校验
|
//CRC校验
|
||||||
static quint16 getRevCrc_16(quint8 *data, int len, quint16 init, const quint16 *table);
|
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 getCrc_16(quint8 *data, int len, quint16 init, const quint16 *table);
|
||||||
static quint16 getModbus16(quint8 *data, int len);
|
static quint16 getModbus16(quint8 *data, int len);
|
||||||
static QByteArray getCRCCode(const QByteArray &data);
|
static QByteArray getCRCCode(const QByteArray &data);
|
||||||
|
|
||||||
|
//字节数组与Ascii字符串互转
|
||||||
//字节数组转Ascii字符串
|
static void initAsciiStr();
|
||||||
static QString byteArrayToAsciiStr(const QByteArray &data);
|
static QString byteArrayToAsciiStr(const QByteArray &data);
|
||||||
|
static QByteArray asciiStrToByteArray(const QString &data);
|
||||||
|
|
||||||
//16进制字符串转字节数组
|
//16进制字符串与字节数组互转
|
||||||
static QByteArray hexStrToByteArray(const QString &str);
|
static char hexStrToChar(char data);
|
||||||
static char convertHexChar(char ch);
|
static QByteArray hexStrToByteArray(const QString &data);
|
||||||
|
|
||||||
//Ascii字符串转字节数组
|
|
||||||
static QByteArray asciiStrToByteArray(const QString &str);
|
|
||||||
|
|
||||||
//字节数组转16进制字符串
|
|
||||||
static QString byteArrayToHexStr(const QByteArray &data);
|
static QString byteArrayToHexStr(const QByteArray &data);
|
||||||
|
|
||||||
//获取保存的文件
|
//获取保存的文件
|
||||||
static QString getSaveName(const QString &filter, QString defaultDir = QCoreApplication::applicationDirPath());
|
static QString getSaveName(const QString &filter, QString defaultDir = QCoreApplication::applicationDirPath());
|
||||||
|
|
||||||
//获取选择的文件
|
//获取选择的文件
|
||||||
static QString getFileName(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 QStringList getFileNames(const QString &filter, QString defaultDir = QCoreApplication::applicationDirPath());
|
||||||
|
|
||||||
//获取选择的目录
|
//获取选择的目录
|
||||||
static QString getFolderName();
|
static QString getFolderName();
|
||||||
|
|
||||||
//获取文件名,含拓展名
|
//获取文件名,含拓展名
|
||||||
static QString getFileNameWithExtension(const QString &strFilePath);
|
static QString getFileNameWithExtension(const QString &strFilePath);
|
||||||
|
|
||||||
//获取选择文件夹中的文件
|
//获取选择文件夹中的文件
|
||||||
static QStringList getFolderFileNames(const QStringList &filter);
|
static QStringList getFolderFileNames(const QStringList &filter);
|
||||||
|
|
||||||
//文件夹是否存在
|
//文件夹是否存在
|
||||||
static bool folderIsExist(const QString &strFolder);
|
static bool folderIsExist(const QString &strFolder);
|
||||||
|
|
||||||
//文件是否存在
|
//文件是否存在
|
||||||
static bool fileIsExist(const QString &strFile);
|
static bool fileIsExist(const QString &strFile);
|
||||||
|
|
||||||
//复制文件
|
//复制文件
|
||||||
static bool copyFile(const QString &sourceFile, const QString &targetFile);
|
static bool copyFile(const QString &sourceFile, const QString &targetFile);
|
||||||
|
|
||||||
//删除文件夹下所有文件
|
//删除文件夹下所有文件
|
||||||
static void deleteDirectory(const QString &path);
|
static void deleteDirectory(const QString &path);
|
||||||
|
|
||||||
//判断IP地址及端口是否在线
|
//判断IP地址及端口是否在线
|
||||||
static bool ipLive(const QString &ip, int port, int timeout = 1000);
|
static bool ipLive(const QString &ip, int port, int timeout = 1000);
|
||||||
|
|
||||||
//获取网页所有源代码
|
//获取网页所有源代码
|
||||||
static QString getHtml(const QString &url);
|
static QString getHtml(const QString &url);
|
||||||
|
|
||||||
//获取本机公网IP地址
|
//获取本机公网IP地址
|
||||||
static QString getNetIP(const QString &webCode);
|
static QString getNetIP(const QString &html);
|
||||||
|
|
||||||
//获取本机IP
|
//获取本机IP
|
||||||
static QString getLocalIP();
|
static QString getLocalIP();
|
||||||
|
//获取本机IP地址集合
|
||||||
|
static QStringList getLocalIPs();
|
||||||
//Url地址转为IP地址
|
//Url地址转为IP地址
|
||||||
static QString urlToIP(const QString &url);
|
static QString urlToIP(const QString &url);
|
||||||
|
|
||||||
|
//字符串补全
|
||||||
|
static QString getValue(quint8 value);
|
||||||
//判断是否通外网
|
//判断是否通外网
|
||||||
static bool isWebOk();
|
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 showMessageBoxInfo(const QString &info, int closeSec = 0, bool exec = false);
|
||||||
//弹出错误框
|
//弹出错误框
|
||||||
|
@ -551,70 +786,64 @@ public:
|
||||||
//弹出询问框
|
//弹出询问框
|
||||||
static int showMessageBoxQuestion(const QString &info);
|
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,
|
static QString showInputBox(const QString &title, int type = 0, int closeSec = 0,
|
||||||
QString defaultValue = QString(), bool pwd = false);
|
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 showDateSelect(QString &dateStart, QString &dateEnd, const QString &format = "yyyy-MM-dd");
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
//图形字体处理类
|
//设置按钮样式
|
||||||
class IconHelper : public QObject
|
static QString setPushButtonQss(QPushButton *btn, //按钮对象
|
||||||
{
|
int radius = 5, //圆角半径
|
||||||
Q_OBJECT
|
int padding = 8, //间距
|
||||||
|
const QString &normalColor = "#34495E", //正常颜色
|
||||||
public:
|
const QString &normalTextColor = "#FFFFFF", //文字颜色
|
||||||
static IconHelper *Instance();
|
const QString &hoverColor = "#4E6D8C", //悬停颜色
|
||||||
explicit IconHelper(QObject *parent = 0);
|
const QString &hoverTextColor = "#F0F0F0", //悬停文字颜色
|
||||||
|
const QString &pressedColor = "#2D3E50", //按下颜色
|
||||||
void setIcon(QLabel *lab, QChar c, quint32 size = 12);
|
const QString &pressedTextColor = "#B8C6D1"); //按下文字颜色
|
||||||
void setIcon(QAbstractButton *btn, QChar c, quint32 size = 12);
|
//设置文本框样式
|
||||||
QPixmap getPixmap(const QString &color, QChar c, quint32 size = 12,
|
static QString setLineEditQss(QLineEdit *txt, //文本框对象
|
||||||
quint32 pixWidth = 10, quint32 pixHeight = 10);
|
int radius = 3, //圆角半径
|
||||||
|
int borderWidth = 2, //边框大小
|
||||||
//根据按钮获取该按钮对应的图标
|
const QString &normalColor = "#DCE4EC", //正常颜色
|
||||||
QPixmap getPixmap(QToolButton *btn, bool normal);
|
const QString &focusColor = "#34495E"); //选中颜色
|
||||||
|
//设置进度条样式
|
||||||
//指定导航面板样式,不带图标
|
static QString setProgressBarQss(QProgressBar *bar,
|
||||||
static void setStyle(QWidget *widget, const QString &type = "left", int borderWidth = 3,
|
int barHeight = 8, //进度条高度
|
||||||
const QString &borderColor = "#029FEA",
|
int barRadius = 5, //进度条半径
|
||||||
const QString &normalBgColor = "#292F38",
|
int fontSize = 9, //文字字号
|
||||||
const QString &darkBgColor = "#1D2025",
|
const QString &normalColor = "#E8EDF2", //正常颜色
|
||||||
const QString &normalTextColor = "#54626F",
|
const QString &chunkColor = "#E74C3C"); //进度颜色
|
||||||
const QString &darkTextColor = "#FDFDFD");
|
//设置滑块条样式
|
||||||
|
static QString setSliderQss(QSlider *slider, //滑动条对象
|
||||||
//移除导航面板样式,防止重复
|
int sliderHeight = 8, //滑动条高度
|
||||||
void removeStyle(QList<QToolButton *> btns);
|
const QString &normalColor = "#E8EDF2", //正常颜色
|
||||||
|
const QString &grooveColor = "#1ABC9C", //滑块颜色
|
||||||
//指定QWidget导航面板样式,带图标和效果切换
|
const QString &handleBorderColor = "#1ABC9C", //指示器边框颜色
|
||||||
void setStyle(QWidget *widget, QList<QToolButton *> btns, QList<int> pixChar,
|
const QString &handleColor = "#FFFFFF", //指示器颜色
|
||||||
quint32 iconSize = 12, quint32 iconWidth = 10, quint32 iconHeight = 10,
|
const QString &textColor = "#000000"); //文字颜色
|
||||||
const QString &type = "left", int borderWidth = 3,
|
//设置单选框样式
|
||||||
const QString &borderColor = "#029FEA",
|
static QString setRadioButtonQss(QRadioButton *rbtn, //单选框对象
|
||||||
const QString &normalBgColor = "#292F38",
|
int indicatorRadius = 8, //指示器圆角角度
|
||||||
const QString &darkBgColor = "#1D2025",
|
const QString &normalColor = "#D7DBDE", //正常颜色
|
||||||
const QString &normalTextColor = "#54626F",
|
const QString &checkColor = "#34495E"); //选中颜色
|
||||||
const QString &darkTextColor = "#FDFDFD");
|
//设置滚动条样式
|
||||||
|
static QString setScrollBarQss(QWidget *scroll, //滚动条对象
|
||||||
//指定QFrame导航按钮样式,带图标
|
int radius = 6, //圆角角度
|
||||||
void setStyle(QFrame *frame, QList<QToolButton *> btns, QList<int> pixChar,
|
int min = 120, //指示器最小长度
|
||||||
quint32 iconSize = 12, quint32 iconWidth = 10, quint32 iconHeight = 10,
|
int max = 12, //滚动条最大长度
|
||||||
const QString &normalBgColor = "#2FC5A2",
|
const QString &bgColor = "#606060", //背景色
|
||||||
const QString &darkBgColor = "#3EA7E9",
|
const QString &handleNormalColor = "#34495E", //指示器正常颜色
|
||||||
const QString &normalTextColor = "#EEEEEE",
|
const QString &handleHoverColor = "#1ABC9C", //指示器悬停颜色
|
||||||
const QString &darkTextColor = "#FFFFFF");
|
const QString &handlePressedColor = "#E74C3C"); //指示器按下颜色
|
||||||
|
|
||||||
protected:
|
|
||||||
bool eventFilter(QObject *watched, QEvent *event);
|
|
||||||
|
|
||||||
private:
|
|
||||||
static IconHelper *self; //对象自身
|
|
||||||
QFont iconFont; //图形字体
|
|
||||||
QList<QToolButton *> btns; //按钮队列
|
|
||||||
QList<QPixmap> pixNormal; //正常图片队列
|
|
||||||
QList<QPixmap> pixDark; //加深图片队列
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//全局变量控制
|
//全局变量控制
|
||||||
|
|
|
@ -2,9 +2,7 @@
|
||||||
#include "ui_frmmain.h"
|
#include "ui_frmmain.h"
|
||||||
#include "quiwidget.h"
|
#include "quiwidget.h"
|
||||||
|
|
||||||
frmMain::frmMain(QWidget *parent) :
|
frmMain::frmMain(QWidget *parent) : QWidget(parent), ui(new Ui::frmMain)
|
||||||
QWidget(parent),
|
|
||||||
ui(new Ui::frmMain)
|
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
this->initForm();
|
this->initForm();
|
||||||
|
|
|
@ -7,3 +7,4 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#pragma execution_character_set("utf-8")
|
#pragma execution_character_set("utf-8")
|
||||||
|
#include "app.h"
|
||||||
|
|
|
@ -66,7 +66,8 @@ bool App::SelectAllWebServer = true;
|
||||||
|
|
||||||
void App::readConfig()
|
void App::readConfig()
|
||||||
{
|
{
|
||||||
if (!checkConfig()) {
|
if (!QUIHelper::checkIniFile(App::ConfigFile)) {
|
||||||
|
writeConfig();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,43 +219,6 @@ void App::writeConfig()
|
||||||
set.endGroup();
|
set.endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool App::checkConfig()
|
|
||||||
{
|
|
||||||
//如果配置文件大小为0,则以初始值继续运行,并生成配置文件
|
|
||||||
QFile file(App::ConfigFile);
|
|
||||||
if (file.size() == 0) {
|
|
||||||
writeConfig();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//如果配置文件不完整,则以初始值继续运行,并生成配置文件
|
|
||||||
if (file.open(QFile::ReadOnly)) {
|
|
||||||
bool ok = true;
|
|
||||||
while (!file.atEnd()) {
|
|
||||||
QString line = file.readLine();
|
|
||||||
line = line.replace("\r", "");
|
|
||||||
line = line.replace("\n", "");
|
|
||||||
QStringList list = line.split("=");
|
|
||||||
if (list.count() == 2) {
|
|
||||||
if (list.at(1) == "") {
|
|
||||||
ok = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ok) {
|
|
||||||
writeConfig();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
writeConfig();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList App::Intervals = QStringList();
|
QStringList App::Intervals = QStringList();
|
||||||
QStringList App::Datas = QStringList();
|
QStringList App::Datas = QStringList();
|
||||||
QStringList App::Keys = QStringList();
|
QStringList App::Keys = QStringList();
|
||||||
|
|
|
@ -78,7 +78,6 @@ public:
|
||||||
//读写配置参数及其他操作
|
//读写配置参数及其他操作
|
||||||
static void readConfig(); //读取配置参数
|
static void readConfig(); //读取配置参数
|
||||||
static void writeConfig(); //写入配置参数
|
static void writeConfig(); //写入配置参数
|
||||||
static bool checkConfig(); //校验配置文件
|
|
||||||
|
|
||||||
static QStringList Intervals;
|
static QStringList Intervals;
|
||||||
static QStringList Datas;
|
static QStringList Datas;
|
||||||
|
|
|
@ -2186,6 +2186,42 @@ void QUIHelper::initFile(const QString &sourceName, const QString &targetName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool QUIHelper::checkIniFile(const QString &iniFile)
|
||||||
|
{
|
||||||
|
//如果配置文件大小为0,则以初始值继续运行,并生成配置文件
|
||||||
|
QFile file(iniFile);
|
||||||
|
if (file.size() == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//如果配置文件不完整,则以初始值继续运行,并生成配置文件
|
||||||
|
if (file.open(QFile::ReadOnly)) {
|
||||||
|
bool ok = true;
|
||||||
|
while (!file.atEnd()) {
|
||||||
|
QString line = file.readLine();
|
||||||
|
line = line.replace("\r", "");
|
||||||
|
line = line.replace("\n", "");
|
||||||
|
QStringList list = line.split("=");
|
||||||
|
|
||||||
|
if (list.count() == 2) {
|
||||||
|
if (list.at(1) == "") {
|
||||||
|
qDebug() << TIMEMS << "ini node no value" << list.at(0);
|
||||||
|
ok = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ok) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void QUIHelper::setIconBtn(QAbstractButton *btn, const QString &png, const QChar &str)
|
void QUIHelper::setIconBtn(QAbstractButton *btn, const QString &png, const QChar &str)
|
||||||
{
|
{
|
||||||
int size = 16;
|
int size = 16;
|
||||||
|
|
|
@ -601,6 +601,9 @@ public:
|
||||||
//初始化文件,不存在则拷贝
|
//初始化文件,不存在则拷贝
|
||||||
static void initFile(const QString &sourceName, const QString &targetName);
|
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 setIconBtn(QAbstractButton *btn, const QString &png, const QChar &str);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue