修复BUG

This commit is contained in:
feiyangqingyun
2021-08-31 16:19:06 +08:00
parent a6a63e6196
commit 08d29fb44c
5 changed files with 66 additions and 20 deletions

View File

@@ -5,6 +5,7 @@
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#include "windows.h" #include "windows.h"
#include "windowsx.h"
#pragma comment (lib,"user32.lib") #pragma comment (lib,"user32.lib")
#endif #endif
@@ -274,8 +275,10 @@ bool FramelessDialog::nativeEvent(const QByteArray &eventType, void *message, lo
return true; return true;
} else if (msg->message == WM_NCHITTEST) { } else if (msg->message == WM_NCHITTEST) {
//计算鼠标对应的屏幕坐标 //计算鼠标对应的屏幕坐标
long x = LOWORD(msg->lParam); //这里最开始用的 LOWORD HIWORD 在多屏幕的时候会有问题
long y = HIWORD(msg->lParam); //官方说明在这里 https://docs.microsoft.com/zh-cn/windows/win32/inputdev/wm-nchittest
long x = GET_X_LPARAM(msg->lParam);
long y = GET_Y_LPARAM(msg->lParam);
QPoint pos = mapFromGlobal(QPoint(x, y)); QPoint pos = mapFromGlobal(QPoint(x, y));
//判断当前鼠标位置在哪个区域 //判断当前鼠标位置在哪个区域

View File

@@ -5,6 +5,7 @@
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#include "windows.h" #include "windows.h"
#include "windowsx.h"
#pragma comment (lib,"user32.lib") #pragma comment (lib,"user32.lib")
#endif #endif
@@ -274,8 +275,10 @@ bool FramelessMainWindow::nativeEvent(const QByteArray &eventType, void *message
return true; return true;
} else if (msg->message == WM_NCHITTEST) { } else if (msg->message == WM_NCHITTEST) {
//计算鼠标对应的屏幕坐标 //计算鼠标对应的屏幕坐标
long x = LOWORD(msg->lParam); //这里最开始用的 LOWORD HIWORD 在多屏幕的时候会有问题
long y = HIWORD(msg->lParam); //官方说明在这里 https://docs.microsoft.com/zh-cn/windows/win32/inputdev/wm-nchittest
long x = GET_X_LPARAM(msg->lParam);
long y = GET_Y_LPARAM(msg->lParam);
QPoint pos = mapFromGlobal(QPoint(x, y)); QPoint pos = mapFromGlobal(QPoint(x, y));
//判断当前鼠标位置在哪个区域 //判断当前鼠标位置在哪个区域

View File

@@ -5,6 +5,7 @@
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#include "windows.h" #include "windows.h"
#include "windowsx.h"
#pragma comment (lib,"user32.lib") #pragma comment (lib,"user32.lib")
#endif #endif
@@ -274,8 +275,10 @@ bool FramelessWidget::nativeEvent(const QByteArray &eventType, void *message, lo
return true; return true;
} else if (msg->message == WM_NCHITTEST) { } else if (msg->message == WM_NCHITTEST) {
//计算鼠标对应的屏幕坐标 //计算鼠标对应的屏幕坐标
long x = LOWORD(msg->lParam); //这里最开始用的 LOWORD HIWORD 在多屏幕的时候会有问题
long y = HIWORD(msg->lParam); //官方说明在这里 https://docs.microsoft.com/zh-cn/windows/win32/inputdev/wm-nchittest
long x = GET_X_LPARAM(msg->lParam);
long y = GET_Y_LPARAM(msg->lParam);
QPoint pos = mapFromGlobal(QPoint(x, y)); QPoint pos = mapFromGlobal(QPoint(x, y));
//判断当前鼠标位置在哪个区域 //判断当前鼠标位置在哪个区域

View File

@@ -300,7 +300,11 @@ void QUIHelper::setFramelessForm(QWidget *widgetMain, bool tool, bool top, bool
widgetMain->setProperty("canMove", true); widgetMain->setProperty("canMove", true);
//根据设定逐个追加属性 //根据设定逐个追加属性
#ifdef __arm__
widgetMain->setWindowFlags(Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint); widgetMain->setWindowFlags(Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint);
#else
widgetMain->setWindowFlags(Qt::FramelessWindowHint);
#endif
if (tool) { if (tool) {
widgetMain->setWindowFlags(widgetMain->windowFlags() | Qt::Tool); widgetMain->setWindowFlags(widgetMain->windowFlags() | Qt::Tool);
} }
@@ -323,8 +327,12 @@ void QUIHelper::setFramelessForm(QWidget *widgetMain, QWidget *widgetTitle,
widgetMain->setProperty("form", true); widgetMain->setProperty("form", true);
widgetMain->setProperty("canMove", true); widgetMain->setProperty("canMove", true);
//根据设定逐个追加属性 去掉了 Qt::X11BypassWindowManagerHint //根据设定逐个追加属性
#ifdef __arm__
widgetMain->setWindowFlags(Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint);
#else
widgetMain->setWindowFlags(Qt::FramelessWindowHint); widgetMain->setWindowFlags(Qt::FramelessWindowHint);
#endif
if (tool) { if (tool) {
widgetMain->setWindowFlags(widgetMain->windowFlags() | Qt::Tool); widgetMain->setWindowFlags(widgetMain->windowFlags() | Qt::Tool);
} }
@@ -982,24 +990,58 @@ bool QUIHelper::ipLive(const QString &ip, int port, int timeout)
timer.setSingleShot(true); timer.setSingleShot(true);
timer.start(timeout); timer.start(timeout);
//主动测试下连接
QTcpSocket tcpSocket; QTcpSocket tcpSocket;
QObject::connect(&tcpSocket, SIGNAL(connected()), &eventLoop, SLOT(quit())); QObject::connect(&tcpSocket, SIGNAL(connected()), &eventLoop, SLOT(quit()));
tcpSocket.connectToHost(ip, port); tcpSocket.connectToHost(ip, port);
eventLoop.exec(); eventLoop.exec();
//判断最终状态
bool ok = (tcpSocket.state() == QAbstractSocket::ConnectedState); bool ok = (tcpSocket.state() == QAbstractSocket::ConnectedState);
return ok; return ok;
} }
QString QUIHelper::getHtml(const QString &url) bool QUIHelper::download(const QString &url, const QString &fileName, int timeout)
{ {
QByteArray data = getHtml(url, timeout);
if (!data.isEmpty()) {
QFile file(fileName);
if (file.open(QFile::WriteOnly | QFile::Truncate)) {
file.write(data);
file.close();
}
return true;
}
return false;
}
QByteArray QUIHelper::getHtml(const QString &url, int timeout)
{
//初始化网络请求对象
QNetworkAccessManager manager; QNetworkAccessManager manager;
QNetworkReply *reply = manager.get(QNetworkRequest(QUrl(url))); //局部的事件循环,不卡主界面
QEventLoop eventLoop; QEventLoop eventLoop;
QObject::connect(&manager, SIGNAL(finished(QNetworkReply *)), &eventLoop, SLOT(quit()));
//设置超时 5.15开始自带了超时时间函数 默认30秒
#if (QT_VERSION >= QT_VERSION_CHECK(5,15,0))
manager.setTransferTimeout(timeout);
#else
QTimer timer;
QObject::connect(&timer, SIGNAL(timeout()), &eventLoop, SLOT(quit()));
timer.setSingleShot(true);
timer.start(timeout);
#endif
//启动网络请求
QNetworkReply *reply = manager.get(QNetworkRequest(QUrl(url)));
QObject::connect(reply, SIGNAL(finished()), &eventLoop, SLOT(quit()));
eventLoop.exec(); eventLoop.exec();
//读取结果
QByteArray data = reply->readAll(); QByteArray data = reply->readAll();
reply->deleteLater(); reply->deleteLater();
return QString(data); return data;
} }
QString QUIHelper::getNetIP(const QString &html) QString QUIHelper::getNetIP(const QString &html)
@@ -1083,12 +1125,6 @@ QString QUIHelper::getValue(quint8 value)
return result; return result;
} }
bool QUIHelper::isWebOk()
{
//能接通百度IP 115.239.211.112 说明可以通外网
return ipLive("www.baidu.com", 80);
}
bool QUIHelper::isCustomUI = false; bool QUIHelper::isCustomUI = false;
int QUIHelper::showMessageBox(const QString &info, int type, int closeSec, bool exec) int QUIHelper::showMessageBox(const QString &info, int type, int closeSec, bool exec)
{ {

View File

@@ -164,8 +164,11 @@ public:
//判断IP地址及端口是否在线 //判断IP地址及端口是否在线
static bool ipLive(const QString &ip, int port, int timeout = 1000); static bool ipLive(const QString &ip, int port, int timeout = 1000);
//下载网络文件
static bool download(const QString &url, const QString &fileName, int timeout = 1000);
//获取网页所有源代码 //获取网页所有源代码
static QString getHtml(const QString &url); static QByteArray getHtml(const QString &url, int timeout = 1000);
//获取本机公网IP地址 //获取本机公网IP地址
static QString getNetIP(const QString &html); static QString getNetIP(const QString &html);
//获取本机IP //获取本机IP
@@ -177,8 +180,6 @@ public:
//字符串补全 //字符串补全
static QString getValue(quint8 value); static QString getValue(quint8 value);
//判断是否通外网
static bool isWebOk();
//定义标志位启用系统的还是自定义的对话框 //定义标志位启用系统的还是自定义的对话框
static bool isCustomUI; static bool isCustomUI;