From 1cc373b9eb024e7fa92408e56b63fdbdcb64a903 Mon Sep 17 00:00:00 2001 From: dreamsourcelabTAI Date: Sat, 20 Apr 2024 21:19:45 +0800 Subject: [PATCH] Control the moving dialog in windows --- DSView/pv/appcontrol.h | 2 ++ DSView/pv/toolbars/titlebar.cpp | 28 +++++++++++----------------- DSView/pv/toolbars/titlebar.h | 8 -------- DSView/pv/winnativewidget.cpp | 4 +++- 4 files changed, 16 insertions(+), 26 deletions(-) diff --git a/DSView/pv/appcontrol.h b/DSView/pv/appcontrol.h index 399579b3..38071ebf 100644 --- a/DSView/pv/appcontrol.h +++ b/DSView/pv/appcontrol.h @@ -23,6 +23,7 @@ #include #include +#include struct sr_context; class QWidget; @@ -67,6 +68,7 @@ public: public: std::string _open_file_name; + QRect _screenRect; private: pv::SigSession *_session; diff --git a/DSView/pv/toolbars/titlebar.cpp b/DSView/pv/toolbars/titlebar.cpp index d755df22..d852826b 100644 --- a/DSView/pv/toolbars/titlebar.cpp +++ b/DSView/pv/toolbars/titlebar.cpp @@ -59,10 +59,6 @@ TitleBar::TitleBar(bool top, QWidget *parent, ITitleParent *titleParent, bool ha assert(parent); -#ifdef _WIN32 - _hMonitor = NULL; -#endif - setObjectName("TitleBar"); setContentsMargins(0,0,0,0); setFixedHeight(32); @@ -264,12 +260,6 @@ void TitleBar::mouseMoveEvent(QMouseEvent *event) if (!_moving){ if (ABS_VAL(datX) >= 2 || ABS_VAL(datY) >= 2){ _moving = true; - -#ifdef _WIN32 - POINT cursorPos; - GetCursorPos(&cursorPos); - _hMonitor = MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST); -#endif } else{ return; @@ -288,13 +278,17 @@ void TitleBar::mouseMoveEvent(QMouseEvent *event) else{ #ifdef _WIN32 - POINT cursorPos; - GetCursorPos(&cursorPos); - HMONITOR hMonitor = MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST); - if (hMonitor != _hMonitor){ - event->ignore(); - return; - } + + QRect screenRect = AppControl::Instance()->_screenRect; + + if (screenRect.width() > 0) + { + QRect rect = _parent->frameGeometry(); + if (!(rect.left() > screenRect.left() && rect.right() < screenRect.right())){ + event->ignore(); + return; + } + } #endif _parent->move(x, y); diff --git a/DSView/pv/toolbars/titlebar.h b/DSView/pv/toolbars/titlebar.h index 91842a1e..7aa79225 100644 --- a/DSView/pv/toolbars/titlebar.h +++ b/DSView/pv/toolbars/titlebar.h @@ -24,10 +24,6 @@ #include -#ifdef _WIN32 -#include -#endif - #include "../interface/icallbacks.h" #include "../ui/xtoolbutton.h" #include "../ui/uimanager.h" @@ -114,10 +110,6 @@ protected: ITitleParent *_titleParent; bool _is_done_moved; bool _is_able_drag; - -#ifdef _WIN32 -HMONITOR _hMonitor; -#endif }; } // namespace toolbars diff --git a/DSView/pv/winnativewidget.cpp b/DSView/pv/winnativewidget.cpp index 439f68e9..9c72c805 100644 --- a/DSView/pv/winnativewidget.cpp +++ b/DSView/pv/winnativewidget.cpp @@ -39,6 +39,7 @@ #include "log.h" #include "mainframe.h" #include "dsvdef.h" +#include "appcontrol.h" #define FIXED_WIDTH(widget) (widget->minimumWidth() >= widget->maximumWidth()) #define FIXED_HEIGHT(widget) (widget->minimumHeight() >= widget->maximumHeight()) @@ -628,7 +629,8 @@ QScreen* WinNativeWidget::screenFromCurrentMonitorHandle() for (QScreen *screen : QGuiApplication::screens()) { if (screen->geometry().topLeft() == top_left) - { + { + AppControl::Instance()->_screenRect = screen->availableGeometry(); return screen; } }