Kstars

TimeSpinBox.qml
1// SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com>
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4import QtQuick.Controls 2.0
5import QtQuick 2.6
6import "../../constants" 1.0
7
8SpinBox {
9 id: control
10 from: -41
11 to: 41
12 anchors.verticalCenter: parent.verticalCenter
13 editable: false
14
15 background: Rectangle {
16 implicitWidth: 160
17 color: Num.sysPalette.base
18 }
19
20 contentItem: Text {
21 z: 2
22 text: control.textFromValue(control.value, control.locale)
23 anchors.verticalCenter: parent.verticalCenter
24
25 font: control.font
26 color: Num.sysPalette.text
27 horizontalAlignment: Qt.AlignHCenter
28 verticalAlignment: Qt.AlignVCenter
29 }
30
31 property int spacingg: 0
32
33 Connections {
34 target: up
35 onPressed: {
36 console.log(up.pressed)
37 }
38 }
39
40 up.indicator: Rectangle {
41 z: 0
42 x: control.mirrored ? -spacingg : parent.width - width + spacingg
43 anchors.verticalCenter: parent.verticalCenter
44 implicitWidth: 37
45 implicitHeight: 37
46 color: up.pressed || !enabled ? Num.sysPalette.light : Num.sysPalette.base
47 border.color: up.pressed || !enabled ? Num.sysPalette.base : Num.sysPalette.light
48 radius: 5
49
50 Text {
51 z: 1
52 text: "+"
53 font.pixelSize: control.font.pixelSize * 2
54 color: up.pressed || !enabled ? Num.sysPalette.dark : Num.sysPalette.text
55 anchors.fill: parent
56 fontSizeMode: Text.Fit
57 horizontalAlignment: Text.AlignHCenter
58 verticalAlignment: Text.AlignVCenter
59 }
60 }
61
62 down.indicator: Rectangle {
63 z: 0
64 x: control.mirrored ? parent.width - width + spacingg : -spacingg
65 anchors.verticalCenter: parent.verticalCenter
66 implicitWidth: 37
67 implicitHeight: 37
68 color: down.pressed || !enabled ? Num.sysPalette.light : Num.sysPalette.base
69 border.color: down.pressed || !enabled ? Num.sysPalette.base : Num.sysPalette.light
70 radius: 5
71
72 Text {
73 text: "-"
74 font.pixelSize: control.font.pixelSize * 2
75 color: down.pressed || !enabled ? Num.sysPalette.dark : Num.sysPalette.text
76 anchors.fill: parent
77 fontSizeMode: Text.Fit
78 horizontalAlignment: Text.AlignHCenter
79 verticalAlignment: Text.AlignVCenter
80 }
81 }
82
83 property bool daysOnly: false
84
85 onDaysOnlyChanged: {
86 setDaysOnly()
87 }
88
89 Component.onCompleted: {
90 setDaysOnly()
91 }
92
93 property double secs_per_day: 86400.0
94 property double sidereal_year: 31558149.77
95 property double tropical_year: 31556925.19
96
97 property var timeString: []
98 property var timeScale: []
99
100 //TimeUnit control
101 property int unitValue: 1
102 property int allunits: 8
103 property int dayunits: 5
104 property int minUnitValue
105 property int maxUnitValue
106 property var unitStep: []
107
108 function setDaysOnly() {
109 var i = 0; //index for timeScale values
110
111 timeScale[0] = 0.0
112 if(!daysOnly) {
113 timeScale[1] = 0.1; // 0.1 sec
114 timeScale[2] = 0.25; // 0.25 sec
115 timeScale[3] = 0.5; // 0.5 sec
116 timeScale[4] = 1.0; // 1 sec (real-time)
117 timeScale[5] = 2.0; // 2 sec
118 timeScale[6] = 5.0; // 5 sec
119 timeScale[7] = 10.0; // 10 sec
120 timeScale[8] = 20.0; // 20 sec
121 timeScale[9] = 30.0; // 30 sec
122 timeScale[10] = 60.0; // 1 min
123 timeScale[11] = 120.0; // 2 min
124 timeScale[12] = 300.0; // 5 min
125 timeScale[13] = 600.0; // 10 min
126 timeScale[14] = 900.0; // 15 min
127 timeScale[15] = 1800.0; // 30 min
128 timeScale[16] = 3600.0; // 1 hr
129 timeScale[17] = 7200.0; // 2 hr
130 timeScale[18] = 10800.0; // 3 hr
131 timeScale[19] = 21600.0; // 6 hr
132 timeScale[20] = 43200.0; // 12 hr
133 i = 20;
134 }
135
136 timeScale[i+1] = 86164.1; // 23 hr 56 min
137 timeScale[i+2] = secs_per_day; // 1 day
138 timeScale[i+3] = 2.*secs_per_day; // 2 days
139 timeScale[i+4] = 3.*secs_per_day; // 3 days
140 timeScale[i+5] = 5.*secs_per_day; // 5 days
141 timeScale[i+6] = 7.*secs_per_day; // 1 week
142 timeScale[i+7] = 14.*secs_per_day; //2 weeks
143 timeScale[i+8] = 21.*secs_per_day; //3 weeks
144 //Months aren't a simple measurement of time; I'll just use fractions of a year
145 timeScale[i+9] = sidereal_year/12.0; // 1 month
146 timeScale[i+10] = sidereal_year/6.0; // 2 months
147 timeScale[i+11] = 0.25*sidereal_year; // 3 months
148 timeScale[i+12] = sidereal_year/3.0; // 4 months
149 timeScale[i+13] = 0.5*sidereal_year; // 6 months
150 timeScale[i+14] = 0.75*sidereal_year; // 9 months
151 timeScale[i+15] = sidereal_year; // 1 year
152 timeScale[i+16] = 2.0*sidereal_year; // 2 years
153 timeScale[i+17] = 3.0*sidereal_year; // 3 years
154 timeScale[i+18] = 5.0*sidereal_year; // 5 years
155 timeScale[i+19] = 10.0*sidereal_year; // 10 years
156 timeScale[i+20] = 25.0*sidereal_year; // 25 years
157 timeScale[i+21] = 50.0*sidereal_year; // 50 years
158 timeScale[i+22] = 100.0*sidereal_year; // 100 years
159
160 timeString = []
161 if ( ! daysOnly ) {
162 timeString.push( i18n( "0 secs" ));
163 timeString.push( i18n( "0.1 secs" ));
164 timeString.push( i18n( "0.25 secs" ));
165 timeString.push( i18n( "0.5 secs" ));
166 timeString.push( i18n( "1 sec" ));
167 timeString.push( i18n( "2 secs" ));
168 timeString.push( i18n( "5 secs" ));
169 timeString.push( i18n( "10 secs" ));
170 timeString.push( i18n( "20 secs" ));
171 timeString.push( i18n( "30 secs" ));
172 timeString.push( i18n( "1 min" ));
173 timeString.push( i18n( "2 mins" ));
174 timeString.push( i18n( "5 mins" ));
175 timeString.push( i18n( "10 mins" ));
176 timeString.push( i18n( "15 mins" ));
177 timeString.push( i18n( "30 mins" ));
178 timeString.push( i18n( "1 hour" ));
179 timeString.push( i18n( "2 hrs" ));
180 timeString.push( i18n( "3 hrs" ));
181 timeString.push( i18n( "6 hrs" ));
182 timeString.push( i18n( "12 hrs" ));
183 } else {
184 timeString.push( i18n( "0 days" ));
185 }
186 timeString.push( i18n( "1 sid day" ));
187 timeString.push( i18n( "1 day" ));
188 timeString.push( i18n( "2 days" ));
189 timeString.push( i18n( "3 days" ));
190 timeString.push( i18n( "5 days" ));
191 timeString.push( i18n( "1 week" ));
192 timeString.push( i18n( "2 wks" ));
193 timeString.push( i18n( "3 wks" ));
194 timeString.push( i18n( "1 month" ));
195 timeString.push( i18n( "2 mths" ));
196 timeString.push( i18n( "3 mths" ));
197 timeString.push( i18n( "4 mths" ));
198 timeString.push( i18n( "6 mths" ));
199 timeString.push( i18n( "9 mths" ));
200 timeString.push( i18n( "1 year" ));
201 timeString.push( i18n( "2 yrs" ));
202 timeString.push( i18n( "3 yrs" ));
203 timeString.push( i18n( "5 yrs" ));
204 timeString.push( i18n( "10 yrs" ));
205 timeString.push( i18n( "25 yrs" ));
206 timeString.push( i18n( "50 yrs" ));
207 timeString.push( i18n( "100 yrs" ));
208
209 if ( !daysOnly ) {
210 from = -41
211 to = 41
212 } else {
213 from = -21
214 to = 21
215 }
216
217 if ( daysOnly ) {
218 minUnitValue = 1-dayunits
219 maxUnitValue = dayunits-1
220 unitValue = 1 // Start out with days units
221
222 unitStep[0] = 0;
223 unitStep[1] = 1;
224 unitStep[2] = 5;
225 unitStep[3] = 8;
226 unitStep[4] = 14;
227 } else {
228 minUnitValue = 1-allunits
229 maxUnitValue = allunits-1
230 unitValue = 1 // Start out with seconds units
231
232 unitStep[0] = 0;
233 unitStep[1] = 4;
234 unitStep[2] = 10;
235 unitStep[3] = 16;
236 unitStep[4] = 21;
237 unitStep[5] = 25;
238 unitStep[6] = 28;
239 unitStep[7] = 34;
240 }
241
242 value = 4
243 }
244
245 function increaseTimeUnit() {
246 if(unitValue < maxUnitValue) {
247 unitValue = unitValue + 1
248 value = getUnitValue()
249 }
250 }
251
252 function decreaseTimeUnit() {
253 if(unitValue > minUnitValue) {
254 unitValue = unitValue - 1
255 value = getUnitValue()
256 }
257 }
258
259 function getUnitValue() {
260 var uval;
261 if ( unitValue >= 0 ) uval = unitStep[ unitValue ];
262 else uval = -1*unitStep[ Math.abs( unitValue ) ];
263 return uval;
264 }
265
266 function unitValueFromNum( val ) {
267 if ( val >= 0 ) return unitStep[ val ];
268 else return -1*unitStep[ Math.abs( val ) ];
269 }
270
271 function getTimeScale() {
272 return value > 0 ? timeScale[ value ] : -1.*timeScale[ Math.abs(value) ];
273 }
274
275 function reportChange() {
276 console.log("Reporting new timestep value: " + getTimeScale())
277 KStarsLite.scaleChanged( getTimeScale() )
278 }
279
280 textFromValue: function(value) {
281 var result
282 var posval = Math.abs( value )
283 if ( posval > timeString.length - 1 ) posval = 4;
284
285 result = timeString[ posval ];
286
287 if ( value < 0 ) { result = '-' + result; }
288
289 reportChange()
290 return result;
291 }
292
293 valueFromText: function(text) {
294
295 for (var i = 0; i < timeString.length; ++i) {
296 if (text === timeString[i]) return i
297 if (text.substring(1) === timeString[i]) return -1*i
298 }
299
300 return 0
301 }
302}
This class loads QML files and connects SkyMapLite and KStarsData Unlike KStars class it is not a mai...
Definition kstarslite.h:47
void scaleChanged(float)
Emitted whenever TimeSpinBox in QML changes the scale.
QString i18n(const char *text, const TYPE &arg...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:16:41 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.