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