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