新增网页效果图

master
feiyangqingyun 2021-01-22 17:20:01 +08:00
parent 44a237e0a9
commit 95ea56d5e7
10 changed files with 85 additions and 59 deletions

View File

@ -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<QNetworkInterface> netInterfaces = QNetworkInterface::allInterfaces();
foreach (const QNetworkInterface &netInterface, netInterfaces) {
//移除虚拟机和抓包工具的虚拟网卡
@ -3559,6 +3592,7 @@ QStringList QUIHelper::getLocalIPs()
}
}
}
#endif
}
return ips;

View File

@ -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);
//设置系统时间

View File

@ -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<QNetworkInterface> netInterfaces = QNetworkInterface::allInterfaces();
foreach (const QNetworkInterface &netInterface, netInterfaces) {
//移除虚拟机和抓包工具的虚拟网卡
@ -3559,6 +3592,7 @@ QStringList QUIHelper::getLocalIPs()
}
}
}
#endif
}
return ips;

View File

@ -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);
//设置系统时间

View File

@ -35,31 +35,7 @@ void frmTcpServer::initForm()
void frmTcpServer::initIP()
{
//获取本机所有IP
QStringList ips;
QList<QNetworkInterface> 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<QNetworkAddressEntry> 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");
}

View File

@ -31,31 +31,7 @@ void frmUdpServer::initForm()
void frmUdpServer::initIP()
{
//获取本机所有IP
QStringList ips;
QList<QNetworkInterface> 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<QNetworkAddressEntry> 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");
}

View File

@ -6,13 +6,9 @@ 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);
//设置编码以及加载中文翻译文件
QUIHelper::setCode();
QUIHelper::setFont(":/DroidSansFallback.ttf");
QUIHelper::setTranslator(":/qt_zh_CN.qm");
QUIHelper::setTranslator(":/widgets.qm");
QUIHelper::initRand();

BIN
websnap/snap_demo1.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 MiB

BIN
websnap/snap_demo2.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 MiB

BIN
websnap/snap_demo3.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 303 KiB