QGCButton.qml 3.54 KB
Newer Older
Don Gagne's avatar
Don Gagne committed
1 2 3
import QtQuick 2.2
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2
4
import QtQuick.Controls.Private 1.0
Don Gagne's avatar
Don Gagne committed
5 6 7 8

import QGroundControl.Palette 1.0

Button {
9 10 11 12 13 14
    // primary: true - this is the primary button for this group of buttons
    property bool primary: false

    property var __qgcPal: QGCPalette { colorGroupEnabled: enabled }

    property bool __showHighlight: pressed | hovered | checked
Don Gagne's avatar
Don Gagne committed
15 16

    style: ButtonStyle {
17
/*
Don Gagne's avatar
Don Gagne committed
18 19 20
            background: Rectangle {
                implicitWidth: 100
                implicitHeight: 25
21 22 23
                color: __showHighlight ?
                    control.__qgcPal.buttonHighlight :
                    (primary ? control.__qgcPal.primaryButton : control.__qgcPal.button)
Don Gagne's avatar
Don Gagne committed
24 25 26 27 28 29 30 31 32 33
            }

            label: Text {
                width: parent.width
                height: parent.height

                verticalAlignment: TextEdit.AlignVCenter
                horizontalAlignment: TextEdit.AlignHCenter

                text: control.text
34 35 36
                color: __showHighlight ?
                    control.__qgcPal.buttonHighlightText :
                    (primary ? control.__qgcPal.primaryButtonText : control.__qgcPal.buttonText)
Don Gagne's avatar
Don Gagne committed
37
            }
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
*/

            /*! 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)
                    }
                }
            }
Don Gagne's avatar
Don Gagne committed
99 100
        }
}