diff --git a/comtool/api/quiwidget.cpp b/comtool/api/quiwidget.cpp index 8adaa68..a4524c3 100644 --- a/comtool/api/quiwidget.cpp +++ b/comtool/api/quiwidget.cpp @@ -2163,6 +2163,14 @@ void QUIHelper::initRand() qsrand(t.msec() + t.second() * 1000); } +QString QUIHelper::getUuid() +{ + QString uuid = QUuid::createUuid().toString(); + uuid = uuid.replace("{", ""); + uuid = uuid.replace("}", ""); + return uuid; +} + void QUIHelper::initDb(const QString &dbName) { initFile(QString(":/%1.db").arg(appName()), dbName); @@ -2544,6 +2552,28 @@ void QUIHelper::setCode() #endif } +void QUIHelper::setFont(const QString &ttfFile, const QString &fontName, int fontSize) +{ + QFont font; + font.setFamily(fontName); + font.setPixelSize(fontSize); + + //如果存在字体文件则设备字体文件中的字体 + //安卓版本和网页版本需要字体文件一起打包单独设置字体 + if (!ttfFile.isEmpty()) { + QFontDatabase fontDb; + int fontId = fontDb.addApplicationFont(ttfFile); + if (fontId != -1) { + QStringList androidFont = fontDb.applicationFontFamilies(fontId); + if (androidFont.size() != 0) { + font.setFamily(androidFont.at(0)); + font.setPixelSize(fontSize); + } + } + } + qApp->setFont(font); +} + void QUIHelper::sleep(int msec) { if (msec > 0) { @@ -3536,6 +3566,9 @@ QStringList QUIHelper::getLocalIPs() { static QStringList ips; if (ips.count() == 0) { +#ifdef emsdk + ips << "127.0.0.1"; +#else QList netInterfaces = QNetworkInterface::allInterfaces(); foreach (const QNetworkInterface &netInterface, netInterfaces) { //移除虚拟机和抓包工具的虚拟网卡 @@ -3559,6 +3592,7 @@ QStringList QUIHelper::getLocalIPs() } } } +#endif } return ips; diff --git a/comtool/api/quiwidget.h b/comtool/api/quiwidget.h index f82981c..589f8d6 100644 --- a/comtool/api/quiwidget.h +++ b/comtool/api/quiwidget.h @@ -593,6 +593,8 @@ public: //初始化随机数种子 static void initRand(); + //获取uuid + static QString getUuid(); //初始化数据库 static void initDb(const QString &dbName); @@ -641,6 +643,9 @@ public: static void setTranslator(const QString &qmFile = ":/image/qt_zh_CN.qm"); //设置编码 static void setCode(); + //设置字体 + static void setFont(const QString &ttfFile = ":/image/DroidSansFallback.ttf", + const QString &fontName = "Microsoft Yahei", int fontSize = 12); //设置延时 static void sleep(int msec); //设置系统时间 diff --git a/nettool/api/quiwidget.cpp b/nettool/api/quiwidget.cpp index 8adaa68..a4524c3 100644 --- a/nettool/api/quiwidget.cpp +++ b/nettool/api/quiwidget.cpp @@ -2163,6 +2163,14 @@ void QUIHelper::initRand() qsrand(t.msec() + t.second() * 1000); } +QString QUIHelper::getUuid() +{ + QString uuid = QUuid::createUuid().toString(); + uuid = uuid.replace("{", ""); + uuid = uuid.replace("}", ""); + return uuid; +} + void QUIHelper::initDb(const QString &dbName) { initFile(QString(":/%1.db").arg(appName()), dbName); @@ -2544,6 +2552,28 @@ void QUIHelper::setCode() #endif } +void QUIHelper::setFont(const QString &ttfFile, const QString &fontName, int fontSize) +{ + QFont font; + font.setFamily(fontName); + font.setPixelSize(fontSize); + + //如果存在字体文件则设备字体文件中的字体 + //安卓版本和网页版本需要字体文件一起打包单独设置字体 + if (!ttfFile.isEmpty()) { + QFontDatabase fontDb; + int fontId = fontDb.addApplicationFont(ttfFile); + if (fontId != -1) { + QStringList androidFont = fontDb.applicationFontFamilies(fontId); + if (androidFont.size() != 0) { + font.setFamily(androidFont.at(0)); + font.setPixelSize(fontSize); + } + } + } + qApp->setFont(font); +} + void QUIHelper::sleep(int msec) { if (msec > 0) { @@ -3536,6 +3566,9 @@ QStringList QUIHelper::getLocalIPs() { static QStringList ips; if (ips.count() == 0) { +#ifdef emsdk + ips << "127.0.0.1"; +#else QList netInterfaces = QNetworkInterface::allInterfaces(); foreach (const QNetworkInterface &netInterface, netInterfaces) { //移除虚拟机和抓包工具的虚拟网卡 @@ -3559,6 +3592,7 @@ QStringList QUIHelper::getLocalIPs() } } } +#endif } return ips; diff --git a/nettool/api/quiwidget.h b/nettool/api/quiwidget.h index f82981c..589f8d6 100644 --- a/nettool/api/quiwidget.h +++ b/nettool/api/quiwidget.h @@ -593,6 +593,8 @@ public: //初始化随机数种子 static void initRand(); + //获取uuid + static QString getUuid(); //初始化数据库 static void initDb(const QString &dbName); @@ -641,6 +643,9 @@ public: static void setTranslator(const QString &qmFile = ":/image/qt_zh_CN.qm"); //设置编码 static void setCode(); + //设置字体 + static void setFont(const QString &ttfFile = ":/image/DroidSansFallback.ttf", + const QString &fontName = "Microsoft Yahei", int fontSize = 12); //设置延时 static void sleep(int msec); //设置系统时间 diff --git a/nettool/form/frmtcpserver.cpp b/nettool/form/frmtcpserver.cpp index e40d828..25fa421 100644 --- a/nettool/form/frmtcpserver.cpp +++ b/nettool/form/frmtcpserver.cpp @@ -35,31 +35,7 @@ void frmTcpServer::initForm() void frmTcpServer::initIP() { //获取本机所有IP - QStringList ips; - QList netInterfaces = QNetworkInterface::allInterfaces(); - foreach(const QNetworkInterface &netInterface, netInterfaces) { - //移除虚拟机和抓包工具的虚拟网卡 - QString humanReadableName = netInterface.humanReadableName().toLower(); - if(humanReadableName.startsWith("vmware network adapter") || humanReadableName.startsWith("npcap loopback adapter")) { - continue; - } - - //过滤当前网络接口 - bool flag = (netInterface.flags() == (QNetworkInterface::IsUp | QNetworkInterface::IsRunning | QNetworkInterface::CanBroadcast | QNetworkInterface::CanMulticast)); - if(flag) { - QList addrs = netInterface.addressEntries(); - foreach(QNetworkAddressEntry addr, addrs) { - //只取出IPV4的地址 - if(addr.ip().protocol() == QAbstractSocket::IPv4Protocol) { - QString ip4 = addr.ip().toString(); - if(ip4 != "127.0.0.1") { - ips.append(ip4); - } - } - } - } - } - + QStringList ips = QUIHelper::getLocalIPs(); ui->cboxListenIP->addItems(ips); ui->cboxListenIP->addItem("127.0.0.1"); } @@ -79,7 +55,7 @@ void frmTcpServer::initConfig() connect(ui->ckDebug, SIGNAL(stateChanged(int)), this, SLOT(saveConfig())); ui->ckAutoSend->setChecked(App::AutoSendTcpServer); - connect(ui->ckAutoSend, SIGNAL(stateChanged(int)), this, SLOT(saveConfig())); + connect(ui->ckAutoSend, SIGNAL(stateChanged(int)), this, SLOT(saveConfig())); ui->cboxInterval->setCurrentIndex(ui->cboxInterval->findText(QString::number(App::IntervalTcpServer))); connect(ui->cboxInterval, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig())); @@ -102,7 +78,7 @@ void frmTcpServer::saveConfig() App::HexReceiveTcpServer = ui->ckHexReceive->isChecked(); App::AsciiTcpServer = ui->ckAscii->isChecked(); App::DebugTcpServer = ui->ckDebug->isChecked(); - App::AutoSendTcpServer = ui->ckAutoSend->isChecked(); + App::AutoSendTcpServer = ui->ckAutoSend->isChecked(); App::IntervalTcpServer = ui->cboxInterval->currentText().toInt(); App::TcpListenIP = ui->cboxListenIP->currentText(); App::TcpListenPort = ui->txtListenPort->text().trimmed().toInt(); diff --git a/nettool/form/frmudpserver.cpp b/nettool/form/frmudpserver.cpp index 2787a31..ac3d914 100644 --- a/nettool/form/frmudpserver.cpp +++ b/nettool/form/frmudpserver.cpp @@ -31,31 +31,7 @@ void frmUdpServer::initForm() void frmUdpServer::initIP() { //获取本机所有IP - QStringList ips; - QList netInterfaces = QNetworkInterface::allInterfaces(); - foreach(const QNetworkInterface &netInterface, netInterfaces) { - //移除虚拟机和抓包工具的虚拟网卡 - QString humanReadableName = netInterface.humanReadableName().toLower(); - if(humanReadableName.startsWith("vmware network adapter") || humanReadableName.startsWith("npcap loopback adapter")) { - continue; - } - - //过滤当前网络接口 - bool flag = (netInterface.flags() == (QNetworkInterface::IsUp | QNetworkInterface::IsRunning | QNetworkInterface::CanBroadcast | QNetworkInterface::CanMulticast)); - if(flag) { - QList addrs = netInterface.addressEntries(); - foreach(QNetworkAddressEntry addr, addrs) { - //只取出IPV4的地址 - if(addr.ip().protocol() == QAbstractSocket::IPv4Protocol) { - QString ip4 = addr.ip().toString(); - if(ip4 != "127.0.0.1") { - ips.append(ip4); - } - } - } - } - } - + QStringList ips = QUIHelper::getLocalIPs(); ui->cboxListenIP->addItems(ips); ui->cboxListenIP->addItem("127.0.0.1"); } diff --git a/nettool/main.cpp b/nettool/main.cpp index 322fe9b..d45b283 100644 --- a/nettool/main.cpp +++ b/nettool/main.cpp @@ -4,15 +4,11 @@ int main(int argc, char *argv[]) { QApplication a(argc, argv); - a.setWindowIcon(QIcon(":/main.ico")); - - QFont font; - font.setFamily(QUIConfig::FontName); - font.setPixelSize(QUIConfig::FontSize); - a.setFont(font); + a.setWindowIcon(QIcon(":/main.ico")); //设置编码以及加载中文翻译文件 QUIHelper::setCode(); + QUIHelper::setFont(":/DroidSansFallback.ttf"); QUIHelper::setTranslator(":/qt_zh_CN.qm"); QUIHelper::setTranslator(":/widgets.qm"); QUIHelper::initRand(); @@ -24,7 +20,7 @@ int main(int argc, char *argv[]) App::readDeviceData(); frmMain w; - w.setWindowTitle(QString("网络调试助手V2020 本机IP: %1 QQ: 517216493").arg(QUIHelper::getLocalIP())); + w.setWindowTitle(QString("网络调试助手V2020 本机IP: %1 QQ: 517216493").arg(QUIHelper::getLocalIP())); w.show(); return a.exec(); diff --git a/websnap/snap_demo1.gif b/websnap/snap_demo1.gif new file mode 100644 index 0000000..25c807a Binary files /dev/null and b/websnap/snap_demo1.gif differ diff --git a/websnap/snap_demo2.gif b/websnap/snap_demo2.gif new file mode 100644 index 0000000..4f2bcba Binary files /dev/null and b/websnap/snap_demo2.gif differ diff --git a/websnap/snap_demo3.gif b/websnap/snap_demo3.gif new file mode 100644 index 0000000..04f5d74 Binary files /dev/null and b/websnap/snap_demo3.gif differ