Skip to content

Commit

Permalink
Fix implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
droidmonkey authored and phoerious committed Dec 22, 2020
1 parent 9b21d88 commit 627e0aa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
29 changes: 20 additions & 9 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand All @@ -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<QWindow*>(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<QMouseEvent*>(event);
if (mainWindow->m_ui->tabWidget->tabBar()->tabAt(m->pos()) == -1) {
mainWindow->windowHandle()->startSystemMove();
return true;
}
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/gui/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<MainWindow> m_mainWindow;
};
#endif

Expand Down

0 comments on commit 627e0aa

Please sign in to comment.