diff options
author | Gabriel de Dietrich <gabriel.dedietrich@digia.com> | 2013-04-29 15:35:26 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-04-30 13:59:13 +0200 |
commit | 0bba341da5e5d0c78c17f6a00e75fad804315e77 (patch) | |
tree | a43017aa20684439f4e6d94d41155f3e942a07cb | |
parent | 153770998e3eceda6d5237e995a70a3ed00d7cfa (diff) | |
download | qtquickcontrols-0bba341da5e5d0c78c17f6a00e75fad804315e77.tar.gz |
Button: Add 'menu' property to get pull-down button
Change-Id: I97ce3f35153beee2d7b1113880f25fd01904ce5f
Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com>
-rw-r--r-- | examples/quick/controls/gallery/content/Controls.qml | 9 | ||||
-rw-r--r-- | src/controls/Button.qml | 37 | ||||
-rw-r--r-- | src/private/BasicButton.qml | 5 | ||||
-rw-r--r-- | src/private/qquickstyleitem.cpp | 19 | ||||
-rw-r--r-- | src/styles/Desktop/ButtonStyle.qml | 3 |
5 files changed, 69 insertions, 4 deletions
diff --git a/examples/quick/controls/gallery/content/Controls.qml b/examples/quick/controls/gallery/content/Controls.qml index abcebbeb..93b933d7 100644 --- a/examples/quick/controls/gallery/content/Controls.qml +++ b/examples/quick/controls/gallery/content/Controls.qml @@ -66,13 +66,18 @@ Item { Button { id: button1 text: "Button 1" - width: 97 + width: 92 tooltip:"This is an interesting tool tip" } Button { id:button2 text:"Button 2" - width:97 + width: 102 + menu: Menu { + MenuItem { text: "This Button" } + MenuItem { text: "Happens To Have" } + MenuItem { text: "A Menu Assigned" } + } } } ComboBox { diff --git a/src/controls/Button.qml b/src/controls/Button.qml index ff84aecd..ccf1973b 100644 --- a/src/controls/Button.qml +++ b/src/controls/Button.qml @@ -83,9 +83,46 @@ BasicButton { */ property url iconSource + /*! Assign a \l Menu to this property to get a pull-down menu button. + + The default value is \c null. + */ + property Menu menu: null + activeFocusOnTab: true Accessible.name: text style: Qt.createComponent(Settings.theme() + "/ButtonStyle.qml", button) + + readonly property bool pressed: __behavior.effectivePressed || menu && menu.__popupVisible + + Binding { + target: menu + property: "__minimumWidth" + value: button.__panel.width + } + + Binding { + target: menu + property: "__visualItem" + value: button + } + + Connections { + target: __behavior + onEffectivePressedChanged: { + if (__behavior.effectivePressed && menu) + popupMenuTimer.start() + } + } + + Timer { + id: popupMenuTimer + interval: 10 + onTriggered: { + __behavior.keyPressed = false + menu.__popup(0, button.height, 0) + } + } } diff --git a/src/private/BasicButton.qml b/src/private/BasicButton.qml index 759a9f90..f3ab5973 100644 --- a/src/private/BasicButton.qml +++ b/src/private/BasicButton.qml @@ -59,7 +59,7 @@ Control { /*! \qmlproperty bool BasicButton::pressed This property holds whether the button is pressed. */ - property alias pressed: behavior.effectivePressed + readonly property bool pressed: behavior.effectivePressed /*! This property holds whether the button is checkable. @@ -166,6 +166,9 @@ Control { } } + /*! \internal */ + property var __behavior: behavior + SystemPalette { id: syspal } states: [ diff --git a/src/private/qquickstyleitem.cpp b/src/private/qquickstyleitem.cpp index b54f3869..548e8104 100644 --- a/src/private/qquickstyleitem.cpp +++ b/src/private/qquickstyleitem.cpp @@ -199,6 +199,25 @@ void QQuickStyleItem::initStyleOption() const QFont *font = QGuiApplicationPrivate::platformTheme()->font(platformFont); if (font) opt->fontMetrics = QFontMetrics(*font); + if (QObject * menu = m_properties["menu"].value<QObject *>()) { + opt->features |= QStyleOptionButton::HasMenu; +#ifdef Q_OS_MAC + if (style() == "mac") { + if (platformFont == QPlatformTheme::PushButtonFont) + menu->setProperty("__xOffset", 12); + else + menu->setProperty("__xOffset", 11); + if (platformFont == QPlatformTheme::MiniFont) + menu->setProperty("__yOffset", 5); + else if (platformFont == QPlatformTheme::SmallFont) + menu->setProperty("__yOffset", 6); + else + menu->setProperty("__yOffset", 3); + if (font) + menu->setProperty("__font", *font); + } +#endif + } } break; case ItemRow: { diff --git a/src/styles/Desktop/ButtonStyle.qml b/src/styles/Desktop/ButtonStyle.qml index b8f5c189..3ae42c03 100644 --- a/src/styles/Desktop/ButtonStyle.qml +++ b/src/styles/Desktop/ButtonStyle.qml @@ -54,7 +54,8 @@ Style { activeControl: control.isDefault ? "default" : "f" properties: { - "icon": control.__action.__icon + "icon": control.__action.__icon, + "menu": control.menu } } } |