-rw-r--r-- | libopie/otimepicker.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/libopie/otimepicker.cpp b/libopie/otimepicker.cpp index 1eca7c5..11b80ed 100644 --- a/libopie/otimepicker.cpp +++ b/libopie/otimepicker.cpp | |||
@@ -1,242 +1,242 @@ | |||
1 | #include "otimepicker.h" | 1 | #include "otimepicker.h" |
2 | 2 | ||
3 | #include <qlayout.h> | 3 | #include <qlayout.h> |
4 | #include <stdio.h> | 4 | #include <stdio.h> |
5 | #include <qlineedit.h> | 5 | #include <qlineedit.h> |
6 | 6 | ||
7 | 7 | ||
8 | /** | 8 | /** |
9 | * Constructs the widget | 9 | * Constructs the widget |
10 | * @param parent The parent of the OTimePicker | 10 | * @param parent The parent of the OTimePicker |
11 | * @param name The name of the object | 11 | * @param name The name of the object |
12 | * @param fl Window Flags | 12 | * @param fl Window Flags |
13 | */ | 13 | */ |
14 | OTimePicker::OTimePicker(QWidget* parent, const char* name, | 14 | OTimePicker::OTimePicker(QWidget* parent, const char* name, |
15 | WFlags fl) : | 15 | WFlags fl) : |
16 | QWidget(parent,name,fl) | 16 | QWidget(parent,name,fl) |
17 | { | 17 | { |
18 | 18 | ||
19 | QVBoxLayout *vbox=new QVBoxLayout(this); | 19 | QVBoxLayout *vbox=new QVBoxLayout(this); |
20 | 20 | ||
21 | OClickableLabel *r; | 21 | OClickableLabel *r; |
22 | QString s; | 22 | QString s; |
23 | 23 | ||
24 | // Hour Row | 24 | // Hour Row |
25 | QWidget *row=new QWidget(this); | 25 | QWidget *row=new QWidget(this); |
26 | QHBoxLayout *l=new QHBoxLayout(row); | 26 | QHBoxLayout *l=new QHBoxLayout(row); |
27 | vbox->addWidget(row); | 27 | vbox->addWidget(row); |
28 | 28 | ||
29 | 29 | ||
30 | for (int i=0; i<24; i++) { | 30 | for (int i=0; i<24; i++) { |
31 | r=new OClickableLabel(row); | 31 | r=new OClickableLabel(row); |
32 | hourLst.append(r); | 32 | hourLst.append(r); |
33 | s.sprintf("%.2d",i); | 33 | s.sprintf("%.2d",i); |
34 | r->setText(s); | 34 | r->setText(s); |
35 | r->setToggleButton(true); | 35 | r->setToggleButton(true); |
36 | r->setAlignment(AlignHCenter | AlignVCenter); | 36 | r->setAlignment(AlignHCenter | AlignVCenter); |
37 | l->addWidget(r); | 37 | l->addWidget(r); |
38 | connect(r, SIGNAL(toggled(bool)), | 38 | connect(r, SIGNAL(toggled(bool)), |
39 | this, SLOT(slotHour(bool))); | 39 | this, SLOT(slotHour(bool))); |
40 | 40 | ||
41 | if (i==11) { // Second row | 41 | if (i==11) { // Second row |
42 | row=new QWidget(this); | 42 | row=new QWidget(this); |
43 | l=new QHBoxLayout(row); | 43 | l=new QHBoxLayout(row); |
44 | vbox->addWidget(row); | 44 | vbox->addWidget(row); |
45 | } | 45 | } |
46 | } | 46 | } |
47 | 47 | ||
48 | // Minute Row | 48 | // Minute Row |
49 | row=new QWidget(this); | 49 | row=new QWidget(this); |
50 | l=new QHBoxLayout(row); | 50 | l=new QHBoxLayout(row); |
51 | vbox->addWidget(row); | 51 | vbox->addWidget(row); |
52 | 52 | ||
53 | for (int i=0; i<60; i+=5) { | 53 | for (int i=0; i<60; i+=5) { |
54 | r=new OClickableLabel(row); | 54 | r=new OClickableLabel(row); |
55 | minuteLst.append(r); | 55 | minuteLst.append(r); |
56 | s.sprintf("%.2d",i); | 56 | s.sprintf("%.2d",i); |
57 | r->setText(s); | 57 | r->setText(s); |
58 | r->setToggleButton(true); | 58 | r->setToggleButton(true); |
59 | r->setAlignment(AlignHCenter | AlignVCenter); | 59 | r->setAlignment(AlignHCenter | AlignVCenter); |
60 | l->addWidget(r); | 60 | l->addWidget(r); |
61 | connect(r, SIGNAL(toggled(bool)), | 61 | connect(r, SIGNAL(toggled(bool)), |
62 | this, SLOT(slotMinute(bool))); | 62 | this, SLOT(slotMinute(bool))); |
63 | } | 63 | } |
64 | } | 64 | } |
65 | 65 | ||
66 | /** | 66 | /** |
67 | * This method return the current time | 67 | * This method return the current time |
68 | * @return the time | 68 | * @return the time |
69 | */ | 69 | */ |
70 | QTime OTimePicker::time()const { | 70 | QTime OTimePicker::time()const { |
71 | return tm; | 71 | return tm; |
72 | } | 72 | } |
73 | 73 | ||
74 | void OTimePicker::slotHour(bool b) { | 74 | void OTimePicker::slotHour(bool b) { |
75 | 75 | ||
76 | OClickableLabel *r = (OClickableLabel *) sender(); | 76 | OClickableLabel *r = (OClickableLabel *) sender(); |
77 | 77 | ||
78 | if (b) { | 78 | if (b) { |
79 | QValueListIterator<OClickableLabel *> it; | 79 | QValueListIterator<OClickableLabel *> it; |
80 | for (it=hourLst.begin(); it!=hourLst.end(); it++) { | 80 | for (it=hourLst.begin(); it!=hourLst.end(); it++) { |
81 | if (*it != r) (*it)->setOn(false); | 81 | if (*it != r) (*it)->setOn(false); |
82 | else tm.setHMS((*it)->text().toInt(), tm.minute(), 0); | 82 | else tm.setHMS((*it)->text().toInt(), tm.minute(), 0); |
83 | } | 83 | } |
84 | emit timeChanged(tm); | 84 | emit timeChanged(tm); |
85 | } else { | 85 | } else { |
86 | r->setOn(true); | 86 | r->setOn(true); |
87 | } | 87 | } |
88 | 88 | ||
89 | } | 89 | } |
90 | 90 | ||
91 | void OTimePicker::slotMinute(bool b) { | 91 | void OTimePicker::slotMinute(bool b) { |
92 | 92 | ||
93 | OClickableLabel *r = (OClickableLabel *) sender(); | 93 | OClickableLabel *r = (OClickableLabel *) sender(); |
94 | 94 | ||
95 | if (b) { | 95 | if (b) { |
96 | QValueListIterator<OClickableLabel *> it; | 96 | QValueListIterator<OClickableLabel *> it; |
97 | for (it=minuteLst.begin(); it!=minuteLst.end(); it++) { | 97 | for (it=minuteLst.begin(); it!=minuteLst.end(); it++) { |
98 | if (*it != r) (*it)->setOn(false); | 98 | if (*it != r) (*it)->setOn(false); |
99 | else tm.setHMS(tm.hour(),(*it)->text().toInt(), 0); | 99 | else tm.setHMS(tm.hour(),(*it)->text().toInt(), 0); |
100 | } | 100 | } |
101 | emit timeChanged(tm); | 101 | emit timeChanged(tm); |
102 | } else { | 102 | } else { |
103 | r->setOn(true); | 103 | r->setOn(true); |
104 | } | 104 | } |
105 | 105 | ||
106 | } | 106 | } |
107 | 107 | ||
108 | /** | 108 | /** |
109 | * Method to set the time. No signal gets emitted during this method call | 109 | * Method to set the time. No signal gets emitted during this method call |
110 | * Minutes must be within 5 minutes step starting at 0 ( 0,5,10,15,20... ) | 110 | * Minutes must be within 5 minutes step starting at 0 ( 0,5,10,15,20... ) |
111 | * @param t The time to be set | 111 | * @param t The time to be set |
112 | */ | 112 | */ |
113 | void OTimePicker::setTime( const QTime& t) { | 113 | void OTimePicker::setTime( const QTime& t) { |
114 | setTime( t.hour(), t.minute() ); | 114 | setTime( t.hour(), t.minute() ); |
115 | } | 115 | } |
116 | 116 | ||
117 | /** | 117 | /** |
118 | * Method to set the time. No signal gets emitted during this method call | 118 | * Method to set the time. No signal gets emitted during this method call |
119 | * @param h The hour | 119 | * @param h The hour |
120 | * @param m The minute. Minutes need to set by 5 minute steps | 120 | * @param m The minute. Minutes need to set by 5 minute steps |
121 | */ | 121 | */ |
122 | void OTimePicker::setTime( int h, int m ) { | 122 | void OTimePicker::setTime( int h, int m ) { |
123 | setHour(h); | 123 | setHour(h); |
124 | setMinute(m); | 124 | setMinute(m); |
125 | } | 125 | } |
126 | 126 | ||
127 | /* | 127 | /* |
128 | * FIXME round minutes to the 5 minute arrangement -zecke | 128 | * FIXME round minutes to the 5 minute arrangement -zecke |
129 | */ | 129 | */ |
130 | /** | 130 | /** |
131 | * Method to set the minutes | 131 | * Method to set the minutes |
132 | * @param m minutes | 132 | * @param m minutes |
133 | */ | 133 | */ |
134 | void OTimePicker::setMinute(int m) { | 134 | void OTimePicker::setMinute(int m) { |
135 | 135 | ||
136 | QString minute; | 136 | QString minute; |
137 | minute.sprintf("%.2d",m); | 137 | minute.sprintf("%.2d",m); |
138 | 138 | ||
139 | QValueListIterator<OClickableLabel *> it; | 139 | QValueListIterator<OClickableLabel *> it; |
140 | for (it=minuteLst.begin(); it!=minuteLst.end(); it++) { | 140 | for (it=minuteLst.begin(); it!=minuteLst.end(); it++) { |
141 | if ((*it)->text() == minute) (*it)->setOn(true); | 141 | if ((*it)->text() == minute) (*it)->setOn(true); |
142 | else (*it)->setOn(false); | 142 | else (*it)->setOn(false); |
143 | } | 143 | } |
144 | 144 | ||
145 | tm.setHMS(tm.hour(),m,0); | 145 | tm.setHMS(tm.hour(),m,0); |
146 | } | 146 | } |
147 | 147 | ||
148 | /** | 148 | /** |
149 | * Method to set the hour | 149 | * Method to set the hour |
150 | */ | 150 | */ |
151 | void OTimePicker::setHour(int h) { | 151 | void OTimePicker::setHour(int h) { |
152 | 152 | ||
153 | QString hour; | 153 | QString hour; |
154 | hour.sprintf("%.2d",h); | 154 | hour.sprintf("%.2d",h); |
155 | 155 | ||
156 | QValueListIterator<OClickableLabel *> it; | 156 | QValueListIterator<OClickableLabel *> it; |
157 | for (it=hourLst.begin(); it!=hourLst.end(); it++) { | 157 | for (it=hourLst.begin(); it!=hourLst.end(); it++) { |
158 | if ((*it)->text() == hour) (*it)->setOn(true); | 158 | if ((*it)->text() == hour) (*it)->setOn(true); |
159 | else (*it)->setOn(false); | 159 | else (*it)->setOn(false); |
160 | } | 160 | } |
161 | tm.setHMS(h,tm.minute(),0); | 161 | tm.setHMS(h,tm.minute(),0); |
162 | } | 162 | } |
163 | 163 | ||
164 | 164 | ||
165 | /** | 165 | /** |
166 | * This is a modal Dialog. | 166 | * This is a modal Dialog. |
167 | * | 167 | * |
168 | * @param parent The parent widget | 168 | * @param parent The parent widget |
169 | * @param name The name of the object | 169 | * @param name The name of the object |
170 | * @param fl Possible window flags | 170 | * @param fl Possible window flags |
171 | */ | 171 | */ |
172 | OTimePickerDialog::OTimePickerDialog ( QWidget* parent, const char* name, WFlags fl ) | 172 | OTimePickerDialog::OTimePickerDialog ( QWidget* parent, const char* name, WFlags fl ) |
173 | : OTimePickerDialogBase (parent , name, true , fl) | 173 | : OTimePickerDialogBase (parent , name, true , fl) |
174 | { | 174 | { |
175 | 175 | ||
176 | connect ( m_timePicker, SIGNAL( timeChanged( const QTime& ) ), | 176 | connect ( m_timePicker, SIGNAL( timeChanged(const QTime&) ), |
177 | this, SLOT( setTime ( const QTime& ) ) ); | 177 | this, SLOT( setTime(const QTime&) ) ); |
178 | connect ( minuteField, SIGNAL( textChanged ( const QString& ) ), | 178 | connect ( minuteField, SIGNAL( textChanged(const QString&) ), |
179 | this, SLOT ( setMinute ( const QString& ) ) ); | 179 | this, SLOT ( setMinute(const QString&) ) ); |
180 | connect ( hourField, SIGNAL( textChanged ( const QString& ) ), | 180 | connect ( hourField, SIGNAL( textChanged(const QString&) ), |
181 | this, SLOT ( setHour ( const QString& ) ) ); | 181 | this, SLOT ( setHour(const QString&) ) ); |
182 | 182 | ||
183 | } | 183 | } |
184 | 184 | ||
185 | /** | 185 | /** |
186 | * @return the time | 186 | * @return the time |
187 | */ | 187 | */ |
188 | QTime OTimePickerDialog::time()const | 188 | QTime OTimePickerDialog::time()const |
189 | { | 189 | { |
190 | return m_time; | 190 | return m_time; |
191 | } | 191 | } |
192 | 192 | ||
193 | /** | 193 | /** |
194 | * Set the time to time | 194 | * Set the time to time |
195 | * @param time The time to be set | 195 | * @param time The time to be set |
196 | */ | 196 | */ |
197 | void OTimePickerDialog::setTime( const QTime& time ) | 197 | void OTimePickerDialog::setTime( const QTime& time ) |
198 | { | 198 | { |
199 | m_time = time; | 199 | m_time = time; |
200 | 200 | ||
201 | m_timePicker->setHour ( time.hour() ); | 201 | m_timePicker->setHour ( time.hour() ); |
202 | m_timePicker->setMinute( time.minute() ); | 202 | m_timePicker->setMinute( time.minute() ); |
203 | 203 | ||
204 | // Set Textfields | 204 | // Set Textfields |
205 | if ( time.hour() < 10 ) | 205 | if ( time.hour() < 10 ) |
206 | hourField->setText( "0" + QString::number( time.hour() ) ); | 206 | hourField->setText( "0" + QString::number( time.hour() ) ); |
207 | else | 207 | else |
208 | hourField->setText( QString::number( time.hour() ) ); | 208 | hourField->setText( QString::number( time.hour() ) ); |
209 | 209 | ||
210 | if ( time.minute() < 10 ) | 210 | if ( time.minute() < 10 ) |
211 | minuteField->setText( "0" + QString::number( time.minute() ) ); | 211 | minuteField->setText( "0" + QString::number( time.minute() ) ); |
212 | else | 212 | else |
213 | minuteField->setText( QString::number( time.minute() ) ); | 213 | minuteField->setText( QString::number( time.minute() ) ); |
214 | 214 | ||
215 | } | 215 | } |
216 | 216 | ||
217 | /** | 217 | /** |
218 | * This method takes the current minute and tries to set hour | 218 | * This method takes the current minute and tries to set hour |
219 | * to hour. This succeeds if the resulting date is valid | 219 | * to hour. This succeeds if the resulting date is valid |
220 | * @param hour The hour as a string | 220 | * @param hour The hour as a string |
221 | */ | 221 | */ |
222 | void OTimePickerDialog::setHour ( const QString& hour ) | 222 | void OTimePickerDialog::setHour ( const QString& hour ) |
223 | { | 223 | { |
224 | if ( QTime::isValid ( hour.toInt(), m_time.minute() , 00 ) ){ | 224 | if ( QTime::isValid ( hour.toInt(), m_time.minute() , 00 ) ){ |
225 | m_time.setHMS ( hour.toInt(), m_time.minute() , 00 ); | 225 | m_time.setHMS ( hour.toInt(), m_time.minute() , 00 ); |
226 | setTime ( m_time ); | 226 | setTime ( m_time ); |
227 | } | 227 | } |
228 | 228 | ||
229 | } | 229 | } |
230 | 230 | ||
231 | /** | 231 | /** |
232 | * Method to set a new minute. It tries to convert the string to int and | 232 | * Method to set a new minute. It tries to convert the string to int and |
233 | * if the resulting date is valid a new date is set. | 233 | * if the resulting date is valid a new date is set. |
234 | * @see setHour | 234 | * @see setHour |
235 | */ | 235 | */ |
236 | void OTimePickerDialog::setMinute ( const QString& minute ) | 236 | void OTimePickerDialog::setMinute ( const QString& minute ) |
237 | { | 237 | { |
238 | if ( QTime::isValid ( m_time.hour(), minute.toInt(), 00 ) ){ | 238 | if ( QTime::isValid ( m_time.hour(), minute.toInt(), 00 ) ){ |
239 | m_time.setHMS ( m_time.hour(), minute.toInt(), 00 ); | 239 | m_time.setHMS ( m_time.hour(), minute.toInt(), 00 ); |
240 | setTime ( m_time ); | 240 | setTime ( m_time ); |
241 | } | 241 | } |
242 | } | 242 | } |