From 47e50cb3d0088e1080c98996601664119d3d588e Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 21 Mar 2016 15:17:55 +0100 Subject: Popup: fix margins Change-Id: I09f974a00a5a2a8f14645ff5d9bfbd6bad03d324 Task-number: QTBUG-51990 Reviewed-by: Mitch Curtis --- src/imports/controls/Popup.qml | 6 ++++-- src/imports/controls/material/Popup.qml | 6 ++++-- src/imports/controls/universal/Popup.qml | 6 ++++-- src/templates/qquickpopup.cpp | 14 +++++++++++++- 4 files changed, 25 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/imports/controls/Popup.qml b/src/imports/controls/Popup.qml index 60ea326a..309c317b 100644 --- a/src/imports/controls/Popup.qml +++ b/src/imports/controls/Popup.qml @@ -40,8 +40,10 @@ import Qt.labs.templates 1.0 as T T.Popup { id: control - implicitWidth: Math.max(background ? background.implicitWidth : 0, contentWidth + leftPadding + rightPadding) - implicitHeight: Math.max(background ? background.implicitHeight : 0, contentHeight + topPadding + bottomPadding) + implicitWidth: Math.max(background ? background.implicitWidth : 0, + contentWidth > 0 ? contentWidth + leftPadding + rightPadding : 0) + implicitHeight: Math.max(background ? background.implicitHeight : 0, + contentWidth > 0 ? contentHeight + topPadding + bottomPadding : 0) contentWidth: contentItem.implicitWidth || (contentChildren.length === 1 ? contentChildren[0].implicitWidth : 0) contentHeight: contentItem.implicitHeight || (contentChildren.length === 1 ? contentChildren[0].implicitHeight : 0) diff --git a/src/imports/controls/material/Popup.qml b/src/imports/controls/material/Popup.qml index 8fa9f7f7..d882840a 100644 --- a/src/imports/controls/material/Popup.qml +++ b/src/imports/controls/material/Popup.qml @@ -42,8 +42,10 @@ import Qt.labs.controls.material 1.0 T.Popup { id: control - implicitWidth: Math.max(background ? background.implicitWidth : 0, contentWidth + leftPadding + rightPadding) - implicitHeight: Math.max(background ? background.implicitHeight : 0, contentHeight + topPadding + bottomPadding) + implicitWidth: Math.max(background ? background.implicitWidth : 0, + contentWidth > 0 ? contentWidth + leftPadding + rightPadding : 0) + implicitHeight: Math.max(background ? background.implicitHeight : 0, + contentWidth > 0 ? contentHeight + topPadding + bottomPadding : 0) contentWidth: contentItem.implicitWidth || (contentChildren.length === 1 ? contentChildren[0].implicitWidth : 0) contentHeight: contentItem.implicitHeight || (contentChildren.length === 1 ? contentChildren[0].implicitHeight : 0) diff --git a/src/imports/controls/universal/Popup.qml b/src/imports/controls/universal/Popup.qml index d26dd02d..7ab79545 100644 --- a/src/imports/controls/universal/Popup.qml +++ b/src/imports/controls/universal/Popup.qml @@ -41,8 +41,10 @@ import Qt.labs.controls.universal 1.0 T.Popup { id: control - implicitWidth: Math.max(background ? background.implicitWidth : 0, contentWidth + leftPadding + rightPadding) - implicitHeight: Math.max(background ? background.implicitHeight : 0, contentHeight + topPadding + bottomPadding) + implicitWidth: Math.max(background ? background.implicitWidth : 0, + contentWidth > 0 ? contentWidth + leftPadding + rightPadding : 0) + implicitHeight: Math.max(background ? background.implicitHeight : 0, + contentWidth > 0 ? contentHeight + topPadding + bottomPadding : 0) contentWidth: contentItem.implicitWidth || (contentChildren.length === 1 ? contentChildren[0].implicitWidth : 0) contentHeight: contentItem.implicitHeight || (contentChildren.length === 1 ? contentChildren[0].implicitHeight : 0) diff --git a/src/templates/qquickpopup.cpp b/src/templates/qquickpopup.cpp index 8d40dd0c..f8df8df0 100644 --- a/src/templates/qquickpopup.cpp +++ b/src/templates/qquickpopup.cpp @@ -488,7 +488,19 @@ void QQuickPopupPositioner::repositionPopup() QQuickWindow *window = m_parentItem->window(); if (window) { - const QRectF bounds = QRectF(0, 0, window->width(), window->height()).marginsRemoved(m_popup->getMargins()); + const QMarginsF margins = m_popup->getMargins(); + const QRectF bounds = QRectF(0, 0, window->width(), window->height()).marginsRemoved(margins); + + // push inside the margins + if (margins.top() > 0 && rect.top() < bounds.top()) + rect.moveTop(margins.top()); + if (margins.bottom() > 0 && rect.bottom() > bounds.bottom()) + rect.moveBottom(bounds.bottom()); + if (margins.left() > 0 && rect.left() < bounds.left()) + rect.moveLeft(margins.left()); + if (margins.right() > 0 && rect.right() > bounds.right()) + rect.moveRight(bounds.right()); + if (rect.top() < bounds.top() || rect.bottom() > bounds.bottom()) { // if the popup doesn't fit inside the window, try flipping it around (below <-> above) const QRectF flipped = m_parentItem->mapRectToScene(QRectF(m_x, m_parentItem->height() - m_y - rect.height(), rect.width(), rect.height())); -- cgit v1.2.3 From 4c66fbe8892e644b3d3c62d5bd94f03831ff76de Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Tue, 22 Mar 2016 10:12:02 +0100 Subject: Fix QQuickPopupPositioner tst_tooltip revealed a bug that QQuickPopupPositioner wasn't cleaning up its ancestor listeners properly. When QQuickPopup was destructed, it left a listener on the window root item. When the root item got later destructed, it tried to call a listener (the popup) that was already deleted. Change-Id: If041458da24be927f0bad19b9549dcabd1931977 Reviewed-by: Mitch Curtis --- src/templates/qquickpopup.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/templates/qquickpopup.cpp b/src/templates/qquickpopup.cpp index f8df8df0..ef092bed 100644 --- a/src/templates/qquickpopup.cpp +++ b/src/templates/qquickpopup.cpp @@ -458,10 +458,10 @@ void QQuickPopupPositioner::itemParentChanged(QQuickItem *, QQuickItem *parent) addAncestorListeners(parent); } -void QQuickPopupPositioner::itemChildRemoved(QQuickItem *, QQuickItem *child) +void QQuickPopupPositioner::itemChildRemoved(QQuickItem *item, QQuickItem *child) { if (isAncestor(child)) - removeAncestorListeners(child); + removeAncestorListeners(item); } void QQuickPopupPositioner::itemDestroyed(QQuickItem *item) @@ -561,7 +561,7 @@ bool QQuickPopupPositioner::isAncestor(QQuickItem *item) const if (!m_parentItem) return false; - QQuickItem *parent = m_parentItem->parentItem(); + QQuickItem *parent = m_parentItem; while (parent) { if (parent == item) return true; -- cgit v1.2.3