diff options
author | J-P Nurmi <jpnurmi@theqtcompany.com> | 2016-03-01 13:26:21 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@theqtcompany.com> | 2016-03-22 19:32:37 +0000 |
commit | cd716f1b1c903b7a2fdfd82bb88959119ebca72d (patch) | |
tree | a8ff297e58d34b0c8b6fd24a51a2301c8c2708bb /src/imports | |
parent | faa65aebb2e52cc809248f6cbb86b994ff329285 (diff) |
Introduce ToolTip
Change-Id: I917f7e83219788fc63389773eb07ee39757bed7f
Task-number: QTBUG-51003
Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
Diffstat (limited to 'src/imports')
24 files changed, 547 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 Binary files differnew file mode 100644 index 00000000..c082c840 --- /dev/null +++ b/src/imports/controls/doc/images/qtquickcontrols-tooltip-background.png diff --git a/src/imports/controls/doc/images/qtquickcontrols-tooltip-contentItem.png b/src/imports/controls/doc/images/qtquickcontrols-tooltip-contentItem.png Binary files differnew file mode 100644 index 00000000..d79a336f --- /dev/null +++ b/src/imports/controls/doc/images/qtquickcontrols-tooltip-contentItem.png diff --git a/src/imports/controls/doc/images/qtquickcontrols-tooltip-delay.png b/src/imports/controls/doc/images/qtquickcontrols-tooltip-delay.png Binary files differnew file mode 100644 index 00000000..eb9499fd --- /dev/null +++ b/src/imports/controls/doc/images/qtquickcontrols-tooltip-delay.png diff --git a/src/imports/controls/doc/images/qtquickcontrols-tooltip-hover.png b/src/imports/controls/doc/images/qtquickcontrols-tooltip-hover.png Binary files differnew file mode 100644 index 00000000..b5c70d86 --- /dev/null +++ b/src/imports/controls/doc/images/qtquickcontrols-tooltip-hover.png diff --git a/src/imports/controls/doc/images/qtquickcontrols-tooltip-pressandhold.png b/src/imports/controls/doc/images/qtquickcontrols-tooltip-pressandhold.png Binary files differnew file mode 100644 index 00000000..b5c70d86 --- /dev/null +++ b/src/imports/controls/doc/images/qtquickcontrols-tooltip-pressandhold.png diff --git a/src/imports/controls/doc/images/qtquickcontrols-tooltip-slider.png b/src/imports/controls/doc/images/qtquickcontrols-tooltip-slider.png Binary files differnew file mode 100644 index 00000000..6dad4464 --- /dev/null +++ b/src/imports/controls/doc/images/qtquickcontrols-tooltip-slider.png diff --git a/src/imports/controls/doc/images/qtquickcontrols-tooltip.png b/src/imports/controls/doc/images/qtquickcontrols-tooltip.png Binary files differnew file mode 100644 index 00000000..ffac3ed6 --- /dev/null +++ b/src/imports/controls/doc/images/qtquickcontrols-tooltip.png 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"); |