SubMenuButton.qml 3 KB
Newer Older
1 2
import QtQuick                  2.3
import QtQuick.Controls         1.2
3
import QtQuick.Controls.Styles  1.4
4
import QtGraphicalEffects       1.0
5

6 7
import QGroundControl.Palette       1.0
import QGroundControl.ScreenTools   1.0
Don Gagne's avatar
Don Gagne committed
8

9 10 11
// Important Note: SubMenuButtons must manage their checked state manually in order to support
// view switch prevention. This means they can't be checkable or autoExclusive.

Don Gagne's avatar
Don Gagne committed
12
Button {
DonLakeFlyer's avatar
DonLakeFlyer committed
13
    id:             _rootButton
14 15
    property bool   setupComplete:  true                                    ///< true: setup complete indicator shows as completed
    property bool   setupIndicator: true                                    ///< true: show setup complete indicator
16
    property var    imageColor:     undefined
17
    property string imageResource:  "/qmlimages/subMenuButtonImage.png"     ///< Button image
18
    property size   sourceSize:     Qt.size(ScreenTools.defaultFontPixelHeight * 2, ScreenTools.defaultFontPixelHeight * 2)
Don Gagne's avatar
Don Gagne committed
19

20 21
    text:               "Button"  ///< Pass in your own button text
    activeFocusOnPress: true
22

dogmaphobic's avatar
dogmaphobic committed
23
    implicitHeight: ScreenTools.isTinyScreen ? ScreenTools.defaultFontPixelHeight * 3.5 : ScreenTools.defaultFontPixelHeight * 2.5
DonLakeFlyer's avatar
DonLakeFlyer committed
24
    implicitWidth:  __panel.implicitWidth
Don Gagne's avatar
Don Gagne committed
25

26 27
    onCheckedChanged: checkable = false

Don Gagne's avatar
Don Gagne committed
28 29 30
    style: ButtonStyle {
        id: buttonStyle

31 32 33
        QGCPalette {
            id:                 qgcPal
            colorGroupEnabled:  control.enabled
Don Gagne's avatar
Don Gagne committed
34 35
        }

36
        property bool showHighlight: control.pressed | control.checked
37

Don Gagne's avatar
Don Gagne committed
38
        background: Rectangle {
39
            id:     innerRect
40
            color:  showHighlight ? qgcPal.buttonHighlight : qgcPal.windowShade
Don Gagne's avatar
Don Gagne committed
41

42 43
            implicitWidth: titleBar.x + titleBar.contentWidth + ScreenTools.defaultFontPixelWidth

44 45 46 47 48 49 50 51
            QGCColoredImage {
                id:                     image
                anchors.leftMargin:     ScreenTools.defaultFontPixelWidth
                anchors.left:           parent.left
                anchors.verticalCenter: parent.verticalCenter
                width:                  ScreenTools.defaultFontPixelHeight * 2
                height:                 ScreenTools.defaultFontPixelHeight * 2
                fillMode:               Image.PreserveAspectFit
52
                mipmap:                 true
53
                color:                  imageColor ? imageColor : (control.setupComplete ? qgcPal.button : "red")
54
                source:                 control.imageResource
55
                sourceSize:             _rootButton.sourceSize
56
            }
Don Gagne's avatar
Don Gagne committed
57

58 59
            QGCLabel {
                id:                     titleBar
60 61 62
                anchors.leftMargin:     ScreenTools.defaultFontPixelWidth
                anchors.left:           image.right
                anchors.verticalCenter: parent.verticalCenter
63 64 65
                verticalAlignment:      TextEdit.AlignVCenter
                color:                  showHighlight ? qgcPal.buttonHighlightText : qgcPal.buttonText
                text:                   control.text
Don Gagne's avatar
Don Gagne committed
66 67 68
            }
        }

69
        label: Item {}
Don Gagne's avatar
Don Gagne committed
70 71
    }
}