Warning, /education/kstars/kstars/kstarslite/qml/modules/helpers/TimeSpinBox.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com> 0002 // SPDX-License-Identifier: GPL-2.0-or-later 0003 0004 import QtQuick.Controls 2.0 0005 import QtQuick 2.6 0006 import "../../constants" 1.0 0007 0008 SpinBox { 0009 id: control 0010 from: -41 0011 to: 41 0012 anchors.verticalCenter: parent.verticalCenter 0013 editable: false 0014 0015 background: Rectangle { 0016 implicitWidth: 160 0017 color: Num.sysPalette.base 0018 } 0019 0020 contentItem: Text { 0021 z: 2 0022 text: control.textFromValue(control.value, control.locale) 0023 anchors.verticalCenter: parent.verticalCenter 0024 0025 font: control.font 0026 color: Num.sysPalette.text 0027 horizontalAlignment: Qt.AlignHCenter 0028 verticalAlignment: Qt.AlignVCenter 0029 } 0030 0031 property int spacingg: 0 0032 0033 Connections { 0034 target: up 0035 onPressed: { 0036 console.log(up.pressed) 0037 } 0038 } 0039 0040 up.indicator: Rectangle { 0041 z: 0 0042 x: control.mirrored ? -spacingg : parent.width - width + spacingg 0043 anchors.verticalCenter: parent.verticalCenter 0044 implicitWidth: 37 0045 implicitHeight: 37 0046 color: up.pressed || !enabled ? Num.sysPalette.light : Num.sysPalette.base 0047 border.color: up.pressed || !enabled ? Num.sysPalette.base : Num.sysPalette.light 0048 radius: 5 0049 0050 Text { 0051 z: 1 0052 text: "+" 0053 font.pixelSize: control.font.pixelSize * 2 0054 color: up.pressed || !enabled ? Num.sysPalette.dark : Num.sysPalette.text 0055 anchors.fill: parent 0056 fontSizeMode: Text.Fit 0057 horizontalAlignment: Text.AlignHCenter 0058 verticalAlignment: Text.AlignVCenter 0059 } 0060 } 0061 0062 down.indicator: Rectangle { 0063 z: 0 0064 x: control.mirrored ? parent.width - width + spacingg : -spacingg 0065 anchors.verticalCenter: parent.verticalCenter 0066 implicitWidth: 37 0067 implicitHeight: 37 0068 color: down.pressed || !enabled ? Num.sysPalette.light : Num.sysPalette.base 0069 border.color: down.pressed || !enabled ? Num.sysPalette.base : Num.sysPalette.light 0070 radius: 5 0071 0072 Text { 0073 text: "-" 0074 font.pixelSize: control.font.pixelSize * 2 0075 color: down.pressed || !enabled ? Num.sysPalette.dark : Num.sysPalette.text 0076 anchors.fill: parent 0077 fontSizeMode: Text.Fit 0078 horizontalAlignment: Text.AlignHCenter 0079 verticalAlignment: Text.AlignVCenter 0080 } 0081 } 0082 0083 property bool daysOnly: false 0084 0085 onDaysOnlyChanged: { 0086 setDaysOnly() 0087 } 0088 0089 Component.onCompleted: { 0090 setDaysOnly() 0091 } 0092 0093 property double secs_per_day: 86400.0 0094 property double sidereal_year: 31558149.77 0095 property double tropical_year: 31556925.19 0096 0097 property var timeString: [] 0098 property var timeScale: [] 0099 0100 //TimeUnit control 0101 property int unitValue: 1 0102 property int allunits: 8 0103 property int dayunits: 5 0104 property int minUnitValue 0105 property int maxUnitValue 0106 property var unitStep: [] 0107 0108 function setDaysOnly() { 0109 var i = 0; //index for timeScale values 0110 0111 timeScale[0] = 0.0 0112 if(!daysOnly) { 0113 timeScale[1] = 0.1; // 0.1 sec 0114 timeScale[2] = 0.25; // 0.25 sec 0115 timeScale[3] = 0.5; // 0.5 sec 0116 timeScale[4] = 1.0; // 1 sec (real-time) 0117 timeScale[5] = 2.0; // 2 sec 0118 timeScale[6] = 5.0; // 5 sec 0119 timeScale[7] = 10.0; // 10 sec 0120 timeScale[8] = 20.0; // 20 sec 0121 timeScale[9] = 30.0; // 30 sec 0122 timeScale[10] = 60.0; // 1 min 0123 timeScale[11] = 120.0; // 2 min 0124 timeScale[12] = 300.0; // 5 min 0125 timeScale[13] = 600.0; // 10 min 0126 timeScale[14] = 900.0; // 15 min 0127 timeScale[15] = 1800.0; // 30 min 0128 timeScale[16] = 3600.0; // 1 hr 0129 timeScale[17] = 7200.0; // 2 hr 0130 timeScale[18] = 10800.0; // 3 hr 0131 timeScale[19] = 21600.0; // 6 hr 0132 timeScale[20] = 43200.0; // 12 hr 0133 i = 20; 0134 } 0135 0136 timeScale[i+1] = 86164.1; // 23 hr 56 min 0137 timeScale[i+2] = secs_per_day; // 1 day 0138 timeScale[i+3] = 2.*secs_per_day; // 2 days 0139 timeScale[i+4] = 3.*secs_per_day; // 3 days 0140 timeScale[i+5] = 5.*secs_per_day; // 5 days 0141 timeScale[i+6] = 7.*secs_per_day; // 1 week 0142 timeScale[i+7] = 14.*secs_per_day; //2 weeks 0143 timeScale[i+8] = 21.*secs_per_day; //3 weeks 0144 //Months aren't a simple measurement of time; I'll just use fractions of a year 0145 timeScale[i+9] = sidereal_year/12.0; // 1 month 0146 timeScale[i+10] = sidereal_year/6.0; // 2 months 0147 timeScale[i+11] = 0.25*sidereal_year; // 3 months 0148 timeScale[i+12] = sidereal_year/3.0; // 4 months 0149 timeScale[i+13] = 0.5*sidereal_year; // 6 months 0150 timeScale[i+14] = 0.75*sidereal_year; // 9 months 0151 timeScale[i+15] = sidereal_year; // 1 year 0152 timeScale[i+16] = 2.0*sidereal_year; // 2 years 0153 timeScale[i+17] = 3.0*sidereal_year; // 3 years 0154 timeScale[i+18] = 5.0*sidereal_year; // 5 years 0155 timeScale[i+19] = 10.0*sidereal_year; // 10 years 0156 timeScale[i+20] = 25.0*sidereal_year; // 25 years 0157 timeScale[i+21] = 50.0*sidereal_year; // 50 years 0158 timeScale[i+22] = 100.0*sidereal_year; // 100 years 0159 0160 timeString = [] 0161 if ( ! daysOnly ) { 0162 timeString.push( i18n( "0 secs" )); 0163 timeString.push( i18n( "0.1 secs" )); 0164 timeString.push( i18n( "0.25 secs" )); 0165 timeString.push( i18n( "0.5 secs" )); 0166 timeString.push( i18n( "1 sec" )); 0167 timeString.push( i18n( "2 secs" )); 0168 timeString.push( i18n( "5 secs" )); 0169 timeString.push( i18n( "10 secs" )); 0170 timeString.push( i18n( "20 secs" )); 0171 timeString.push( i18n( "30 secs" )); 0172 timeString.push( i18n( "1 min" )); 0173 timeString.push( i18n( "2 mins" )); 0174 timeString.push( i18n( "5 mins" )); 0175 timeString.push( i18n( "10 mins" )); 0176 timeString.push( i18n( "15 mins" )); 0177 timeString.push( i18n( "30 mins" )); 0178 timeString.push( i18n( "1 hour" )); 0179 timeString.push( i18n( "2 hrs" )); 0180 timeString.push( i18n( "3 hrs" )); 0181 timeString.push( i18n( "6 hrs" )); 0182 timeString.push( i18n( "12 hrs" )); 0183 } else { 0184 timeString.push( i18n( "0 days" )); 0185 } 0186 timeString.push( i18n( "1 sid day" )); 0187 timeString.push( i18n( "1 day" )); 0188 timeString.push( i18n( "2 days" )); 0189 timeString.push( i18n( "3 days" )); 0190 timeString.push( i18n( "5 days" )); 0191 timeString.push( i18n( "1 week" )); 0192 timeString.push( i18n( "2 wks" )); 0193 timeString.push( i18n( "3 wks" )); 0194 timeString.push( i18n( "1 month" )); 0195 timeString.push( i18n( "2 mths" )); 0196 timeString.push( i18n( "3 mths" )); 0197 timeString.push( i18n( "4 mths" )); 0198 timeString.push( i18n( "6 mths" )); 0199 timeString.push( i18n( "9 mths" )); 0200 timeString.push( i18n( "1 year" )); 0201 timeString.push( i18n( "2 yrs" )); 0202 timeString.push( i18n( "3 yrs" )); 0203 timeString.push( i18n( "5 yrs" )); 0204 timeString.push( i18n( "10 yrs" )); 0205 timeString.push( i18n( "25 yrs" )); 0206 timeString.push( i18n( "50 yrs" )); 0207 timeString.push( i18n( "100 yrs" )); 0208 0209 if ( !daysOnly ) { 0210 from = -41 0211 to = 41 0212 } else { 0213 from = -21 0214 to = 21 0215 } 0216 0217 if ( daysOnly ) { 0218 minUnitValue = 1-dayunits 0219 maxUnitValue = dayunits-1 0220 unitValue = 1 // Start out with days units 0221 0222 unitStep[0] = 0; 0223 unitStep[1] = 1; 0224 unitStep[2] = 5; 0225 unitStep[3] = 8; 0226 unitStep[4] = 14; 0227 } else { 0228 minUnitValue = 1-allunits 0229 maxUnitValue = allunits-1 0230 unitValue = 1 // Start out with seconds units 0231 0232 unitStep[0] = 0; 0233 unitStep[1] = 4; 0234 unitStep[2] = 10; 0235 unitStep[3] = 16; 0236 unitStep[4] = 21; 0237 unitStep[5] = 25; 0238 unitStep[6] = 28; 0239 unitStep[7] = 34; 0240 } 0241 0242 value = 4 0243 } 0244 0245 function increaseTimeUnit() { 0246 if(unitValue < maxUnitValue) { 0247 unitValue = unitValue + 1 0248 value = getUnitValue() 0249 } 0250 } 0251 0252 function decreaseTimeUnit() { 0253 if(unitValue > minUnitValue) { 0254 unitValue = unitValue - 1 0255 value = getUnitValue() 0256 } 0257 } 0258 0259 function getUnitValue() { 0260 var uval; 0261 if ( unitValue >= 0 ) uval = unitStep[ unitValue ]; 0262 else uval = -1*unitStep[ Math.abs( unitValue ) ]; 0263 return uval; 0264 } 0265 0266 function unitValueFromNum( val ) { 0267 if ( val >= 0 ) return unitStep[ val ]; 0268 else return -1*unitStep[ Math.abs( val ) ]; 0269 } 0270 0271 function getTimeScale() { 0272 return value > 0 ? timeScale[ value ] : -1.*timeScale[ Math.abs(value) ]; 0273 } 0274 0275 function reportChange() { 0276 console.log("Reporting new timestep value: " + getTimeScale()) 0277 KStarsLite.scaleChanged( getTimeScale() ) 0278 } 0279 0280 textFromValue: function(value) { 0281 var result 0282 var posval = Math.abs( value ) 0283 if ( posval > timeString.length - 1 ) posval = 4; 0284 0285 result = timeString[ posval ]; 0286 0287 if ( value < 0 ) { result = '-' + result; } 0288 0289 reportChange() 0290 return result; 0291 } 0292 0293 valueFromText: function(text) { 0294 0295 for (var i = 0; i < timeString.length; ++i) { 0296 if (text === timeString[i]) return i 0297 if (text.substring(1) === timeString[i]) return -1*i 0298 } 0299 0300 return 0 0301 } 0302 }