From cde3cda1e5982aa3c105629887672da62f6b5425 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Tue, 24 Feb 2015 09:52:23 -0800 Subject: [PATCH] Added menu support to QGCButton --- qgroundcontrol.qrc | 1 + src/QmlControls/QGCButton.qml | 63 +++++++++++++++++++++++++++++++++ src/QmlControls/QmlTest.qml | 31 ++++++++++++++++ src/QmlControls/arrow-down.png | Bin 0 -> 184 bytes 4 files changed, 95 insertions(+) create mode 100644 src/QmlControls/arrow-down.png diff --git a/qgroundcontrol.qrc b/qgroundcontrol.qrc index 4eb52b401..3d85f365e 100644 --- a/qgroundcontrol.qrc +++ b/qgroundcontrol.qrc @@ -253,6 +253,7 @@ src/QmlControls/QGCCheckBox.qml src/QmlControls/QGCLabel.qml src/QmlControls/QGCTextField.qml + src/QmlControls/arrow-down.png files/images/px4/airframes/octo_x.png files/images/px4/boards/px4fmu_2.x.png diff --git a/src/QmlControls/QGCButton.qml b/src/QmlControls/QGCButton.qml index 95d15cb0a..fddf540b3 100644 --- a/src/QmlControls/QGCButton.qml +++ b/src/QmlControls/QGCButton.qml @@ -1,6 +1,7 @@ import QtQuick 2.2 import QtQuick.Controls 1.2 import QtQuick.Controls.Styles 1.2 +import QtQuick.Controls.Private 1.0 import QGroundControl.Palette 1.0 @@ -13,6 +14,7 @@ Button { property bool __showHighlight: pressed | hovered | checked style: ButtonStyle { +/* background: Rectangle { implicitWidth: 100 implicitHeight: 25 @@ -33,5 +35,66 @@ Button { control.__qgcPal.buttonHighlightText : (primary ? control.__qgcPal.primaryButtonText : control.__qgcPal.buttonText) } +*/ + + /*! The padding between the background and the label components. */ + padding { + top: 4 + left: 4 + right: control.menu !== null ? Math.round(TextSingleton.implicitHeight * 0.5) : 4 + bottom: 4 + } + + /*! This defines the background of the button. */ + background: Item { + property bool down: control.pressed || (control.checkable && control.checked) + implicitWidth: Math.round(TextSingleton.implicitHeight * 4.5) + implicitHeight: Math.max(25, Math.round(TextSingleton.implicitHeight * 1.2)) + + Rectangle { + anchors.fill: parent + color: __showHighlight ? + control.__qgcPal.buttonHighlight : + (primary ? control.__qgcPal.primaryButton : control.__qgcPal.button) + } + + Image { + id: imageItem + visible: control.menu !== null + source: "arrow-down.png" + anchors.verticalCenter: parent.verticalCenter + anchors.right: parent.right + anchors.rightMargin: padding.right + opacity: control.enabled ? 0.6 : 0.5 + } + } + + /*! This defines the label of the button. */ + label: Item { + implicitWidth: row.implicitWidth + implicitHeight: row.implicitHeight + baselineOffset: row.y + text.y + text.baselineOffset + + Row { + id: row + anchors.centerIn: parent + spacing: 2 + + Image { + source: control.iconSource + anchors.verticalCenter: parent.verticalCenter + } + + Text { + id: text + renderType: Text.NativeRendering + anchors.verticalCenter: parent.verticalCenter + text: control.text + color: __showHighlight ? + control.__qgcPal.buttonHighlightText : + (primary ? control.__qgcPal.primaryButtonText : control.__qgcPal.buttonText) + } + } + } } } diff --git a/src/QmlControls/QmlTest.qml b/src/QmlControls/QmlTest.qml index 1dd32bffb..f3581bca4 100644 --- a/src/QmlControls/QmlTest.qml +++ b/src/QmlControls/QmlTest.qml @@ -367,6 +367,37 @@ Rectangle { enabled: false } + // QGCButton - menu + Loader { + sourceComponent: ctlRowHeader + property var text: "QGCButton(menu)" + } + Menu { + id: buttonMenu + MenuItem { + text: "Item 1" + } + MenuItem { + text: "Item 2" + } + MenuItem { + text: "Item 3" + } + } + QGCButton { + width: 100 + height: 20 + text: "Button" + menu: buttonMenu + } + QGCButton { + width: 100 + height: 20 + text: "Button" + enabled: false + menu: buttonMenu + } + // QGCRadioButton Loader { sourceComponent: ctlRowHeader diff --git a/src/QmlControls/arrow-down.png b/src/QmlControls/arrow-down.png new file mode 100644 index 0000000000000000000000000000000000000000..c20f6256b35d278a0f4c45f660fb48d06acfbac0 GIT binary patch literal 184 zcmeAS@N?(olHy`uVBq!ia0vp^>_E)I!3HFqj;YpyIK@t$Asj$Z!;#Vf2?p zUk71ECym(^Ktah8*NBqf{Irtt#G+J&^73-M%)IR4