Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

otimepicker.cpp

Go to the documentation of this file.
00001 #include "otimepicker.h"
00002 
00003 #include <qlayout.h>
00004 #include <stdio.h>
00005 #include <qlineedit.h>
00006 
00007 
00014 OTimePicker::OTimePicker(QWidget* parent, const char* name,
00015                        WFlags fl) :
00016   QWidget(parent,name,fl)
00017 {
00018 
00019   QVBoxLayout *vbox=new QVBoxLayout(this);
00020 
00021   OClickableLabel *r;
00022   QString s;
00023 
00024   // Hour Row
00025   QWidget *row=new QWidget(this);
00026   QHBoxLayout *l=new QHBoxLayout(row);
00027   vbox->addWidget(row);
00028 
00029 
00030   for (int i=0; i<24; i++) {
00031     r=new OClickableLabel(row);
00032     hourLst.append(r);
00033     s.sprintf("%.2d",i);
00034     r->setText(s);
00035     r->setToggleButton(true);
00036     r->setAlignment(AlignHCenter | AlignVCenter);
00037     l->addWidget(r);
00038     connect(r, SIGNAL(toggled(bool)),
00039             this, SLOT(slotHour(bool)));
00040 
00041     if (i==11) { // Second row
00042       row=new QWidget(this);
00043       l=new QHBoxLayout(row);
00044       vbox->addWidget(row);
00045     }
00046   }
00047 
00048   // Minute Row
00049   row=new QWidget(this);
00050   l=new QHBoxLayout(row);
00051   vbox->addWidget(row);
00052 
00053   for (int i=0; i<60; i+=5) {
00054     r=new OClickableLabel(row);
00055     minuteLst.append(r);
00056     s.sprintf("%.2d",i);
00057     r->setText(s);
00058     r->setToggleButton(true);
00059     r->setAlignment(AlignHCenter | AlignVCenter);
00060     l->addWidget(r);
00061     connect(r, SIGNAL(toggled(bool)),
00062             this, SLOT(slotMinute(bool)));
00063   }
00064 }
00065 
00070 QTime OTimePicker::time()const {
00071     return tm;
00072 }
00073 
00074 void OTimePicker::slotHour(bool b) {
00075 
00076   OClickableLabel *r = (OClickableLabel *) sender();
00077 
00078   if (b) {
00079     QValueListIterator<OClickableLabel *> it;
00080     for (it=hourLst.begin(); it!=hourLst.end(); it++) {
00081       if (*it != r) (*it)->setOn(false);
00082       else tm.setHMS((*it)->text().toInt(), tm.minute(), 0);
00083     }
00084     emit timeChanged(tm);
00085   } else {
00086     r->setOn(true);
00087   }
00088 
00089 }
00090 
00091 void OTimePicker::slotMinute(bool b) {
00092 
00093   OClickableLabel *r = (OClickableLabel *) sender();
00094 
00095   if (b) {
00096     QValueListIterator<OClickableLabel *> it;
00097     for (it=minuteLst.begin(); it!=minuteLst.end(); it++) {
00098       if (*it != r) (*it)->setOn(false);
00099       else tm.setHMS(tm.hour(),(*it)->text().toInt(), 0);
00100     }
00101     emit timeChanged(tm);
00102   } else {
00103     r->setOn(true);
00104   }
00105 
00106 }
00107 
00113 void OTimePicker::setTime( const QTime& t) {
00114     setTime( t.hour(), t.minute() );
00115 }
00116 
00122 void OTimePicker::setTime( int h,  int m ) {
00123     setHour(h);
00124     setMinute(m);
00125 }
00126 
00127 /*
00128  * FIXME round minutes to the 5 minute arrangement -zecke
00129  */
00134 void OTimePicker::setMinute(int m) {
00135 
00136   QString minute;
00137   minute.sprintf("%.2d",m);
00138 
00139   QValueListIterator<OClickableLabel *> it;
00140   for (it=minuteLst.begin(); it!=minuteLst.end(); it++) {
00141     if ((*it)->text() == minute) (*it)->setOn(true);
00142     else (*it)->setOn(false);
00143   }
00144 
00145   tm.setHMS(tm.hour(),m,0);
00146 }
00147 
00151 void OTimePicker::setHour(int h) {
00152 
00153   QString hour;
00154   hour.sprintf("%.2d",h);
00155 
00156   QValueListIterator<OClickableLabel *> it;
00157   for (it=hourLst.begin(); it!=hourLst.end(); it++) {
00158     if ((*it)->text() == hour) (*it)->setOn(true);
00159     else (*it)->setOn(false);
00160   }
00161   tm.setHMS(h,tm.minute(),0);
00162 }
00163 
00164 
00172 OTimePickerDialog::OTimePickerDialog ( QWidget* parent, const char* name, WFlags fl )
00173         : OTimePickerDialogBase (parent , name, true , fl)
00174 {
00175 
00176         connect ( m_timePicker, SIGNAL( timeChanged(const QTime&) ),
00177                   this, SLOT( setTime(const QTime&) ) );
00178         connect ( minuteField, SIGNAL( textChanged(const QString&) ),
00179                   this, SLOT ( setMinute(const QString&) ) );
00180         connect ( hourField, SIGNAL( textChanged(const QString&) ),
00181                   this, SLOT ( setHour(const QString&) ) );
00182 
00183 }
00184 
00188 QTime OTimePickerDialog::time()const
00189 {
00190         return m_time;
00191 }
00192 
00197 void OTimePickerDialog::setTime( const QTime& time )
00198 {
00199         m_time = time;
00200 
00201         m_timePicker->setHour ( time.hour() );
00202         m_timePicker->setMinute( time.minute() );
00203 
00204         // Set Textfields
00205         if ( time.hour() < 10 )
00206                 hourField->setText( "0" + QString::number( time.hour() ) );
00207         else
00208                 hourField->setText( QString::number( time.hour() ) );
00209 
00210         if ( time.minute() < 10 )
00211                 minuteField->setText( "0" + QString::number( time.minute() ) );
00212         else
00213                 minuteField->setText( QString::number( time.minute() ) );
00214 
00215 }
00216 
00222 void OTimePickerDialog::setHour ( const QString& hour )
00223 {
00224         if ( QTime::isValid ( hour.toInt(),  m_time.minute() , 00 ) ){
00225                 m_time.setHMS ( hour.toInt(),  m_time.minute() , 00 );
00226                 setTime ( m_time );
00227         }
00228 
00229 }
00230 
00236 void OTimePickerDialog::setMinute ( const QString& minute )
00237 {
00238         if ( QTime::isValid ( m_time.hour(), minute.toInt(), 00 ) ){
00239                 m_time.setHMS ( m_time.hour(), minute.toInt(), 00 );
00240                 setTime ( m_time );
00241         }
00242 }

Generated on Sat Nov 5 16:16:28 2005 for OPIE by  doxygen 1.4.2