Debian Codegraph @

src/GUI/qml/AircraftPreviewPanel.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.Launcher 1.0
6 import FlightGear 1.0
7
8 Rectangle {
9 id: root
10 property var previews: []
11 property int activePreview: 0
12 property alias packageId: preview.packageId
13
14 readonly property bool __havePreviews: (previews.length > 0)
15 onPreviewsChanged: {
16 activePreview = 0;
17 preview.clearImage();
18 }
19
20 height: width / preview.aspectRatio
21 color: Style.minorFrameColor
22
23 border.width: 1
24 border.color: Style.themeColor
25
26 Timer {
27 id: previewCycleTimer
28 }
29
30 PreviewImage {
31 id: preview
32 width: parent.width
33 height: parent.height
34
35 function activePreviewUrl()
36 {
37 if (!__havePreviews) return "";
38 if (root.previews.length <= root.activePreview) return "";
39 return root.previews[root.activePreview];
40 }
41
42 imageUrl: activePreviewUrl();
43
44 Rectangle {
45 anchors.fill: parent
46 visible: parent.isLoading
47 opacity: 0.5
48 color: "black"
49 }
50
51 AnimatedImage {
52 id: spinner
53 source: "qrc:///spinner"
54 anchors.centerIn: parent
55 visible: parent.isLoading
56 }
57 }
58
59 Row {
60 visible: (previews.length > 1)
61 anchors.bottom: parent.bottom
62 anchors.bottomMargin: 8
63
64 anchors.horizontalCenter: parent.horizontalCenter
65 spacing: 8
66
67 Repeater
68 {
69 model: root.previews
70 Rectangle {
71 height: 8
72 width: 8
73 radius: 4
74 color: (model.index == root.activePreview) ? "white" : Style.themeColor
75 }
76 }
77 }
78
79 Image {
80 id: leftArrow
81
82 source: "qrc:///preview/left-arrow-icon"
83 anchors.left: parent.left
84 anchors.verticalCenter: parent.verticalCenter
85 opacity: leftMouseArea.containsMouse ? 1.0 : 0.3
86 visible: root.activePreview > 0
87
88 MouseArea {
89 id: leftMouseArea
90 anchors.fill: parent
91 hoverEnabled: true
92 onClicked: {
93 root.activePreview = Math.max(root.activePreview - 1, 0)
94 }
95 }
96 }
97
98 Image {
99 id: rightArrow
100
101 source: "qrc:///preview/right-arrow-icon"
102 anchors.right: parent.right
103 anchors.verticalCenter: parent.verticalCenter
104 opacity: rightMouseArea.containsMouse ? 1.0 : 0.3
105 visible: root.activePreview < (root.previews.length - 1)
106
107 MouseArea {
108 id: rightMouseArea
109 anchors.fill: parent
110 hoverEnabled: true
111 onClicked: {
112 root.activePreview = Math.min(root.activePreview + 1, root.previews.length - 1)
113 }
114 }
115
116 GettingStartedTip {
117 anchors {
118 verticalCenter: parent.verticalCenter
119 right: parent.left
120 }
121 arrow: GettingStartedTip.RightCenter
122 text: qsTr("Click here to cycle through preview images")
123 }
124 }
125 }