1/****************************************************************************
2**
3** Copyright (C) 2017 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the examples of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:BSD$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** BSD License Usage
18** Alternatively, you may use this file under the terms of the BSD license
19** as follows:
20**
21** "Redistribution and use in source and binary forms, with or without
22** modification, are permitted provided that the following conditions are
23** met:
24**   * Redistributions of source code must retain the above copyright
25**     notice, this list of conditions and the following disclaimer.
26**   * Redistributions in binary form must reproduce the above copyright
27**     notice, this list of conditions and the following disclaimer in
28**     the documentation and/or other materials provided with the
29**     distribution.
30**   * Neither the name of The Qt Company Ltd nor the names of its
31**     contributors may be used to endorse or promote products derived
32**     from this software without specific prior written permission.
33**
34**
35** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
46**
47** $QT_END_LICENSE$
48**
49****************************************************************************/
50
51import QtQuick 2.0
52import Local 1.0
53
54Rectangle {
55    id: page
56    width: 360
57    height: 360
58
59    SatelliteModel {
60        id: satelliteModel
61        running: true
62        onErrorFound: errorLabel.text = qsTr("Last Error: %1", "%1=error number").arg(code)
63    }
64
65    Item {
66        id: header
67        height: column.height + 30
68        width: parent.width
69        state: "running"
70
71        anchors.top: parent.top
72
73        function toggle()
74        {
75            switch (header.state) {
76            case "single": header.state = "running"; break;
77            default:
78            case "running": header.state = "stopped"; break;
79            case "stopped": header.state = "single"; break;
80            }
81        }
82
83        function enterSingle()
84        {
85            satelliteModel.singleRequestMode = true;
86            satelliteModel.running = true;
87        }
88
89        function enterRunning()
90        {
91            satelliteModel.running = false;
92            satelliteModel.singleRequestMode = false;
93            satelliteModel.running = true;
94        }
95
96        states: [
97            State {
98                name: "stopped"
99                PropertyChanges { target: startStop; bText: qsTr("Single") }
100                PropertyChanges {
101                    target: modeLabel; text: qsTr("Current Mode: stopped")
102                }
103                PropertyChanges { target: satelliteModel; running: false; }
104            },
105            State {
106                name: "single"
107                PropertyChanges { target: startStop; bText: qsTr("Start") }
108                PropertyChanges {
109                    target: modeLabel; text: qsTr("Current Mode: single")
110                }
111                StateChangeScript { script: header.enterSingle(); }
112            },
113            State {
114                name: "running"
115                PropertyChanges { target: startStop; bText: qsTr("Stop") }
116                PropertyChanges {
117                    target: modeLabel; text: qsTr("Current Mode: running")
118                }
119                StateChangeScript { script: header.enterRunning(); }
120            }
121        ]
122
123        Column {
124            id: column
125            anchors.verticalCenter: parent.verticalCenter
126            anchors.left: parent.left
127            anchors.margins: 7
128            Text {
129                id:  overview
130                text: satelliteModel.satelliteInfoAvailable
131                      ? qsTr("Known Satellites")
132                      : qsTr("Known Satellites (Demo Mode)")
133                font.pointSize: 12
134            }
135
136            Text {
137                id: modeLabel
138                font.pointSize: 12
139            }
140
141            Text {
142                id: errorLabel
143                text: qsTr("Last Error: None")
144                font.pointSize: 12
145            }
146        }
147        Rectangle {
148            id: startStop
149            border.color: "black"
150            border.width: 3
151            anchors.right: parent.right
152            anchors.verticalCenter: parent.verticalCenter
153            anchors.margins: 7
154            radius: 10
155            height: maxField.height*1.4
156            width: maxField.width*1.4
157
158            property string bText: qsTr("Stop");
159
160            Text { //need this for sizing
161                id: maxField
162                text: qsTr("Single")
163                font.pointSize: 13
164                opacity: 0
165            }
166
167            Text {
168                id: buttonText
169                anchors.centerIn: parent
170                text: startStop.bText
171                font.pointSize: 13
172            }
173
174            MouseArea {
175                anchors.fill: parent
176                onPressed: { startStop.color = "lightGray" }
177                onClicked: { header.toggle() }
178                onReleased: { startStop.color = "white" }
179            }
180        }
181    }
182
183    Rectangle {
184        anchors.top: header.bottom
185        anchors.bottom: parent.bottom
186        anchors.left: parent.left
187        anchors.right: parent.right
188        anchors.margins: rect.myMargin
189        border.width: 3
190        radius: 10
191        border.color: "black"
192
193        Item {
194            id: rect
195            anchors.fill: parent
196            anchors.margins: myMargin
197            property int myMargin: 7
198
199            Row {
200                id: view
201                property int rows: repeater.model.entryCount
202                property int singleWidth: ((rect.width - scale.width)/rows )-rect.myMargin
203                spacing: rect.myMargin
204
205                Rectangle {
206                    id: scale
207                    width: strengthLabel.width+10
208                    height: rect.height
209                    color: "#32cd32"
210                    Text {
211                        anchors.horizontalCenter: parent.horizontalCenter
212                        anchors.bottom: lawngreenRect.top
213                        font.pointSize: 11
214                        text: "50"
215                    }
216                    Text {
217                        anchors.horizontalCenter: parent.horizontalCenter
218                        anchors.top: parent.top
219                        font.pointSize: 11
220                        text: "100"
221                    }
222
223                    Rectangle {
224                        id: redRect
225                        width: parent.width
226                        color: "red"
227                        height: parent.height*10/100
228                        anchors.bottom: parent.bottom
229                        Text {
230                            id: strengthLabel
231                            anchors.horizontalCenter: parent.horizontalCenter
232                            anchors.bottom: parent.bottom
233                            font.pointSize: 11
234                            text: "00"
235                        }
236                    }
237                    Rectangle {
238                        id: orangeRect
239                        height: parent.height*10/100
240                        anchors.bottom: redRect.top
241                        width: parent.width
242                        color: "#ffa500"
243                        Text {
244                            anchors.horizontalCenter: parent.horizontalCenter
245                            anchors.bottom: parent.bottom
246                            font.pointSize: 11
247                            text: "10"
248                        }
249                    }
250                    Rectangle {
251                        id: goldRect
252                        height: parent.height*10/100
253                        anchors.bottom: orangeRect.top
254                        width: parent.width
255                        color: "#ffd700"
256                        Text {
257                            anchors.horizontalCenter: parent.horizontalCenter
258                            anchors.bottom: parent.bottom
259                            font.pointSize: 11
260                            text: "20"
261                        }
262                    }
263                    Rectangle {
264                        id: yellowRect
265                        height: parent.height*10/100
266                        anchors.bottom: goldRect.top
267                        width: parent.width
268                        color: "yellow"
269                        Text {
270                            anchors.horizontalCenter: parent.horizontalCenter
271                            anchors.bottom: parent.bottom
272                            font.pointSize: 11
273                            text: "30"
274                        }
275                    }
276                    Rectangle {
277                        id: lawngreenRect
278                        height: parent.height*10/100
279                        anchors.bottom: yellowRect.top
280                        width: parent.width
281                        color: "#7cFc00"
282                        Text {
283                            anchors.horizontalCenter: parent.horizontalCenter
284                            anchors.bottom: parent.bottom
285                            font.pointSize: 11
286                            text: "40"
287                        }
288                    }
289                }
290
291                Repeater {
292                    id: repeater
293                    model: satelliteModel
294                    delegate: Rectangle {
295                        height: rect.height
296                        width: view.singleWidth
297                        Rectangle {
298                            anchors.bottom: parent.bottom
299                            width: parent.width
300                            height: parent.height*signalStrength/100
301                            color: isInUse ? "#7FFF0000" : "#7F0000FF"
302                        }
303                        Text {
304                            anchors.horizontalCenter: parent.horizontalCenter
305                            anchors.bottom: parent.bottom
306                            text: satelliteIdentifier
307                        }
308                    }
309                }
310            }
311        }
312    }
313}
314
315