aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2016-03-01 13:26:21 +0100
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2016-03-22 19:32:37 +0000
commitcd716f1b1c903b7a2fdfd82bb88959119ebca72d (patch)
treea8ff297e58d34b0c8b6fd24a51a2301c8c2708bb /src
parentfaa65aebb2e52cc809248f6cbb86b994ff329285 (diff)
Introduce ToolTip
Change-Id: I917f7e83219788fc63389773eb07ee39757bed7f Task-number: QTBUG-51003 Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r--src/imports/controls/ToolTip.qml69
-rw-r--r--src/imports/controls/controls.pri1
-rw-r--r--src/imports/controls/doc/images/qtquickcontrols-tooltip-background.pngbin0 -> 1014 bytes
-rw-r--r--src/imports/controls/doc/images/qtquickcontrols-tooltip-contentItem.pngbin0 -> 1046 bytes
-rw-r--r--src/imports/controls/doc/images/qtquickcontrols-tooltip-delay.pngbin0 -> 1278 bytes
-rw-r--r--src/imports/controls/doc/images/qtquickcontrols-tooltip-hover.pngbin0 -> 1275 bytes
-rw-r--r--src/imports/controls/doc/images/qtquickcontrols-tooltip-pressandhold.pngbin0 -> 1275 bytes
-rw-r--r--src/imports/controls/doc/images/qtquickcontrols-tooltip-slider.pngbin0 -> 2130 bytes
-rw-r--r--src/imports/controls/doc/images/qtquickcontrols-tooltip.pngbin0 -> 5611 bytes
-rw-r--r--src/imports/controls/doc/snippets/qtquickcontrols-tooltip-background.qml49
-rw-r--r--src/imports/controls/doc/snippets/qtquickcontrols-tooltip-contentItem.qml49
-rw-r--r--src/imports/controls/doc/snippets/qtquickcontrols-tooltip-hover.qml41
-rw-r--r--src/imports/controls/doc/snippets/qtquickcontrols-tooltip-pressandhold.qml39
-rw-r--r--src/imports/controls/doc/snippets/qtquickcontrols-tooltip-slider.qml53
-rw-r--r--src/imports/controls/doc/snippets/qtquickcontrols-tooltip.qml51
-rw-r--r--src/imports/controls/doc/src/qtlabscontrols-customize.qdoc19
-rw-r--r--src/imports/controls/material/ToolTip.qml88
-rw-r--r--src/imports/controls/material/material.pri1
-rw-r--r--src/imports/controls/material/qquickmaterialstyle.cpp5
-rw-r--r--src/imports/controls/material/qquickmaterialstyle_p.h2
-rw-r--r--src/imports/controls/qtquickcontrolsplugin.cpp1
-rw-r--r--src/imports/controls/universal/ToolTip.qml75
-rw-r--r--src/imports/controls/universal/universal.pri1
-rw-r--r--src/imports/templates/qtquicktemplatesplugin.cpp3
-rw-r--r--src/templates/qquicktooltip.cpp560
-rw-r--r--src/templates/qquicktooltip_p.h148
-rw-r--r--src/templates/templates.pri2
27 files changed, 1257 insertions, 0 deletions
diff --git a/src/imports/controls/ToolTip.qml b/src/imports/controls/ToolTip.qml
new file mode 100644
index 00000000..3f78aa21
--- /dev/null
+++ b/src/imports/controls/ToolTip.qml
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Labs Controls 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$
+**
+****************************************************************************/
+
+import QtQuick 2.6
+import Qt.labs.controls 1.0
+import Qt.labs.templates 1.0 as T
+
+T.ToolTip {
+ id: control
+
+ x: parent ? (parent.width - implicitWidth) / 2 : 0
+ y: -implicitHeight - 3
+
+ implicitWidth: Math.max(background ? background.implicitWidth : 0,
+ contentItem.implicitWidth + leftPadding + rightPadding)
+ implicitHeight: Math.max(background ? background.implicitHeight : 0,
+ contentItem.implicitHeight + topPadding + bottomPadding)
+
+ padding: 6
+
+ closePolicy: T.Popup.OnEscape | T.Popup.OnPressOutsideParent | T.Popup.OnReleaseOutsideParent
+
+ //! [contentItem]
+ contentItem: Text {
+ text: control.text
+ // TODO: font: control.font
+ // TODO: wrapMode: Label.Wrap
+ }
+ //! [contentItem]
+
+ //! [background]
+ background: Rectangle {
+ border.color: "#353637"
+ }
+ //! [background]
+}
diff --git a/src/imports/controls/controls.pri b/src/imports/controls/controls.pri
index 669db06e..0b0881b9 100644
--- a/src/imports/controls/controls.pri
+++ b/src/imports/controls/controls.pri
@@ -41,6 +41,7 @@ QML_CONTROLS = \
TextField.qml \
ToolBar.qml \
ToolButton.qml \
+ ToolTip.qml \
Tumbler.qml
!qtquickcompiler: QML_FILES += $$QML_CONTROLS
diff --git a/src/imports/controls/doc/images/qtquickcontrols-tooltip-background.png b/src/imports/controls/doc/images/qtquickcontrols-tooltip-background.png
new file mode 100644
index 00000000..c082c840
--- /dev/null
+++ b/src/imports/controls/doc/images/qtquickcontrols-tooltip-background.png
Binary files differ
diff --git a/src/imports/controls/doc/images/qtquickcontrols-tooltip-contentItem.png b/src/imports/controls/doc/images/qtquickcontrols-tooltip-contentItem.png
new file mode 100644
index 00000000..d79a336f
--- /dev/null
+++ b/src/imports/controls/doc/images/qtquickcontrols-tooltip-contentItem.png
Binary files differ
diff --git a/src/imports/controls/doc/images/qtquickcontrols-tooltip-delay.png b/src/imports/controls/doc/images/qtquickcontrols-tooltip-delay.png
new file mode 100644
index 00000000..eb9499fd
--- /dev/null
+++ b/src/imports/controls/doc/images/qtquickcontrols-tooltip-delay.png
Binary files differ
diff --git a/src/imports/controls/doc/images/qtquickcontrols-tooltip-hover.png b/src/imports/controls/doc/images/qtquickcontrols-tooltip-hover.png
new file mode 100644
index 00000000..b5c70d86
--- /dev/null
+++ b/src/imports/controls/doc/images/qtquickcontrols-tooltip-hover.png
Binary files differ
diff --git a/src/imports/controls/doc/images/qtquickcontrols-tooltip-pressandhold.png b/src/imports/controls/doc/images/qtquickcontrols-tooltip-pressandhold.png
new file mode 100644
index 00000000..b5c70d86
--- /dev/null
+++ b/src/imports/controls/doc/images/qtquickcontrols-tooltip-pressandhold.png
Binary files differ
diff --git a/src/imports/controls/doc/images/qtquickcontrols-tooltip-slider.png b/src/imports/controls/doc/images/qtquickcontrols-tooltip-slider.png
new file mode 100644
index 00000000..6dad4464
--- /dev/null
+++ b/src/imports/controls/doc/images/qtquickcontrols-tooltip-slider.png
Binary files differ
diff --git a/src/imports/controls/doc/images/qtquickcontrols-tooltip.png b/src/imports/controls/doc/images/qtquickcontrols-tooltip.png
new file mode 100644
index 00000000..ffac3ed6
--- /dev/null
+++ b/src/imports/controls/doc/images/qtquickcontrols-tooltip.png
Binary files differ
diff --git a/src/imports/controls/doc/snippets/qtquickcontrols-tooltip-background.qml b/src/imports/controls/doc/snippets/qtquickcontrols-tooltip-background.qml
new file mode 100644
index 00000000..fe4f33a5
--- /dev/null
+++ b/src/imports/controls/doc/snippets/qtquickcontrols-tooltip-background.qml
@@ -0,0 +1,49 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** 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 Free Documentation License Usage
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file. Please review the following information to ensure
+** the GNU Free Documentation License version 1.3 requirements
+** will be met: http://www.gnu.org/copyleft/fdl.html.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+import QtQuick.Window 2.2
+import Qt.labs.controls 1.0
+
+Item {
+ id: root
+ width: tip.width
+ height: tip.height
+
+ ToolTip {
+ id: tip
+ text: "ToolTip"
+ visible: root.Window.active
+
+ Rectangle {
+ parent: tip.background
+ anchors.fill: parent
+ color: 'transparent'
+ border.color: 'red'
+ }
+ }
+}
diff --git a/src/imports/controls/doc/snippets/qtquickcontrols-tooltip-contentItem.qml b/src/imports/controls/doc/snippets/qtquickcontrols-tooltip-contentItem.qml
new file mode 100644
index 00000000..2a62c86a
--- /dev/null
+++ b/src/imports/controls/doc/snippets/qtquickcontrols-tooltip-contentItem.qml
@@ -0,0 +1,49 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** 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 Free Documentation License Usage
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file. Please review the following information to ensure
+** the GNU Free Documentation License version 1.3 requirements
+** will be met: http://www.gnu.org/copyleft/fdl.html.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+import QtQuick.Window 2.2
+import Qt.labs.controls 1.0
+
+Item {
+ id: root
+ width: tip.width
+ height: tip.height
+
+ ToolTip {
+ id: tip
+ text: "ToolTip"
+ visible: root.Window.active
+
+ Rectangle {
+ parent: tip.contentItem
+ anchors.fill: parent
+ color: 'transparent'
+ border.color: 'red'
+ }
+ }
+}
diff --git a/src/imports/controls/doc/snippets/qtquickcontrols-tooltip-hover.qml b/src/imports/controls/doc/snippets/qtquickcontrols-tooltip-hover.qml
new file mode 100644
index 00000000..a8df6277
--- /dev/null
+++ b/src/imports/controls/doc/snippets/qtquickcontrols-tooltip-hover.qml
@@ -0,0 +1,41 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** 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 Free Documentation License Usage
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file. Please review the following information to ensure
+** the GNU Free Documentation License version 1.3 requirements
+** will be met: http://www.gnu.org/copyleft/fdl.html.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+import Qt.labs.controls 1.0
+
+//! [1]
+Button {
+ text: qsTr("Button")
+ hoverEnabled: true
+
+ ToolTip.delay: 1000
+ ToolTip.timeout: 5000
+ ToolTip.visible: hovered
+ ToolTip.text: qsTr("This tool tip is shown after hovering the button for a second.")
+}
+//! [1]
diff --git a/src/imports/controls/doc/snippets/qtquickcontrols-tooltip-pressandhold.qml b/src/imports/controls/doc/snippets/qtquickcontrols-tooltip-pressandhold.qml
new file mode 100644
index 00000000..47f1440c
--- /dev/null
+++ b/src/imports/controls/doc/snippets/qtquickcontrols-tooltip-pressandhold.qml
@@ -0,0 +1,39 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** 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 Free Documentation License Usage
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file. Please review the following information to ensure
+** the GNU Free Documentation License version 1.3 requirements
+** will be met: http://www.gnu.org/copyleft/fdl.html.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+import Qt.labs.controls 1.0
+
+//! [1]
+Button {
+ text: qsTr("Button")
+
+ ToolTip.visible: pressed
+ ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval
+ ToolTip.text: qsTr("This tool tip is shown after pressing and holding the button down.")
+}
+//! [1]
diff --git a/src/imports/controls/doc/snippets/qtquickcontrols-tooltip-slider.qml b/src/imports/controls/doc/snippets/qtquickcontrols-tooltip-slider.qml
new file mode 100644
index 00000000..cac6872c
--- /dev/null
+++ b/src/imports/controls/doc/snippets/qtquickcontrols-tooltip-slider.qml
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** 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 Free Documentation License Usage
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file. Please review the following information to ensure
+** the GNU Free Documentation License version 1.3 requirements
+** will be met: http://www.gnu.org/copyleft/fdl.html.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+import QtQuick.Window 2.2
+import Qt.labs.controls 1.0
+
+Item {
+ id: root
+ width: slider.width
+ height: slider.height * 2.0
+
+ Binding { target: slider.anchors; property: "centerIn"; value: root }
+ Binding { target: slider.anchors; property: "verticalCenterOffset"; value: slider.height / 2 }
+ Binding { target: slider; property: "pressed"; value: root.Window.active }
+
+ //! [1]
+ Slider {
+ id: slider
+ value: 0.5
+
+ ToolTip {
+ parent: slider.handle
+ visible: slider.pressed
+ text: slider.position.toFixed(1)
+ }
+ }
+ //! [1]
+}
diff --git a/src/imports/controls/doc/snippets/qtquickcontrols-tooltip.qml b/src/imports/controls/doc/snippets/qtquickcontrols-tooltip.qml
new file mode 100644
index 00000000..7a061b2d
--- /dev/null
+++ b/src/imports/controls/doc/snippets/qtquickcontrols-tooltip.qml
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** 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 Free Documentation License Usage
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file. Please review the following information to ensure
+** the GNU Free Documentation License version 1.3 requirements
+** will be met: http://www.gnu.org/copyleft/fdl.html.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+import QtQuick.Window 2.2
+import Qt.labs.controls 1.0
+
+Item {
+ id: root
+ width: 360
+ height: button.height * 2
+
+ property Button button: children[0]
+
+ Binding { target: button; property: "pressed"; value: root.Window.active }
+ Binding { target: button.anchors; property: "bottom"; value: root.bottom }
+ Binding { target: button.anchors; property: "horizontalCenter"; value: root.horizontalCenter }
+
+ //! [1]
+ Button {
+ text: qsTr("Button")
+
+ ToolTip.visible: pressed
+ ToolTip.text: qsTr("A descriptive tool tip of what the button does")
+ }
+ //! [1]
+}
diff --git a/src/imports/controls/doc/src/qtlabscontrols-customize.qdoc b/src/imports/controls/doc/src/qtlabscontrols-customize.qdoc
index 47702132..bc1e2504 100644
--- a/src/imports/controls/doc/src/qtlabscontrols-customize.qdoc
+++ b/src/imports/controls/doc/src/qtlabscontrols-customize.qdoc
@@ -575,6 +575,25 @@
\snippet ToolButton.qml contentItem
+
+ \section1 Customizing ToolTip
+
+ ToolTip consists of two visual items: \l {Popup::background}{background}
+ and \l {Popup::contentItem}{content item}.
+
+ \section3 Background
+
+ \image qtquickcontrols-tooltip-background.png
+
+ \snippet ToolTip.qml background
+
+ \section3 Content item
+
+ \image qtquickcontrols-tooltip-contentItem.png
+
+ \snippet ToolTip.qml contentItem
+
+
\section1 Customizing Tumbler
Tumbler consists of three visual items:
diff --git a/src/imports/controls/material/ToolTip.qml b/src/imports/controls/material/ToolTip.qml
new file mode 100644
index 00000000..29760354
--- /dev/null
+++ b/src/imports/controls/material/ToolTip.qml
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Labs Controls 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$
+**
+****************************************************************************/
+
+import QtQuick 2.6
+import Qt.labs.templates 1.0 as T
+import Qt.labs.controls.material 1.0
+
+T.ToolTip {
+ id: control
+
+ x: parent ? (parent.width - implicitWidth) / 2 : 0
+ y: -implicitHeight - 24
+
+ implicitWidth: Math.max(background ? background.implicitWidth : 0,
+ contentItem.implicitWidth + leftPadding + rightPadding)
+ implicitHeight: Math.max(background ? background.implicitHeight : 0,
+ contentItem.implicitHeight + topPadding + bottomPadding)
+
+ topPadding: 8
+ leftPadding: 16
+ rightPadding: 16
+ bottomPadding: 8
+
+ closePolicy: T.Popup.OnEscape | T.Popup.OnPressOutsideParent | T.Popup.OnReleaseOutsideParent
+
+ Material.theme: Material.Dark
+
+ enter: Transition {
+ // toast_enter
+ NumberAnimation { property: "opacity"; from: 0.0; to: 1.0; easing.type: Easing.OutQuad; duration: 500 }
+ }
+
+ exit: Transition {
+ // toast_exit
+ NumberAnimation { property: "opacity"; from: 1.0; to: 0.0; easing.type: Easing.InQuad; duration: 500 }
+ }
+
+ //! [contentItem]
+ contentItem: Text {
+ text: control.text
+ // TODO: font: control.font
+ // TODO: wrapMode: Label.Wrap
+ color: control.Material.primaryTextColor
+ }
+ //! [contentItem]
+
+ //! [background]
+ background: Rectangle {
+ implicitHeight: 32
+ color: control.Material.tooltipColor
+ opacity: 0.9
+ radius: 2
+ }
+ //! [background]
+}
diff --git a/src/imports/controls/material/material.pri b/src/imports/controls/material/material.pri
index 6682c09b..02e6d683 100644
--- a/src/imports/controls/material/material.pri
+++ b/src/imports/controls/material/material.pri
@@ -47,4 +47,5 @@ QML_FILES += \
$$PWD/TextField.qml \
$$PWD/ToolBar.qml \
$$PWD/ToolButton.qml \
+ $$PWD/ToolTip.qml \
$$PWD/Tumbler.qml
diff --git a/src/imports/controls/material/qquickmaterialstyle.cpp b/src/imports/controls/material/qquickmaterialstyle.cpp
index e73aaef5..9757db9f 100644
--- a/src/imports/controls/material/qquickmaterialstyle.cpp
+++ b/src/imports/controls/material/qquickmaterialstyle.cpp
@@ -850,6 +850,11 @@ QColor QQuickMaterialStyle::listHighlightColor() const
return QColor::fromRgba(m_theme == Light ? 0x1e000000 : 0x1effffff);
}
+QColor QQuickMaterialStyle::tooltipColor() const
+{
+ return color(Grey, Shade700);
+}
+
QColor QQuickMaterialStyle::color(QQuickMaterialStyle::Color color, QQuickMaterialStyle::Shade shade) const
{
int count = sizeof(colors) / sizeof(colors[0]);
diff --git a/src/imports/controls/material/qquickmaterialstyle_p.h b/src/imports/controls/material/qquickmaterialstyle_p.h
index aa8aa9f4..5b1a31ea 100644
--- a/src/imports/controls/material/qquickmaterialstyle_p.h
+++ b/src/imports/controls/material/qquickmaterialstyle_p.h
@@ -100,6 +100,7 @@ class QQuickMaterialStyle : public QQuickStyleAttached
Q_PROPERTY(QColor dialogColor READ dialogColor NOTIFY paletteChanged FINAL)
Q_PROPERTY(QColor backgroundDimColor READ backgroundDimColor NOTIFY paletteChanged FINAL)
Q_PROPERTY(QColor listHighlightColor READ listHighlightColor NOTIFY paletteChanged FINAL)
+ Q_PROPERTY(QColor tooltipColor READ tooltipColor NOTIFY paletteChanged FINAL)
public:
enum Theme {
@@ -211,6 +212,7 @@ public:
QColor dialogColor() const;
QColor backgroundDimColor() const;
QColor listHighlightColor() const;
+ QColor tooltipColor() const;
Q_INVOKABLE QColor color(Color color, Shade shade = Shade500) const;
Q_INVOKABLE QColor shade(const QColor &color, Shade shade) const;
diff --git a/src/imports/controls/qtquickcontrolsplugin.cpp b/src/imports/controls/qtquickcontrolsplugin.cpp
index 88692be7..824d9707 100644
--- a/src/imports/controls/qtquickcontrolsplugin.cpp
+++ b/src/imports/controls/qtquickcontrolsplugin.cpp
@@ -129,6 +129,7 @@ void QtQuickControlsPlugin::registerTypes(const char *uri)
qmlRegisterType(selector.select(QStringLiteral("TextField.qml")), uri, 1, 0, "TextField");
qmlRegisterType(selector.select(QStringLiteral("ToolBar.qml")), uri, 1, 0, "ToolBar");
qmlRegisterType(selector.select(QStringLiteral("ToolButton.qml")), uri, 1, 0, "ToolButton");
+ qmlRegisterType(selector.select(QStringLiteral("/ToolTip.qml")), uri, 1, 0, "ToolTip");
qmlRegisterType(selector.select(QStringLiteral("Tumbler.qml")), uri, 1, 0, "Tumbler");
}
diff --git a/src/imports/controls/universal/ToolTip.qml b/src/imports/controls/universal/ToolTip.qml
new file mode 100644
index 00000000..7422b3c5
--- /dev/null
+++ b/src/imports/controls/universal/ToolTip.qml
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Labs Controls 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$
+**
+****************************************************************************/
+
+import QtQuick 2.6
+import Qt.labs.templates 1.0 as T
+import Qt.labs.controls.universal 1.0
+
+T.ToolTip {
+ id: control
+
+ x: parent ? (parent.width - implicitWidth) / 2 : 0
+ y: -implicitHeight - 16
+
+ implicitWidth: Math.max(background ? background.implicitWidth : 0,
+ contentItem.implicitWidth + leftPadding + rightPadding)
+ implicitHeight: Math.max(background ? background.implicitHeight : 0,
+ contentItem.implicitHeight + topPadding + bottomPadding)
+
+ topPadding: 5
+ leftPadding: 8
+ rightPadding: 8
+ bottomPadding: 7
+
+ closePolicy: T.Popup.OnEscape | T.Popup.OnPressOutsideParent | T.Popup.OnReleaseOutsideParent
+
+ //! [contentItem]
+ contentItem: Text {
+ text: control.text
+ // TODO: font: control.font
+ // TODO: wrapMode: Label.Wrap
+ color: control.Universal.baseHighColor
+ }
+ //! [contentItem]
+
+ //! [background]
+ background: Rectangle {
+ color: control.Universal.chromeMediumLowColor
+ border.color: control.Universal.chromeHighColor
+ border.width: 1 // ToolTipBorderThemeThickness
+ }
+ //! [background]
+}
diff --git a/src/imports/controls/universal/universal.pri b/src/imports/controls/universal/universal.pri
index dc3002a3..a42589f7 100644
--- a/src/imports/controls/universal/universal.pri
+++ b/src/imports/controls/universal/universal.pri
@@ -31,6 +31,7 @@ QML_FILES += \
$$PWD/TextField.qml \
$$PWD/ToolBar.qml \
$$PWD/ToolButton.qml \
+ $$PWD/ToolTip.qml \
$$PWD/Tumbler.qml
HEADERS += \
diff --git a/src/imports/templates/qtquicktemplatesplugin.cpp b/src/imports/templates/qtquicktemplatesplugin.cpp
index e8a679a4..28e77482 100644
--- a/src/imports/templates/qtquicktemplatesplugin.cpp
+++ b/src/imports/templates/qtquicktemplatesplugin.cpp
@@ -74,6 +74,7 @@
#include <QtQuickTemplates/private/qquicktextfield_p.h>
#include <QtQuickTemplates/private/qquicktoolbar_p.h>
#include <QtQuickTemplates/private/qquicktoolbutton_p.h>
+#include <QtQuickTemplates/private/qquicktooltip_p.h>
#include <QtQuickTemplates/private/qquicktumbler_p.h>
static inline void initResources()
@@ -145,6 +146,8 @@ void QtQuickTemplatesPlugin::registerTypes(const char *uri)
qmlRegisterType<QQuickTextField>(uri, 1, 0, "TextField");
qmlRegisterType<QQuickToolBar>(uri, 1, 0, "ToolBar");
qmlRegisterType<QQuickToolButton>(uri, 1, 0, "ToolButton");
+ qmlRegisterType<QQuickToolTipAttached>();
+ qmlRegisterType<QQuickToolTip>(uri, 1, 0, "ToolTip");
qmlRegisterType<QQuickTumblerAttached>();
qmlRegisterType<QQuickTumbler>(uri, 1, 0, "Tumbler");
diff --git a/src/templates/qquicktooltip.cpp b/src/templates/qquicktooltip.cpp
new file mode 100644
index 00000000..c62c0431
--- /dev/null
+++ b/src/templates/qquicktooltip.cpp
@@ -0,0 +1,560 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Labs Templates 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 "qquicktooltip_p.h"
+#include "qquickpopup_p_p.h"
+
+#include <QtCore/qbasictimer.h>
+#include <QtQml/qqmlengine.h>
+#include <QtQml/qqmlcontext.h>
+#include <QtQml/qqmlcomponent.h>
+#include <QtQuick/qquickwindow.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \qmltype ToolTip
+ \inherits Popup
+ \instantiates QQuickToolTip
+ \inqmlmodule Qt.labs.controls
+ \ingroup qtlabscontrols-popups
+ \brief Provides tool tips for any control.
+
+ A tool tip is a short piece of text that informs the user of a control's
+ function. It is typically placed above or below the parent control. The
+ tip text can be any \l{Rich Text Processing}{rich text} formatted string.
+
+ \image qtquickcontrols-tooltip.png
+
+ The most straight-forward way to setup tool tips for controls is to
+ specify \l text and \l {visible}{visibility} via attached properties.
+ The following example illustrates this approach:
+
+ \snippet qtquickcontrols-tooltip.qml 1
+
+ Under normal circumstances, there is only one tool tip visible at a time.
+ In order to save resources, all items that use the ToolTip attached property
+ share the same visual tool tip label instance. Even though the visuals are
+ shared, \c text, \c timeout and \c delay are stored individually for each item
+ that uses the respective attached property. However, multiple items cannot
+ make the shared tool tip visible at the same time. The shared tool tip is only
+ shown for the last item that made it visible. The position of the shared tool
+ tip is determined by the framework.
+
+ \section2 Delay and Timeout
+
+ Tool tips are typically transient in a sense that they are shown as a
+ result of a certain external event or user interaction, and they usually
+ hide after a certain timeout. It is possible to control the delay when
+ a tool tip is shown, and the timeout when it is hidden. This makes it
+ possible to implement varying strategies for showing and hiding tool tips.
+
+ For example, on touch screens, it is a common pattern to show a tool tip
+ as a result of pressing and holding down a button. The following example
+ demonstrates how to delay showing a tool tip until the press-and-hold
+ interval is reached. In this example, the tool tip hides as soon as the
+ button is released.
+
+ \snippet qtquickcontrols-tooltip-pressandhold.qml 1
+
+ With pointer devices, however, it might be desired to show a tool tip as
+ a result of hovering a button for a while. The following example presents
+ how to show a tool tip after hovering a button for a second, and hide it
+ after a timeout of five seconds.
+
+ \snippet qtquickcontrols-tooltip-hover.qml 1
+
+ \section2 Custom Tool Tips
+
+ Should one need more fine-grained control over the tool tip position, or
+ multiple simultaneous tool tip instances are needed, it is also possible
+ to create local tool tip instances. This way, it is possible to
+ \l {Customizing ToolTip}{customize} the tool tip, and the whole \l Popup
+ API is available. The following example presents a tool tip that presents
+ the value of a slider when the handle is dragged.
+
+ \image qtquickcontrols-tooltip-slider.png
+
+ \snippet qtquickcontrols-tooltip-slider.qml 1
+
+ \labs
+
+ \sa {Customizing ToolTip}
+*/
+
+class QQuickToolTipPrivate : public QQuickPopupPrivate
+{
+ Q_DECLARE_PUBLIC(QQuickToolTip)
+
+public:
+ QQuickToolTipPrivate() : delay(0), timeout(-1) { }
+
+ void startDelay();
+ void stopDelay();
+
+ void startTimeout();
+ void stopTimeout();
+
+ void reposition() override;
+
+ int delay;
+ int timeout;
+ QString text;
+ QBasicTimer delayTimer;
+ QBasicTimer timeoutTimer;
+};
+
+void QQuickToolTipPrivate::startDelay()
+{
+ Q_Q(QQuickToolTip);
+ if (delay > 0)
+ delayTimer.start(delay, q);
+}
+
+void QQuickToolTipPrivate::stopDelay()
+{
+ delayTimer.stop();
+}
+
+void QQuickToolTipPrivate::startTimeout()
+{
+ Q_Q(QQuickToolTip);
+ if (timeout > 0)
+ timeoutTimer.start(timeout, q);
+}
+
+void QQuickToolTipPrivate::stopTimeout()
+{
+ timeoutTimer.stop();
+}
+
+void QQuickToolTipPrivate::reposition()
+{
+ Q_Q(QQuickToolTip);
+ const qreal w = popupItem->width();
+ const qreal h = popupItem->height();
+ const qreal iw = popupItem->implicitWidth();
+ const qreal ih = popupItem->implicitHeight();
+
+ bool widthAdjusted = false;
+ bool heightAdjusted = false;
+
+ QRectF rect(x, y, iw > 0 ? iw : w, ih > 0 ? ih : h);
+ if (parentItem) {
+ rect = parentItem->mapRectToScene(rect);
+
+ QQuickWindow *window = q->window();
+ if (window) {
+ const QRectF bounds = QRectF(0, 0, window->width(), window->height()).marginsRemoved(getMargins());
+
+ if (rect.left() < bounds.left() || rect.right() > bounds.right()) {
+ // if the tooltip doesn't fit inside the window, try flipping it around (left <-> right)
+ const QRectF flipped = parentItem->mapRectToScene(QRectF(parentItem->width() - x - rect.width(), y, rect.width(), rect.height()));
+
+ if (flipped.intersected(bounds).width() > rect.intersected(bounds).width())
+ rect.moveLeft(flipped.left());
+
+ if (iw > 0) {
+ // neither the flipped around geometry fits inside the window, choose
+ // whichever side (left vs. right) fits larger part of the popup
+ if (rect.left() < bounds.left() && bounds.left() + rect.width() <= bounds.right())
+ rect.moveLeft(bounds.left());
+ else if (rect.right() > bounds.right() && bounds.right() - rect.width() >= bounds.left())
+ rect.moveRight(bounds.right());
+
+ // as a last resort, adjust width to fit the window
+ if (rect.left() < bounds.left()) {
+ rect.setLeft(bounds.left());
+ widthAdjusted = true;
+ }
+ if (rect.right() > bounds.right()) {
+ rect.setRight(bounds.right());
+ widthAdjusted = true;
+ }
+ }
+ }
+
+ if (rect.top() < bounds.top() || rect.bottom() > bounds.bottom()) {
+ // if the tooltip doesn't fit inside the window, try flipping it around (above <-> below)
+ const QRectF flipped = parentItem->mapRectToScene(QRectF(x, parentItem->height() - y - rect.height(), rect.width(), rect.height()));
+
+ if (flipped.intersected(bounds).height() > rect.intersected(bounds).height())
+ rect.moveTop(flipped.top());
+
+ if (ih > 0) {
+ // neither the flipped around geometry fits inside the window, choose
+ // whichever side (above vs. below) fits larger part of the popup
+ if (rect.top() < bounds.top() && bounds.top() + rect.height() <= bounds.bottom())
+ rect.moveTop(bounds.top());
+ else if (rect.bottom() > bounds.bottom() && bounds.bottom() - rect.height() >= bounds.top())
+ rect.moveBottom(bounds.bottom());
+
+ // as a last resort, adjust height to fit the window
+ if (rect.top() < bounds.top()) {
+ rect.setTop(bounds.top());
+ heightAdjusted = true;
+ }
+ if (rect.bottom() > bounds.bottom()) {
+ rect.setBottom(bounds.bottom());
+ heightAdjusted = true;
+ }
+ }
+ }
+ }
+ }
+
+ popupItem->setPosition(rect.topLeft());
+ if (widthAdjusted && rect.width() > 0)
+ popupItem->setWidth(rect.width());
+ if (heightAdjusted && rect.height() > 0)
+ popupItem->setHeight(rect.height());
+}
+
+QQuickToolTip::QQuickToolTip(QQuickItem *parent) :
+ QQuickPopup(*(new QQuickToolTipPrivate), parent)
+{
+}
+
+/*!
+ \qmlproperty string Qt.labs.controls::ToolTip::text
+
+ This property holds the text shown on the tool tip.
+*/
+QString QQuickToolTip::text() const
+{
+ Q_D(const QQuickToolTip);
+ return d->text;
+}
+
+void QQuickToolTip::setText(const QString &text)
+{
+ Q_D(QQuickToolTip);
+ if (d->text == text)
+ return;
+
+ d->text = text;
+ emit textChanged();
+}
+
+/*!
+ \qmlproperty int Qt.labs.controls::ToolTip::delay
+
+ This property holds the delay (milliseconds) after which the tool tip is
+ shown. A tooltip with a negative delay is shown immediately. The default
+ value is \c 0.
+*/
+int QQuickToolTip::delay() const
+{
+ Q_D(const QQuickToolTip);
+ return d->delay;
+}
+
+void QQuickToolTip::setDelay(int delay)
+{
+ Q_D(QQuickToolTip);
+ if (d->delay == delay)
+ return;
+
+ d->delay = delay;
+ emit delayChanged();
+}
+
+/*!
+ \qmlproperty int Qt.labs.controls::ToolTip::timeout
+
+ This property holds the timeout (milliseconds) after which the tool tip is
+ hidden. A tooltip with a negative timeout does not hide automatically. The
+ default value is \c -1.
+*/
+int QQuickToolTip::timeout() const
+{
+ Q_D(const QQuickToolTip);
+ return d->timeout;
+}
+
+void QQuickToolTip::setTimeout(int timeout)
+{
+ Q_D(QQuickToolTip);
+ if (d->timeout == timeout)
+ return;
+
+ if (timeout <= 0)
+ d->stopTimeout();
+ else if (isVisible())
+ d->startTimeout();
+
+ d->timeout = timeout;
+ emit timeoutChanged();
+}
+
+QQuickToolTipAttached *QQuickToolTip::qmlAttachedProperties(QObject *object)
+{
+ QQuickItem *item = qobject_cast<QQuickItem *>(object);
+ if (!item) {
+ qWarning() << "ToolTip must be attached to an Item" << object;
+ return nullptr;
+ }
+
+ return new QQuickToolTipAttached(item);
+}
+
+void QQuickToolTip::open()
+{
+ Q_D(QQuickToolTip);
+ if (d->delay > 0)
+ d->startDelay();
+ else
+ QQuickPopup::open();
+}
+
+void QQuickToolTip::close()
+{
+ Q_D(QQuickToolTip);
+ d->stopDelay();
+ QQuickPopup::close();
+}
+
+void QQuickToolTip::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data)
+{
+ Q_D(QQuickToolTip);
+ QQuickPopup::itemChange(change, data);
+ if (change == QQuickItem::ItemVisibleHasChanged) {
+ if (data.boolValue)
+ d->startTimeout();
+ else
+ d->stopTimeout();
+
+ QQuickToolTipAttached *attached = qobject_cast<QQuickToolTipAttached *>(qmlAttachedPropertiesObject<QQuickToolTip>(d->parentItem, false));
+ if (attached)
+ emit attached->visibleChanged();
+ }
+}
+
+void QQuickToolTip::timerEvent(QTimerEvent *event)
+{
+ Q_D(QQuickToolTip);
+ if (event->timerId() == d->timeoutTimer.timerId()) {
+ d->stopTimeout();
+ close();
+ } else if (event->timerId() == d->delayTimer.timerId()) {
+ d->stopDelay();
+ QQuickPopup::open();
+ }
+}
+
+#ifndef QT_NO_ACCESSIBILITY
+QAccessible::Role QQuickToolTip::accessibleRole() const
+{
+ return QAccessible::ToolTip;
+}
+#endif
+
+class QQuickToolTipAttachedPrivate : public QObjectPrivate
+{
+ Q_DECLARE_PUBLIC(QQuickToolTipAttached)
+
+public:
+ QQuickToolTipAttachedPrivate() : delay(0), timeout(-1) { }
+
+ QQuickToolTip *instance(bool create) const;
+
+ int delay;
+ int timeout;
+ QString text;
+};
+
+QQuickToolTip *QQuickToolTipAttachedPrivate::instance(bool create) const
+{
+ static QPointer<QQuickToolTip> tip;
+ if (!tip && create) {
+ // TODO: a cleaner way to create the instance? QQml(Meta)Type?
+ QQmlContext *context = qmlContext(parent);
+ QQmlComponent component(context->engine());
+ component.setData("import Qt.labs.controls 1.0; ToolTip { }", QUrl());
+
+ QObject *object = component.create(context);
+ tip = qobject_cast<QQuickToolTip *>(object);
+ if (!tip)
+ delete object;
+ }
+ return tip;
+}
+
+QQuickToolTipAttached::QQuickToolTipAttached(QQuickItem *item) :
+ QObject(*(new QQuickToolTipAttachedPrivate), item)
+{
+}
+
+/*!
+ \qmlattachedproperty string Qt.labs.controls::ToolTip::text
+
+ This attached property holds the text of the shared tool tip instance.
+ The property can be attached to any item.
+*/
+QString QQuickToolTipAttached::text() const
+{
+ Q_D(const QQuickToolTipAttached);
+ return d->text;
+}
+
+void QQuickToolTipAttached::setText(const QString &text)
+{
+ Q_D(QQuickToolTipAttached);
+ if (d->text == text)
+ return;
+
+ d->text = text;
+ emit textChanged();
+
+ d->instance(true)->setText(text);
+}
+
+/*!
+ \qmlattachedproperty int Qt.labs.controls::ToolTip::delay
+
+ This attached property holds the delay (milliseconds) of the shared tool tip.
+ The property can be attached to any item.
+*/
+int QQuickToolTipAttached::delay() const
+{
+ Q_D(const QQuickToolTipAttached);
+ return d->delay;
+}
+
+void QQuickToolTipAttached::setDelay(int delay)
+{
+ Q_D(QQuickToolTipAttached);
+ if (d->delay == delay)
+ return;
+
+ d->delay = delay;
+ emit delayChanged();
+}
+
+/*!
+ \qmlattachedproperty int Qt.labs.controls::ToolTip::timeout
+
+ This attached property holds the timeout (milliseconds) of the shared tool tip.
+ The property can be attached to any item.
+*/
+int QQuickToolTipAttached::timeout() const
+{
+ Q_D(const QQuickToolTipAttached);
+ return d->timeout;
+}
+
+void QQuickToolTipAttached::setTimeout(int timeout)
+{
+ Q_D(QQuickToolTipAttached);
+ if (d->timeout == timeout)
+ return;
+
+ d->timeout = timeout;
+ emit timeoutChanged();
+}
+
+/*!
+ \qmlattachedproperty bool Qt.labs.controls::ToolTip::visible
+
+ This attached property holds whether the shared tool tip is visible.
+ The property can be attached to any item.
+*/
+bool QQuickToolTipAttached::isVisible() const
+{
+ Q_D(const QQuickToolTipAttached);
+ QQuickToolTip *tip = d->instance(false);
+ if (!tip)
+ return false;
+
+ return tip->isVisible() && tip->parentItem() == parent();
+}
+
+void QQuickToolTipAttached::setVisible(bool visible)
+{
+ Q_D(QQuickToolTipAttached);
+ if (visible)
+ show(d->text);
+ else
+ hide();
+}
+
+/*!
+ \qmlattachedproperty ToolTip Qt.labs.controls::ToolTip::toolTip
+
+ This attached property holds the shared tool tip instance. The property
+ can be attached to any item.
+*/
+QQuickToolTip *QQuickToolTipAttached::toolTip() const
+{
+ Q_D(const QQuickToolTipAttached);
+ return d->instance(true);
+}
+
+/*!
+ \qmlattachedmethod void Qt.labs.controls::ToolTip::show(string text, int timeout = -1)
+
+ This attached method shows the shared tooltip with \a text and \a timeout (milliseconds).
+ The method can be attached to any item.
+*/
+void QQuickToolTipAttached::show(const QString &text, int ms)
+{
+ Q_D(QQuickToolTipAttached);
+ QQuickToolTip *tip = d->instance(true);
+ tip->resetWidth();
+ tip->resetHeight();
+ tip->setParentItem(qobject_cast<QQuickItem *>(parent()));
+ tip->setTimeout(ms >= 0 ? ms : d->timeout);
+ tip->setDelay(d->delay);
+ tip->setText(text);
+ tip->open();
+}
+
+/*!
+ \qmlattachedmethod void Qt.labs.controls::ToolTip::hide()
+
+ This attached method hides the shared tooltip. The method can be attached to any item.
+*/
+void QQuickToolTipAttached::hide()
+{
+ Q_D(QQuickToolTipAttached);
+ QQuickToolTip *tip = d->instance(false);
+ if (!tip)
+ return;
+
+ tip->close();
+}
+
+QT_END_NAMESPACE
diff --git a/src/templates/qquicktooltip_p.h b/src/templates/qquicktooltip_p.h
new file mode 100644
index 00000000..07e6815d
--- /dev/null
+++ b/src/templates/qquicktooltip_p.h
@@ -0,0 +1,148 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Labs Templates 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 QQUICKTOOLTIP_P_H
+#define QQUICKTOOLTIP_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 <QtQuickTemplates/private/qquickpopup_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QQuickToolTipPrivate;
+class QQuickToolTipAttached;
+class QQuickToolTipAttachedPrivate;
+
+class Q_QUICKTEMPLATES_EXPORT QQuickToolTip : public QQuickPopup
+{
+ Q_OBJECT
+ Q_PROPERTY(int delay READ delay WRITE setDelay NOTIFY delayChanged FINAL)
+ Q_PROPERTY(int timeout READ timeout WRITE setTimeout NOTIFY timeoutChanged FINAL)
+ Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged FINAL)
+
+public:
+ explicit QQuickToolTip(QQuickItem *parent = nullptr);
+
+ QString text() const;
+ void setText(const QString &text);
+
+ int delay() const;
+ void setDelay(int delay);
+
+ int timeout() const;
+ void setTimeout(int timeout);
+
+ static QQuickToolTipAttached *qmlAttachedProperties(QObject *object);
+
+public Q_SLOTS:
+ void open();
+ void close();
+
+Q_SIGNALS:
+ void textChanged();
+ void delayChanged();
+ void timeoutChanged();
+
+protected:
+ void itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) override;
+ void timerEvent(QTimerEvent *event) override;
+
+#ifndef QT_NO_ACCESSIBILITY
+ QAccessible::Role accessibleRole() const override;
+#endif
+
+private:
+ Q_DISABLE_COPY(QQuickToolTip)
+ Q_DECLARE_PRIVATE(QQuickToolTip)
+};
+
+class Q_QUICKTEMPLATES_EXPORT QQuickToolTipAttached : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged FINAL)
+ Q_PROPERTY(int delay READ delay WRITE setDelay NOTIFY delayChanged FINAL)
+ Q_PROPERTY(int timeout READ timeout WRITE setTimeout NOTIFY timeoutChanged FINAL)
+ Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged FINAL)
+ Q_PROPERTY(QQuickToolTip *toolTip READ toolTip CONSTANT FINAL)
+
+public:
+ explicit QQuickToolTipAttached(QQuickItem *item);
+
+ QString text() const;
+ void setText(const QString &text);
+
+ int delay() const;
+ void setDelay(int delay);
+
+ int timeout() const;
+ void setTimeout(int timeout);
+
+ bool isVisible() const;
+ void setVisible(bool visible);
+
+ QQuickToolTip *toolTip() const;
+
+Q_SIGNALS:
+ void textChanged();
+ void delayChanged();
+ void timeoutChanged();
+ void visibleChanged();
+
+public Q_SLOTS:
+ void show(const QString &text, int ms = -1);
+ void hide();
+
+private:
+ Q_DISABLE_COPY(QQuickToolTipAttached)
+ Q_DECLARE_PRIVATE(QQuickToolTipAttached)
+};
+
+QT_END_NAMESPACE
+
+QML_DECLARE_TYPE(QQuickToolTip)
+QML_DECLARE_TYPEINFO(QQuickToolTip, QML_HAS_ATTACHED_PROPERTIES)
+
+#endif // QQUICKTOOLTIP_P_H
diff --git a/src/templates/templates.pri b/src/templates/templates.pri
index fccf1972..d31f461a 100644
--- a/src/templates/templates.pri
+++ b/src/templates/templates.pri
@@ -52,6 +52,7 @@ HEADERS += \
$$PWD/qquicktextfield_p_p.h \
$$PWD/qquicktoolbar_p.h \
$$PWD/qquicktoolbutton_p.h \
+ $$PWD/qquicktooltip_p.h \
$$PWD/qquicktumbler_p.h \
$$PWD/qquickvelocitycalculator_p_p.h
@@ -97,5 +98,6 @@ SOURCES += \
$$PWD/qquicktextfield.cpp \
$$PWD/qquicktoolbar.cpp \
$$PWD/qquicktoolbutton.cpp \
+ $$PWD/qquicktooltip.cpp \
$$PWD/qquicktumbler.cpp \
$$PWD/qquickvelocitycalculator.cpp