Diffstat (limited to 'libopie2/opieui/otimepicker.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opieui/otimepicker.cpp | 295 |
1 files changed, 295 insertions, 0 deletions
diff --git a/libopie2/opieui/otimepicker.cpp b/libopie2/opieui/otimepicker.cpp new file mode 100644 index 0000000..9f9f2c2 --- a/dev/null +++ b/libopie2/opieui/otimepicker.cpp | |||
@@ -0,0 +1,295 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) Stefan Eilers <eilers.stefan@epost.de> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
29 | |||
30 | /* QT */ | ||
31 | #include <qbuttongroup.h> | ||
32 | #include <qlayout.h> | ||
33 | #include <qlineedit.h> | ||
34 | #include <qstring.h> | ||
35 | #include <qtoolbutton.h> | ||
36 | |||
37 | /* OPIE */ | ||
38 | #include <opie2/otimepicker.h> | ||
39 | |||
40 | using namespace Opie; | ||
41 | |||
42 | /** | ||
43 | * Constructs the widget | ||
44 | * @param parent The parent of the OTimePicker | ||
45 | * @param name The name of the object | ||
46 | * @param fl Window Flags | ||
47 | */ | ||
48 | OTimePicker::OTimePicker(QWidget* parent, const char* name, Qt::WFlags fl) | ||
49 | :QWidget(parent,name,fl) | ||
50 | { | ||
51 | QVBoxLayout *vbox=new QVBoxLayout(this); | ||
52 | |||
53 | OClickableLabel *r; | ||
54 | QString s; | ||
55 | |||
56 | // Hour Row | ||
57 | QWidget *row=new QWidget(this); | ||
58 | QHBoxLayout *l=new QHBoxLayout(row); | ||
59 | vbox->addWidget(row); | ||
60 | |||
61 | for (int i=0; i<24; i++) | ||
62 | { | ||
63 | r=new OClickableLabel(row); | ||
64 | hourLst.append(r); | ||
65 | s.sprintf("%.2d",i); | ||
66 | r->setText(s); | ||
67 | r->setToggleButton(true); | ||
68 | r->setAlignment(AlignHCenter | AlignVCenter); | ||
69 | l->addWidget(r); | ||
70 | connect(r, SIGNAL(toggled(bool)), | ||
71 | this, SLOT(slotHour(bool))); | ||
72 | |||
73 | if (i==11) | ||
74 | { // Second row | ||
75 | row=new QWidget(this); | ||
76 | l=new QHBoxLayout(row); | ||
77 | vbox->addWidget(row); | ||
78 | } | ||
79 | } | ||
80 | |||
81 | // Minute Row | ||
82 | row=new QWidget(this); | ||
83 | l=new QHBoxLayout(row); | ||
84 | vbox->addWidget(row); | ||
85 | |||
86 | for (int i=0; i<60; i+=5) | ||
87 | { | ||
88 | r=new OClickableLabel(row); | ||
89 | minuteLst.append(r); | ||
90 | s.sprintf("%.2d",i); | ||
91 | r->setText(s); | ||
92 | r->setToggleButton(true); | ||
93 | r->setAlignment(AlignHCenter | AlignVCenter); | ||
94 | l->addWidget(r); | ||
95 | connect(r, SIGNAL(toggled(bool)), | ||
96 | this, SLOT(slotMinute(bool))); | ||
97 | } | ||
98 | } | ||
99 | |||
100 | /** | ||
101 | * This method return the current time | ||
102 | * @return the time | ||
103 | */ | ||
104 | QTime OTimePicker::time()const | ||
105 | { | ||
106 | return tm; | ||
107 | } | ||
108 | |||
109 | void OTimePicker::slotHour(bool b) | ||
110 | { | ||
111 | |||
112 | OClickableLabel *r = (OClickableLabel *) sender(); | ||
113 | |||
114 | if (b) | ||
115 | { | ||
116 | QValueListIterator<OClickableLabel *> it; | ||
117 | for (it=hourLst.begin(); it!=hourLst.end(); it++) | ||
118 | { | ||
119 | if (*it != r) (*it)->setOn(false); | ||
120 | else tm.setHMS((*it)->text().toInt(), tm.minute(), 0); | ||
121 | } | ||
122 | emit timeChanged(tm); | ||
123 | } | ||
124 | else | ||
125 | { | ||
126 | r->setOn(true); | ||
127 | } | ||
128 | |||
129 | } | ||
130 | |||
131 | void OTimePicker::slotMinute(bool b) | ||
132 | { | ||
133 | |||
134 | OClickableLabel *r = (OClickableLabel *) sender(); | ||
135 | |||
136 | if (b) | ||
137 | { | ||
138 | QValueListIterator<OClickableLabel *> it; | ||
139 | for (it=minuteLst.begin(); it!=minuteLst.end(); it++) | ||
140 | { | ||
141 | if (*it != r) (*it)->setOn(false); | ||
142 | else tm.setHMS(tm.hour(),(*it)->text().toInt(), 0); | ||
143 | } | ||
144 | emit timeChanged(tm); | ||
145 | } | ||
146 | else | ||
147 | { | ||
148 | r->setOn(true); | ||
149 | } | ||
150 | |||
151 | } | ||
152 | |||
153 | /** | ||
154 | * Method to set the time. No signal gets emitted during this method call | ||
155 | * Minutes must be within 5 minutes step starting at 0 ( 0,5,10,15,20... ) | ||
156 | * @param t The time to be set | ||
157 | */ | ||
158 | void OTimePicker::setTime( const QTime& t) | ||
159 | { | ||
160 | setTime( t.hour(), t.minute() ); | ||
161 | } | ||
162 | |||
163 | /** | ||
164 | * Method to set the time. No signal gets emitted during this method call | ||
165 | * @param h The hour | ||
166 | * @param m The minute. Minutes need to set by 5 minute steps | ||
167 | */ | ||
168 | void OTimePicker::setTime( int h, int m ) | ||
169 | { | ||
170 | setHour(h); | ||
171 | setMinute(m); | ||
172 | } | ||
173 | |||
174 | /* | ||
175 | * FIXME round minutes to the 5 minute arrangement -zecke | ||
176 | */ | ||
177 | /** | ||
178 | * Method to set the minutes | ||
179 | * @param m minutes | ||
180 | */ | ||
181 | void OTimePicker::setMinute(int m) | ||
182 | { | ||
183 | |||
184 | QString minute; | ||
185 | minute.sprintf("%.2d",m); | ||
186 | |||
187 | QValueListIterator<OClickableLabel *> it; | ||
188 | for (it=minuteLst.begin(); it!=minuteLst.end(); it++) | ||
189 | { | ||
190 | if ((*it)->text() == minute) (*it)->setOn(true); | ||
191 | else (*it)->setOn(false); | ||
192 | } | ||
193 | |||
194 | tm.setHMS(tm.hour(),m,0); | ||
195 | } | ||
196 | |||
197 | /** | ||
198 | * Method to set the hour | ||
199 | */ | ||
200 | void OTimePicker::setHour(int h) | ||
201 | { | ||
202 | |||
203 | QString hour; | ||
204 | hour.sprintf("%.2d",h); | ||
205 | |||
206 | QValueListIterator<OClickableLabel *> it; | ||
207 | for (it=hourLst.begin(); it!=hourLst.end(); it++) | ||
208 | { | ||
209 | if ((*it)->text() == hour) (*it)->setOn(true); | ||
210 | else (*it)->setOn(false); | ||
211 | } | ||
212 | tm.setHMS(h,tm.minute(),0); | ||
213 | } | ||
214 | |||
215 | |||
216 | /** | ||
217 | * This is a modal Dialog. | ||
218 | * | ||
219 | * @param parent The parent widget | ||
220 | * @param name The name of the object | ||
221 | * @param fl Possible window flags | ||
222 | */ | ||
223 | OTimePickerDialog::OTimePickerDialog ( QWidget* parent, const char* name, WFlags fl ) | ||
224 | : OTimePickerDialogBase (parent , name, true , fl) | ||
225 | { | ||
226 | |||
227 | connect ( m_timePicker, SIGNAL( timeChanged( const QTime& ) ), | ||
228 | this, SLOT( setTime ( const QTime& ) ) ); | ||
229 | connect ( minuteField, SIGNAL( textChanged ( const QString& ) ), | ||
230 | this, SLOT ( setMinute ( const QString& ) ) ); | ||
231 | connect ( hourField, SIGNAL( textChanged ( const QString& ) ), | ||
232 | this, SLOT ( setHour ( const QString& ) ) ); | ||
233 | |||
234 | } | ||
235 | |||
236 | /** | ||
237 | * @return the time | ||
238 | */ | ||
239 | QTime OTimePickerDialog::time()const | ||
240 | { | ||
241 | return m_time; | ||
242 | } | ||
243 | |||
244 | /** | ||
245 | * Set the time to time | ||
246 | * @param time The time to be set | ||
247 | */ | ||
248 | void OTimePickerDialog::setTime( const QTime& time ) | ||
249 | { | ||
250 | m_time = time; | ||
251 | |||
252 | m_timePicker->setHour ( time.hour() ); | ||
253 | m_timePicker->setMinute( time.minute() ); | ||
254 | |||
255 | // Set Textfields | ||
256 | if ( time.hour() < 10 ) | ||
257 | hourField->setText( "0" + QString::number( time.hour() ) ); | ||
258 | else | ||
259 | hourField->setText( QString::number( time.hour() ) ); | ||
260 | |||
261 | if ( time.minute() < 10 ) | ||
262 | minuteField->setText( "0" + QString::number( time.minute() ) ); | ||
263 | else | ||
264 | minuteField->setText( QString::number( time.minute() ) ); | ||
265 | |||
266 | } | ||
267 | |||
268 | /** | ||
269 | * This method takes the current minute and tries to set hour | ||
270 | * to hour. This succeeds if the resulting date is valid | ||
271 | * @param hour The hour as a string | ||
272 | */ | ||
273 | void OTimePickerDialog::setHour ( const QString& hour ) | ||
274 | { | ||
275 | if ( QTime::isValid ( hour.toInt(), m_time.minute() , 00 ) ) | ||
276 | { | ||
277 | m_time.setHMS ( hour.toInt(), m_time.minute() , 00 ); | ||
278 | setTime ( m_time ); | ||
279 | } | ||
280 | |||
281 | } | ||
282 | |||
283 | /** | ||
284 | * Method to set a new minute. It tries to convert the string to int and | ||
285 | * if the resulting date is valid a new date is set. | ||
286 | * @see setHour | ||
287 | */ | ||
288 | void OTimePickerDialog::setMinute ( const QString& minute ) | ||
289 | { | ||
290 | if ( QTime::isValid ( m_time.hour(), minute.toInt(), 00 ) ) | ||
291 | { | ||
292 | m_time.setHMS ( m_time.hour(), minute.toInt(), 00 ); | ||
293 | setTime ( m_time ); | ||
294 | } | ||
295 | } | ||