更新代码
This commit is contained in:
@@ -9,11 +9,9 @@
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
|
||||||
QApplication::setAttribute(Qt::AA_Use96Dpi);
|
|
||||||
#endif
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
|
||||||
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor);
|
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||||
|
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
|
|||||||
@@ -4,21 +4,41 @@
|
|||||||
|
|
||||||
#define TIMEMS qPrintable(QTime::currentTime().toString("HH:mm:ss zzz"))
|
#define TIMEMS qPrintable(QTime::currentTime().toString("HH:mm:ss zzz"))
|
||||||
|
|
||||||
QList<QRect> QtHelper::getScreenRects(bool available)
|
bool QtHelper::useRatio = true;
|
||||||
|
|
||||||
|
//full指宽屏/就是将所有屏幕拼接在一起
|
||||||
|
QList<QRect> QtHelper::getScreenRects(bool available, bool full)
|
||||||
{
|
{
|
||||||
|
QRect rect;
|
||||||
QList<QRect> rects;
|
QList<QRect> rects;
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
||||||
int screenCount = qApp->screens().count();
|
|
||||||
QList<QScreen *> screens = qApp->screens();
|
QList<QScreen *> screens = qApp->screens();
|
||||||
|
int screenCount = screens.count();
|
||||||
for (int i = 0; i < screenCount; ++i) {
|
for (int i = 0; i < screenCount; ++i) {
|
||||||
QScreen *screen = screens.at(i);
|
QScreen *screen = screens.at(i);
|
||||||
rects << (available ? screen->availableGeometry() : screen->geometry());
|
if (full) {
|
||||||
|
rect = (available ? screen->availableVirtualGeometry() : screen->virtualGeometry());
|
||||||
|
} else {
|
||||||
|
rect = (available ? screen->availableGeometry() : screen->geometry());
|
||||||
|
}
|
||||||
|
|
||||||
|
//需要根据缩放比来重新调整宽高
|
||||||
|
qreal ratio = (QtHelper::useRatio ? screen->devicePixelRatio() : 1);
|
||||||
|
rect.setWidth(rect.width() * ratio);
|
||||||
|
rect.setHeight(rect.height() * ratio);
|
||||||
|
rects << rect;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
int screenCount = qApp->desktop()->screenCount();
|
|
||||||
QDesktopWidget *desk = qApp->desktop();
|
QDesktopWidget *desk = qApp->desktop();
|
||||||
|
int screenCount = desk->screenCount();
|
||||||
for (int i = 0; i < screenCount; ++i) {
|
for (int i = 0; i < screenCount; ++i) {
|
||||||
rects << (available ? desk->availableGeometry(i) : desk->screenGeometry(i));
|
if (full) {
|
||||||
|
rect = (available ? desk->geometry() : desk->geometry());
|
||||||
|
} else {
|
||||||
|
rect = (available ? desk->availableGeometry(i) : desk->screenGeometry(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
rects << rect;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return rects;
|
return rects;
|
||||||
@@ -42,22 +62,23 @@ int QtHelper::getScreenIndex()
|
|||||||
return screenIndex;
|
return screenIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
QRect QtHelper::getScreenRect(bool available)
|
QRect QtHelper::getScreenRect(bool available, bool full)
|
||||||
{
|
{
|
||||||
int screenIndex = getScreenIndex();
|
int screenIndex = getScreenIndex();
|
||||||
QList<QRect> rects = getScreenRects(available);
|
QList<QRect> rects = getScreenRects(available, full);
|
||||||
return rects.at(screenIndex);
|
return rects.at(screenIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal QtHelper::getScreenRatio(bool devicePixel)
|
qreal QtHelper::getScreenRatio(int index, bool devicePixel)
|
||||||
{
|
{
|
||||||
qreal ratio = 1.0;
|
qreal ratio = 1.0;
|
||||||
int screenIndex = getScreenIndex();
|
//索引-1则自动获取鼠标所在当前屏幕
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
int screenIndex = (index == -1 ? getScreenIndex() : index);
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(5,5,0))
|
||||||
QScreen *screen = qApp->screens().at(screenIndex);
|
QScreen *screen = qApp->screens().at(screenIndex);
|
||||||
if (devicePixel) {
|
if (devicePixel) {
|
||||||
//需要开启 AA_EnableHighDpiScaling 属性才能正常获取
|
//需要开启 AA_EnableHighDpiScaling 属性才能正常获取
|
||||||
ratio = screen->devicePixelRatio() * 100;
|
ratio = screen->devicePixelRatio() * 96;
|
||||||
} else {
|
} else {
|
||||||
ratio = screen->logicalDotsPerInch();
|
ratio = screen->logicalDotsPerInch();
|
||||||
}
|
}
|
||||||
@@ -188,10 +209,15 @@ QString QtHelper::getIniValue(const QString &fileName, const QString &key)
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QtHelper::getIniValue(char *argv[], const QString &key, const QString &dir)
|
QString QtHelper::getIniValue(char *argv[], const QString &key, const QString &dir, const QString &file)
|
||||||
{
|
{
|
||||||
QString path, name;
|
QString path, name;
|
||||||
QtHelper::getCurrentInfo(argv, path, name);
|
QtHelper::getCurrentInfo(argv, path, name);
|
||||||
|
//指定了名称则取指定的名称/防止程序重命名
|
||||||
|
if (!file.isEmpty()) {
|
||||||
|
name = file;
|
||||||
|
}
|
||||||
|
|
||||||
QString fileName = QString("%1/%2%3.ini").arg(path).arg(dir).arg(name);
|
QString fileName = QString("%1/%2%3.ini").arg(path).arg(dir).arg(name);
|
||||||
return getIniValue(fileName, key);
|
return getIniValue(fileName, key);
|
||||||
}
|
}
|
||||||
@@ -236,6 +262,33 @@ QStringList QtHelper::getLocalIPs()
|
|||||||
return ips;
|
return ips;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QtHelper::initLocalIPs(QComboBox *cbox, const QString &defaultIP, bool local127)
|
||||||
|
{
|
||||||
|
QStringList ips;
|
||||||
|
if (local127) {
|
||||||
|
ips << "127.0.0.1";
|
||||||
|
}
|
||||||
|
|
||||||
|
//添加本地网卡地址集合
|
||||||
|
ips << QtHelper::getLocalIPs();
|
||||||
|
|
||||||
|
//不在网卡地址列表中则取第一个
|
||||||
|
QString ip = defaultIP;
|
||||||
|
if (ips.count() > 0) {
|
||||||
|
ip = ips.contains(ip) ? ip : ips.first();
|
||||||
|
}
|
||||||
|
|
||||||
|
//设置当前下拉框索引
|
||||||
|
int index = ips.indexOf(ip);
|
||||||
|
cbox->addItems(ips);
|
||||||
|
cbox->setCurrentIndex(index < 0 ? 0 : index);
|
||||||
|
|
||||||
|
//如果有文本框还要设置文本框的值
|
||||||
|
if (cbox->lineEdit()) {
|
||||||
|
cbox->lineEdit()->setText(ip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QList<QColor> QtHelper::colors = QList<QColor>();
|
QList<QColor> QtHelper::colors = QList<QColor>();
|
||||||
QList<QColor> QtHelper::getColorList()
|
QList<QColor> QtHelper::getColorList()
|
||||||
{
|
{
|
||||||
@@ -416,7 +469,8 @@ void QtHelper::checkRun()
|
|||||||
void QtHelper::setStyle()
|
void QtHelper::setStyle()
|
||||||
{
|
{
|
||||||
//打印下所有内置风格的名字
|
//打印下所有内置风格的名字
|
||||||
qDebug() << TIMEMS << "QStyleFactory::keys" << QStyleFactory::keys();
|
//qDebug() << TIMEMS << "QStyleFactory::keys" << QStyleFactory::keys();
|
||||||
|
|
||||||
//设置内置风格
|
//设置内置风格
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
||||||
qApp->setStyle("Fusion");
|
qApp->setStyle("Fusion");
|
||||||
@@ -477,22 +531,16 @@ void QtHelper::setFont(int fontSize)
|
|||||||
|
|
||||||
void QtHelper::setCode(bool utf8)
|
void QtHelper::setCode(bool utf8)
|
||||||
{
|
{
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
|
||||||
//如果想要控制台打印信息中文正常就注释掉这个设置
|
|
||||||
if (utf8) {
|
|
||||||
QTextCodec *codec = QTextCodec::codecForName("utf-8");
|
QTextCodec *codec = QTextCodec::codecForName("utf-8");
|
||||||
QTextCodec::setCodecForLocale(codec);
|
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
|
||||||
}
|
|
||||||
#else
|
|
||||||
#if _MSC_VER
|
|
||||||
QTextCodec *codec = QTextCodec::codecForName("gbk");
|
|
||||||
#else
|
|
||||||
QTextCodec *codec = QTextCodec::codecForName("utf-8");
|
|
||||||
#endif
|
|
||||||
QTextCodec::setCodecForLocale(codec);
|
|
||||||
QTextCodec::setCodecForCStrings(codec);
|
QTextCodec::setCodecForCStrings(codec);
|
||||||
QTextCodec::setCodecForTr(codec);
|
QTextCodec::setCodecForTr(codec);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//如果想要控制台打印信息中文正常就注释掉这个设置/setCodecForLocale会影响toLocal8Bit函数
|
||||||
|
if (utf8) {
|
||||||
|
QTextCodec::setCodecForLocale(codec);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtHelper::setTranslator(const QString &qmFile)
|
void QtHelper::setTranslator(const QString &qmFile)
|
||||||
@@ -585,11 +633,16 @@ void QtHelper::initAll(bool utf8, bool style, int fontSize)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef webengine
|
||||||
|
#include "qquickwindow.h"
|
||||||
|
#endif
|
||||||
void QtHelper::initMain(bool desktopSettingsAware, bool use96Dpi, bool logCritical)
|
void QtHelper::initMain(bool desktopSettingsAware, bool use96Dpi, bool logCritical)
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_LINUX
|
||||||
//Qt6.5开始默认是ffmpeg后端但是不成熟需要换成系统的
|
#ifndef Q_OS_ANDROID
|
||||||
qputenv("QT_MEDIA_BACKEND", "windows");
|
//Qt6开始默认用wayland/由于没有坐标系统导致无边框窗体不可用
|
||||||
|
//qputenv("QT_QPA_PLATFORM", "xcb");
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
||||||
@@ -597,15 +650,17 @@ void QtHelper::initMain(bool desktopSettingsAware, bool use96Dpi, bool logCritic
|
|||||||
QApplication::setDesktopSettingsAware(desktopSettingsAware);
|
QApplication::setDesktopSettingsAware(desktopSettingsAware);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool highDpi = !use96Dpi;
|
//安卓必须启用高分屏
|
||||||
#ifdef Q_OS_ANDROID
|
#ifdef Q_OS_ANDROID
|
||||||
highDpi = true;
|
use96Dpi = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,6,0))
|
QtHelper::useRatio = use96Dpi;
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(5,6,0) && QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||||
//开启高分屏缩放支持
|
//开启高分屏缩放支持
|
||||||
if (highDpi) {
|
if (!use96Dpi) {
|
||||||
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||||
|
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -622,7 +677,7 @@ void QtHelper::initMain(bool desktopSettingsAware, bool use96Dpi, bool logCritic
|
|||||||
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
|
||||||
//高分屏缩放策略
|
//高分屏缩放策略
|
||||||
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor);
|
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
||||||
@@ -636,6 +691,13 @@ void QtHelper::initMain(bool desktopSettingsAware, bool use96Dpi, bool logCritic
|
|||||||
//设置opengl共享上下文
|
//设置opengl共享上下文
|
||||||
QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
|
QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
||||||
|
#ifdef webengine
|
||||||
|
//修复openglwidget和webengine共存出现黑屏的bug
|
||||||
|
QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtHelper::initOpenGL(quint8 type, bool checkCardEnable, bool checkVirtualSystem)
|
void QtHelper::initOpenGL(quint8 type, bool checkCardEnable, bool checkVirtualSystem)
|
||||||
@@ -664,6 +726,39 @@ void QtHelper::initOpenGL(quint8 type, bool checkCardEnable, bool checkVirtualSy
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString QtHelper::getStyle(const QString &qssFile)
|
||||||
|
{
|
||||||
|
QString qss;
|
||||||
|
QFile file(qssFile);
|
||||||
|
if (file.open(QFile::ReadOnly)) {
|
||||||
|
#if 0
|
||||||
|
qss = QLatin1String(file.readAll());
|
||||||
|
#else
|
||||||
|
//用下面这种方式读取可以不用区分文件编码
|
||||||
|
QStringList list;
|
||||||
|
QTextStream stream(&file);
|
||||||
|
while (!stream.atEnd()) {
|
||||||
|
QString line;
|
||||||
|
stream >> line;
|
||||||
|
list << line;
|
||||||
|
}
|
||||||
|
qss = list.join("\n");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
return qss.trimmed();
|
||||||
|
}
|
||||||
|
|
||||||
|
void QtHelper::setStyle(const QString &qssFile)
|
||||||
|
{
|
||||||
|
QString qss = QtHelper::getStyle(qssFile);
|
||||||
|
if (!qss.isEmpty()) {
|
||||||
|
QString paletteColor = qss.mid(20, 7);
|
||||||
|
qApp->setPalette(QPalette(QColor(paletteColor)));
|
||||||
|
qApp->setStyleSheet(qss);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QString QtHelper::doCmd(const QString &program, const QStringList &arguments, int timeout)
|
QString QtHelper::doCmd(const QString &program, const QStringList &arguments, int timeout)
|
||||||
{
|
{
|
||||||
QString result;
|
QString result;
|
||||||
@@ -728,6 +823,7 @@ bool QtHelper::isVirtualSystem()
|
|||||||
return virtualSystem;
|
return virtualSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool QtHelper::replaceCRLF = true;
|
||||||
QVector<int> QtHelper::msgTypes = QVector<int>() << 0 << 1 << 2 << 3 << 4;
|
QVector<int> QtHelper::msgTypes = QVector<int>() << 0 << 1 << 2 << 3 << 4;
|
||||||
QVector<QString> QtHelper::msgKeys = QVector<QString>() << QString::fromUtf8("发送") << QString::fromUtf8("接收") << QString::fromUtf8("解析") << QString::fromUtf8("错误") << QString::fromUtf8("提示");
|
QVector<QString> QtHelper::msgKeys = QVector<QString>() << QString::fromUtf8("发送") << QString::fromUtf8("接收") << QString::fromUtf8("解析") << QString::fromUtf8("错误") << QString::fromUtf8("提示");
|
||||||
QVector<QColor> QtHelper::msgColors = QVector<QColor>() << QColor("#3BA372") << QColor("#EE6668") << QColor("#9861B4") << QColor("#FA8359") << QColor("#22A3A9");
|
QVector<QColor> QtHelper::msgColors = QVector<QColor>() << QColor("#3BA372") << QColor("#EE6668") << QColor("#9861B4") << QColor("#FA8359") << QColor("#22A3A9");
|
||||||
@@ -758,8 +854,11 @@ QString QtHelper::appendMsg(QTextEdit *textEdit, int type, const QString &data,
|
|||||||
|
|
||||||
//过滤回车换行符
|
//过滤回车换行符
|
||||||
QString strData = data;
|
QString strData = data;
|
||||||
|
if (replaceCRLF) {
|
||||||
strData.replace("\r", "");
|
strData.replace("\r", "");
|
||||||
strData.replace("\n", "");
|
strData.replace("\n", "");
|
||||||
|
}
|
||||||
|
|
||||||
strData = QString("时间[%1] %2: %3").arg(TIMEMS).arg(strType).arg(strData);
|
strData = QString("时间[%1] %2: %3").arg(TIMEMS).arg(strType).arg(strData);
|
||||||
textEdit->append(strData);
|
textEdit->append(strData);
|
||||||
currentCount++;
|
currentCount++;
|
||||||
@@ -809,7 +908,7 @@ void QtHelper::showMessageBoxInfo(const QString &text, int closeSec, bool exec)
|
|||||||
{
|
{
|
||||||
QMessageBox box(QMessageBox::Information, "提示", text);
|
QMessageBox box(QMessageBox::Information, "提示", text);
|
||||||
box.setStandardButtons(QMessageBox::Yes);
|
box.setStandardButtons(QMessageBox::Yes);
|
||||||
box.setButtonText(QMessageBox::Yes, QString("确 定"));
|
box.button(QMessageBox::Yes)->setText("确 定");
|
||||||
box.exec();
|
box.exec();
|
||||||
//QMessageBox::information(0, "提示", info, QMessageBox::Yes);
|
//QMessageBox::information(0, "提示", info, QMessageBox::Yes);
|
||||||
}
|
}
|
||||||
@@ -818,7 +917,7 @@ void QtHelper::showMessageBoxError(const QString &text, int closeSec, bool exec)
|
|||||||
{
|
{
|
||||||
QMessageBox box(QMessageBox::Critical, "错误", text);
|
QMessageBox box(QMessageBox::Critical, "错误", text);
|
||||||
box.setStandardButtons(QMessageBox::Yes);
|
box.setStandardButtons(QMessageBox::Yes);
|
||||||
box.setButtonText(QMessageBox::Yes, QString("确 定"));
|
box.button(QMessageBox::Yes)->setText("确 定");
|
||||||
box.exec();
|
box.exec();
|
||||||
//QMessageBox::critical(0, "错误", info, QMessageBox::Yes);
|
//QMessageBox::critical(0, "错误", info, QMessageBox::Yes);
|
||||||
}
|
}
|
||||||
@@ -827,8 +926,8 @@ int QtHelper::showMessageBoxQuestion(const QString &text)
|
|||||||
{
|
{
|
||||||
QMessageBox box(QMessageBox::Question, "询问", text);
|
QMessageBox box(QMessageBox::Question, "询问", text);
|
||||||
box.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
box.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
||||||
box.setButtonText(QMessageBox::Yes, QString("确 定"));
|
box.button(QMessageBox::Yes)->setText("确 定");
|
||||||
box.setButtonText(QMessageBox::No, QString("取 消"));
|
box.button(QMessageBox::No)->setText("取 消");
|
||||||
return box.exec();
|
return box.exec();
|
||||||
//return QMessageBox::question(0, "询问", info, QMessageBox::Yes | QMessageBox::No);
|
//return QMessageBox::question(0, "询问", info, QMessageBox::Yes | QMessageBox::No);
|
||||||
}
|
}
|
||||||
@@ -1165,16 +1264,16 @@ QString QtHelper::getSizeString(quint64 size)
|
|||||||
void QtHelper::setSystemDateTime(const QString &year, const QString &month, const QString &day, const QString &hour, const QString &min, const QString &sec)
|
void QtHelper::setSystemDateTime(const QString &year, const QString &month, const QString &day, const QString &hour, const QString &min, const QString &sec)
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
QProcess p(0);
|
QProcess p;
|
||||||
//先设置日期
|
//先设置日期
|
||||||
p.start("cmd");
|
p.start("cmd", QStringList());
|
||||||
p.waitForStarted();
|
p.waitForStarted();
|
||||||
p.write(QString("date %1-%2-%3\n").arg(year).arg(month).arg(day).toLatin1());
|
p.write(QString("date %1-%2-%3\n").arg(year).arg(month).arg(day).toLatin1());
|
||||||
p.closeWriteChannel();
|
p.closeWriteChannel();
|
||||||
p.waitForFinished(1000);
|
p.waitForFinished(1000);
|
||||||
p.close();
|
p.close();
|
||||||
//再设置时间
|
//再设置时间
|
||||||
p.start("cmd");
|
p.start("cmd", QStringList());
|
||||||
p.waitForStarted();
|
p.waitForStarted();
|
||||||
p.write(QString("time %1:%2:%3.00\n").arg(hour).arg(min).arg(sec).toLatin1());
|
p.write(QString("time %1:%2:%3.00\n").arg(hour).arg(min).arg(sec).toLatin1());
|
||||||
p.closeWriteChannel();
|
p.closeWriteChannel();
|
||||||
@@ -1203,11 +1302,11 @@ void QtHelper::runWithSystem(const QString &fileName, const QString &filePath, b
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtHelper::runBin(const QString &path, const QString &name)
|
void QtHelper::start(const QString &path, const QString &name, bool bin)
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
QString cmd1 = "tasklist";
|
QString cmd1 = "tasklist";
|
||||||
QString cmd2 = QString("%1/%2.exe").arg(path).arg(name);
|
QString cmd2 = QString("%1/%2%3").arg(path).arg(name).arg(bin ? ".exe" : "");
|
||||||
#else
|
#else
|
||||||
QString cmd1 = "ps -aux";
|
QString cmd1 = "ps -aux";
|
||||||
QString cmd2 = QString("%1/%2").arg(path).arg(name);
|
QString cmd2 = QString("%1/%2").arg(path).arg(name);
|
||||||
@@ -1215,7 +1314,7 @@ void QtHelper::runBin(const QString &path, const QString &name)
|
|||||||
|
|
||||||
#ifndef Q_OS_WASM
|
#ifndef Q_OS_WASM
|
||||||
QProcess p;
|
QProcess p;
|
||||||
p.start(cmd1);
|
p.start(cmd1, QStringList());
|
||||||
if (p.waitForFinished()) {
|
if (p.waitForFinished()) {
|
||||||
QString result = p.readAll();
|
QString result = p.readAll();
|
||||||
if (result.contains(name)) {
|
if (result.contains(name)) {
|
||||||
@@ -1228,7 +1327,11 @@ void QtHelper::runBin(const QString &path, const QString &name)
|
|||||||
cmd2 = "\"" + cmd2 + "\"";
|
cmd2 = "\"" + cmd2 + "\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
//QProcess::execute(cmd2);
|
//切换到当前目录
|
||||||
QProcess::startDetached(cmd2);
|
QDir::setCurrent(path);
|
||||||
|
//QProcess::execute(cmd2, QStringList());
|
||||||
|
QProcess::startDetached(cmd2, QStringList());
|
||||||
|
//执行完成后切换回默认目录
|
||||||
|
QDir::setCurrent(QtHelper::appPath());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,10 +7,11 @@ class QtHelper
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//获取所有屏幕区域/当前鼠标所在屏幕索引/区域尺寸/缩放系数
|
//获取所有屏幕区域/当前鼠标所在屏幕索引/区域尺寸/缩放系数
|
||||||
static QList<QRect> getScreenRects(bool available = true);
|
static bool useRatio;
|
||||||
|
static QList<QRect> getScreenRects(bool available = true, bool full = false);
|
||||||
static int getScreenIndex();
|
static int getScreenIndex();
|
||||||
static QRect getScreenRect(bool available = true);
|
static QRect getScreenRect(bool available = true, bool full = false);
|
||||||
static qreal getScreenRatio(bool devicePixel = false);
|
static qreal getScreenRatio(int index = -1, bool devicePixel = false);
|
||||||
|
|
||||||
//矫正当前鼠标所在屏幕居中尺寸
|
//矫正当前鼠标所在屏幕居中尺寸
|
||||||
static QRect checkCenterRect(QRect &rect, bool available = true);
|
static QRect checkCenterRect(QRect &rect, bool available = true);
|
||||||
@@ -34,10 +35,12 @@ public:
|
|||||||
static void getCurrentInfo(char *argv[], QString &path, QString &name);
|
static void getCurrentInfo(char *argv[], QString &path, QString &name);
|
||||||
//程序最前面读取配置文件节点的值
|
//程序最前面读取配置文件节点的值
|
||||||
static QString getIniValue(const QString &fileName, const QString &key);
|
static QString getIniValue(const QString &fileName, const QString &key);
|
||||||
static QString getIniValue(char *argv[], const QString &key, const QString &dir = QString());
|
static QString getIniValue(char *argv[], const QString &key, const QString &dir = QString(), const QString &file = QString());
|
||||||
|
|
||||||
//获取本地网卡IP集合
|
//获取本地网卡IP集合
|
||||||
static QStringList getLocalIPs();
|
static QStringList getLocalIPs();
|
||||||
|
//添加网卡集合并根据默认值设置当前项
|
||||||
|
static void initLocalIPs(QComboBox *cbox, const QString &defaultIP, bool local127 = true);
|
||||||
|
|
||||||
//获取内置颜色集合
|
//获取内置颜色集合
|
||||||
static QList<QColor> colors;
|
static QList<QColor> colors;
|
||||||
@@ -84,10 +87,15 @@ public:
|
|||||||
//一次性设置所有包括编码样式字体等
|
//一次性设置所有包括编码样式字体等
|
||||||
static void initAll(bool utf8 = true, bool style = true, int fontSize = 13);
|
static void initAll(bool utf8 = true, bool style = true, int fontSize = 13);
|
||||||
//初始化main函数最前面执行的一段代码
|
//初始化main函数最前面执行的一段代码
|
||||||
static void initMain(bool desktopSettingsAware = false, bool use96Dpi = true, bool logCritical = true);
|
static void initMain(bool desktopSettingsAware = false, bool use96Dpi = false, bool logCritical = true);
|
||||||
//初始化opengl类型(1=AA_UseDesktopOpenGL 2=AA_UseOpenGLES 3=AA_UseSoftwareOpenGL)
|
//初始化opengl类型(1=AA_UseDesktopOpenGL 2=AA_UseOpenGLES 3=AA_UseSoftwareOpenGL)
|
||||||
static void initOpenGL(quint8 type = 0, bool checkCardEnable = false, bool checkVirtualSystem = false);
|
static void initOpenGL(quint8 type = 0, bool checkCardEnable = false, bool checkVirtualSystem = false);
|
||||||
|
|
||||||
|
//读取qss文件获取样式表内容
|
||||||
|
static QString getStyle(const QString &qssFile);
|
||||||
|
//设置qss文件到全局样式
|
||||||
|
static void setStyle(const QString &qssFile);
|
||||||
|
|
||||||
//执行命令行返回执行结果
|
//执行命令行返回执行结果
|
||||||
static QString doCmd(const QString &program, const QStringList &arguments, int timeout = 1000);
|
static QString doCmd(const QString &program, const QStringList &arguments, int timeout = 1000);
|
||||||
//获取显卡是否被禁用
|
//获取显卡是否被禁用
|
||||||
@@ -96,6 +104,7 @@ public:
|
|||||||
static bool isVirtualSystem();
|
static bool isVirtualSystem();
|
||||||
|
|
||||||
//插入消息
|
//插入消息
|
||||||
|
static bool replaceCRLF;
|
||||||
static QVector<int> msgTypes;
|
static QVector<int> msgTypes;
|
||||||
static QVector<QString> msgKeys;
|
static QVector<QString> msgKeys;
|
||||||
static QVector<QColor> msgColors;
|
static QVector<QColor> msgColors;
|
||||||
@@ -173,8 +182,9 @@ public:
|
|||||||
//设置开机自启动
|
//设置开机自启动
|
||||||
static void runWithSystem(bool autoRun = true);
|
static void runWithSystem(bool autoRun = true);
|
||||||
static void runWithSystem(const QString &fileName, const QString &filePath, bool autoRun = true);
|
static void runWithSystem(const QString &fileName, const QString &filePath, bool autoRun = true);
|
||||||
|
|
||||||
//启动运行程序(已经在运行则不启动)
|
//启动运行程序(已经在运行则不启动)
|
||||||
static void runBin(const QString &path, const QString &name);
|
static void start(const QString &path, const QString &name, bool bin = true);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QTHELPER_H
|
#endif // QTHELPER_H
|
||||||
|
|||||||
@@ -3,13 +3,7 @@
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
QtHelper::initMain();
|
||||||
QApplication::setAttribute(Qt::AA_Use96Dpi);
|
|
||||||
#endif
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
|
|
||||||
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
a.setWindowIcon(QIcon(":/main.ico"));
|
a.setWindowIcon(QIcon(":/main.ico"));
|
||||||
|
|
||||||
@@ -24,7 +18,7 @@ int main(int argc, char *argv[])
|
|||||||
AppData::readDeviceData();
|
AppData::readDeviceData();
|
||||||
|
|
||||||
frmComTool w;
|
frmComTool w;
|
||||||
w.setWindowTitle("串口调试助手 V2023 (QQ: 517216493 WX: feiyangqingyun)");
|
w.setWindowTitle("串口调试助手 V2024 (QQ: 517216493 WX: feiyangqingyun)");
|
||||||
w.resize(900, 650);
|
w.resize(900, 650);
|
||||||
QtHelper::setFormInCenter(&w);
|
QtHelper::setFormInCenter(&w);
|
||||||
w.show();
|
w.show();
|
||||||
|
|||||||
@@ -4,21 +4,41 @@
|
|||||||
|
|
||||||
#define TIMEMS qPrintable(QTime::currentTime().toString("HH:mm:ss zzz"))
|
#define TIMEMS qPrintable(QTime::currentTime().toString("HH:mm:ss zzz"))
|
||||||
|
|
||||||
QList<QRect> QtHelper::getScreenRects(bool available)
|
bool QtHelper::useRatio = true;
|
||||||
|
|
||||||
|
//full指宽屏/就是将所有屏幕拼接在一起
|
||||||
|
QList<QRect> QtHelper::getScreenRects(bool available, bool full)
|
||||||
{
|
{
|
||||||
|
QRect rect;
|
||||||
QList<QRect> rects;
|
QList<QRect> rects;
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
||||||
int screenCount = qApp->screens().count();
|
|
||||||
QList<QScreen *> screens = qApp->screens();
|
QList<QScreen *> screens = qApp->screens();
|
||||||
|
int screenCount = screens.count();
|
||||||
for (int i = 0; i < screenCount; ++i) {
|
for (int i = 0; i < screenCount; ++i) {
|
||||||
QScreen *screen = screens.at(i);
|
QScreen *screen = screens.at(i);
|
||||||
rects << (available ? screen->availableGeometry() : screen->geometry());
|
if (full) {
|
||||||
|
rect = (available ? screen->availableVirtualGeometry() : screen->virtualGeometry());
|
||||||
|
} else {
|
||||||
|
rect = (available ? screen->availableGeometry() : screen->geometry());
|
||||||
|
}
|
||||||
|
|
||||||
|
//需要根据缩放比来重新调整宽高
|
||||||
|
qreal ratio = (QtHelper::useRatio ? screen->devicePixelRatio() : 1);
|
||||||
|
rect.setWidth(rect.width() * ratio);
|
||||||
|
rect.setHeight(rect.height() * ratio);
|
||||||
|
rects << rect;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
int screenCount = qApp->desktop()->screenCount();
|
|
||||||
QDesktopWidget *desk = qApp->desktop();
|
QDesktopWidget *desk = qApp->desktop();
|
||||||
|
int screenCount = desk->screenCount();
|
||||||
for (int i = 0; i < screenCount; ++i) {
|
for (int i = 0; i < screenCount; ++i) {
|
||||||
rects << (available ? desk->availableGeometry(i) : desk->screenGeometry(i));
|
if (full) {
|
||||||
|
rect = (available ? desk->geometry() : desk->geometry());
|
||||||
|
} else {
|
||||||
|
rect = (available ? desk->availableGeometry(i) : desk->screenGeometry(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
rects << rect;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return rects;
|
return rects;
|
||||||
@@ -42,22 +62,23 @@ int QtHelper::getScreenIndex()
|
|||||||
return screenIndex;
|
return screenIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
QRect QtHelper::getScreenRect(bool available)
|
QRect QtHelper::getScreenRect(bool available, bool full)
|
||||||
{
|
{
|
||||||
int screenIndex = getScreenIndex();
|
int screenIndex = getScreenIndex();
|
||||||
QList<QRect> rects = getScreenRects(available);
|
QList<QRect> rects = getScreenRects(available, full);
|
||||||
return rects.at(screenIndex);
|
return rects.at(screenIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal QtHelper::getScreenRatio(bool devicePixel)
|
qreal QtHelper::getScreenRatio(int index, bool devicePixel)
|
||||||
{
|
{
|
||||||
qreal ratio = 1.0;
|
qreal ratio = 1.0;
|
||||||
int screenIndex = getScreenIndex();
|
//索引-1则自动获取鼠标所在当前屏幕
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
int screenIndex = (index == -1 ? getScreenIndex() : index);
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(5,5,0))
|
||||||
QScreen *screen = qApp->screens().at(screenIndex);
|
QScreen *screen = qApp->screens().at(screenIndex);
|
||||||
if (devicePixel) {
|
if (devicePixel) {
|
||||||
//需要开启 AA_EnableHighDpiScaling 属性才能正常获取
|
//需要开启 AA_EnableHighDpiScaling 属性才能正常获取
|
||||||
ratio = screen->devicePixelRatio() * 100;
|
ratio = screen->devicePixelRatio() * 96;
|
||||||
} else {
|
} else {
|
||||||
ratio = screen->logicalDotsPerInch();
|
ratio = screen->logicalDotsPerInch();
|
||||||
}
|
}
|
||||||
@@ -188,10 +209,15 @@ QString QtHelper::getIniValue(const QString &fileName, const QString &key)
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QtHelper::getIniValue(char *argv[], const QString &key, const QString &dir)
|
QString QtHelper::getIniValue(char *argv[], const QString &key, const QString &dir, const QString &file)
|
||||||
{
|
{
|
||||||
QString path, name;
|
QString path, name;
|
||||||
QtHelper::getCurrentInfo(argv, path, name);
|
QtHelper::getCurrentInfo(argv, path, name);
|
||||||
|
//指定了名称则取指定的名称/防止程序重命名
|
||||||
|
if (!file.isEmpty()) {
|
||||||
|
name = file;
|
||||||
|
}
|
||||||
|
|
||||||
QString fileName = QString("%1/%2%3.ini").arg(path).arg(dir).arg(name);
|
QString fileName = QString("%1/%2%3.ini").arg(path).arg(dir).arg(name);
|
||||||
return getIniValue(fileName, key);
|
return getIniValue(fileName, key);
|
||||||
}
|
}
|
||||||
@@ -236,6 +262,33 @@ QStringList QtHelper::getLocalIPs()
|
|||||||
return ips;
|
return ips;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QtHelper::initLocalIPs(QComboBox *cbox, const QString &defaultIP, bool local127)
|
||||||
|
{
|
||||||
|
QStringList ips;
|
||||||
|
if (local127) {
|
||||||
|
ips << "127.0.0.1";
|
||||||
|
}
|
||||||
|
|
||||||
|
//添加本地网卡地址集合
|
||||||
|
ips << QtHelper::getLocalIPs();
|
||||||
|
|
||||||
|
//不在网卡地址列表中则取第一个
|
||||||
|
QString ip = defaultIP;
|
||||||
|
if (ips.count() > 0) {
|
||||||
|
ip = ips.contains(ip) ? ip : ips.first();
|
||||||
|
}
|
||||||
|
|
||||||
|
//设置当前下拉框索引
|
||||||
|
int index = ips.indexOf(ip);
|
||||||
|
cbox->addItems(ips);
|
||||||
|
cbox->setCurrentIndex(index < 0 ? 0 : index);
|
||||||
|
|
||||||
|
//如果有文本框还要设置文本框的值
|
||||||
|
if (cbox->lineEdit()) {
|
||||||
|
cbox->lineEdit()->setText(ip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QList<QColor> QtHelper::colors = QList<QColor>();
|
QList<QColor> QtHelper::colors = QList<QColor>();
|
||||||
QList<QColor> QtHelper::getColorList()
|
QList<QColor> QtHelper::getColorList()
|
||||||
{
|
{
|
||||||
@@ -416,7 +469,8 @@ void QtHelper::checkRun()
|
|||||||
void QtHelper::setStyle()
|
void QtHelper::setStyle()
|
||||||
{
|
{
|
||||||
//打印下所有内置风格的名字
|
//打印下所有内置风格的名字
|
||||||
qDebug() << TIMEMS << "QStyleFactory::keys" << QStyleFactory::keys();
|
//qDebug() << TIMEMS << "QStyleFactory::keys" << QStyleFactory::keys();
|
||||||
|
|
||||||
//设置内置风格
|
//设置内置风格
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
||||||
qApp->setStyle("Fusion");
|
qApp->setStyle("Fusion");
|
||||||
@@ -477,22 +531,16 @@ void QtHelper::setFont(int fontSize)
|
|||||||
|
|
||||||
void QtHelper::setCode(bool utf8)
|
void QtHelper::setCode(bool utf8)
|
||||||
{
|
{
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
|
||||||
//如果想要控制台打印信息中文正常就注释掉这个设置
|
|
||||||
if (utf8) {
|
|
||||||
QTextCodec *codec = QTextCodec::codecForName("utf-8");
|
QTextCodec *codec = QTextCodec::codecForName("utf-8");
|
||||||
QTextCodec::setCodecForLocale(codec);
|
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
|
||||||
}
|
|
||||||
#else
|
|
||||||
#if _MSC_VER
|
|
||||||
QTextCodec *codec = QTextCodec::codecForName("gbk");
|
|
||||||
#else
|
|
||||||
QTextCodec *codec = QTextCodec::codecForName("utf-8");
|
|
||||||
#endif
|
|
||||||
QTextCodec::setCodecForLocale(codec);
|
|
||||||
QTextCodec::setCodecForCStrings(codec);
|
QTextCodec::setCodecForCStrings(codec);
|
||||||
QTextCodec::setCodecForTr(codec);
|
QTextCodec::setCodecForTr(codec);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//如果想要控制台打印信息中文正常就注释掉这个设置/setCodecForLocale会影响toLocal8Bit函数
|
||||||
|
if (utf8) {
|
||||||
|
QTextCodec::setCodecForLocale(codec);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtHelper::setTranslator(const QString &qmFile)
|
void QtHelper::setTranslator(const QString &qmFile)
|
||||||
@@ -585,11 +633,16 @@ void QtHelper::initAll(bool utf8, bool style, int fontSize)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef webengine
|
||||||
|
#include "qquickwindow.h"
|
||||||
|
#endif
|
||||||
void QtHelper::initMain(bool desktopSettingsAware, bool use96Dpi, bool logCritical)
|
void QtHelper::initMain(bool desktopSettingsAware, bool use96Dpi, bool logCritical)
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_LINUX
|
||||||
//Qt6.5开始默认是ffmpeg后端但是不成熟需要换成系统的
|
#ifndef Q_OS_ANDROID
|
||||||
qputenv("QT_MEDIA_BACKEND", "windows");
|
//Qt6开始默认用wayland/由于没有坐标系统导致无边框窗体不可用
|
||||||
|
//qputenv("QT_QPA_PLATFORM", "xcb");
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
||||||
@@ -597,15 +650,17 @@ void QtHelper::initMain(bool desktopSettingsAware, bool use96Dpi, bool logCritic
|
|||||||
QApplication::setDesktopSettingsAware(desktopSettingsAware);
|
QApplication::setDesktopSettingsAware(desktopSettingsAware);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool highDpi = !use96Dpi;
|
//安卓必须启用高分屏
|
||||||
#ifdef Q_OS_ANDROID
|
#ifdef Q_OS_ANDROID
|
||||||
highDpi = true;
|
use96Dpi = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,6,0))
|
QtHelper::useRatio = use96Dpi;
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(5,6,0) && QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||||
//开启高分屏缩放支持
|
//开启高分屏缩放支持
|
||||||
if (highDpi) {
|
if (!use96Dpi) {
|
||||||
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||||
|
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -622,7 +677,7 @@ void QtHelper::initMain(bool desktopSettingsAware, bool use96Dpi, bool logCritic
|
|||||||
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
|
||||||
//高分屏缩放策略
|
//高分屏缩放策略
|
||||||
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor);
|
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
||||||
@@ -636,6 +691,13 @@ void QtHelper::initMain(bool desktopSettingsAware, bool use96Dpi, bool logCritic
|
|||||||
//设置opengl共享上下文
|
//设置opengl共享上下文
|
||||||
QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
|
QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
||||||
|
#ifdef webengine
|
||||||
|
//修复openglwidget和webengine共存出现黑屏的bug
|
||||||
|
QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtHelper::initOpenGL(quint8 type, bool checkCardEnable, bool checkVirtualSystem)
|
void QtHelper::initOpenGL(quint8 type, bool checkCardEnable, bool checkVirtualSystem)
|
||||||
@@ -664,6 +726,39 @@ void QtHelper::initOpenGL(quint8 type, bool checkCardEnable, bool checkVirtualSy
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString QtHelper::getStyle(const QString &qssFile)
|
||||||
|
{
|
||||||
|
QString qss;
|
||||||
|
QFile file(qssFile);
|
||||||
|
if (file.open(QFile::ReadOnly)) {
|
||||||
|
#if 0
|
||||||
|
qss = QLatin1String(file.readAll());
|
||||||
|
#else
|
||||||
|
//用下面这种方式读取可以不用区分文件编码
|
||||||
|
QStringList list;
|
||||||
|
QTextStream stream(&file);
|
||||||
|
while (!stream.atEnd()) {
|
||||||
|
QString line;
|
||||||
|
stream >> line;
|
||||||
|
list << line;
|
||||||
|
}
|
||||||
|
qss = list.join("\n");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
return qss.trimmed();
|
||||||
|
}
|
||||||
|
|
||||||
|
void QtHelper::setStyle(const QString &qssFile)
|
||||||
|
{
|
||||||
|
QString qss = QtHelper::getStyle(qssFile);
|
||||||
|
if (!qss.isEmpty()) {
|
||||||
|
QString paletteColor = qss.mid(20, 7);
|
||||||
|
qApp->setPalette(QPalette(QColor(paletteColor)));
|
||||||
|
qApp->setStyleSheet(qss);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QString QtHelper::doCmd(const QString &program, const QStringList &arguments, int timeout)
|
QString QtHelper::doCmd(const QString &program, const QStringList &arguments, int timeout)
|
||||||
{
|
{
|
||||||
QString result;
|
QString result;
|
||||||
@@ -728,6 +823,7 @@ bool QtHelper::isVirtualSystem()
|
|||||||
return virtualSystem;
|
return virtualSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool QtHelper::replaceCRLF = true;
|
||||||
QVector<int> QtHelper::msgTypes = QVector<int>() << 0 << 1 << 2 << 3 << 4;
|
QVector<int> QtHelper::msgTypes = QVector<int>() << 0 << 1 << 2 << 3 << 4;
|
||||||
QVector<QString> QtHelper::msgKeys = QVector<QString>() << QString::fromUtf8("发送") << QString::fromUtf8("接收") << QString::fromUtf8("解析") << QString::fromUtf8("错误") << QString::fromUtf8("提示");
|
QVector<QString> QtHelper::msgKeys = QVector<QString>() << QString::fromUtf8("发送") << QString::fromUtf8("接收") << QString::fromUtf8("解析") << QString::fromUtf8("错误") << QString::fromUtf8("提示");
|
||||||
QVector<QColor> QtHelper::msgColors = QVector<QColor>() << QColor("#3BA372") << QColor("#EE6668") << QColor("#9861B4") << QColor("#FA8359") << QColor("#22A3A9");
|
QVector<QColor> QtHelper::msgColors = QVector<QColor>() << QColor("#3BA372") << QColor("#EE6668") << QColor("#9861B4") << QColor("#FA8359") << QColor("#22A3A9");
|
||||||
@@ -758,8 +854,11 @@ QString QtHelper::appendMsg(QTextEdit *textEdit, int type, const QString &data,
|
|||||||
|
|
||||||
//过滤回车换行符
|
//过滤回车换行符
|
||||||
QString strData = data;
|
QString strData = data;
|
||||||
|
if (replaceCRLF) {
|
||||||
strData.replace("\r", "");
|
strData.replace("\r", "");
|
||||||
strData.replace("\n", "");
|
strData.replace("\n", "");
|
||||||
|
}
|
||||||
|
|
||||||
strData = QString("时间[%1] %2: %3").arg(TIMEMS).arg(strType).arg(strData);
|
strData = QString("时间[%1] %2: %3").arg(TIMEMS).arg(strType).arg(strData);
|
||||||
textEdit->append(strData);
|
textEdit->append(strData);
|
||||||
currentCount++;
|
currentCount++;
|
||||||
@@ -809,7 +908,7 @@ void QtHelper::showMessageBoxInfo(const QString &text, int closeSec, bool exec)
|
|||||||
{
|
{
|
||||||
QMessageBox box(QMessageBox::Information, "提示", text);
|
QMessageBox box(QMessageBox::Information, "提示", text);
|
||||||
box.setStandardButtons(QMessageBox::Yes);
|
box.setStandardButtons(QMessageBox::Yes);
|
||||||
box.setButtonText(QMessageBox::Yes, QString("确 定"));
|
box.button(QMessageBox::Yes)->setText("确 定");
|
||||||
box.exec();
|
box.exec();
|
||||||
//QMessageBox::information(0, "提示", info, QMessageBox::Yes);
|
//QMessageBox::information(0, "提示", info, QMessageBox::Yes);
|
||||||
}
|
}
|
||||||
@@ -818,7 +917,7 @@ void QtHelper::showMessageBoxError(const QString &text, int closeSec, bool exec)
|
|||||||
{
|
{
|
||||||
QMessageBox box(QMessageBox::Critical, "错误", text);
|
QMessageBox box(QMessageBox::Critical, "错误", text);
|
||||||
box.setStandardButtons(QMessageBox::Yes);
|
box.setStandardButtons(QMessageBox::Yes);
|
||||||
box.setButtonText(QMessageBox::Yes, QString("确 定"));
|
box.button(QMessageBox::Yes)->setText("确 定");
|
||||||
box.exec();
|
box.exec();
|
||||||
//QMessageBox::critical(0, "错误", info, QMessageBox::Yes);
|
//QMessageBox::critical(0, "错误", info, QMessageBox::Yes);
|
||||||
}
|
}
|
||||||
@@ -827,8 +926,8 @@ int QtHelper::showMessageBoxQuestion(const QString &text)
|
|||||||
{
|
{
|
||||||
QMessageBox box(QMessageBox::Question, "询问", text);
|
QMessageBox box(QMessageBox::Question, "询问", text);
|
||||||
box.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
box.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
||||||
box.setButtonText(QMessageBox::Yes, QString("确 定"));
|
box.button(QMessageBox::Yes)->setText("确 定");
|
||||||
box.setButtonText(QMessageBox::No, QString("取 消"));
|
box.button(QMessageBox::No)->setText("取 消");
|
||||||
return box.exec();
|
return box.exec();
|
||||||
//return QMessageBox::question(0, "询问", info, QMessageBox::Yes | QMessageBox::No);
|
//return QMessageBox::question(0, "询问", info, QMessageBox::Yes | QMessageBox::No);
|
||||||
}
|
}
|
||||||
@@ -1165,16 +1264,16 @@ QString QtHelper::getSizeString(quint64 size)
|
|||||||
void QtHelper::setSystemDateTime(const QString &year, const QString &month, const QString &day, const QString &hour, const QString &min, const QString &sec)
|
void QtHelper::setSystemDateTime(const QString &year, const QString &month, const QString &day, const QString &hour, const QString &min, const QString &sec)
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
QProcess p(0);
|
QProcess p;
|
||||||
//先设置日期
|
//先设置日期
|
||||||
p.start("cmd");
|
p.start("cmd", QStringList());
|
||||||
p.waitForStarted();
|
p.waitForStarted();
|
||||||
p.write(QString("date %1-%2-%3\n").arg(year).arg(month).arg(day).toLatin1());
|
p.write(QString("date %1-%2-%3\n").arg(year).arg(month).arg(day).toLatin1());
|
||||||
p.closeWriteChannel();
|
p.closeWriteChannel();
|
||||||
p.waitForFinished(1000);
|
p.waitForFinished(1000);
|
||||||
p.close();
|
p.close();
|
||||||
//再设置时间
|
//再设置时间
|
||||||
p.start("cmd");
|
p.start("cmd", QStringList());
|
||||||
p.waitForStarted();
|
p.waitForStarted();
|
||||||
p.write(QString("time %1:%2:%3.00\n").arg(hour).arg(min).arg(sec).toLatin1());
|
p.write(QString("time %1:%2:%3.00\n").arg(hour).arg(min).arg(sec).toLatin1());
|
||||||
p.closeWriteChannel();
|
p.closeWriteChannel();
|
||||||
@@ -1203,11 +1302,11 @@ void QtHelper::runWithSystem(const QString &fileName, const QString &filePath, b
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtHelper::runBin(const QString &path, const QString &name)
|
void QtHelper::start(const QString &path, const QString &name, bool bin)
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
QString cmd1 = "tasklist";
|
QString cmd1 = "tasklist";
|
||||||
QString cmd2 = QString("%1/%2.exe").arg(path).arg(name);
|
QString cmd2 = QString("%1/%2%3").arg(path).arg(name).arg(bin ? ".exe" : "");
|
||||||
#else
|
#else
|
||||||
QString cmd1 = "ps -aux";
|
QString cmd1 = "ps -aux";
|
||||||
QString cmd2 = QString("%1/%2").arg(path).arg(name);
|
QString cmd2 = QString("%1/%2").arg(path).arg(name);
|
||||||
@@ -1215,7 +1314,7 @@ void QtHelper::runBin(const QString &path, const QString &name)
|
|||||||
|
|
||||||
#ifndef Q_OS_WASM
|
#ifndef Q_OS_WASM
|
||||||
QProcess p;
|
QProcess p;
|
||||||
p.start(cmd1);
|
p.start(cmd1, QStringList());
|
||||||
if (p.waitForFinished()) {
|
if (p.waitForFinished()) {
|
||||||
QString result = p.readAll();
|
QString result = p.readAll();
|
||||||
if (result.contains(name)) {
|
if (result.contains(name)) {
|
||||||
@@ -1228,7 +1327,11 @@ void QtHelper::runBin(const QString &path, const QString &name)
|
|||||||
cmd2 = "\"" + cmd2 + "\"";
|
cmd2 = "\"" + cmd2 + "\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
//QProcess::execute(cmd2);
|
//切换到当前目录
|
||||||
QProcess::startDetached(cmd2);
|
QDir::setCurrent(path);
|
||||||
|
//QProcess::execute(cmd2, QStringList());
|
||||||
|
QProcess::startDetached(cmd2, QStringList());
|
||||||
|
//执行完成后切换回默认目录
|
||||||
|
QDir::setCurrent(QtHelper::appPath());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,10 +7,11 @@ class QtHelper
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//获取所有屏幕区域/当前鼠标所在屏幕索引/区域尺寸/缩放系数
|
//获取所有屏幕区域/当前鼠标所在屏幕索引/区域尺寸/缩放系数
|
||||||
static QList<QRect> getScreenRects(bool available = true);
|
static bool useRatio;
|
||||||
|
static QList<QRect> getScreenRects(bool available = true, bool full = false);
|
||||||
static int getScreenIndex();
|
static int getScreenIndex();
|
||||||
static QRect getScreenRect(bool available = true);
|
static QRect getScreenRect(bool available = true, bool full = false);
|
||||||
static qreal getScreenRatio(bool devicePixel = false);
|
static qreal getScreenRatio(int index = -1, bool devicePixel = false);
|
||||||
|
|
||||||
//矫正当前鼠标所在屏幕居中尺寸
|
//矫正当前鼠标所在屏幕居中尺寸
|
||||||
static QRect checkCenterRect(QRect &rect, bool available = true);
|
static QRect checkCenterRect(QRect &rect, bool available = true);
|
||||||
@@ -34,10 +35,12 @@ public:
|
|||||||
static void getCurrentInfo(char *argv[], QString &path, QString &name);
|
static void getCurrentInfo(char *argv[], QString &path, QString &name);
|
||||||
//程序最前面读取配置文件节点的值
|
//程序最前面读取配置文件节点的值
|
||||||
static QString getIniValue(const QString &fileName, const QString &key);
|
static QString getIniValue(const QString &fileName, const QString &key);
|
||||||
static QString getIniValue(char *argv[], const QString &key, const QString &dir = QString());
|
static QString getIniValue(char *argv[], const QString &key, const QString &dir = QString(), const QString &file = QString());
|
||||||
|
|
||||||
//获取本地网卡IP集合
|
//获取本地网卡IP集合
|
||||||
static QStringList getLocalIPs();
|
static QStringList getLocalIPs();
|
||||||
|
//添加网卡集合并根据默认值设置当前项
|
||||||
|
static void initLocalIPs(QComboBox *cbox, const QString &defaultIP, bool local127 = true);
|
||||||
|
|
||||||
//获取内置颜色集合
|
//获取内置颜色集合
|
||||||
static QList<QColor> colors;
|
static QList<QColor> colors;
|
||||||
@@ -84,10 +87,15 @@ public:
|
|||||||
//一次性设置所有包括编码样式字体等
|
//一次性设置所有包括编码样式字体等
|
||||||
static void initAll(bool utf8 = true, bool style = true, int fontSize = 13);
|
static void initAll(bool utf8 = true, bool style = true, int fontSize = 13);
|
||||||
//初始化main函数最前面执行的一段代码
|
//初始化main函数最前面执行的一段代码
|
||||||
static void initMain(bool desktopSettingsAware = false, bool use96Dpi = true, bool logCritical = true);
|
static void initMain(bool desktopSettingsAware = false, bool use96Dpi = false, bool logCritical = true);
|
||||||
//初始化opengl类型(1=AA_UseDesktopOpenGL 2=AA_UseOpenGLES 3=AA_UseSoftwareOpenGL)
|
//初始化opengl类型(1=AA_UseDesktopOpenGL 2=AA_UseOpenGLES 3=AA_UseSoftwareOpenGL)
|
||||||
static void initOpenGL(quint8 type = 0, bool checkCardEnable = false, bool checkVirtualSystem = false);
|
static void initOpenGL(quint8 type = 0, bool checkCardEnable = false, bool checkVirtualSystem = false);
|
||||||
|
|
||||||
|
//读取qss文件获取样式表内容
|
||||||
|
static QString getStyle(const QString &qssFile);
|
||||||
|
//设置qss文件到全局样式
|
||||||
|
static void setStyle(const QString &qssFile);
|
||||||
|
|
||||||
//执行命令行返回执行结果
|
//执行命令行返回执行结果
|
||||||
static QString doCmd(const QString &program, const QStringList &arguments, int timeout = 1000);
|
static QString doCmd(const QString &program, const QStringList &arguments, int timeout = 1000);
|
||||||
//获取显卡是否被禁用
|
//获取显卡是否被禁用
|
||||||
@@ -96,6 +104,7 @@ public:
|
|||||||
static bool isVirtualSystem();
|
static bool isVirtualSystem();
|
||||||
|
|
||||||
//插入消息
|
//插入消息
|
||||||
|
static bool replaceCRLF;
|
||||||
static QVector<int> msgTypes;
|
static QVector<int> msgTypes;
|
||||||
static QVector<QString> msgKeys;
|
static QVector<QString> msgKeys;
|
||||||
static QVector<QColor> msgColors;
|
static QVector<QColor> msgColors;
|
||||||
@@ -173,8 +182,9 @@ public:
|
|||||||
//设置开机自启动
|
//设置开机自启动
|
||||||
static void runWithSystem(bool autoRun = true);
|
static void runWithSystem(bool autoRun = true);
|
||||||
static void runWithSystem(const QString &fileName, const QString &filePath, bool autoRun = true);
|
static void runWithSystem(const QString &fileName, const QString &filePath, bool autoRun = true);
|
||||||
|
|
||||||
//启动运行程序(已经在运行则不启动)
|
//启动运行程序(已经在运行则不启动)
|
||||||
static void runBin(const QString &path, const QString &name);
|
static void start(const QString &path, const QString &name, bool bin = true);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QTHELPER_H
|
#endif // QTHELPER_H
|
||||||
|
|||||||
@@ -3,13 +3,7 @@
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
QtHelper::initMain();
|
||||||
QApplication::setAttribute(Qt::AA_Use96Dpi);
|
|
||||||
#endif
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
|
|
||||||
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
a.setWindowIcon(QIcon(":/main.ico"));
|
a.setWindowIcon(QIcon(":/main.ico"));
|
||||||
|
|
||||||
@@ -21,7 +15,7 @@ int main(int argc, char *argv[])
|
|||||||
AppConfig::readConfig();
|
AppConfig::readConfig();
|
||||||
|
|
||||||
frmMain w;
|
frmMain w;
|
||||||
w.setWindowTitle("网络中转服务器 V2023 (QQ: 517216493 WX: feiyangqingyun)");
|
w.setWindowTitle("网络中转服务器 V2024 (QQ: 517216493 WX: feiyangqingyun)");
|
||||||
w.resize(900, 650);
|
w.resize(900, 650);
|
||||||
QtHelper::setFormInCenter(&w);
|
QtHelper::setFormInCenter(&w);
|
||||||
w.show();
|
w.show();
|
||||||
|
|||||||
@@ -4,21 +4,41 @@
|
|||||||
|
|
||||||
#define TIMEMS qPrintable(QTime::currentTime().toString("HH:mm:ss zzz"))
|
#define TIMEMS qPrintable(QTime::currentTime().toString("HH:mm:ss zzz"))
|
||||||
|
|
||||||
QList<QRect> QtHelper::getScreenRects(bool available)
|
bool QtHelper::useRatio = true;
|
||||||
|
|
||||||
|
//full指宽屏/就是将所有屏幕拼接在一起
|
||||||
|
QList<QRect> QtHelper::getScreenRects(bool available, bool full)
|
||||||
{
|
{
|
||||||
|
QRect rect;
|
||||||
QList<QRect> rects;
|
QList<QRect> rects;
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
||||||
int screenCount = qApp->screens().count();
|
|
||||||
QList<QScreen *> screens = qApp->screens();
|
QList<QScreen *> screens = qApp->screens();
|
||||||
|
int screenCount = screens.count();
|
||||||
for (int i = 0; i < screenCount; ++i) {
|
for (int i = 0; i < screenCount; ++i) {
|
||||||
QScreen *screen = screens.at(i);
|
QScreen *screen = screens.at(i);
|
||||||
rects << (available ? screen->availableGeometry() : screen->geometry());
|
if (full) {
|
||||||
|
rect = (available ? screen->availableVirtualGeometry() : screen->virtualGeometry());
|
||||||
|
} else {
|
||||||
|
rect = (available ? screen->availableGeometry() : screen->geometry());
|
||||||
|
}
|
||||||
|
|
||||||
|
//需要根据缩放比来重新调整宽高
|
||||||
|
qreal ratio = (QtHelper::useRatio ? screen->devicePixelRatio() : 1);
|
||||||
|
rect.setWidth(rect.width() * ratio);
|
||||||
|
rect.setHeight(rect.height() * ratio);
|
||||||
|
rects << rect;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
int screenCount = qApp->desktop()->screenCount();
|
|
||||||
QDesktopWidget *desk = qApp->desktop();
|
QDesktopWidget *desk = qApp->desktop();
|
||||||
|
int screenCount = desk->screenCount();
|
||||||
for (int i = 0; i < screenCount; ++i) {
|
for (int i = 0; i < screenCount; ++i) {
|
||||||
rects << (available ? desk->availableGeometry(i) : desk->screenGeometry(i));
|
if (full) {
|
||||||
|
rect = (available ? desk->geometry() : desk->geometry());
|
||||||
|
} else {
|
||||||
|
rect = (available ? desk->availableGeometry(i) : desk->screenGeometry(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
rects << rect;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return rects;
|
return rects;
|
||||||
@@ -42,22 +62,23 @@ int QtHelper::getScreenIndex()
|
|||||||
return screenIndex;
|
return screenIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
QRect QtHelper::getScreenRect(bool available)
|
QRect QtHelper::getScreenRect(bool available, bool full)
|
||||||
{
|
{
|
||||||
int screenIndex = getScreenIndex();
|
int screenIndex = getScreenIndex();
|
||||||
QList<QRect> rects = getScreenRects(available);
|
QList<QRect> rects = getScreenRects(available, full);
|
||||||
return rects.at(screenIndex);
|
return rects.at(screenIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal QtHelper::getScreenRatio(bool devicePixel)
|
qreal QtHelper::getScreenRatio(int index, bool devicePixel)
|
||||||
{
|
{
|
||||||
qreal ratio = 1.0;
|
qreal ratio = 1.0;
|
||||||
int screenIndex = getScreenIndex();
|
//索引-1则自动获取鼠标所在当前屏幕
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
int screenIndex = (index == -1 ? getScreenIndex() : index);
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(5,5,0))
|
||||||
QScreen *screen = qApp->screens().at(screenIndex);
|
QScreen *screen = qApp->screens().at(screenIndex);
|
||||||
if (devicePixel) {
|
if (devicePixel) {
|
||||||
//需要开启 AA_EnableHighDpiScaling 属性才能正常获取
|
//需要开启 AA_EnableHighDpiScaling 属性才能正常获取
|
||||||
ratio = screen->devicePixelRatio() * 100;
|
ratio = screen->devicePixelRatio() * 96;
|
||||||
} else {
|
} else {
|
||||||
ratio = screen->logicalDotsPerInch();
|
ratio = screen->logicalDotsPerInch();
|
||||||
}
|
}
|
||||||
@@ -188,10 +209,15 @@ QString QtHelper::getIniValue(const QString &fileName, const QString &key)
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QtHelper::getIniValue(char *argv[], const QString &key, const QString &dir)
|
QString QtHelper::getIniValue(char *argv[], const QString &key, const QString &dir, const QString &file)
|
||||||
{
|
{
|
||||||
QString path, name;
|
QString path, name;
|
||||||
QtHelper::getCurrentInfo(argv, path, name);
|
QtHelper::getCurrentInfo(argv, path, name);
|
||||||
|
//指定了名称则取指定的名称/防止程序重命名
|
||||||
|
if (!file.isEmpty()) {
|
||||||
|
name = file;
|
||||||
|
}
|
||||||
|
|
||||||
QString fileName = QString("%1/%2%3.ini").arg(path).arg(dir).arg(name);
|
QString fileName = QString("%1/%2%3.ini").arg(path).arg(dir).arg(name);
|
||||||
return getIniValue(fileName, key);
|
return getIniValue(fileName, key);
|
||||||
}
|
}
|
||||||
@@ -236,6 +262,33 @@ QStringList QtHelper::getLocalIPs()
|
|||||||
return ips;
|
return ips;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QtHelper::initLocalIPs(QComboBox *cbox, const QString &defaultIP, bool local127)
|
||||||
|
{
|
||||||
|
QStringList ips;
|
||||||
|
if (local127) {
|
||||||
|
ips << "127.0.0.1";
|
||||||
|
}
|
||||||
|
|
||||||
|
//添加本地网卡地址集合
|
||||||
|
ips << QtHelper::getLocalIPs();
|
||||||
|
|
||||||
|
//不在网卡地址列表中则取第一个
|
||||||
|
QString ip = defaultIP;
|
||||||
|
if (ips.count() > 0) {
|
||||||
|
ip = ips.contains(ip) ? ip : ips.first();
|
||||||
|
}
|
||||||
|
|
||||||
|
//设置当前下拉框索引
|
||||||
|
int index = ips.indexOf(ip);
|
||||||
|
cbox->addItems(ips);
|
||||||
|
cbox->setCurrentIndex(index < 0 ? 0 : index);
|
||||||
|
|
||||||
|
//如果有文本框还要设置文本框的值
|
||||||
|
if (cbox->lineEdit()) {
|
||||||
|
cbox->lineEdit()->setText(ip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QList<QColor> QtHelper::colors = QList<QColor>();
|
QList<QColor> QtHelper::colors = QList<QColor>();
|
||||||
QList<QColor> QtHelper::getColorList()
|
QList<QColor> QtHelper::getColorList()
|
||||||
{
|
{
|
||||||
@@ -416,7 +469,8 @@ void QtHelper::checkRun()
|
|||||||
void QtHelper::setStyle()
|
void QtHelper::setStyle()
|
||||||
{
|
{
|
||||||
//打印下所有内置风格的名字
|
//打印下所有内置风格的名字
|
||||||
qDebug() << TIMEMS << "QStyleFactory::keys" << QStyleFactory::keys();
|
//qDebug() << TIMEMS << "QStyleFactory::keys" << QStyleFactory::keys();
|
||||||
|
|
||||||
//设置内置风格
|
//设置内置风格
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
||||||
qApp->setStyle("Fusion");
|
qApp->setStyle("Fusion");
|
||||||
@@ -477,22 +531,16 @@ void QtHelper::setFont(int fontSize)
|
|||||||
|
|
||||||
void QtHelper::setCode(bool utf8)
|
void QtHelper::setCode(bool utf8)
|
||||||
{
|
{
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
|
||||||
//如果想要控制台打印信息中文正常就注释掉这个设置
|
|
||||||
if (utf8) {
|
|
||||||
QTextCodec *codec = QTextCodec::codecForName("utf-8");
|
QTextCodec *codec = QTextCodec::codecForName("utf-8");
|
||||||
QTextCodec::setCodecForLocale(codec);
|
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
|
||||||
}
|
|
||||||
#else
|
|
||||||
#if _MSC_VER
|
|
||||||
QTextCodec *codec = QTextCodec::codecForName("gbk");
|
|
||||||
#else
|
|
||||||
QTextCodec *codec = QTextCodec::codecForName("utf-8");
|
|
||||||
#endif
|
|
||||||
QTextCodec::setCodecForLocale(codec);
|
|
||||||
QTextCodec::setCodecForCStrings(codec);
|
QTextCodec::setCodecForCStrings(codec);
|
||||||
QTextCodec::setCodecForTr(codec);
|
QTextCodec::setCodecForTr(codec);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//如果想要控制台打印信息中文正常就注释掉这个设置/setCodecForLocale会影响toLocal8Bit函数
|
||||||
|
if (utf8) {
|
||||||
|
QTextCodec::setCodecForLocale(codec);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtHelper::setTranslator(const QString &qmFile)
|
void QtHelper::setTranslator(const QString &qmFile)
|
||||||
@@ -585,11 +633,16 @@ void QtHelper::initAll(bool utf8, bool style, int fontSize)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef webengine
|
||||||
|
#include "qquickwindow.h"
|
||||||
|
#endif
|
||||||
void QtHelper::initMain(bool desktopSettingsAware, bool use96Dpi, bool logCritical)
|
void QtHelper::initMain(bool desktopSettingsAware, bool use96Dpi, bool logCritical)
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_LINUX
|
||||||
//Qt6.5开始默认是ffmpeg后端但是不成熟需要换成系统的
|
#ifndef Q_OS_ANDROID
|
||||||
qputenv("QT_MEDIA_BACKEND", "windows");
|
//Qt6开始默认用wayland/由于没有坐标系统导致无边框窗体不可用
|
||||||
|
//qputenv("QT_QPA_PLATFORM", "xcb");
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
||||||
@@ -597,15 +650,17 @@ void QtHelper::initMain(bool desktopSettingsAware, bool use96Dpi, bool logCritic
|
|||||||
QApplication::setDesktopSettingsAware(desktopSettingsAware);
|
QApplication::setDesktopSettingsAware(desktopSettingsAware);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool highDpi = !use96Dpi;
|
//安卓必须启用高分屏
|
||||||
#ifdef Q_OS_ANDROID
|
#ifdef Q_OS_ANDROID
|
||||||
highDpi = true;
|
use96Dpi = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,6,0))
|
QtHelper::useRatio = use96Dpi;
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(5,6,0) && QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||||
//开启高分屏缩放支持
|
//开启高分屏缩放支持
|
||||||
if (highDpi) {
|
if (!use96Dpi) {
|
||||||
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||||
|
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -622,7 +677,7 @@ void QtHelper::initMain(bool desktopSettingsAware, bool use96Dpi, bool logCritic
|
|||||||
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
|
||||||
//高分屏缩放策略
|
//高分屏缩放策略
|
||||||
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor);
|
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
||||||
@@ -636,6 +691,13 @@ void QtHelper::initMain(bool desktopSettingsAware, bool use96Dpi, bool logCritic
|
|||||||
//设置opengl共享上下文
|
//设置opengl共享上下文
|
||||||
QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
|
QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
||||||
|
#ifdef webengine
|
||||||
|
//修复openglwidget和webengine共存出现黑屏的bug
|
||||||
|
QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtHelper::initOpenGL(quint8 type, bool checkCardEnable, bool checkVirtualSystem)
|
void QtHelper::initOpenGL(quint8 type, bool checkCardEnable, bool checkVirtualSystem)
|
||||||
@@ -664,6 +726,39 @@ void QtHelper::initOpenGL(quint8 type, bool checkCardEnable, bool checkVirtualSy
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString QtHelper::getStyle(const QString &qssFile)
|
||||||
|
{
|
||||||
|
QString qss;
|
||||||
|
QFile file(qssFile);
|
||||||
|
if (file.open(QFile::ReadOnly)) {
|
||||||
|
#if 0
|
||||||
|
qss = QLatin1String(file.readAll());
|
||||||
|
#else
|
||||||
|
//用下面这种方式读取可以不用区分文件编码
|
||||||
|
QStringList list;
|
||||||
|
QTextStream stream(&file);
|
||||||
|
while (!stream.atEnd()) {
|
||||||
|
QString line;
|
||||||
|
stream >> line;
|
||||||
|
list << line;
|
||||||
|
}
|
||||||
|
qss = list.join("\n");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
return qss.trimmed();
|
||||||
|
}
|
||||||
|
|
||||||
|
void QtHelper::setStyle(const QString &qssFile)
|
||||||
|
{
|
||||||
|
QString qss = QtHelper::getStyle(qssFile);
|
||||||
|
if (!qss.isEmpty()) {
|
||||||
|
QString paletteColor = qss.mid(20, 7);
|
||||||
|
qApp->setPalette(QPalette(QColor(paletteColor)));
|
||||||
|
qApp->setStyleSheet(qss);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QString QtHelper::doCmd(const QString &program, const QStringList &arguments, int timeout)
|
QString QtHelper::doCmd(const QString &program, const QStringList &arguments, int timeout)
|
||||||
{
|
{
|
||||||
QString result;
|
QString result;
|
||||||
@@ -728,6 +823,7 @@ bool QtHelper::isVirtualSystem()
|
|||||||
return virtualSystem;
|
return virtualSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool QtHelper::replaceCRLF = true;
|
||||||
QVector<int> QtHelper::msgTypes = QVector<int>() << 0 << 1 << 2 << 3 << 4;
|
QVector<int> QtHelper::msgTypes = QVector<int>() << 0 << 1 << 2 << 3 << 4;
|
||||||
QVector<QString> QtHelper::msgKeys = QVector<QString>() << QString::fromUtf8("发送") << QString::fromUtf8("接收") << QString::fromUtf8("解析") << QString::fromUtf8("错误") << QString::fromUtf8("提示");
|
QVector<QString> QtHelper::msgKeys = QVector<QString>() << QString::fromUtf8("发送") << QString::fromUtf8("接收") << QString::fromUtf8("解析") << QString::fromUtf8("错误") << QString::fromUtf8("提示");
|
||||||
QVector<QColor> QtHelper::msgColors = QVector<QColor>() << QColor("#3BA372") << QColor("#EE6668") << QColor("#9861B4") << QColor("#FA8359") << QColor("#22A3A9");
|
QVector<QColor> QtHelper::msgColors = QVector<QColor>() << QColor("#3BA372") << QColor("#EE6668") << QColor("#9861B4") << QColor("#FA8359") << QColor("#22A3A9");
|
||||||
@@ -758,8 +854,11 @@ QString QtHelper::appendMsg(QTextEdit *textEdit, int type, const QString &data,
|
|||||||
|
|
||||||
//过滤回车换行符
|
//过滤回车换行符
|
||||||
QString strData = data;
|
QString strData = data;
|
||||||
|
if (replaceCRLF) {
|
||||||
strData.replace("\r", "");
|
strData.replace("\r", "");
|
||||||
strData.replace("\n", "");
|
strData.replace("\n", "");
|
||||||
|
}
|
||||||
|
|
||||||
strData = QString("时间[%1] %2: %3").arg(TIMEMS).arg(strType).arg(strData);
|
strData = QString("时间[%1] %2: %3").arg(TIMEMS).arg(strType).arg(strData);
|
||||||
textEdit->append(strData);
|
textEdit->append(strData);
|
||||||
currentCount++;
|
currentCount++;
|
||||||
@@ -809,7 +908,7 @@ void QtHelper::showMessageBoxInfo(const QString &text, int closeSec, bool exec)
|
|||||||
{
|
{
|
||||||
QMessageBox box(QMessageBox::Information, "提示", text);
|
QMessageBox box(QMessageBox::Information, "提示", text);
|
||||||
box.setStandardButtons(QMessageBox::Yes);
|
box.setStandardButtons(QMessageBox::Yes);
|
||||||
box.setButtonText(QMessageBox::Yes, QString("确 定"));
|
box.button(QMessageBox::Yes)->setText("确 定");
|
||||||
box.exec();
|
box.exec();
|
||||||
//QMessageBox::information(0, "提示", info, QMessageBox::Yes);
|
//QMessageBox::information(0, "提示", info, QMessageBox::Yes);
|
||||||
}
|
}
|
||||||
@@ -818,7 +917,7 @@ void QtHelper::showMessageBoxError(const QString &text, int closeSec, bool exec)
|
|||||||
{
|
{
|
||||||
QMessageBox box(QMessageBox::Critical, "错误", text);
|
QMessageBox box(QMessageBox::Critical, "错误", text);
|
||||||
box.setStandardButtons(QMessageBox::Yes);
|
box.setStandardButtons(QMessageBox::Yes);
|
||||||
box.setButtonText(QMessageBox::Yes, QString("确 定"));
|
box.button(QMessageBox::Yes)->setText("确 定");
|
||||||
box.exec();
|
box.exec();
|
||||||
//QMessageBox::critical(0, "错误", info, QMessageBox::Yes);
|
//QMessageBox::critical(0, "错误", info, QMessageBox::Yes);
|
||||||
}
|
}
|
||||||
@@ -827,8 +926,8 @@ int QtHelper::showMessageBoxQuestion(const QString &text)
|
|||||||
{
|
{
|
||||||
QMessageBox box(QMessageBox::Question, "询问", text);
|
QMessageBox box(QMessageBox::Question, "询问", text);
|
||||||
box.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
box.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
||||||
box.setButtonText(QMessageBox::Yes, QString("确 定"));
|
box.button(QMessageBox::Yes)->setText("确 定");
|
||||||
box.setButtonText(QMessageBox::No, QString("取 消"));
|
box.button(QMessageBox::No)->setText("取 消");
|
||||||
return box.exec();
|
return box.exec();
|
||||||
//return QMessageBox::question(0, "询问", info, QMessageBox::Yes | QMessageBox::No);
|
//return QMessageBox::question(0, "询问", info, QMessageBox::Yes | QMessageBox::No);
|
||||||
}
|
}
|
||||||
@@ -1165,16 +1264,16 @@ QString QtHelper::getSizeString(quint64 size)
|
|||||||
void QtHelper::setSystemDateTime(const QString &year, const QString &month, const QString &day, const QString &hour, const QString &min, const QString &sec)
|
void QtHelper::setSystemDateTime(const QString &year, const QString &month, const QString &day, const QString &hour, const QString &min, const QString &sec)
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
QProcess p(0);
|
QProcess p;
|
||||||
//先设置日期
|
//先设置日期
|
||||||
p.start("cmd");
|
p.start("cmd", QStringList());
|
||||||
p.waitForStarted();
|
p.waitForStarted();
|
||||||
p.write(QString("date %1-%2-%3\n").arg(year).arg(month).arg(day).toLatin1());
|
p.write(QString("date %1-%2-%3\n").arg(year).arg(month).arg(day).toLatin1());
|
||||||
p.closeWriteChannel();
|
p.closeWriteChannel();
|
||||||
p.waitForFinished(1000);
|
p.waitForFinished(1000);
|
||||||
p.close();
|
p.close();
|
||||||
//再设置时间
|
//再设置时间
|
||||||
p.start("cmd");
|
p.start("cmd", QStringList());
|
||||||
p.waitForStarted();
|
p.waitForStarted();
|
||||||
p.write(QString("time %1:%2:%3.00\n").arg(hour).arg(min).arg(sec).toLatin1());
|
p.write(QString("time %1:%2:%3.00\n").arg(hour).arg(min).arg(sec).toLatin1());
|
||||||
p.closeWriteChannel();
|
p.closeWriteChannel();
|
||||||
@@ -1203,11 +1302,11 @@ void QtHelper::runWithSystem(const QString &fileName, const QString &filePath, b
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtHelper::runBin(const QString &path, const QString &name)
|
void QtHelper::start(const QString &path, const QString &name, bool bin)
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
QString cmd1 = "tasklist";
|
QString cmd1 = "tasklist";
|
||||||
QString cmd2 = QString("%1/%2.exe").arg(path).arg(name);
|
QString cmd2 = QString("%1/%2%3").arg(path).arg(name).arg(bin ? ".exe" : "");
|
||||||
#else
|
#else
|
||||||
QString cmd1 = "ps -aux";
|
QString cmd1 = "ps -aux";
|
||||||
QString cmd2 = QString("%1/%2").arg(path).arg(name);
|
QString cmd2 = QString("%1/%2").arg(path).arg(name);
|
||||||
@@ -1215,7 +1314,7 @@ void QtHelper::runBin(const QString &path, const QString &name)
|
|||||||
|
|
||||||
#ifndef Q_OS_WASM
|
#ifndef Q_OS_WASM
|
||||||
QProcess p;
|
QProcess p;
|
||||||
p.start(cmd1);
|
p.start(cmd1, QStringList());
|
||||||
if (p.waitForFinished()) {
|
if (p.waitForFinished()) {
|
||||||
QString result = p.readAll();
|
QString result = p.readAll();
|
||||||
if (result.contains(name)) {
|
if (result.contains(name)) {
|
||||||
@@ -1228,7 +1327,11 @@ void QtHelper::runBin(const QString &path, const QString &name)
|
|||||||
cmd2 = "\"" + cmd2 + "\"";
|
cmd2 = "\"" + cmd2 + "\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
//QProcess::execute(cmd2);
|
//切换到当前目录
|
||||||
QProcess::startDetached(cmd2);
|
QDir::setCurrent(path);
|
||||||
|
//QProcess::execute(cmd2, QStringList());
|
||||||
|
QProcess::startDetached(cmd2, QStringList());
|
||||||
|
//执行完成后切换回默认目录
|
||||||
|
QDir::setCurrent(QtHelper::appPath());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,10 +7,11 @@ class QtHelper
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//获取所有屏幕区域/当前鼠标所在屏幕索引/区域尺寸/缩放系数
|
//获取所有屏幕区域/当前鼠标所在屏幕索引/区域尺寸/缩放系数
|
||||||
static QList<QRect> getScreenRects(bool available = true);
|
static bool useRatio;
|
||||||
|
static QList<QRect> getScreenRects(bool available = true, bool full = false);
|
||||||
static int getScreenIndex();
|
static int getScreenIndex();
|
||||||
static QRect getScreenRect(bool available = true);
|
static QRect getScreenRect(bool available = true, bool full = false);
|
||||||
static qreal getScreenRatio(bool devicePixel = false);
|
static qreal getScreenRatio(int index = -1, bool devicePixel = false);
|
||||||
|
|
||||||
//矫正当前鼠标所在屏幕居中尺寸
|
//矫正当前鼠标所在屏幕居中尺寸
|
||||||
static QRect checkCenterRect(QRect &rect, bool available = true);
|
static QRect checkCenterRect(QRect &rect, bool available = true);
|
||||||
@@ -34,10 +35,12 @@ public:
|
|||||||
static void getCurrentInfo(char *argv[], QString &path, QString &name);
|
static void getCurrentInfo(char *argv[], QString &path, QString &name);
|
||||||
//程序最前面读取配置文件节点的值
|
//程序最前面读取配置文件节点的值
|
||||||
static QString getIniValue(const QString &fileName, const QString &key);
|
static QString getIniValue(const QString &fileName, const QString &key);
|
||||||
static QString getIniValue(char *argv[], const QString &key, const QString &dir = QString());
|
static QString getIniValue(char *argv[], const QString &key, const QString &dir = QString(), const QString &file = QString());
|
||||||
|
|
||||||
//获取本地网卡IP集合
|
//获取本地网卡IP集合
|
||||||
static QStringList getLocalIPs();
|
static QStringList getLocalIPs();
|
||||||
|
//添加网卡集合并根据默认值设置当前项
|
||||||
|
static void initLocalIPs(QComboBox *cbox, const QString &defaultIP, bool local127 = true);
|
||||||
|
|
||||||
//获取内置颜色集合
|
//获取内置颜色集合
|
||||||
static QList<QColor> colors;
|
static QList<QColor> colors;
|
||||||
@@ -84,10 +87,15 @@ public:
|
|||||||
//一次性设置所有包括编码样式字体等
|
//一次性设置所有包括编码样式字体等
|
||||||
static void initAll(bool utf8 = true, bool style = true, int fontSize = 13);
|
static void initAll(bool utf8 = true, bool style = true, int fontSize = 13);
|
||||||
//初始化main函数最前面执行的一段代码
|
//初始化main函数最前面执行的一段代码
|
||||||
static void initMain(bool desktopSettingsAware = false, bool use96Dpi = true, bool logCritical = true);
|
static void initMain(bool desktopSettingsAware = false, bool use96Dpi = false, bool logCritical = true);
|
||||||
//初始化opengl类型(1=AA_UseDesktopOpenGL 2=AA_UseOpenGLES 3=AA_UseSoftwareOpenGL)
|
//初始化opengl类型(1=AA_UseDesktopOpenGL 2=AA_UseOpenGLES 3=AA_UseSoftwareOpenGL)
|
||||||
static void initOpenGL(quint8 type = 0, bool checkCardEnable = false, bool checkVirtualSystem = false);
|
static void initOpenGL(quint8 type = 0, bool checkCardEnable = false, bool checkVirtualSystem = false);
|
||||||
|
|
||||||
|
//读取qss文件获取样式表内容
|
||||||
|
static QString getStyle(const QString &qssFile);
|
||||||
|
//设置qss文件到全局样式
|
||||||
|
static void setStyle(const QString &qssFile);
|
||||||
|
|
||||||
//执行命令行返回执行结果
|
//执行命令行返回执行结果
|
||||||
static QString doCmd(const QString &program, const QStringList &arguments, int timeout = 1000);
|
static QString doCmd(const QString &program, const QStringList &arguments, int timeout = 1000);
|
||||||
//获取显卡是否被禁用
|
//获取显卡是否被禁用
|
||||||
@@ -96,6 +104,7 @@ public:
|
|||||||
static bool isVirtualSystem();
|
static bool isVirtualSystem();
|
||||||
|
|
||||||
//插入消息
|
//插入消息
|
||||||
|
static bool replaceCRLF;
|
||||||
static QVector<int> msgTypes;
|
static QVector<int> msgTypes;
|
||||||
static QVector<QString> msgKeys;
|
static QVector<QString> msgKeys;
|
||||||
static QVector<QColor> msgColors;
|
static QVector<QColor> msgColors;
|
||||||
@@ -173,8 +182,9 @@ public:
|
|||||||
//设置开机自启动
|
//设置开机自启动
|
||||||
static void runWithSystem(bool autoRun = true);
|
static void runWithSystem(bool autoRun = true);
|
||||||
static void runWithSystem(const QString &fileName, const QString &filePath, bool autoRun = true);
|
static void runWithSystem(const QString &fileName, const QString &filePath, bool autoRun = true);
|
||||||
|
|
||||||
//启动运行程序(已经在运行则不启动)
|
//启动运行程序(已经在运行则不启动)
|
||||||
static void runBin(const QString &path, const QString &name);
|
static void start(const QString &path, const QString &name, bool bin = true);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QTHELPER_H
|
#endif // QTHELPER_H
|
||||||
|
|||||||
@@ -3,13 +3,7 @@
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
QtHelper::initMain();
|
||||||
QApplication::setAttribute(Qt::AA_Use96Dpi);
|
|
||||||
#endif
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
|
|
||||||
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
a.setWindowIcon(QIcon(":/main.ico"));
|
a.setWindowIcon(QIcon(":/main.ico"));
|
||||||
|
|
||||||
@@ -25,7 +19,7 @@ int main(int argc, char *argv[])
|
|||||||
AppData::readDeviceData();
|
AppData::readDeviceData();
|
||||||
|
|
||||||
frmMain w;
|
frmMain w;
|
||||||
w.setWindowTitle("网络调试助手 V2023 (QQ: 517216493 WX: feiyangqingyun)");
|
w.setWindowTitle("网络调试助手 V2024 (QQ: 517216493 WX: feiyangqingyun)");
|
||||||
w.resize(950, 700);
|
w.resize(950, 700);
|
||||||
QtHelper::setFormInCenter(&w);
|
QtHelper::setFormInCenter(&w);
|
||||||
w.show();
|
w.show();
|
||||||
|
|||||||
@@ -34,26 +34,17 @@ bool AppInit::eventFilter(QObject *watched, QEvent *event)
|
|||||||
static bool mousePressed = false;
|
static bool mousePressed = false;
|
||||||
|
|
||||||
int type = event->type();
|
int type = event->type();
|
||||||
QPoint p;
|
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
|
||||||
QMouseEvent *mouseEvent = (QMouseEvent *)(event);
|
|
||||||
if (mouseEvent) {
|
|
||||||
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
|
||||||
p = mouseEvent->globalPos();
|
|
||||||
#else
|
|
||||||
p = mouseEvent->globalPosition().toPoint();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type == QEvent::MouseButtonPress) {
|
if (type == QEvent::MouseButtonPress) {
|
||||||
if (mouseEvent->button() == Qt::LeftButton) {
|
if (mouseEvent->button() == Qt::LeftButton) {
|
||||||
mousePressed = true;
|
mousePressed = true;
|
||||||
mousePoint = p - w->pos();
|
mousePoint = mouseEvent->globalPos() - w->pos();
|
||||||
}
|
}
|
||||||
} else if (type == QEvent::MouseButtonRelease) {
|
} else if (type == QEvent::MouseButtonRelease) {
|
||||||
mousePressed = false;
|
mousePressed = false;
|
||||||
} else if (type == QEvent::MouseMove) {
|
} else if (type == QEvent::MouseMove) {
|
||||||
if (mousePressed) {
|
if (mousePressed) {
|
||||||
w->move(p - mousePoint);
|
w->move(mouseEvent->globalPos() - mousePoint);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,9 +19,6 @@ DESTDIR = $$PWD/../bin
|
|||||||
|
|
||||||
#把所有警告都关掉眼不见为净
|
#把所有警告都关掉眼不见为净
|
||||||
CONFIG += warn_off
|
CONFIG += warn_off
|
||||||
#QMAKE_CXXFLAGS_WARN_ON -= -w34100
|
|
||||||
#QMAKE_CXXFLAGS *= -Wno-unused-parameter
|
|
||||||
|
|
||||||
#开启大资源支持
|
#开启大资源支持
|
||||||
CONFIG += resources_big
|
CONFIG += resources_big
|
||||||
#开启后会将打印信息用控制台输出
|
#开启后会将打印信息用控制台输出
|
||||||
@@ -29,8 +26,7 @@ CONFIG += resources_big
|
|||||||
#开启后不会生成空的 debug release 目录
|
#开启后不会生成空的 debug release 目录
|
||||||
#CONFIG -= debug_and_release
|
#CONFIG -= debug_and_release
|
||||||
|
|
||||||
#引入全志H3芯片依赖(不需要的用户可以删除)
|
include ($$PWD/core_util.pri)
|
||||||
include ($$PWD/h3.pri)
|
|
||||||
#将当前目录加入到头文件路径
|
#将当前目录加入到头文件路径
|
||||||
INCLUDEPATH += $$PWD
|
INCLUDEPATH += $$PWD
|
||||||
|
|
||||||
|
|||||||
37
ui/core_helper/core_util.pri
Normal file
37
ui/core_helper/core_util.pri
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#定义复制文件到目录的函数
|
||||||
|
#为什么上面不加win{}这种
|
||||||
|
#因为还有在win/linux上的安卓套件/他并不是win/linux套件
|
||||||
|
#所以两种命令都执行保证任意系统可用
|
||||||
|
defineTest(copyToDestDir) {
|
||||||
|
#取出对应的参数变量
|
||||||
|
srcFile = $$1
|
||||||
|
dstPath = $$2
|
||||||
|
|
||||||
|
#linux和mac系统拷贝
|
||||||
|
system($$QMAKE_COPY $$srcFile $$dstPath)
|
||||||
|
|
||||||
|
#win上需要转换路径
|
||||||
|
srcFile2 = $$srcFile
|
||||||
|
dstPath2 = $$dstPath
|
||||||
|
srcFile2 ~= s,/,\\,g
|
||||||
|
dstPath2 ~= s,/,\\,g
|
||||||
|
system($$QMAKE_COPY $$srcFile2 $$dstPath2)
|
||||||
|
}
|
||||||
|
|
||||||
|
#新建目录/在win上目录不存在的话需要主动新建/linux会自动
|
||||||
|
defineTest(newPath) {
|
||||||
|
path = $$1
|
||||||
|
win32 {
|
||||||
|
path ~= s,/,\\,g
|
||||||
|
}
|
||||||
|
system(mkdir $$path)
|
||||||
|
}
|
||||||
|
|
||||||
|
#引入全志H3芯片依赖(不需要的用户可以删除)
|
||||||
|
unix:!macx {
|
||||||
|
contains(QT_ARCH, arm) {
|
||||||
|
contains(DEFINES, arma7) {
|
||||||
|
INCLUDEPATH += /usr/local/openssl-1.0.2m-h3-gcc-4.9.2/include
|
||||||
|
LIBS += -L/usr/local/openssl-1.0.2m-h3-gcc-4.9.2/lib -lssl -lcrypto
|
||||||
|
LIBS += -L/usr/local/h3_rootfsv -lXdmcp
|
||||||
|
}}}
|
||||||
@@ -4,26 +4,40 @@
|
|||||||
|
|
||||||
#define TIMEMS qPrintable(QTime::currentTime().toString("HH:mm:ss zzz"))
|
#define TIMEMS qPrintable(QTime::currentTime().toString("HH:mm:ss zzz"))
|
||||||
|
|
||||||
QList<QRect> QtHelper::getScreenRects(bool available)
|
bool QtHelper::useRatio = true;
|
||||||
|
|
||||||
|
//full指宽屏/就是将所有屏幕拼接在一起
|
||||||
|
QList<QRect> QtHelper::getScreenRects(bool available, bool full)
|
||||||
{
|
{
|
||||||
|
QRect rect;
|
||||||
QList<QRect> rects;
|
QList<QRect> rects;
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
||||||
int screenCount = qApp->screens().count();
|
|
||||||
QList<QScreen *> screens = qApp->screens();
|
QList<QScreen *> screens = qApp->screens();
|
||||||
|
int screenCount = screens.count();
|
||||||
for (int i = 0; i < screenCount; ++i) {
|
for (int i = 0; i < screenCount; ++i) {
|
||||||
QScreen *screen = screens.at(i);
|
QScreen *screen = screens.at(i);
|
||||||
|
if (full) {
|
||||||
|
rect = (available ? screen->availableVirtualGeometry() : screen->virtualGeometry());
|
||||||
|
} else {
|
||||||
|
rect = (available ? screen->availableGeometry() : screen->geometry());
|
||||||
|
}
|
||||||
|
|
||||||
//需要根据缩放比来重新调整宽高
|
//需要根据缩放比来重新调整宽高
|
||||||
qreal ratio = screen->devicePixelRatio();
|
qreal ratio = (QtHelper::useRatio ? screen->devicePixelRatio() : 1);
|
||||||
QRect rect = (available ? screen->availableGeometry() : screen->geometry());
|
|
||||||
rect.setWidth(rect.width() * ratio);
|
rect.setWidth(rect.width() * ratio);
|
||||||
rect.setHeight(rect.height() * ratio);
|
rect.setHeight(rect.height() * ratio);
|
||||||
rects << rect;
|
rects << rect;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
int screenCount = qApp->desktop()->screenCount();
|
|
||||||
QDesktopWidget *desk = qApp->desktop();
|
QDesktopWidget *desk = qApp->desktop();
|
||||||
|
int screenCount = desk->screenCount();
|
||||||
for (int i = 0; i < screenCount; ++i) {
|
for (int i = 0; i < screenCount; ++i) {
|
||||||
QRect rect = (available ? desk->availableGeometry(i) : desk->screenGeometry(i));
|
if (full) {
|
||||||
|
rect = (available ? desk->geometry() : desk->geometry());
|
||||||
|
} else {
|
||||||
|
rect = (available ? desk->availableGeometry(i) : desk->screenGeometry(i));
|
||||||
|
}
|
||||||
|
|
||||||
rects << rect;
|
rects << rect;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -48,10 +62,10 @@ int QtHelper::getScreenIndex()
|
|||||||
return screenIndex;
|
return screenIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
QRect QtHelper::getScreenRect(bool available)
|
QRect QtHelper::getScreenRect(bool available, bool full)
|
||||||
{
|
{
|
||||||
int screenIndex = getScreenIndex();
|
int screenIndex = getScreenIndex();
|
||||||
QList<QRect> rects = getScreenRects(available);
|
QList<QRect> rects = getScreenRects(available, full);
|
||||||
return rects.at(screenIndex);
|
return rects.at(screenIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -455,7 +469,8 @@ void QtHelper::checkRun()
|
|||||||
void QtHelper::setStyle()
|
void QtHelper::setStyle()
|
||||||
{
|
{
|
||||||
//打印下所有内置风格的名字
|
//打印下所有内置风格的名字
|
||||||
qDebug() << TIMEMS << "QStyleFactory::keys" << QStyleFactory::keys();
|
//qDebug() << TIMEMS << "QStyleFactory::keys" << QStyleFactory::keys();
|
||||||
|
|
||||||
//设置内置风格
|
//设置内置风格
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
||||||
qApp->setStyle("Fusion");
|
qApp->setStyle("Fusion");
|
||||||
@@ -618,6 +633,9 @@ void QtHelper::initAll(bool utf8, bool style, int fontSize)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef webengine
|
||||||
|
#include "qquickwindow.h"
|
||||||
|
#endif
|
||||||
void QtHelper::initMain(bool desktopSettingsAware, bool use96Dpi, bool logCritical)
|
void QtHelper::initMain(bool desktopSettingsAware, bool use96Dpi, bool logCritical)
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_LINUX
|
#ifdef Q_OS_LINUX
|
||||||
@@ -632,15 +650,17 @@ void QtHelper::initMain(bool desktopSettingsAware, bool use96Dpi, bool logCritic
|
|||||||
QApplication::setDesktopSettingsAware(desktopSettingsAware);
|
QApplication::setDesktopSettingsAware(desktopSettingsAware);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool highDpi = !use96Dpi;
|
//安卓必须启用高分屏
|
||||||
#ifdef Q_OS_ANDROID
|
#ifdef Q_OS_ANDROID
|
||||||
highDpi = true;
|
use96Dpi = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
QtHelper::useRatio = use96Dpi;
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,6,0) && QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5,6,0) && QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||||
//开启高分屏缩放支持
|
//开启高分屏缩放支持
|
||||||
if (highDpi) {
|
if (!use96Dpi) {
|
||||||
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||||
|
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -657,7 +677,7 @@ void QtHelper::initMain(bool desktopSettingsAware, bool use96Dpi, bool logCritic
|
|||||||
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
|
||||||
//高分屏缩放策略
|
//高分屏缩放策略
|
||||||
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor);
|
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
||||||
@@ -671,6 +691,13 @@ void QtHelper::initMain(bool desktopSettingsAware, bool use96Dpi, bool logCritic
|
|||||||
//设置opengl共享上下文
|
//设置opengl共享上下文
|
||||||
QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
|
QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
||||||
|
#ifdef webengine
|
||||||
|
//修复openglwidget和webengine共存出现黑屏的bug
|
||||||
|
QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtHelper::initOpenGL(quint8 type, bool checkCardEnable, bool checkVirtualSystem)
|
void QtHelper::initOpenGL(quint8 type, bool checkCardEnable, bool checkVirtualSystem)
|
||||||
@@ -1275,11 +1302,11 @@ void QtHelper::runWithSystem(const QString &fileName, const QString &filePath, b
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtHelper::runBin(const QString &path, const QString &name)
|
void QtHelper::start(const QString &path, const QString &name, bool bin)
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
QString cmd1 = "tasklist";
|
QString cmd1 = "tasklist";
|
||||||
QString cmd2 = QString("%1/%2.exe").arg(path).arg(name);
|
QString cmd2 = QString("%1/%2%3").arg(path).arg(name).arg(bin ? ".exe" : "");
|
||||||
#else
|
#else
|
||||||
QString cmd1 = "ps -aux";
|
QString cmd1 = "ps -aux";
|
||||||
QString cmd2 = QString("%1/%2").arg(path).arg(name);
|
QString cmd2 = QString("%1/%2").arg(path).arg(name);
|
||||||
|
|||||||
@@ -7,9 +7,10 @@ class QtHelper
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//获取所有屏幕区域/当前鼠标所在屏幕索引/区域尺寸/缩放系数
|
//获取所有屏幕区域/当前鼠标所在屏幕索引/区域尺寸/缩放系数
|
||||||
static QList<QRect> getScreenRects(bool available = true);
|
static bool useRatio;
|
||||||
|
static QList<QRect> getScreenRects(bool available = true, bool full = false);
|
||||||
static int getScreenIndex();
|
static int getScreenIndex();
|
||||||
static QRect getScreenRect(bool available = true);
|
static QRect getScreenRect(bool available = true, bool full = false);
|
||||||
static qreal getScreenRatio(int index = -1, bool devicePixel = false);
|
static qreal getScreenRatio(int index = -1, bool devicePixel = false);
|
||||||
|
|
||||||
//矫正当前鼠标所在屏幕居中尺寸
|
//矫正当前鼠标所在屏幕居中尺寸
|
||||||
@@ -86,7 +87,7 @@ public:
|
|||||||
//一次性设置所有包括编码样式字体等
|
//一次性设置所有包括编码样式字体等
|
||||||
static void initAll(bool utf8 = true, bool style = true, int fontSize = 13);
|
static void initAll(bool utf8 = true, bool style = true, int fontSize = 13);
|
||||||
//初始化main函数最前面执行的一段代码
|
//初始化main函数最前面执行的一段代码
|
||||||
static void initMain(bool desktopSettingsAware = false, bool use96Dpi = true, bool logCritical = true);
|
static void initMain(bool desktopSettingsAware = false, bool use96Dpi = false, bool logCritical = true);
|
||||||
//初始化opengl类型(1=AA_UseDesktopOpenGL 2=AA_UseOpenGLES 3=AA_UseSoftwareOpenGL)
|
//初始化opengl类型(1=AA_UseDesktopOpenGL 2=AA_UseOpenGLES 3=AA_UseSoftwareOpenGL)
|
||||||
static void initOpenGL(quint8 type = 0, bool checkCardEnable = false, bool checkVirtualSystem = false);
|
static void initOpenGL(quint8 type = 0, bool checkCardEnable = false, bool checkVirtualSystem = false);
|
||||||
|
|
||||||
@@ -181,8 +182,9 @@ public:
|
|||||||
//设置开机自启动
|
//设置开机自启动
|
||||||
static void runWithSystem(bool autoRun = true);
|
static void runWithSystem(bool autoRun = true);
|
||||||
static void runWithSystem(const QString &fileName, const QString &filePath, bool autoRun = true);
|
static void runWithSystem(const QString &fileName, const QString &filePath, bool autoRun = true);
|
||||||
|
|
||||||
//启动运行程序(已经在运行则不启动)
|
//启动运行程序(已经在运行则不启动)
|
||||||
static void runBin(const QString &path, const QString &name);
|
static void start(const QString &path, const QString &name, bool bin = true);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QTHELPER_H
|
#endif // QTHELPER_H
|
||||||
|
|||||||
@@ -6,13 +6,6 @@
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
|
||||||
QApplication::setAttribute(Qt::AA_Use96Dpi);
|
|
||||||
#endif
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
|
|
||||||
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
QFont font;
|
QFont font;
|
||||||
font.setFamily("Microsoft Yahei");
|
font.setFamily("Microsoft Yahei");
|
||||||
|
|||||||
@@ -6,14 +6,9 @@
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
qputenv("QT_FONT_DPI", "96");
|
||||||
QApplication::setAttribute(Qt::AA_Use96Dpi);
|
|
||||||
#endif
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
|
|
||||||
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
|
|
||||||
QFont font;
|
QFont font;
|
||||||
font.setFamily("Microsoft Yahei");
|
font.setFamily("Microsoft Yahei");
|
||||||
font.setPixelSize(13);
|
font.setPixelSize(13);
|
||||||
|
|||||||
Reference in New Issue
Block a user