QGCButton.qml 3.11 KB
Newer Older
1 2 3
import QtQuick                  2.3
import QtQuick.Controls         2.12
import QtQuick.Controls.Styles  1.4
Don Gagne's avatar
Don Gagne committed
4 5

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

Button {
9 10 11 12 13 14 15
    id:             control
    hoverEnabled:   true
    topPadding:     _verticalPadding
    bottomPadding:  _verticalPadding
    leftPadding:    _horizontalPadding
    rightPadding:   _horizontalPadding
    focusPolicy:    Qt.ClickFocus
16

Gus Grubba's avatar
Gus Grubba committed
17 18
    property bool   primary:        false                               ///< primary button for a group of buttons
    property real   pointSize:      ScreenTools.defaultFontPointSize    ///< Point size for button text
19
    property bool   showBorder:     qgcPal.globalTheme === QGCPalette.Light
Gus Grubba's avatar
Gus Grubba committed
20 21 22
    property bool   iconLeft:       false
    property real   backRadius:     0
    property real   heightFactor:   0.5
23
    property string iconSource
24

25
    property bool   _showHighlight:     pressed | hovered | checked
Don Gagne's avatar
Don Gagne committed
26

27
    property int _horizontalPadding:    ScreenTools.defaultFontPixelWidth
Gus Grubba's avatar
Gus Grubba committed
28
    property int _verticalPadding:      Math.round(ScreenTools.defaultFontPixelHeight * heightFactor)
Don Gagne's avatar
Don Gagne committed
29

30
    QGCPalette { id: qgcPal; colorGroupEnabled: enabled }
Don Gagne's avatar
Don Gagne committed
31

32 33 34 35 36 37 38 39 40 41
    background: Rectangle {
        id:             backRect
        implicitWidth:  ScreenTools.implicitButtonWidth
        implicitHeight: ScreenTools.implicitButtonHeight
        radius:         backRadius
        border.width:   showBorder ? 1 : 0
        border.color:   qgcPal.buttonText
        color:          _showHighlight ?
                            qgcPal.buttonHighlight :
                            (primary ? qgcPal.primaryButton : qgcPal.button)
Don Gagne's avatar
Don Gagne committed
42
    }
43

44 45 46 47
    contentItem: Item {
        implicitWidth:  text.implicitWidth + icon.width
        implicitHeight: text.implicitHeight
        baselineOffset: text.y + text.baselineOffset
48

49 50 51 52 53 54 55 56 57 58 59 60 61 62
        QGCColoredImage {
            id:                     icon
            source:                 control.iconSource
            height:                 source === "" ? 0 : text.height
            width:                  height
            color:                  text.color
            fillMode:               Image.PreserveAspectFit
            sourceSize.height:      height
            anchors.left:           control.iconLeft ? parent.left : undefined
            anchors.leftMargin:     control.iconLeft ? ScreenTools.defaultFontPixelWidth : undefined
            anchors.right:          !control.iconLeft ? parent.right : undefined
            anchors.rightMargin:    !control.iconLeft ? ScreenTools.defaultFontPixelWidth : undefined
            anchors.verticalCenter: parent.verticalCenter
        }
63

64 65 66 67 68 69 70 71 72 73
        Text {
            id:                     text
            anchors.centerIn:       parent
            antialiasing:           true
            text:                   control.text
            font.pointSize:         pointSize
            font.family:            ScreenTools.normalFontFamily
            color:                  _showHighlight ?
                                        qgcPal.buttonHighlightText :
                                        (primary ? qgcPal.primaryButtonText : qgcPal.buttonText)
Don Gagne's avatar
Don Gagne committed
74
        }
75
    }
Don Gagne's avatar
Don Gagne committed
76
}