From 10d0f4cba99d2386db28a3afd71832e35992b797 Mon Sep 17 00:00:00 2001 From: Oleg Yadrov Date: Fri, 17 Feb 2017 11:23:46 -0800 Subject: QMacStyle::sizeFromContents: don't do anything in CT_Menu case In this case we can safely return the same QSize which we accept since it is already contains the right size for the given menu and this size will be bounded to screen geometry before QMenu will be displayed anyway. We also get rid of one dependency on HITheme. Change-Id: I7502a96d180fc4a41ce3dfabe8a200b886016348 Reviewed-by: Gabriel de Dietrich --- src/widgets/styles/qmacstyle_mac.mm | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm index 007ce20175..238e96ab4f 100644 --- a/src/widgets/styles/qmacstyle_mac.mm +++ b/src/widgets/styles/qmacstyle_mac.mm @@ -6759,12 +6759,7 @@ QSize QMacStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, break; } case CT_Menu: { - QStyleHintReturnMask menuMask; - QStyleOption myOption = *opt; - myOption.rect.setSize(sz); - if (proxy()->styleHint(SH_Menu_Mask, &myOption, widget, &menuMask)) { - sz = menuMask.region.boundingRect().size(); - } + sz = csz; break; } case CT_HeaderSection:{ const QStyleOptionHeader *header = qstyleoption_cast(opt); -- cgit v1.2.3 From d57bb19902f863fc6db07674f6bd8881b0886b39 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 20 Feb 2017 13:26:18 +0100 Subject: Fix crash while dropping a tabbed group into a single floating QDockWidget MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The problem was caused by commit 0feeb6f6d2cfaa964763ca1fcab65672812b4eef which fixed QTBUG-58036. It reparented widget that used to be skiped. In particular, floating widgets are skiped. But seting the parent of a floating widget docks it. And so as a result it would not be skiped anymore. This has two side effect: This breaks the animation (as the widget is docked too early; and cause crash when QDockWidgetGroupWindow get reparented as this breaks invariant that these are always floating. So restore the skip from before commit 0feeb6f6d2cfaa964763ca1fcab65672812b4eef, and explicitly set the parent in all cases when the animation finishes. Change-Id: I0e3e29ad22d6ffe4d62242d48a18dadb916fc14f Reviewed-by: Sérgio Martins --- src/widgets/widgets/qdockarealayout.cpp | 2 +- src/widgets/widgets/qmainwindowlayout.cpp | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/widgets/qdockarealayout.cpp b/src/widgets/widgets/qdockarealayout.cpp index b33f2dc798..8d9280ebb5 100644 --- a/src/widgets/widgets/qdockarealayout.cpp +++ b/src/widgets/widgets/qdockarealayout.cpp @@ -2092,7 +2092,7 @@ void QDockAreaLayoutInfo::reparentWidgets(QWidget *parent) const QDockAreaLayoutItem &item = item_list.at(i); if (item.flags & QDockAreaLayoutItem::GapItem) continue; - if (!item.widgetItem && item.skip()) + if (item.skip()) continue; if (item.subinfo) item.subinfo->reparentWidgets(parent); diff --git a/src/widgets/widgets/qmainwindowlayout.cpp b/src/widgets/widgets/qmainwindowlayout.cpp index 68ca571acf..0d9c42fdf0 100644 --- a/src/widgets/widgets/qmainwindowlayout.cpp +++ b/src/widgets/widgets/qmainwindowlayout.cpp @@ -2195,10 +2195,8 @@ void QMainWindowLayout::animationFinished(QWidget *widget) } if (QDockWidget *dw = qobject_cast(widget)) { - if (currentHoveredFloat) { - dw->setParent(currentHoveredFloat); - dw->show(); - } + dw->setParent(currentHoveredFloat ? currentHoveredFloat.data() : parentWidget()); + dw->show(); dw->d_func()->plug(currentGapRect); } #endif -- cgit v1.2.3 From 8c1f147eaf2769f84fa5ae8425394eb315949395 Mon Sep 17 00:00:00 2001 From: Sergio Martins Date: Thu, 16 Feb 2017 09:58:20 +0000 Subject: dockwidgets: recalculate the press position if the window resizes A window can resize while dragging, this happens on Windows when dragging across screens, to a screen with a bigger scale factor. When that occurs it might lead to the press pos being outside of the window. Change-Id: Ic61ec7088c8fa81395d43ce665952dbd2eecba39 Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/widgets/widgets/qdockwidget.cpp | 13 +++++++++++++ src/widgets/widgets/qdockwidget_p.h | 1 + 2 files changed, 14 insertions(+) (limited to 'src/widgets') diff --git a/src/widgets/widgets/qdockwidget.cpp b/src/widgets/widgets/qdockwidget.cpp index 53cb21186f..f51e3c7988 100644 --- a/src/widgets/widgets/qdockwidget.cpp +++ b/src/widgets/widgets/qdockwidget.cpp @@ -1024,6 +1024,12 @@ void QDockWidgetPrivate::nonClientAreaMouseEvent(QMouseEvent *event) } } +void QDockWidgetPrivate::recalculatePressPos(QResizeEvent *event) +{ + qreal ratio = event->oldSize().width() / (1.0 * event->size().width()); + state->pressPos.setX(state->pressPos.x() / ratio); +} + /*! \internal Called when the QDockWidget or the QDockWidgetGroupWindow is moved */ @@ -1540,6 +1546,13 @@ bool QDockWidget::event(QEvent *event) // if the mainwindow is plugging us, we don't want to update undocked geometry if (isFloating() && layout != 0 && layout->pluggingWidget != this) d->undockedGeometry = geometry(); + + // Usually the window won't get resized while it's being moved, but it can happen, + // for example on Windows when moving to a screen with bigger scale factor + // (and Qt::AA_EnableHighDpiScaling is enabled). If that happens we should + // update state->pressPos, otherwise it will be outside the window when the window shrinks. + if (d->state && d->state->dragging) + d->recalculatePressPos(static_cast(event)); break; default: break; diff --git a/src/widgets/widgets/qdockwidget_p.h b/src/widgets/widgets/qdockwidget_p.h index 94a3ad3b34..84bf8efacf 100644 --- a/src/widgets/widgets/qdockwidget_p.h +++ b/src/widgets/widgets/qdockwidget_p.h @@ -118,6 +118,7 @@ public: void startDrag(bool group = true); void endDrag(bool abort = false); void moveEvent(QMoveEvent *event); + void recalculatePressPos(QResizeEvent *event); void unplug(const QRect &rect); void plug(const QRect &rect); -- cgit v1.2.3 From 4d3781b640e8fb0a04e96b2d05199247556b8d86 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 21 Feb 2017 15:45:00 +0100 Subject: QDockWidget: Fix memory leak when dragging a tab outside of a floating tab window MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A QDockWidgetItem will be leaked if a QDockWidget is dragged out of a floating tab window, and then plugged back somewhere. The problem is that QMainWindowLayout::unplug was not returning the QDockWidgetItem* from the floating tab's layout. When that's the case, a new QDockWidgetItem is created in QDockWidgetPrivate::startDrag and will be put into the layout, leaking the old QDockWidgetItem. Change-Id: Ifb9c1c562cb74383ebff1df0f91ee225c5cdb296 Reviewed-by: Sérgio Martins --- src/widgets/widgets/qmainwindowlayout.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/widgets') diff --git a/src/widgets/widgets/qmainwindowlayout.cpp b/src/widgets/widgets/qmainwindowlayout.cpp index 0d9c42fdf0..640154063e 100644 --- a/src/widgets/widgets/qmainwindowlayout.cpp +++ b/src/widgets/widgets/qmainwindowlayout.cpp @@ -2378,7 +2378,8 @@ QLayoutItem *QMainWindowLayout::unplug(QWidget *widget, bool group) // We are unplugging a dock widget from a floating window. if (QDockWidget *dw = qobject_cast(widget)) { dw->d_func()->unplug(widget->geometry()); - return 0; + int index = widget->parentWidget()->layout()->indexOf(widget); + return widget->parentWidget()->layout()->itemAt(index); } } } -- cgit v1.2.3