summaryrefslogtreecommitdiff
path: root/libopie/otimepicker.cpp
Unidiff
Diffstat (limited to 'libopie/otimepicker.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/otimepicker.cpp175
1 files changed, 175 insertions, 0 deletions
diff --git a/libopie/otimepicker.cpp b/libopie/otimepicker.cpp
new file mode 100644
index 0000000..8e8a4e7
--- a/dev/null
+++ b/libopie/otimepicker.cpp
@@ -0,0 +1,175 @@
1#include "otimepicker.h"
2
3#include <qbuttongroup.h>
4#include <qtoolbutton.h>
5#include <qlayout.h>
6#include <qstring.h>
7#include <stdio.h>
8#include <qlineedit.h>
9
10OTimePicker::OTimePicker(QWidget* parent, const char* name,
11 WFlags fl) :
12 QWidget(parent,name,fl)
13{
14 QVBoxLayout *vbox=new QVBoxLayout(this);
15
16 OClickableLabel *r;
17 QString s;
18
19 // Hour Row
20 QWidget *row=new QWidget(this);
21 QHBoxLayout *l=new QHBoxLayout(row);
22 vbox->addWidget(row);
23
24
25 for (int i=0; i<24; i++) {
26 r=new OClickableLabel(row);
27 hourLst.append(r);
28 s.sprintf("%.2d",i);
29 r->setText(s);
30 r->setToggleButton(true);
31 r->setAlignment(AlignHCenter | AlignVCenter);
32 l->addWidget(r);
33 connect(r, SIGNAL(toggled(bool)),
34 this, SLOT(slotHour(bool)));
35
36 if (i==11) { // Second row
37 row=new QWidget(this);
38 l=new QHBoxLayout(row);
39 vbox->addWidget(row);
40 }
41 }
42
43 // Minute Row
44 row=new QWidget(this);
45 l=new QHBoxLayout(row);
46 vbox->addWidget(row);
47
48 for (int i=0; i<60; i+=5) {
49 r=new OClickableLabel(row);
50 minuteLst.append(r);
51 s.sprintf("%.2d",i);
52 r->setText(s);
53 r->setToggleButton(true);
54 r->setAlignment(AlignHCenter | AlignVCenter);
55 l->addWidget(r);
56 connect(r, SIGNAL(toggled(bool)),
57 this, SLOT(slotMinute(bool)));
58 }
59}
60
61void OTimePicker::slotHour(bool b) {
62
63 OClickableLabel *r = (OClickableLabel *) sender();
64
65 if (b) {
66 QValueListIterator<OClickableLabel *> it;
67 for (it=hourLst.begin(); it!=hourLst.end(); it++) {
68 if (*it != r) (*it)->setOn(false);
69 else tm.setHMS((*it)->text().toInt(), tm.minute(), 0);
70 }
71 emit timeChanged(tm);
72 } else {
73 r->setOn(true);
74 }
75
76}
77
78void OTimePicker::slotMinute(bool b) {
79
80 OClickableLabel *r = (OClickableLabel *) sender();
81
82 if (b) {
83 QValueListIterator<OClickableLabel *> it;
84 for (it=minuteLst.begin(); it!=minuteLst.end(); it++) {
85 if (*it != r) (*it)->setOn(false);
86 else tm.setHMS(tm.hour(),(*it)->text().toInt(), 0);
87 }
88 emit timeChanged(tm);
89 } else {
90 r->setOn(true);
91 }
92
93}
94
95void OTimePicker::setMinute(int m) {
96
97 QString minute;
98 minute.sprintf("%.2d",m);
99
100 QValueListIterator<OClickableLabel *> it;
101 for (it=minuteLst.begin(); it!=minuteLst.end(); it++) {
102 if ((*it)->text() == minute) (*it)->setOn(true);
103 else (*it)->setOn(false);
104 }
105
106 tm.setHMS(tm.hour(),m,0);
107}
108
109void OTimePicker::setHour(int h) {
110
111 QString hour;
112 hour.sprintf("%.2d",h);
113
114 QValueListIterator<OClickableLabel *> it;
115 for (it=hourLst.begin(); it!=hourLst.end(); it++) {
116 if ((*it)->text() == hour) (*it)->setOn(true);
117 else (*it)->setOn(false);
118 }
119 tm.setHMS(h,tm.minute(),0);
120}
121
122
123OTimePickerDialog::OTimePickerDialog ( QWidget* parent, const char* name, WFlags fl )
124 : OTimePickerDialogBase (parent , name, true , fl)
125{
126
127 connect ( m_timePicker, SIGNAL( timeChanged( const QTime& ) ),
128 this, SLOT( setTime ( const QTime& ) ) );
129 connect ( minuteField, SIGNAL( textChanged ( const QString& ) ),
130 this, SLOT ( setMinute ( const QString& ) ) );
131 connect ( hourField, SIGNAL( textChanged ( const QString& ) ),
132 this, SLOT ( setHour ( const QString& ) ) );
133
134}
135
136QTime& OTimePickerDialog::time()
137{
138 return m_time;
139}
140void OTimePickerDialog::setTime( const QTime& time )
141{
142 m_time = time;
143
144 m_timePicker->setHour ( time.hour() );
145 m_timePicker->setMinute( time.minute() );
146
147 // Set Textfields
148 if ( time.hour() < 10 )
149 hourField->setText( "0" + QString::number( time.hour() ) );
150 else
151 hourField->setText( QString::number( time.hour() ) );
152
153 if ( time.minute() < 10 )
154 minuteField->setText( "0" + QString::number( time.minute() ) );
155 else
156 minuteField->setText( QString::number( time.minute() ) );
157
158}
159
160void OTimePickerDialog::setHour ( const QString& hour )
161{
162 if ( QTime::isValid ( hour.toInt(), m_time.minute() , 00 ) ){
163 m_time.setHMS ( hour.toInt(), m_time.minute() , 00 );
164 setTime ( m_time );
165 }
166
167}
168
169void OTimePickerDialog::setMinute ( const QString& minute )
170{
171 if ( QTime::isValid ( m_time.hour(), minute.toInt(), 00 ) ){
172 m_time.setHMS ( m_time.hour(), minute.toInt(), 00 );
173 setTime ( m_time );
174 }
175}