Skip to content

Commit

Permalink
Revert "Avoid dock widget separators stealing mouse events from expan…
Browse files Browse the repository at this point in the history
…ded toolbar"

This reverts commit 6b4fa58.

Reason for revert: Not worth the risk for 6.7

Change-Id: Idc7549f0c9cb7a037d702e98af76752c6ec4b580
Reviewed-by: Eike Ziller <[email protected]>
Reviewed-by: Tor Arne Vestbø <[email protected]>
  • Loading branch information
torarnv authored and The Qt Project committed Sep 18, 2024
1 parent 8b083f4 commit 6ab3742
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 130 deletions.
33 changes: 2 additions & 31 deletions src/widgets/widgets/qdockarealayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@
#include "qdockwidget_p.h"
#include <private/qlayoutengine_p.h>

#if QT_CONFIG(toolbar)
#include "qtoolbar.h"
#include "qtoolbarlayout_p.h"
#endif

#include <qpainter.h>
#include <qstyleoption.h>

Expand Down Expand Up @@ -2041,30 +2036,6 @@ bool QDockAreaLayoutInfo::restoreState(QDataStream &stream, QList<QDockWidget*>
}

#if QT_CONFIG(tabbar)

static void raiseSeparatorWidget(QWidget *separatorWidget)
{
Q_ASSERT(separatorWidget);

#if QT_CONFIG(toolbar)
// Raise the separator widget, but make sure it doesn't go above
// an expanded toolbar, as that would break mouse event hit testing.
Q_ASSERT(separatorWidget->parent());
const auto toolBars = separatorWidget->parent()->findChildren<QToolBar*>(Qt::FindDirectChildrenOnly);
for (auto *toolBar : toolBars) {
if (auto *toolBarLayout = qobject_cast<QToolBarLayout*>(toolBar->layout())) {
if (toolBarLayout->expanded) {
separatorWidget->stackUnder(toolBar);
return;
}
}
}
#endif

separatorWidget->raise();
}


