24 #include <QFontMetrics>
30 #define SECS_PER_DAY 86400.
31 #define SIDEREAL_YEAR 31558149.77
32 #define TROPICAL_YEAR 31556925.19
52 setButtonSymbols( QSpinBox::PlusMinus );
53 lineEdit()->setReadOnly(
true );
57 QFontMetrics fm( font() );
58 int extra = width() - lineEdit()->width();
60 for (
int i=0; i < maximum(); ++i ) {
61 uint w = fm.width(
'-' + TimeString[i] );
62 if ( w > wmax ) wmax = w;
64 setFixedWidth( wmax + extra );
66 connect(
this, SIGNAL( valueChanged(
int ) ),
this, SLOT(
reportChange() ) );
86 TimeScale[11] = 120.0;
87 TimeScale[12] = 300.0;
88 TimeScale[13] = 600.0;
89 TimeScale[14] = 900.0;
90 TimeScale[15] = 1800.0;
91 TimeScale[16] = 3600.0;
92 TimeScale[17] = 7200.0;
93 TimeScale[18] = 10800.0;
94 TimeScale[19] = 21600.0;
95 TimeScale[20] = 43200.0;
98 TimeScale[i+1] = 86164.1;
124 TimeString.append(
"0 " +
i18nc(
"seconds",
"secs" ));
125 TimeString.append(
"0.1 " +
i18nc(
"seconds",
"secs" ));
126 TimeString.append(
"0.25 " +
i18nc(
"seconds",
"secs" ));
127 TimeString.append(
"0.5 " +
i18nc(
"seconds",
"secs" ));
128 TimeString.append(
"1 " +
i18nc(
"second",
"sec" ));
129 TimeString.append(
"2 " +
i18nc(
"seconds",
"secs" ));
130 TimeString.append(
"5 " +
i18nc(
"seconds",
"secs" ));
131 TimeString.append(
"10 " +
i18nc(
"seconds",
"secs" ));
132 TimeString.append(
"20 " +
i18nc(
"seconds",
"secs" ));
133 TimeString.append(
"30 " +
i18nc(
"seconds",
"secs" ));
134 TimeString.append(
"1 " +
i18nc(
"minute",
"min" ));
135 TimeString.append(
"2 " +
i18nc(
"minutes",
"mins" ));
136 TimeString.append(
"5 " +
i18nc(
"minutes",
"mins" ));
137 TimeString.append(
"10 " +
i18nc(
"minutes",
"mins" ));
138 TimeString.append(
"15 " +
i18nc(
"minutes",
"mins" ));
139 TimeString.append(
"30 " +
i18nc(
"minutes",
"mins" ));
140 TimeString.append(
"1 " + i18n(
"hour" ));
141 TimeString.append(
"2 " +
i18nc(
"hours",
"hrs" ));
142 TimeString.append(
"3 " +
i18nc(
"hours",
"hrs" ));
143 TimeString.append(
"6 " +
i18nc(
"hours",
"hrs" ));
144 TimeString.append(
"12 " +
i18nc(
"hours",
"hrs" ));
146 TimeString.append(
"0 " + i18n(
"days" ));
148 TimeString.append(
"1 " +
i18nc(
"sidereal day",
"sid day" ));
149 TimeString.append(
"1 " + i18n(
"day" ));
150 TimeString.append(
"2 " + i18n(
"days" ));
151 TimeString.append(
"3 " + i18n(
"days" ));
152 TimeString.append(
"5 " + i18n(
"days" ));
153 TimeString.append(
"1 " + i18n(
"week" ));
154 TimeString.append(
"2 " +
i18nc(
"weeks",
"wks" ));
155 TimeString.append(
"3 " +
i18nc(
"weeks",
"wks" ));
156 TimeString.append(
"1 " + i18n(
"month" ));
157 TimeString.append(
"2 " +
i18nc(
"months",
"mths" ));
158 TimeString.append(
"3 " +
i18nc(
"months",
"mths" ));
159 TimeString.append(
"4 " +
i18nc(
"months",
"mths" ));
160 TimeString.append(
"6 " +
i18nc(
"months",
"mths" ));
161 TimeString.append(
"9 " +
i18nc(
"months",
"mths" ));
162 TimeString.append(
"1 " + i18n(
"year" ));
163 TimeString.append(
"2 " +
i18nc(
"years",
"yrs" ));
164 TimeString.append(
"3 " +
i18nc(
"years",
"yrs" ));
165 TimeString.append(
"5 " +
i18nc(
"years",
"yrs" ));
166 TimeString.append(
"10 " +
i18nc(
"years",
"yrs" ));
167 TimeString.append(
"25 " +
i18nc(
"years",
"yrs" ));
168 TimeString.append(
"50 " +
i18nc(
"years",
"yrs" ));
169 TimeString.append(
"100 " +
i18nc(
"years",
"yrs" ));
181 for (
int i=0; i<TimeString.size(); i++ ) {
182 if ( text == TimeString[i] ) {
return i; }
183 if ( text.mid(1,text.length()) == TimeString[i] ) {
return -1*i; }
190 QString neg(
"-"), result;
191 int posval( abs( value ) );
192 if ( posval > TimeString.size() - 1 ) posval = 4;
194 result = TimeString[ posval ];
196 if ( value<0 ) { result =
'-' + result; }
203 float dx, dxlast(10000000000.0), dxmin(10000000000.0);
204 for (
unsigned int i=0; i<42; ++i ) {
205 dx = fabs( TimeScale[i] - fabs(x) );
206 if ( dx < dxmin ) { imin = i; dxmin = dx; }
207 if ( dx > dxlast )
break;
211 if ( x < 0.0 ) imin *= -1;
216 return value() > 0 ? TimeScale[ value() ] : -1.*TimeScale[ abs(value()) ];
220 kDebug() << i18n(
"Reporting new timestep value: " ) <<
timeScale();
224 #include "timespinbox.moc"
virtual int valueFromText(const QString &text) const
Convert the displayed string to an internal value.
void setDaysOnly(bool daysonly)
virtual QString textFromValue(int value) const
Convert the internal value to a display string.
i18nc("string from libindi, used in the config dialog","100x")
TimeSpinBox(QWidget *parent, bool daysOnly=false)
Constructor.
void scaleChanged(float s)
void changeScale(float s)