diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2021-08-13 15:16:38 +0200 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2021-08-16 11:23:52 +0200 |
commit | 05522a30193a3090dd7cae26b36d675ae1f18e08 (patch) | |
tree | eec5f50d0cc86cf292ab8a40ed46a50b7fc19e01 | |
parent | 78cd4d19cd8ae60f9a0e795337006bf6d504580d (diff) |
Revert "ToolTip: use contentWidth of Text contentItem to account for newlines"
This reverts commit a063cd0be5e8f108a0084831856f4af8c0e9159c.
It causes QTBUG-94764.
Task-number: QTBUG-83630
Task-number: QTBUG-94764
Change-Id: Ib27d827e25d4e4cea805d0f8e3c32b8aa843ec6a
(adapted from from commit 009a0262bc0436d4822a3438fc99e02ed15dfc69)
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
-rw-r--r-- | src/quicktemplates2/qquickpane_p_p.h | 2 | ||||
-rw-r--r-- | src/quicktemplates2/qquicktooltip.cpp | 20 | ||||
-rw-r--r-- | src/quicktemplates2/qquicktooltippopupitem.cpp | 106 | ||||
-rw-r--r-- | src/quicktemplates2/qquicktooltippopupitem_p_p.h | 87 | ||||
-rw-r--r-- | src/quicktemplates2/quicktemplates2.pri | 2 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_tooltip.qml | 22 |
6 files changed, 6 insertions, 233 deletions
diff --git a/src/quicktemplates2/qquickpane_p_p.h b/src/quicktemplates2/qquickpane_p_p.h index 4d82cc32..579371f4 100644 --- a/src/quicktemplates2/qquickpane_p_p.h +++ b/src/quicktemplates2/qquickpane_p_p.h @@ -75,7 +75,7 @@ public: void contentChildrenChange(); - virtual void updateContentWidth(); + void updateContentWidth(); void updateContentHeight(); bool hasContentWidth = false; diff --git a/src/quicktemplates2/qquicktooltip.cpp b/src/quicktemplates2/qquicktooltip.cpp index cb08127c..19c4cc83 100644 --- a/src/quicktemplates2/qquicktooltip.cpp +++ b/src/quicktemplates2/qquicktooltip.cpp @@ -38,7 +38,6 @@ #include "qquickpopup_p_p.h" #include "qquickpopupitem_p_p.h" #include "qquickcontrol_p_p.h" -#include "qquicktooltippopupitem_p_p.h" #include <QtCore/qbasictimer.h> #include <QtQml/qqmlinfo.h> @@ -125,8 +124,6 @@ class QQuickToolTipPrivate : public QQuickPopupPrivate Q_DECLARE_PUBLIC(QQuickToolTip) public: - void init() override; - void startDelay(); void stopDelay(); @@ -140,19 +137,6 @@ public: QBasicTimer timeoutTimer; }; -void QQuickToolTipPrivate::init() -{ - Q_Q(QQuickToolTip); - popupItem = new QQuickToolTipPopupItem(q); - popupItem->setVisible(false); - q->setParentItem(qobject_cast<QQuickItem *>(parent)); - connectToPopupItem(); - - allowVerticalFlip = true; - allowHorizontalFlip = true; - popupItem->setHoverEnabled(false); // QTBUG-63644 -} - void QQuickToolTipPrivate::startDelay() { Q_Q(QQuickToolTip); @@ -181,7 +165,9 @@ QQuickToolTip::QQuickToolTip(QQuickItem *parent) : QQuickPopup(*(new QQuickToolTipPrivate), parent) { Q_D(QQuickToolTip); - d->init(); + d->allowVerticalFlip = true; + d->allowHorizontalFlip = true; + d->popupItem->setHoverEnabled(false); // QTBUG-63644 } /*! diff --git a/src/quicktemplates2/qquicktooltippopupitem.cpp b/src/quicktemplates2/qquicktooltippopupitem.cpp deleted file mode 100644 index 49455ca9..00000000 --- a/src/quicktemplates2/qquicktooltippopupitem.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2021 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Templates 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:COMM$ -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** $QT_END_LICENSE$ -** -** -** -** -** -** -** -** -** -** -** -** -** -** -** -** -****************************************************************************/ - -#include "qquicktooltippopupitem_p_p.h" - -#include <QtQuickTemplates2/private/qquickpopup_p.h> - -QT_BEGIN_NAMESPACE - -QQuickToolTipPopupItemPrivate::QQuickToolTipPopupItemPrivate(QQuickPopup *popup) - : QQuickPopupItemPrivate(popup) -{ -} - -qreal QQuickToolTipPopupItemPrivate::getContentWidth() const -{ - auto textItem = qobject_cast<QQuickText*>(contentItem); - if (textItem) - return textItem->contentWidth(); - - return contentItem ? contentItem->implicitWidth() : 0; -} - -void QQuickToolTipPopupItemPrivate::updateContentWidth() -{ - Q_Q(QQuickToolTipPopupItem); - // Don't need to calculate the implicit contentWidth if an explicit one was set. - if (hasContentWidth) - return; - - auto textItem = qobject_cast<QQuickText*>(contentItem); - if (!textItem) { - // It's not a Text item, so use the base contentWidth logic (i.e. use implicitWidth). - QQuickPopupItemPrivate::updateContentWidth(); - return; - } - - const qreal oldContentWidth = contentWidth; - const qreal newContentWidth = textItem->contentWidth(); - if (qFuzzyCompare(oldContentWidth, newContentWidth)) - return; - - contentWidth = newContentWidth; - q->contentSizeChange(QSizeF(contentWidth, contentHeight), QSizeF(oldContentWidth, contentHeight)); - emit q->contentWidthChanged(); -} - -QQuickToolTipPopupItem::QQuickToolTipPopupItem(QQuickPopup *popup) - : QQuickPopupItem(*(new QQuickToolTipPopupItemPrivate(popup))) -{ -} - -void QQuickToolTipPopupItem::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) -{ - Q_D(QQuickToolTipPopupItem); - QQuickPopupItem::contentItemChange(newItem, oldItem); - - // Text's implicitWidth does not account for newlines and hence is too large, - // so we need to listen to contentWidth's change signals. - auto oldTextItem = qobject_cast<QQuickText*>(oldItem); - if (oldTextItem) { - QObjectPrivate::disconnect(oldTextItem, &QQuickText::contentWidthChanged, - d, &QQuickToolTipPopupItemPrivate::updateContentWidth); - } - - auto newTextItem = qobject_cast<QQuickText*>(newItem); - if (newTextItem) { - QObjectPrivate::connect(newTextItem, &QQuickText::contentWidthChanged, - d, &QQuickToolTipPopupItemPrivate::updateContentWidth); - } -} - -QT_END_NAMESPACE diff --git a/src/quicktemplates2/qquicktooltippopupitem_p_p.h b/src/quicktemplates2/qquicktooltippopupitem_p_p.h deleted file mode 100644 index a86dfd9d..00000000 --- a/src/quicktemplates2/qquicktooltippopupitem_p_p.h +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2021 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Templates 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:COMM$ -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** $QT_END_LICENSE$ -** -** -** -** -** -** -** -** -** -** -** -** -** -** -** -** -****************************************************************************/ - -#ifndef QQUICKTOOLTIPPOPUPITEM_P_P_H -#define QQUICKTOOLTIPPOPUPITEM_P_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <QtQuickTemplates2/private/qquickpopupitem_p.h> -#include <QtQuickTemplates2/private/qquickpopupitem_p_p.h> - -QT_BEGIN_NAMESPACE - -class QQuickPopup; -class QQuickToolTipPopupItemPrivate; - -class QQuickToolTipPopupItem : public QQuickPopupItem -{ - Q_OBJECT - -public: - explicit QQuickToolTipPopupItem(QQuickPopup *popup); - -protected: - void contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) override; - -private: - Q_DISABLE_COPY(QQuickToolTipPopupItem) - Q_DECLARE_PRIVATE(QQuickToolTipPopupItem) -}; - -class QQuickToolTipPopupItemPrivate : public QQuickPopupItemPrivate -{ - Q_DECLARE_PUBLIC(QQuickToolTipPopupItem) - -public: - QQuickToolTipPopupItemPrivate(QQuickPopup *popup); - - qreal getContentWidth() const override; - void updateContentWidth() override; -}; - -QT_END_NAMESPACE - -#endif // QQUICKTOOLTIPPOPUPITEM_P_P_H diff --git a/src/quicktemplates2/quicktemplates2.pri b/src/quicktemplates2/quicktemplates2.pri index 32038ad2..fa6929f9 100644 --- a/src/quicktemplates2/quicktemplates2.pri +++ b/src/quicktemplates2/quicktemplates2.pri @@ -98,7 +98,6 @@ HEADERS += \ $$PWD/qquicktoolbutton_p.h \ $$PWD/qquicktoolseparator_p.h \ $$PWD/qquicktooltip_p.h \ - $$PWD/qquicktooltippopupitem_p_p.h \ $$PWD/qquickvelocitycalculator_p_p.h SOURCES += \ @@ -172,7 +171,6 @@ SOURCES += \ $$PWD/qquicktoolbutton.cpp \ $$PWD/qquicktoolseparator.cpp \ $$PWD/qquicktooltip.cpp \ - $$PWD/qquicktooltippopupitem.cpp \ $$PWD/qquickvelocitycalculator.cpp qtConfig(quick-listview):qtConfig(quick-pathview) { diff --git a/tests/auto/controls/data/tst_tooltip.qml b/tests/auto/controls/data/tst_tooltip.qml index 154eb2bf..6d45b09d 100644 --- a/tests/auto/controls/data/tst_tooltip.qml +++ b/tests/auto/controls/data/tst_tooltip.qml @@ -75,11 +75,6 @@ TestCase { SignalSpy { } } - Component { - id: itemComponent - Item {} - } - QtObject { id: object } @@ -223,8 +218,8 @@ TestCase { } function test_warning() { - ignoreWarning(new RegExp(".*QML QtObject: ToolTip must be attached to an Item")) - ignoreWarning(new RegExp(".*QML ToolTip: cannot find any window to open popup in.")) + ignoreWarning(Qt.resolvedUrl("tst_tooltip.qml") + ":78:5: QML QtObject: ToolTip must be attached to an Item") + ignoreWarning("<Unknown File>:1:30: QML ToolTip: cannot find any window to open popup in.") object.ToolTip.show("") // don't crash (QTBUG-56243) } @@ -479,17 +474,4 @@ TestCase { compare(item.ToolTip.toolTip.contentItem.wrapMode, Text.Wrap) verify(item.ToolTip.toolTip.contentItem.width < item.ToolTip.toolTip.contentItem.implicitWidth) } - - // QTBUG-83630: Test that newlines are accounted for in the implicit contentWidth. - function test_newLines() { - var item = createTemporaryObject(itemComponent, testCase) - verify(item) - - item.ToolTip.show("This is one line of text\nThis is another line of text") - - // The implicitWidth of the Text item for the text above will be larger than - // its contentWidth. ToolTip's implicitWidth uses contentWidth in its calculation, - // so we check that it's less than the Text's implicitWidth. - verify(item.ToolTip.toolTip.implicitWidth < item.ToolTip.toolTip.contentItem.implicitWidth) - } } |