From 627e0aa88f98a5995aee28cc10c2ca39bd4b69bc Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Mon, 21 Dec 2020 21:51:56 -0500 Subject: [PATCH] Fix implementation --- src/gui/MainWindow.cpp | 29 ++++++++++++++++++++--------- src/gui/MainWindow.h | 5 +---- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 25b888a4de..728322b630 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -1809,9 +1809,8 @@ void MainWindow::initViewMenu() #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) -MainWindowEventFilter::MainWindowEventFilter(MainWindow* mainWindow) - : QObject(mainWindow) - , m_mainWindow(mainWindow) +MainWindowEventFilter::MainWindowEventFilter(QObject* parent) + : QObject(parent) { } @@ -1820,15 +1819,27 @@ MainWindowEventFilter::MainWindowEventFilter(MainWindow* mainWindow) */ bool MainWindowEventFilter::eventFilter(QObject* watched, QEvent* event) { - if (!m_mainWindow) { + auto* mainWindow = getMainWindow(); + if (!mainWindow || !mainWindow->m_ui) { return QObject::eventFilter(watched, event); } - if (watched == m_mainWindow->m_ui->menubar || watched == m_mainWindow->m_ui->toolBar - || watched == m_mainWindow->m_ui->tabWidget->tabBar()) { - if (event->type() == QEvent::MouseButtonPress) { - auto* window = qobject_cast(m_mainWindow->windowHandle()); - window->startSystemMove(); + if (event->type() == QEvent::MouseButtonPress) { + if (watched == mainWindow->m_ui->menubar) { + mainWindow->windowHandle()->startSystemMove(); + // Continue processing events, so menus keep working. + return false; + } else if (watched == mainWindow->m_ui->toolBar) { + if (!mainWindow->m_ui->toolBar->isMovable() || mainWindow->m_ui->toolBar->cursor() != Qt::SizeAllCursor) { + mainWindow->windowHandle()->startSystemMove(); + return false; + } + } else if (watched == mainWindow->m_ui->tabWidget->tabBar()) { + auto* m = static_cast(event); + if (mainWindow->m_ui->tabWidget->tabBar()->tabAt(m->pos()) == -1) { + mainWindow->windowHandle()->startSystemMove(); + return true; + } } } diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h index fb3b19bfd9..63163c8d29 100644 --- a/src/gui/MainWindow.h +++ b/src/gui/MainWindow.h @@ -193,11 +193,8 @@ class MainWindowEventFilter : public QObject Q_OBJECT public: - explicit MainWindowEventFilter(MainWindow* mainWindow); + explicit MainWindowEventFilter(QObject* parent); bool eventFilter(QObject* watched, QEvent* event) override; - -private: - QPointer m_mainWindow; }; #endif