Debian Codegraph @

src/GUI/qml/AircraftVariantChoice.qml

raw
1 // SPDX-FileCopyrightText: 2018 James Turner
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 import QtQuick 2.4
5 import FlightGear 1.0
6 import FlightGear.Launcher 1.0
7
8
9 Rectangle {
10 id: root
11
12 implicitHeight: title.implicitHeight
13
14 radius: Style.roundRadius
15 border.color: Style.frameColor
16 border.width: headingMouseArea.containsMouse ? 1 : 0
17 color: headingMouseArea.containsMouse ? "#7fffffff" : "transparent"
18
19 readonly property int centerX: width / 2
20
21 readonly property bool __enabled: aircraftInfo.numVariants > 1
22
23 property alias aircraft: aircraftInfo.uri
24 property alias currentIndex: aircraftInfo.variant
25 property alias fontPixelSize: title.font.pixelSize
26
27 // allow users to control the font sizing
28 // (aircraft variants can have excessively long names)
29 property int popupFontPixelSize: 0
30
31 // expose this to avoid a second AircraftInfo in the compact delegate
32 // really should refactor to put the AircraftInfo up there.
33 readonly property string pathOnDisk: aircraftInfo.pathOnDisk
34
35 signal selected(var index)
36
37 Row {
38 anchors.centerIn: parent
39 height: title.implicitHeight
40 width: childrenRect.width
41
42 Text {
43 id: title
44
45 anchors.verticalCenter: parent.verticalCenter
46
47 // this ugly logic is to keep the up-down arrow at the right
48 // hand side of the text, but allow the font scaling to work if
49 // we're short on horizontal space
50 width: Math.min(implicitWidth,
51 root.width - (Style.margin * 2) - (__enabled ? upDownIcon.implicitWidth : 0))
52
53 horizontalAlignment: Text.AlignHCenter
54 verticalAlignment: Text.AlignVCenter
55
56 font.pixelSize: Style.baseFontPixelSize * 2
57 text: aircraftInfo.name
58 fontSizeMode: Text.Fit
59
60 elide: Text.ElideRight
61 maximumLineCount: 1
62 color: headingMouseArea.containsMouse ? Style.themeColor : Style.baseTextColor
63 }
64
65 Image {
66 id: upDownIcon
67 source: headingMouseArea.containsMouse ? "image://colored-icon/up-down?theme" : "image://colored-icon/up-down?text"
68 // x: root.centerX + Math.min(title.implicitWidth * 0.5, title.width * 0.5)
69 anchors.verticalCenter: parent.verticalCenter
70 visible: __enabled
71 width: __enabled ? implicitWidth : 0
72 }
73 }
74
75 MouseArea {
76 id: headingMouseArea
77 enabled: __enabled
78 anchors.fill: parent
79 hoverEnabled: true
80 onClicked: {
81 var hCenter = root.width / 2;
82 OverlayShared.globalOverlay.showOverlayAtItemOffset(popup, root,
83 Qt.point(hCenter, root.height))
84 }
85 }
86
87 AircraftInfo
88 {
89 id: aircraftInfo
90 }
91
92 Component {
93 id: popup
94 VariantMenu {
95 id: menu
96 aircraftUri: aircraftInfo.uri
97 popupFontPixelSize: root.popupFontPixelSize
98
99 onSelect: function(index) {
100 aircraftInfo.variant = index;
101 root.selected(index)
102 }
103 }
104 } // of popup component
105 }