QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QGCTabButton.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3import QtQuick.Layouts
4
5import QGroundControl
6import QGroundControl.Controls
7
8// We implement our own TabButton to get around the fact that QtQuick.Controls TabBar does not
9// support hiding tabs. This version supports hiding tabs by setting the visible property
10// on the QGCTabButton instances.
11Button {
12 id: control
13 Layout.fillWidth: true
14 topPadding: _verticalPadding
15 bottomPadding: _verticalPadding
16 leftPadding: _horizontalPadding
17 rightPadding: _horizontalPadding
18 focusPolicy: Qt.ClickFocus
19 checkable: true
20
21 property bool primary: false ///< primary button for a group of buttons
22 property real pointSize: ScreenTools.defaultFontPointSize ///< Point size for button text
23 property bool showBorder: qgcPal.globalTheme === QGCPalette.Light
24 property real backRadius: ScreenTools.defaultBorderRadius
25 property real heightFactor: 0.5
26
27 property bool _showSeparator: false
28 property bool _showHighlight: enabled && (pressed | checked)
29 property int _horizontalPadding: ScreenTools.defaultFontPixelWidth
30 property int _verticalPadding: Math.round(ScreenTools.defaultFontPixelHeight * heightFactor)
31 property bool _showIcon: control.icon.source != ""
32
33 QGCPalette { id: qgcPal; colorGroupEnabled: enabled }
34
35 background: Rectangle {
36 id: backRect
37 implicitWidth: ScreenTools.implicitButtonWidth
38 implicitHeight: ScreenTools.implicitButtonHeight
39 //radius: backRadius
40 border.width: showBorder ? 1 : 0
41 border.color: qgcPal.buttonBorder
42 color: _showHighlight ? qgcPal.buttonHighlight : qgcPal.button
43
44 Rectangle {
45 anchors.right: parent.right
46 anchors.top: parent.top
47 anchors.bottom: parent.bottom
48 anchors.topMargin: _vertMargin
49 anchors.bottomMargin: _vertMargin
50 width: 1
51 color: Qt.darker(qgcPal.buttonText, 1.5)
52 visible: control._showSeparator
53
54 property real _vertMargin: ScreenTools.defaultFontPixelHeight * 0.25
55 }
56 }
57
58 contentItem: Item {
59 implicitWidth: _showIcon ? icon.width : text.implicitWidth
60 implicitHeight: _showIcon ? icon.height : text.implicitHeight
61 baselineOffset: text.y + text.baselineOffset
62
63 QGCColoredImage {
64 id: icon
65 anchors.centerIn: parent
66 source: control.icon.source
67 height: source === "" ? 0 : ScreenTools.defaultFontPixelHeight
68 width: height
69 color: _showHighlight ? qgcPal.buttonHighlightText : qgcPal.buttonText
70 fillMode: Image.PreserveAspectFit
71 sourceSize.height: height
72 visible: _showIcon
73 }
74
75 Text {
76 id: text
77 anchors.centerIn: parent
78 antialiasing: true
79 text: control.text
80 font.pointSize: control.pointSize
81 font.family: ScreenTools.normalFontFamily
82 color: _showHighlight ? qgcPal.buttonHighlightText : qgcPal.buttonText
83 visible: !_showIcon
84 }
85 }
86}