From e44fadfa39b59e818722ba2d840ba78cd287e9da Mon Sep 17 00:00:00 2001 From: kaniol-lck <375520360@qq.com> Date: Tue, 9 Jul 2024 23:06:03 +0800 Subject: [PATCH] some qt6 tweaks --- src/main.cpp | 3 --- src/ui/framelesswrapper.cpp | 42 +++++++++++++++++++++++-------------- src/ui/framelesswrapper.h | 8 +++++-- src/ui/modmanager.cpp | 9 ++++---- src/ui/windowstitlebar.cpp | 4 ++++ src/ui/windowstitlebar.h | 4 ++++ 6 files changed, 44 insertions(+), 26 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 09cfb9a..fdb8898 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,9 +12,6 @@ int main(int argc, char *argv[]) { - QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling, false); - QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); - QApplication a(argc, argv); a.setWindowIcon(QIcon(":/image/modmanager.png")); a.setOrganizationName("kaniol"); diff --git a/src/ui/framelesswrapper.cpp b/src/ui/framelesswrapper.cpp index 3c19670..fde11ad 100644 --- a/src/ui/framelesswrapper.cpp +++ b/src/ui/framelesswrapper.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #ifdef Q_OS_WIN @@ -32,6 +33,7 @@ FramelessWrapper::FramelessWrapper(QWidget *widget, QMenuBar *menuBar) : titleBar_(new WindowsTitleBar(widget, menuBar)) { titleBar_->setParentWidget(this); + setAttribute(Qt::WA_Hover); auto w = new QWidget(this); auto layout = new QVBoxLayout; @@ -70,31 +72,36 @@ void FramelessWrapper::updateBlur() } #ifdef Q_OS_WIN + +#if QT_VERSION_MAJOR == 6 +bool FramelessWrapper::nativeEvent(const QByteArray& eventType, void* message, qintptr* result) +#else bool FramelessWrapper::nativeEvent(const QByteArray &eventType, void *message, long *result) +#endif // QT_VERSION_MAJOR { MSG* msg = (MSG*)message; float boundaryWidth = 4; -// qDebug() << msg->message; + + //support highdpi + double dpr = this->devicePixelRatioF(); + switch(msg->message){ case WM_NCCALCSIZE:{ - NCCALCSIZE_PARAMS& params = *reinterpret_cast(msg->lParam); - if (params.rgrc[0].top != 0) - params.rgrc[0].top -= 1; + if(msg->wParam == FALSE) return false; *result = WVR_REDRAW; return true; } case WM_NCHITTEST:{ - //support highdpi - double dpr = this->devicePixelRatioF(); - long x = GET_X_LPARAM(msg->lParam); - long y = GET_Y_LPARAM(msg->lParam); + POINT nativeLocalPos{ GET_X_LPARAM(msg->lParam), GET_Y_LPARAM(msg->lParam) }; + ::ScreenToClient(msg->hwnd, &nativeLocalPos); + auto mousePos = QPoint(nativeLocalPos.x / dpr, nativeLocalPos.y / dpr); - auto mousePos = mapFromGlobal(QPoint(x/dpr,y/dpr)); bool left = mousePos.x() < boundaryWidth; bool right = mousePos.x() > width() - boundaryWidth; bool top = mousePos.y() < boundaryWidth; bool bottom = mousePos.y() > height() - boundaryWidth; + if(left && top) *result = HTTOPLEFT; else if(right && top) @@ -111,27 +118,30 @@ bool FramelessWrapper::nativeEvent(const QByteArray &eventType, void *message, l *result = HTTOP; else if(bottom) *result = HTBOTTOM; + if(*result) return true; - if (!titleBar_->rect().contains(mousePos)) return false; + *result = HTNOWHERE; + if(!titleBar_->rect().contains(mousePos)) return false; return titleBar_->hitTest(mousePos, result); } case WM_GETMINMAXINFO: { + MINMAXINFO* minmaxInfo = reinterpret_cast(msg->lParam); + RECT rect; + SystemParametersInfo(SPI_GETWORKAREA, 0, &rect, 0); if (::IsZoomed(msg->hwnd)) { - RECT frame = { 0, 0, 0, 0 }; - AdjustWindowRectEx(&frame, WS_OVERLAPPEDWINDOW, FALSE, 0); - frame.left = abs(frame.left); - frame.top = abs(frame.bottom); - setContentsMargins(frame.left, frame.top, frame.right, frame.bottom); + int i = abs(minmaxInfo->ptMaxPosition.x / dpr); + setContentsMargins(i, i, i, i); titleBar_->setMaximumed(); } else{ setContentsMargins(0, 0, 0, 0); titleBar_->setNormal(); } *result = ::DefWindowProc(msg->hwnd, msg->message, msg->wParam, msg->lParam); - break; + return true; } } return false; } + #endif //Q_OS_WIN diff --git a/src/ui/framelesswrapper.h b/src/ui/framelesswrapper.h index 5db3666..cf1523d 100644 --- a/src/ui/framelesswrapper.h +++ b/src/ui/framelesswrapper.h @@ -19,8 +19,12 @@ private slots: protected: #ifdef Q_OS_WIN - virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result); -#endif //Q_OS_WIN +#if QT_VERSION_MAJOR == 6 + virtual bool nativeEvent(const QByteArray& eventType, void* message, qintptr* result) override; +#else + virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result) override; +#endif // QT_VERSION_MAJOR +#endif // Q_OS_WIN private: WindowsTitleBar *titleBar_; diff --git a/src/ui/modmanager.cpp b/src/ui/modmanager.cpp index 1fff5ff..49706d2 100644 --- a/src/ui/modmanager.cpp +++ b/src/ui/modmanager.cpp @@ -223,7 +223,7 @@ void ModManager::paintEvent(QPaintEvent *event[[maybe_unused]]) if(!widget->isVisible()) continue; auto rect = widget->rect(); rect.translate(widget->pos()); - p.fillRect(rect, QBrush(QColor(255, 255, 255, 210))); + p.fillRect(rect, QBrush(QColor(255, 50, 255, 210))); } } #endif //defined (DE_KDE) || defined (Q_OS_WIN) @@ -295,16 +295,15 @@ void ModManager::customContextMenuRequested(const QModelIndex &index, const QPoi connect(menu->addAction(QIcon::fromTheme("entry-edit"), tr("Edit")), &QAction::triggered, this, [=]{ editLocalPath(index.row()); }); - auto reloadAction = menu->addAction(QIcon::fromTheme("view-refresh"), tr("Reload")); + auto reloadAction = menu->addAction(QIcon::fromTheme("view-refresh"), tr("Reload"), [=]{ + localBrowser->reload(); + }); if(localBrowser->isLoading()){ reloadAction->setEnabled(false); connect(localBrowser, &LocalModBrowser::loadFinished, this, [=]{ reloadAction->setEnabled(true); }); } - connect(reloadAction, &QAction::triggered, this, [=]{ - localBrowser->reload(); - }); connect(menu->addAction(QIcon::fromTheme("delete"), tr("Delete")), &QAction::triggered, this, [=]{ if(QMessageBox::No == QMessageBox::question(this, tr("Delete"), tr("Delete this mod path?"))) return; LocalModPathManager::removePathAt(index.row()); diff --git a/src/ui/windowstitlebar.cpp b/src/ui/windowstitlebar.cpp index d0fe698..fa8e856 100644 --- a/src/ui/windowstitlebar.cpp +++ b/src/ui/windowstitlebar.cpp @@ -100,7 +100,11 @@ void WindowsTitleBar::setParentWidget(QWidget *newParentWidget) } #ifdef Q_OS_WIN +#if QT_VERSION_MAJOR == 6 +bool WindowsTitleBar::hitTest(QPoint pos, qintptr *result) +#else bool WindowsTitleBar::hitTest(QPoint pos, long *result) +#endif // QT_VERSION_MAJOR { QWidget* child = childAt(pos); if(auto label = qobject_cast(child); label == ui->icon){ diff --git a/src/ui/windowstitlebar.h b/src/ui/windowstitlebar.h index 55fbaa4..106b55e 100644 --- a/src/ui/windowstitlebar.h +++ b/src/ui/windowstitlebar.h @@ -20,7 +20,11 @@ class WindowsTitleBar : public QWidget void setIconVisible(bool bl); void setParentWidget(QWidget *newParentWidget); #ifdef Q_OS_WIN +#if QT_VERSION_MAJOR == 6 + bool hitTest(QPoint pos, qintptr *result); +#else bool hitTest(QPoint pos, long *result); +#endif // QT_VERSION_MAJOR #endif //Q_OS_WIN public slots: