diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2021-06-25 11:38:37 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-08-12 11:03:56 +0000 |
commit | fb1d80b3210d7ebedc6865b57d61f2260e87b2f0 (patch) | |
tree | 0fe1781922867bee45d133081e79bc63eec3d640 | |
parent | 4576e34c255ae8a435ae06d5b0cc7b35edd05c44 (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
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
(cherry picked from commit 009a0262bc0436d4822a3438fc99e02ed15dfc69)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/quicktemplates2/CMakeLists.txt | 1 | ||||
-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-- | tests/auto/quickcontrols2/controls/data/tst_tooltip.qml | 18 |
6 files changed, 4 insertions, 230 deletions
diff --git a/src/quicktemplates2/CMakeLists.txt b/src/quicktemplates2/CMakeLists.txt index 200a586140..51e7623be6 100644 --- a/src/quicktemplates2/CMakeLists.txt +++ b/src/quicktemplates2/CMakeLists.txt @@ -117,7 +117,6 @@ qt_internal_add_qml_module(QuickTemplates2 qquicktoolbutton.cpp qquicktoolbutton_p.h qquicktoolseparator.cpp qquicktoolseparator_p.h qquicktooltip.cpp qquicktooltip_p.h - qquicktooltippopupitem.cpp qquicktooltippopupitem_p_p.h qquickvelocitycalculator.cpp qquickvelocitycalculator_p_p.h qtquicktemplates2global.cpp qtquicktemplates2global_p.h diff --git a/src/quicktemplates2/qquickpane_p_p.h b/src/quicktemplates2/qquickpane_p_p.h index 7dac4f3cf1..bd89aee2f8 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 a6ad371a5e..96c573544e 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(); @@ -144,19 +141,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); @@ -191,7 +175,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 c3a48f6f0b..0000000000 --- a/src/quicktemplates2/qquicktooltippopupitem.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2021 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Templates 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $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 d81c309d0f..0000000000 --- a/src/quicktemplates2/qquicktooltippopupitem_p_p.h +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2021 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Templates 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $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/tests/auto/quickcontrols2/controls/data/tst_tooltip.qml b/tests/auto/quickcontrols2/controls/data/tst_tooltip.qml index 2f98a5f3d2..b4e992a46a 100644 --- a/tests/auto/quickcontrols2/controls/data/tst_tooltip.qml +++ b/tests/auto/quickcontrols2/controls/data/tst_tooltip.qml @@ -75,11 +75,6 @@ TestCase { SignalSpy { } } - Component { - id: itemComponent - Item {} - } - QtObject { id: object } @@ -451,19 +446,6 @@ TestCase { 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) - } - function test_timeoutAfterOpened() { let control = createTemporaryObject(toolTipWithExitTransition, testCase, { timeout: 1, exit: null }) verify(control) |