diff --git a/comtool/main.cpp b/comtool/main.cpp index 23ec214..0be7c0f 100644 --- a/comtool/main.cpp +++ b/comtool/main.cpp @@ -12,10 +12,9 @@ int main(int argc, char *argv[]) a.setFont(font); //设置编码以及加载中文翻译文件 - QUIHelper::setCode(); - QUIHelper::setTranslator(":/qt_zh_CN.qm"); - QUIHelper::setTranslator(":/widgets.qm"); QUIHelper::initRand(); + QUIHelper::setCode(); + QUIHelper::setTranslator(); AppConfig::ConfigFile = QString("%1/%2.ini").arg(QUIHelper::appPath()).arg(QUIHelper::appName()); AppConfig::readConfig(); diff --git a/core_qui/quidateselect.h b/core_qui/quidateselect.h index ca402b4..22b023e 100644 --- a/core_qui/quidateselect.h +++ b/core_qui/quidateselect.h @@ -57,7 +57,9 @@ public: QString getEndDateTime() const; public Q_SLOTS: + //设置左上角图标 void setIconMain(int icon, quint32 size = 12); + //设置日期格式 void setFormat(const QString &format); }; diff --git a/core_qui/quihead.h b/core_qui/quihead.h index 87dc700..53d9a72 100644 --- a/core_qui/quihead.h +++ b/core_qui/quihead.h @@ -1,6 +1,7 @@ #ifndef QUIHEAD_H #define QUIHEAD_H +//日期时间字符串宏定义 #ifndef TIMEMS #define TIMEMS qPrintable(QTime::currentTime().toString("HH:mm:ss zzz")) #endif diff --git a/core_qui/quihelper.cpp b/core_qui/quihelper.cpp index a029928..ea409f5 100644 --- a/core_qui/quihelper.cpp +++ b/core_qui/quihelper.cpp @@ -190,8 +190,21 @@ void QUIHelper::setFont(const QString &ttfFile, const QString &fontName, int fon qApp->setFont(font); } +void QUIHelper::setTranslator() +{ + //以后还有其他的自行加上去就行 + QUIHelper::setTranslator(":/qm/widgets.qm"); + QUIHelper::setTranslator(":/qm/qt_zh_CN.qm"); + QUIHelper::setTranslator(":/qm/designer_zh_CN.qm"); +} + void QUIHelper::setTranslator(const QString &qmFile) { + //过滤下不存在的就不用设置了 + if (!QFile(qmFile).exists()) { + return; + } + QTranslator *translator = new QTranslator(qApp); translator->load(qmFile); qApp->installTranslator(translator); @@ -310,8 +323,13 @@ void QUIHelper::setFormShadow(QWidget *widget, QLayout *layout, const QString &c return; } + //先判断是否已经存在阴影效果 + QGraphicsDropShadowEffect *shadowEffect = (QGraphicsDropShadowEffect *)widget->graphicsEffect(); + if (shadowEffect == 0) { + shadowEffect = new QGraphicsDropShadowEffect(widget); + } + //采用系统自带的函数设置阴影 - QGraphicsDropShadowEffect *shadowEffect = new QGraphicsDropShadowEffect(widget); shadowEffect->setOffset(0, 0); shadowEffect->setColor(color); shadowEffect->setBlurRadius(radius); @@ -1316,7 +1334,8 @@ int QUIHelper::showMessageBoxQuestion(const QString &info) { if (isCustomUI) { QUIMessageBox msg; - msg.setMessage(info, 1);msg.update(); + msg.setMessage(info, 1); + msg.update(); return msg.exec(); } else { QMessageBox box(QMessageBox::Question, "询问", info); @@ -1492,6 +1511,8 @@ void QUIHelper::setLogo(QLabel *label, const QString &file, text.replace(oldColor, newColor); f.close(); + //目录不存在则新建 + QUIHelper::newDir("logo"); //打开新的文件输出 fileName = QString("%1/logo/temp.svg").arg(QUIHelper::appPath()); QFile f2(fileName); diff --git a/core_qui/quihelper.h b/core_qui/quihelper.h index 9da8e90..4c5e954 100644 --- a/core_qui/quihelper.h +++ b/core_qui/quihelper.h @@ -35,7 +35,8 @@ public: static void setFont(const QString &ttfFile = ":/font/DroidSansFallback.ttf", const QString &fontName = "Microsoft Yahei", int fontSize = 12); //设置翻译文件 - static void setTranslator(const QString &qmFile = ":/qm/qt_zh_CN.qm"); + static void setTranslator(); + static void setTranslator(const QString &qmFile); //初始化数据库 static void initDb(const QString &dbName); diff --git a/core_qui/quiinputbox.h b/core_qui/quiinputbox.h index 7ac4b1e..f6824bc 100644 --- a/core_qui/quiinputbox.h +++ b/core_qui/quiinputbox.h @@ -59,7 +59,9 @@ public: QString getValue()const; public Q_SLOTS: + //设置左上角图标 void setIconMain(int 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()); diff --git a/core_qui/quimessagebox.cpp b/core_qui/quimessagebox.cpp index 04212f1..4a8bfbd 100644 --- a/core_qui/quimessagebox.cpp +++ b/core_qui/quimessagebox.cpp @@ -31,6 +31,7 @@ void QUIMessageBox::showEvent(QShowEvent *) QUIHelper::setIconBtn(btnCancel, ":/image/btn_close.png", 0xf00d); QUIHelper::setFormInCenter(this); this->activateWindow(); + //QMetaObject::invokeMethod(this, "autoSize", Qt::QueuedConnection); } void QUIMessageBox::closeEvent(QCloseEvent *) @@ -305,7 +306,12 @@ void QUIMessageBox::setMessage(const QString &msg, int type, int closeSec) this->labInfo->setText(msg); this->setWindowTitle(this->labTitle->text()); + this->autoSize(); +} +void QUIMessageBox::autoSize() +{ + QString msg = labInfo->text(); //长度符合要求比如就两行只需要默认尺寸 bool normal = (msg.length() < 30); //计算有多少个换行符 @@ -322,10 +328,10 @@ void QUIMessageBox::setMessage(const QString &msg, int type, int closeSec) //设置对话框的大小总以最合适的大小显示 if (normal) { - this->layout()->setSizeConstraint(QLayout::SetMinimumSize); - this->setFixedSize(QUIDialogMinWidth, QUIDialogMinHeight); + //this->layout()->setSizeConstraint(QLayout::SetMinimumSize); + this->setFixedSize(QUIDialogMinWidth + 1, QUIDialogMinHeight + 1); } else { - this->layout()->setSizeConstraint(QLayout::SetFixedSize); - //this->setFixedSize(labInfo->sizeHint() + QSize(100, 120)); + //this->layout()->setSizeConstraint(QLayout::SetFixedSize); + this->setFixedSize(labInfo->sizeHint() + QSize(100, 120)); } } diff --git a/core_qui/quimessagebox.h b/core_qui/quimessagebox.h index ffa769d..1de41a1 100644 --- a/core_qui/quimessagebox.h +++ b/core_qui/quimessagebox.h @@ -56,9 +56,14 @@ private slots: void on_btnMenu_Close_clicked(); public Q_SLOTS: + //设置左上角图标 void setIconMain(int icon, quint32 size = 12); + //设置消息图标 图形字体+图片两种方式 void setIconMsg(const QString &png, int icon); + //设置提示信息带类型和关闭倒计时 void setMessage(const QString &msg, int type, int closeSec = 0); + //自适应尺寸 + void autoSize(); }; #endif // QUIMESSAGEBOX_H diff --git a/core_qui/quistyle.cpp b/core_qui/quistyle.cpp index ffaefbe..2712aae 100644 --- a/core_qui/quistyle.cpp +++ b/core_qui/quistyle.cpp @@ -68,8 +68,14 @@ void QUIStyle::setStyle(const QString &qss) list << "QTabBar::tab:right:selected,QTabBar::tab:right:hover{border-width:0px 2px 0px 0px;}"; #endif + //5.2开始颜色支持透明度 + QString txtReadOnlyColor = QUIConfig::NormalColorStart.right(6); +#if (QT_VERSION >= QT_VERSION_CHECK(5,2,0)) + txtReadOnlyColor = "88" + txtReadOnlyColor; +#endif + //增加文本框只读背景颜色 - list << QString("QLineEdit:read-only{background-color:#88%1;}").arg(QUIConfig::NormalColorStart.right(6)); + list << QString("QLineEdit:read-only{background-color:#%1;}").arg(txtReadOnlyColor); QUIHelper::isCustomUI = true; //阴影边框和配色方案自动变化 diff --git a/core_qui/quitipbox.cpp b/core_qui/quitipbox.cpp index 24480fa..c71d95f 100644 --- a/core_qui/quitipbox.cpp +++ b/core_qui/quitipbox.cpp @@ -175,7 +175,7 @@ void QUITipBox::initForm() this->labInfo->setFont(font); //显示和隐藏窗体动画效果 - animation = new QPropertyAnimation(this, "pos"); + animation = new QPropertyAnimation(this, "pos", this); animation->setDuration(500); animation->setEasingCurve(QEasingCurve::InOutQuad); } diff --git a/core_qui/quitipbox.h b/core_qui/quitipbox.h index 0b797f7..8e4f432 100644 --- a/core_qui/quitipbox.h +++ b/core_qui/quitipbox.h @@ -49,8 +49,11 @@ private slots: void on_btnMenu_Close_clicked(); public Q_SLOTS: + //设置左上角图标 void setIconMain(int icon, quint32 size = 12); + //设置提示信息 void setTip(const QString &title, const QString &tip, bool fullScreen = false, bool center = true, int closeSec = 0); + //隐藏界面 void hide(); }; diff --git a/netserver/api/tcpserver1.cpp b/netserver/api/tcpserver1.cpp index 04144a0..5a460c1 100644 --- a/netserver/api/tcpserver1.cpp +++ b/netserver/api/tcpserver1.cpp @@ -7,7 +7,11 @@ TcpClient1::TcpClient1(QObject *parent) : QTcpSocket(parent) port = 6907; deviceID = "SSJC00000001"; +#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0)) + connect(this, SIGNAL(errorOccurred(QAbstractSocket::SocketError)), this, SLOT(deleteLater())); +#else connect(this, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(deleteLater())); +#endif connect(this, SIGNAL(disconnected()), this, SLOT(deleteLater())); connect(this, SIGNAL(readyRead()), this, SLOT(readData())); } @@ -142,10 +146,10 @@ bool TcpServer1::writeData(const QString &deviceID, const QString &data) bool ok = false; foreach (TcpClient1 *client, clients) { if (client->getDeviceID() == deviceID) { - client->sendData(data); - ok = true; + client->sendData(data); + ok = true; } - } + } return ok; } diff --git a/netserver/api/tcpserver2.cpp b/netserver/api/tcpserver2.cpp index f967cdd..1d91ee5 100644 --- a/netserver/api/tcpserver2.cpp +++ b/netserver/api/tcpserver2.cpp @@ -7,7 +7,11 @@ TcpClient2::TcpClient2(QObject *parent) : QTcpSocket(parent) port = 6908; deviceID = "SSJC00000001"; +#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0)) + connect(this, SIGNAL(errorOccurred(QAbstractSocket::SocketError)), this, SLOT(deleteLater())); +#else connect(this, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(deleteLater())); +#endif connect(this, SIGNAL(disconnected()), this, SLOT(deleteLater())); connect(this, SIGNAL(readyRead()), this, SLOT(readData())); } diff --git a/netserver/main.cpp b/netserver/main.cpp index ba25600..32654e4 100644 --- a/netserver/main.cpp +++ b/netserver/main.cpp @@ -12,10 +12,9 @@ int main(int argc, char *argv[]) a.setFont(font); //设置编码以及加载中文翻译文件 - QUIHelper::setCode(); - QUIHelper::setTranslator(":/qt_zh_CN.qm"); - QUIHelper::setTranslator(":/widgets.qm"); QUIHelper::initRand(); + QUIHelper::setCode(); + QUIHelper::setTranslator(); AppConfig::ConfigFile = QString("%1/%2.ini").arg(QUIHelper::appPath()).arg(QUIHelper::appName()); AppConfig::readConfig(); diff --git a/nettool/main.cpp b/nettool/main.cpp index f802695..c5d849b 100644 --- a/nettool/main.cpp +++ b/nettool/main.cpp @@ -7,11 +7,10 @@ int main(int argc, char *argv[]) a.setWindowIcon(QIcon(":/main.ico")); //设置编码+字体+中文翻译文件 + QUIHelper::initRand(); QUIHelper::setCode(); QUIHelper::setFont(":/DroidSansFallback.ttf"); - QUIHelper::setTranslator(":/qt_zh_CN.qm"); - QUIHelper::setTranslator(":/widgets.qm"); - QUIHelper::initRand(); + QUIHelper::setTranslator(); AppConfig::ConfigFile = QString("%1/%2.ini").arg(QUIHelper::appPath()).arg(QUIHelper::appName()); AppConfig::readConfig();