void QDockAreaLayoutInfo::updateSeparatorWidgets() const
{
if (tabbed) {
Expand Down Expand Up @@ -2106,7 +2077,7 @@ void QDockAreaLayoutInfo::updateSeparatorWidgets() const
j++;

Q_ASSERT(sepWidget);
raiseSeparatorWidget(sepWidget);
sepWidget->raise();

QRect sepRect = separatorRect(i).adjusted(-2, -2, 2, 2);
sepWidget->setGeometry(sepRect);
Expand Down Expand Up @@ -3391,7 +3362,7 @@ void QDockAreaLayout::updateSeparatorWidgets() const
j++;

Q_ASSERT(sepWidget);
raiseSeparatorWidget(sepWidget);
sepWidget->raise();

QRect sepRect = separatorRect(i).adjusted(-2, -2, 2, 2);
sepWidget->setGeometry(sepRect);
Expand Down
8 changes: 0 additions & 8 deletions src/widgets/widgets/qmainwindowlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,6 @@ class QDockWidgetGroupLayout : public QLayout,

QDockAreaLayoutInfo *dockAreaLayoutInfo() { return &layoutState; }

#if QT_CONFIG(toolbar)
QToolBarAreaLayout *toolBarAreaLayout()
{
auto *mainWindow = static_cast<QMainWindow*>(parentWidget());
return qt_mainwindow_layout(mainWindow)->toolBarAreaLayout();
}
#endif

bool nativeWindowDeco() const
{
return groupWindow()->hasNativeDecos();
Expand Down
34 changes: 2 additions & 32 deletions src/widgets/widgets/qmainwindowlayout_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ struct QDockWidgetPrivate {
#endif
#if QT_CONFIG(toolbar)
#include "qtoolbararealayout_p.h"
#include "qtoolbar.h"
#endif

#include <QtCore/qloggingcategory.h>
Expand Down Expand Up @@ -93,9 +92,6 @@ class QMainWindowLayoutSeparatorHelper
bool endSeparatorMove(const QPoint &pos);
bool windowEvent(QEvent *e);

private:
QList<int> findSeparator(const QPoint &pos) const;

#endif // QT_CONFIG(dockwidget)

};
Expand Down Expand Up @@ -146,7 +142,7 @@ void QMainWindowLayoutSeparatorHelper<Layout>::adjustCursor(const QPoint &pos)
w->unsetCursor();
}
} else if (movingSeparator.isEmpty()) { // Don't change cursor when moving separator
QList<int> pathToSeparator = findSeparator(pos);
QList<int> pathToSeparator = layout()->dockAreaLayoutInfo()->findSeparator(pos);

if (pathToSeparator != hoverSeparator) {
if (!hoverSeparator.isEmpty())
Expand Down Expand Up @@ -283,35 +279,10 @@ bool QMainWindowLayoutSeparatorHelper<Layout>::windowEvent(QEvent *event)
return false;
}

template <typename Layout>
QList<int> QMainWindowLayoutSeparatorHelper<Layout>::findSeparator(const QPoint &pos) const
{
Layout *layout = const_cast<Layout*>(this->layout());
#if QT_CONFIG(toolbar)
QToolBarAreaLayout *toolBarAreaLayout = layout->toolBarAreaLayout();
if (!toolBarAreaLayout->isEmpty()) {
// We might have a toolbar that is currently expanded, covering
// parts of the dock area, in which case we don't want the dock
// area layout to treat mouse events for the expanded toolbar as
// hitting a separator.
const QWidget *widget = layout->window();
QWidget *childWidget = widget->childAt(pos);
while (childWidget && childWidget != widget) {
if (auto *toolBar = qobject_cast<QToolBar*>(childWidget)) {
if (!toolBarAreaLayout->indexOf(toolBar).isEmpty())
return {};
}
childWidget = childWidget->parentWidget();
}
}
#endif
return layout->dockAreaLayoutInfo()->findSeparator(pos);
}

template <typename Layout>
bool QMainWindowLayoutSeparatorHelper<Layout>::startSeparatorMove(const QPoint &pos)
{
movingSeparator = findSeparator(pos);
movingSeparator = layout()->dockAreaLayoutInfo()->findSeparator(pos);

if (movingSeparator.isEmpty())
return false;
Expand Down Expand Up @@ -522,7 +493,6 @@ class Q_AUTOTEST_EXPORT QMainWindowLayout
void removeToolBar(QToolBar *toolbar);
void toggleToolBarsVisible();
void moveToolBar(QToolBar *toolbar, int pos);
QToolBarAreaLayout *toolBarAreaLayout() { return &layoutState.toolBarAreaLayout; }
#endif

// dock widgets
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/widgets/qtoolbarlayout_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class QToolBarItem : public QWidgetItem
bool customWidget;
};

class Q_AUTOTEST_EXPORT QToolBarLayout : public QLayout
class QToolBarLayout : public QLayout
{
Q_OBJECT

Expand Down
58 changes: 0 additions & 58 deletions tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
#include <qscreen.h>
#include <private/qmainwindowlayout_p.h>
#include <private/qdockarealayout_p.h>
#include <private/qtoolbarlayout_p.h>
#include <private/qtoolbarextension_p.h>

#if QT_CONFIG(tabbar)
#include <qtabbar.h>
Expand Down Expand Up @@ -135,9 +133,6 @@ private slots:
#if QT_CONFIG(dockwidget) && QT_CONFIG(tabbar)
void QTBUG52175_tabifiedDockWidgetActivated();
#endif
#ifdef QT_BUILD_INTERNAL
void expandedToolBarHitTesting();
#endif
};


Expand Down Expand Up @@ -2260,58 +2255,5 @@ void tst_QMainWindow::QTBUG52175_tabifiedDockWidgetActivated()
}
#endif

#ifdef QT_BUILD_INTERNAL
void tst_QMainWindow::expandedToolBarHitTesting()
{
QMainWindow mainWindow;
if (mainWindow.style()->pixelMetric(
QStyle::PM_DockWidgetSeparatorExtent, nullptr, &mainWindow) != 1) {
QSKIP("Style does not trigger the use of qt_qmainwindow_extended_splitter");
}

mainWindow.setAnimated(false);

auto *dockWidget = new QDockWidget(&mainWindow);
dockWidget->setWidget(new QWidget(dockWidget));
mainWindow.addDockWidget(Qt::RightDockWidgetArea, dockWidget);

auto *toolBar = new QToolBar(&mainWindow);
for (int i = 0; i < 10; ++i)
toolBar->addWidget(new QLabel(QString("Label %1").arg(i)));
mainWindow.addToolBar(toolBar);

auto *centralWidget = new QWidget(&mainWindow);
centralWidget->setMinimumSize(QSize(100, 100));
mainWindow.setCentralWidget(centralWidget);

mainWindow.resize(centralWidget->minimumSize());
mainWindow.show();
QVERIFY(QTest::qWaitForWindowActive(&mainWindow));

auto *toolBarExtension = toolBar->findChild<QToolBarExtension*>();
QVERIFY(toolBarExtension);
QPoint buttonCenter = toolBarExtension->parentWidget()->mapTo(&mainWindow, toolBarExtension->geometry().center());
QTest::mouseMove(mainWindow.windowHandle(), buttonCenter);
QTest::mouseClick(mainWindow.windowHandle(), Qt::LeftButton, Qt::NoModifier, buttonCenter);

auto *toolBarLayout = static_cast<QToolBarLayout*>(toolBar->layout());
QVERIFY(toolBarLayout);
QTRY_COMPARE(toolBarLayout->expanded, true);

auto *splitter = mainWindow.findChild<QWidget*>("qt_qmainwindow_extended_splitter");
QVERIFY(splitter);
QCOMPARE(splitter->parentWidget(), &mainWindow);

// Moving the mouse over the splitter when it's covered by the toolbar
// extension area should not trigger a closing of the extension area.
QTest::mouseMove(mainWindow.windowHandle(), splitter->geometry().center());
QCOMPARE(toolBarLayout->expanded, true);

// Nor should it result in a split cursor shape, indicating we can move
// the splitter.
QCOMPARE(mainWindow.cursor().shape(), Qt::ArrowCursor);
}
#endif // QT_BUILD_INTERNAL

QTEST_MAIN(tst_QMainWindow)
#include "tst_qmainwindow.moc"

0 comments on commit 6ab3742

Please sign in to comment.