改进代码
parent
fdcaff2b21
commit
abc123dc7e
|
@ -12,10 +12,9 @@ int main(int argc, char *argv[])
|
||||||
a.setFont(font);
|
a.setFont(font);
|
||||||
|
|
||||||
//设置编码以及加载中文翻译文件
|
//设置编码以及加载中文翻译文件
|
||||||
QUIHelper::setCode();
|
|
||||||
QUIHelper::setTranslator(":/qt_zh_CN.qm");
|
|
||||||
QUIHelper::setTranslator(":/widgets.qm");
|
|
||||||
QUIHelper::initRand();
|
QUIHelper::initRand();
|
||||||
|
QUIHelper::setCode();
|
||||||
|
QUIHelper::setTranslator();
|
||||||
|
|
||||||
AppConfig::ConfigFile = QString("%1/%2.ini").arg(QUIHelper::appPath()).arg(QUIHelper::appName());
|
AppConfig::ConfigFile = QString("%1/%2.ini").arg(QUIHelper::appPath()).arg(QUIHelper::appName());
|
||||||
AppConfig::readConfig();
|
AppConfig::readConfig();
|
||||||
|
|
|
@ -57,7 +57,9 @@ public:
|
||||||
QString getEndDateTime() const;
|
QString getEndDateTime() const;
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
|
//设置左上角图标
|
||||||
void setIconMain(int icon, quint32 size = 12);
|
void setIconMain(int icon, quint32 size = 12);
|
||||||
|
//设置日期格式
|
||||||
void setFormat(const QString &format);
|
void setFormat(const QString &format);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef QUIHEAD_H
|
#ifndef QUIHEAD_H
|
||||||
#define QUIHEAD_H
|
#define QUIHEAD_H
|
||||||
|
|
||||||
|
//日期时间字符串宏定义
|
||||||
#ifndef TIMEMS
|
#ifndef TIMEMS
|
||||||
#define TIMEMS qPrintable(QTime::currentTime().toString("HH:mm:ss zzz"))
|
#define TIMEMS qPrintable(QTime::currentTime().toString("HH:mm:ss zzz"))
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -190,8 +190,21 @@ void QUIHelper::setFont(const QString &ttfFile, const QString &fontName, int fon
|
||||||
qApp->setFont(font);
|
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)
|
void QUIHelper::setTranslator(const QString &qmFile)
|
||||||
{
|
{
|
||||||
|
//过滤下不存在的就不用设置了
|
||||||
|
if (!QFile(qmFile).exists()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QTranslator *translator = new QTranslator(qApp);
|
QTranslator *translator = new QTranslator(qApp);
|
||||||
translator->load(qmFile);
|
translator->load(qmFile);
|
||||||
qApp->installTranslator(translator);
|
qApp->installTranslator(translator);
|
||||||
|
@ -310,8 +323,13 @@ void QUIHelper::setFormShadow(QWidget *widget, QLayout *layout, const QString &c
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//先判断是否已经存在阴影效果
|
||||||
|
QGraphicsDropShadowEffect *shadowEffect = (QGraphicsDropShadowEffect *)widget->graphicsEffect();
|
||||||
|
if (shadowEffect == 0) {
|
||||||
|
shadowEffect = new QGraphicsDropShadowEffect(widget);
|
||||||
|
}
|
||||||
|
|
||||||
//采用系统自带的函数设置阴影
|
//采用系统自带的函数设置阴影
|
||||||
QGraphicsDropShadowEffect *shadowEffect = new QGraphicsDropShadowEffect(widget);
|
|
||||||
shadowEffect->setOffset(0, 0);
|
shadowEffect->setOffset(0, 0);
|
||||||
shadowEffect->setColor(color);
|
shadowEffect->setColor(color);
|
||||||
shadowEffect->setBlurRadius(radius);
|
shadowEffect->setBlurRadius(radius);
|
||||||
|
@ -1316,7 +1334,8 @@ int QUIHelper::showMessageBoxQuestion(const QString &info)
|
||||||
{
|
{
|
||||||
if (isCustomUI) {
|
if (isCustomUI) {
|
||||||
QUIMessageBox msg;
|
QUIMessageBox msg;
|
||||||
msg.setMessage(info, 1);msg.update();
|
msg.setMessage(info, 1);
|
||||||
|
msg.update();
|
||||||
return msg.exec();
|
return msg.exec();
|
||||||
} else {
|
} else {
|
||||||
QMessageBox box(QMessageBox::Question, "询问", info);
|
QMessageBox box(QMessageBox::Question, "询问", info);
|
||||||
|
@ -1492,6 +1511,8 @@ void QUIHelper::setLogo(QLabel *label, const QString &file,
|
||||||
text.replace(oldColor, newColor);
|
text.replace(oldColor, newColor);
|
||||||
f.close();
|
f.close();
|
||||||
|
|
||||||
|
//目录不存在则新建
|
||||||
|
QUIHelper::newDir("logo");
|
||||||
//打开新的文件输出
|
//打开新的文件输出
|
||||||
fileName = QString("%1/logo/temp.svg").arg(QUIHelper::appPath());
|
fileName = QString("%1/logo/temp.svg").arg(QUIHelper::appPath());
|
||||||
QFile f2(fileName);
|
QFile f2(fileName);
|
||||||
|
|
|
@ -35,7 +35,8 @@ public:
|
||||||
static void setFont(const QString &ttfFile = ":/font/DroidSansFallback.ttf",
|
static void setFont(const QString &ttfFile = ":/font/DroidSansFallback.ttf",
|
||||||
const QString &fontName = "Microsoft Yahei", int fontSize = 12);
|
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);
|
static void initDb(const QString &dbName);
|
||||||
|
|
|
@ -59,7 +59,9 @@ public:
|
||||||
QString getValue()const;
|
QString getValue()const;
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
|
//设置左上角图标
|
||||||
void setIconMain(int icon, quint32 size = 12);
|
void setIconMain(int icon, 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 placeholderText = QString(), bool pwd = false,
|
QString placeholderText = QString(), bool pwd = false,
|
||||||
const QString &defaultValue = QString());
|
const QString &defaultValue = QString());
|
||||||
|
|
|
@ -31,6 +31,7 @@ void QUIMessageBox::showEvent(QShowEvent *)
|
||||||
QUIHelper::setIconBtn(btnCancel, ":/image/btn_close.png", 0xf00d);
|
QUIHelper::setIconBtn(btnCancel, ":/image/btn_close.png", 0xf00d);
|
||||||
QUIHelper::setFormInCenter(this);
|
QUIHelper::setFormInCenter(this);
|
||||||
this->activateWindow();
|
this->activateWindow();
|
||||||
|
//QMetaObject::invokeMethod(this, "autoSize", Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QUIMessageBox::closeEvent(QCloseEvent *)
|
void QUIMessageBox::closeEvent(QCloseEvent *)
|
||||||
|
@ -305,7 +306,12 @@ void QUIMessageBox::setMessage(const QString &msg, int type, int closeSec)
|
||||||
|
|
||||||
this->labInfo->setText(msg);
|
this->labInfo->setText(msg);
|
||||||
this->setWindowTitle(this->labTitle->text());
|
this->setWindowTitle(this->labTitle->text());
|
||||||
|
this->autoSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
void QUIMessageBox::autoSize()
|
||||||
|
{
|
||||||
|
QString msg = labInfo->text();
|
||||||
//长度符合要求比如就两行只需要默认尺寸
|
//长度符合要求比如就两行只需要默认尺寸
|
||||||
bool normal = (msg.length() < 30);
|
bool normal = (msg.length() < 30);
|
||||||
//计算有多少个换行符
|
//计算有多少个换行符
|
||||||
|
@ -322,10 +328,10 @@ void QUIMessageBox::setMessage(const QString &msg, int type, int closeSec)
|
||||||
|
|
||||||
//设置对话框的大小总以最合适的大小显示
|
//设置对话框的大小总以最合适的大小显示
|
||||||
if (normal) {
|
if (normal) {
|
||||||
this->layout()->setSizeConstraint(QLayout::SetMinimumSize);
|
//this->layout()->setSizeConstraint(QLayout::SetMinimumSize);
|
||||||
this->setFixedSize(QUIDialogMinWidth, QUIDialogMinHeight);
|
this->setFixedSize(QUIDialogMinWidth + 1, QUIDialogMinHeight + 1);
|
||||||
} else {
|
} else {
|
||||||
this->layout()->setSizeConstraint(QLayout::SetFixedSize);
|
//this->layout()->setSizeConstraint(QLayout::SetFixedSize);
|
||||||
//this->setFixedSize(labInfo->sizeHint() + QSize(100, 120));
|
this->setFixedSize(labInfo->sizeHint() + QSize(100, 120));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,9 +56,14 @@ private slots:
|
||||||
void on_btnMenu_Close_clicked();
|
void on_btnMenu_Close_clicked();
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
|
//设置左上角图标
|
||||||
void setIconMain(int icon, quint32 size = 12);
|
void setIconMain(int icon, quint32 size = 12);
|
||||||
|
//设置消息图标 图形字体+图片两种方式
|
||||||
void setIconMsg(const QString &png, int icon);
|
void setIconMsg(const QString &png, int icon);
|
||||||
|
//设置提示信息带类型和关闭倒计时
|
||||||
void setMessage(const QString &msg, int type, int closeSec = 0);
|
void setMessage(const QString &msg, int type, int closeSec = 0);
|
||||||
|
//自适应尺寸
|
||||||
|
void autoSize();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QUIMESSAGEBOX_H
|
#endif // QUIMESSAGEBOX_H
|
||||||
|
|
|
@ -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;}";
|
list << "QTabBar::tab:right:selected,QTabBar::tab:right:hover{border-width:0px 2px 0px 0px;}";
|
||||||
#endif
|
#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;
|
QUIHelper::isCustomUI = true;
|
||||||
//阴影边框和配色方案自动变化
|
//阴影边框和配色方案自动变化
|
||||||
|
|
|
@ -175,7 +175,7 @@ void QUITipBox::initForm()
|
||||||
this->labInfo->setFont(font);
|
this->labInfo->setFont(font);
|
||||||
|
|
||||||
//显示和隐藏窗体动画效果
|
//显示和隐藏窗体动画效果
|
||||||
animation = new QPropertyAnimation(this, "pos");
|
animation = new QPropertyAnimation(this, "pos", this);
|
||||||
animation->setDuration(500);
|
animation->setDuration(500);
|
||||||
animation->setEasingCurve(QEasingCurve::InOutQuad);
|
animation->setEasingCurve(QEasingCurve::InOutQuad);
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,8 +49,11 @@ private slots:
|
||||||
void on_btnMenu_Close_clicked();
|
void on_btnMenu_Close_clicked();
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
|
//设置左上角图标
|
||||||
void setIconMain(int icon, quint32 size = 12);
|
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 setTip(const QString &title, const QString &tip, bool fullScreen = false, bool center = true, int closeSec = 0);
|
||||||
|
//隐藏界面
|
||||||
void hide();
|
void hide();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,11 @@ TcpClient1::TcpClient1(QObject *parent) : QTcpSocket(parent)
|
||||||
port = 6907;
|
port = 6907;
|
||||||
deviceID = "SSJC00000001";
|
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()));
|
connect(this, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(deleteLater()));
|
||||||
|
#endif
|
||||||
connect(this, SIGNAL(disconnected()), this, SLOT(deleteLater()));
|
connect(this, SIGNAL(disconnected()), this, SLOT(deleteLater()));
|
||||||
connect(this, SIGNAL(readyRead()), this, SLOT(readData()));
|
connect(this, SIGNAL(readyRead()), this, SLOT(readData()));
|
||||||
}
|
}
|
||||||
|
@ -142,10 +146,10 @@ bool TcpServer1::writeData(const QString &deviceID, const QString &data)
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
foreach (TcpClient1 *client, clients) {
|
foreach (TcpClient1 *client, clients) {
|
||||||
if (client->getDeviceID() == deviceID) {
|
if (client->getDeviceID() == deviceID) {
|
||||||
client->sendData(data);
|
client->sendData(data);
|
||||||
ok = true;
|
ok = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,11 @@ TcpClient2::TcpClient2(QObject *parent) : QTcpSocket(parent)
|
||||||
port = 6908;
|
port = 6908;
|
||||||
deviceID = "SSJC00000001";
|
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()));
|
connect(this, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(deleteLater()));
|
||||||
|
#endif
|
||||||
connect(this, SIGNAL(disconnected()), this, SLOT(deleteLater()));
|
connect(this, SIGNAL(disconnected()), this, SLOT(deleteLater()));
|
||||||
connect(this, SIGNAL(readyRead()), this, SLOT(readData()));
|
connect(this, SIGNAL(readyRead()), this, SLOT(readData()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,10 +12,9 @@ int main(int argc, char *argv[])
|
||||||
a.setFont(font);
|
a.setFont(font);
|
||||||
|
|
||||||
//设置编码以及加载中文翻译文件
|
//设置编码以及加载中文翻译文件
|
||||||
QUIHelper::setCode();
|
|
||||||
QUIHelper::setTranslator(":/qt_zh_CN.qm");
|
|
||||||
QUIHelper::setTranslator(":/widgets.qm");
|
|
||||||
QUIHelper::initRand();
|
QUIHelper::initRand();
|
||||||
|
QUIHelper::setCode();
|
||||||
|
QUIHelper::setTranslator();
|
||||||
|
|
||||||
AppConfig::ConfigFile = QString("%1/%2.ini").arg(QUIHelper::appPath()).arg(QUIHelper::appName());
|
AppConfig::ConfigFile = QString("%1/%2.ini").arg(QUIHelper::appPath()).arg(QUIHelper::appName());
|
||||||
AppConfig::readConfig();
|
AppConfig::readConfig();
|
||||||
|
|
|
@ -7,11 +7,10 @@ int main(int argc, char *argv[])
|
||||||
a.setWindowIcon(QIcon(":/main.ico"));
|
a.setWindowIcon(QIcon(":/main.ico"));
|
||||||
|
|
||||||
//设置编码+字体+中文翻译文件
|
//设置编码+字体+中文翻译文件
|
||||||
|
QUIHelper::initRand();
|
||||||
QUIHelper::setCode();
|
QUIHelper::setCode();
|
||||||
QUIHelper::setFont(":/DroidSansFallback.ttf");
|
QUIHelper::setFont(":/DroidSansFallback.ttf");
|
||||||
QUIHelper::setTranslator(":/qt_zh_CN.qm");
|
QUIHelper::setTranslator();
|
||||||
QUIHelper::setTranslator(":/widgets.qm");
|
|
||||||
QUIHelper::initRand();
|
|
||||||
|
|
||||||
AppConfig::ConfigFile = QString("%1/%2.ini").arg(QUIHelper::appPath()).arg(QUIHelper::appName());
|
AppConfig::ConfigFile = QString("%1/%2.ini").arg(QUIHelper::appPath()).arg(QUIHelper::appName());
|
||||||
AppConfig::readConfig();
|
AppConfig::readConfig();
|
||||||
|
|
Loading…
Reference in New Issue