更新代码

This commit is contained in:
feiyangqingyun
2024-04-21 14:41:12 +08:00
parent 41188deae0
commit 47835c1fbe
18 changed files with 599 additions and 239 deletions

View File

@@ -24,7 +24,7 @@ AppInit::AppInit(QObject *parent) : QObject(parent)
}
bool AppInit::eventFilter(QObject *watched, QEvent *event)
{
{
QWidget *w = (QWidget *)watched;
if (!w->property("canMove").toBool()) {
return QObject::eventFilter(watched, event);
@@ -34,26 +34,17 @@ bool AppInit::eventFilter(QObject *watched, QEvent *event)
static bool mousePressed = false;
int type = event->type();
QPoint p;
QMouseEvent *mouseEvent = (QMouseEvent *)(event);
if (mouseEvent) {
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
p = mouseEvent->globalPos();
#else
p = mouseEvent->globalPosition().toPoint();
#endif
}
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
if (type == QEvent::MouseButtonPress) {
if (mouseEvent->button() == Qt::LeftButton) {
mousePressed = true;
mousePoint = p - w->pos();
mousePoint = mouseEvent->globalPos() - w->pos();
}
} else if (type == QEvent::MouseButtonRelease) {
mousePressed = false;
} else if (type == QEvent::MouseMove) {
if (mousePressed) {
w->move(p - mousePoint);
w->move(mouseEvent->globalPos() - mousePoint);
return true;
}
}

View File

@@ -19,9 +19,6 @@ DESTDIR = $$PWD/../bin
#把所有警告都关掉眼不见为净
CONFIG += warn_off
#QMAKE_CXXFLAGS_WARN_ON -= -w34100
#QMAKE_CXXFLAGS *= -Wno-unused-parameter
#开启大资源支持
CONFIG += resources_big
#开启后会将打印信息用控制台输出
@@ -29,8 +26,7 @@ CONFIG += resources_big
#开启后不会生成空的 debug release 目录
#CONFIG -= debug_and_release
#引入全志H3芯片依赖(不需要的用户可以删除)
include ($$PWD/h3.pri)
include ($$PWD/core_util.pri)
#将当前目录加入到头文件路径
INCLUDEPATH += $$PWD

View 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
}}}

View File

@@ -4,26 +4,40 @@
#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;
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
int screenCount = qApp->screens().count();
QList<QScreen *> screens = qApp->screens();
int screenCount = screens.count();
for (int i = 0; i < screenCount; ++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();
QRect 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
int screenCount = qApp->desktop()->screenCount();
QDesktopWidget *desk = qApp->desktop();
int screenCount = desk->screenCount();
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;
}
#endif
@@ -48,10 +62,10 @@ int QtHelper::getScreenIndex()
return screenIndex;
}
QRect QtHelper::getScreenRect(bool available)
QRect QtHelper::getScreenRect(bool available, bool full)
{
int screenIndex = getScreenIndex();
QList<QRect> rects = getScreenRects(available);
QList<QRect> rects = getScreenRects(available, full);
return rects.at(screenIndex);
}
@@ -455,7 +469,8 @@ void QtHelper::checkRun()
void QtHelper::setStyle()
{
//打印下所有内置风格的名字
qDebug() << TIMEMS << "QStyleFactory::keys" << QStyleFactory::keys();
//qDebug() << TIMEMS << "QStyleFactory::keys" << QStyleFactory::keys();
//设置内置风格
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
qApp->setStyle("Fusion");
@@ -618,6 +633,9 @@ void QtHelper::initAll(bool utf8, bool style, int fontSize)
#endif
}
#ifdef webengine
#include "qquickwindow.h"
#endif
void QtHelper::initMain(bool desktopSettingsAware, bool use96Dpi, bool logCritical)
{
#ifdef Q_OS_LINUX
@@ -632,15 +650,17 @@ void QtHelper::initMain(bool desktopSettingsAware, bool use96Dpi, bool logCritic
QApplication::setDesktopSettingsAware(desktopSettingsAware);
#endif
bool highDpi = !use96Dpi;
//安卓必须启用高分屏
#ifdef Q_OS_ANDROID
highDpi = true;
use96Dpi = false;
#endif
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_UseHighDpiPixmaps);
}
#endif
@@ -657,7 +677,7 @@ void QtHelper::initMain(bool desktopSettingsAware, bool use96Dpi, bool logCritic
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
//高分屏缩放策略
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor);
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
#endif
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
@@ -671,6 +691,13 @@ void QtHelper::initMain(bool desktopSettingsAware, bool use96Dpi, bool logCritic
//设置opengl共享上下文
QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
#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)
@@ -1275,11 +1302,11 @@ void QtHelper::runWithSystem(const QString &fileName, const QString &filePath, b
#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
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
QString cmd1 = "ps -aux";
QString cmd2 = QString("%1/%2").arg(path).arg(name);

View File

@@ -7,9 +7,10 @@ class QtHelper
{
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 QRect getScreenRect(bool available = true);
static QRect getScreenRect(bool available = true, bool full = 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);
//初始化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)
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(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

View File

@@ -6,13 +6,6 @@
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);
QFont font;
font.setFamily("Microsoft Yahei");