libopie API Documentation

otimepicker.cpp

00001 #include "otimepicker.h"
00002 
00003 #include <qbuttongroup.h>
00004 #include <qtoolbutton.h>
00005 #include <qlayout.h>
00006 #include <qstring.h>
00007 #include <stdio.h>
00008 #include <qlineedit.h>
00009 
00010 
00017 OTimePicker::OTimePicker(QWidget* parent, const char* name,
00018                WFlags fl) :
00019   QWidget(parent,name,fl)
00020 {
00021 
00022   QVBoxLayout *vbox=new QVBoxLayout(this);
00023 
00024   OClickableLabel *r;
00025   QString s;
00026 
00027   // Hour Row
00028   QWidget *row=new QWidget(this);
00029   QHBoxLayout *l=new QHBoxLayout(row);
00030   vbox->addWidget(row);
00031 
00032 
00033   for (int i=0; i<24; i++) {
00034     r=new OClickableLabel(row);
00035     hourLst.append(r);
00036     s.sprintf("%.2d",i);
00037     r->setText(s);
00038     r->setToggleButton(true);
00039     r->setAlignment(AlignHCenter | AlignVCenter);
00040     l->addWidget(r);
00041     connect(r, SIGNAL(toggled(bool)),
00042         this, SLOT(slotHour(bool)));
00043 
00044     if (i==11) { // Second row
00045       row=new QWidget(this);
00046       l=new QHBoxLayout(row);
00047       vbox->addWidget(row);
00048     }
00049   }
00050 
00051   // Minute Row
00052   row=new QWidget(this);
00053   l=new QHBoxLayout(row);
00054   vbox->addWidget(row);
00055 
00056   for (int i=0; i<60; i+=5) {
00057     r=new OClickableLabel(row);
00058     minuteLst.append(r);
00059     s.sprintf("%.2d",i);
00060     r->setText(s);
00061     r->setToggleButton(true);
00062     r->setAlignment(AlignHCenter | AlignVCenter);
00063     l->addWidget(r);
00064     connect(r, SIGNAL(toggled(bool)),
00065         this, SLOT(slotMinute(bool)));
00066   }
00067 }
00068 
00073 QTime OTimePicker::time()const {
00074     return tm;
00075 }
00076 
00077 void OTimePicker::slotHour(bool b) {
00078 
00079   OClickableLabel *r = (OClickableLabel *) sender();
00080 
00081   if (b) {
00082     QValueListIterator<OClickableLabel *> it;
00083     for (it=hourLst.begin(); it!=hourLst.end(); it++) {
00084       if (*it != r) (*it)->setOn(false);
00085       else tm.setHMS((*it)->text().toInt(), tm.minute(), 0);
00086     }
00087     emit timeChanged(tm);
00088   } else {
00089     r->setOn(true);
00090   }
00091 
00092 }
00093 
00094 void OTimePicker::slotMinute(bool b) {
00095 
00096   OClickableLabel *r = (OClickableLabel *) sender();
00097 
00098   if (b) {
00099     QValueListIterator<OClickableLabel *> it;
00100     for (it=minuteLst.begin(); it!=minuteLst.end(); it++) {
00101       if (*it != r) (*it)->setOn(false);
00102       else tm.setHMS(tm.hour(),(*it)->text().toInt(), 0);
00103     }
00104     emit timeChanged(tm);
00105   } else {
00106     r->setOn(true);
00107   }
00108 
00109 }
00110 
00116 void OTimePicker::setTime( const QTime& t) {
00117     setTime( t.hour(), t.minute() );
00118 }
00119 
00125 void OTimePicker::setTime( int h,  int m ) {
00126     setHour(h);
00127     setMinute(m);
00128 }
00129 
00130 /*
00131  * FIXME round minutes to the 5 minute arrangement -zecke
00132  */
00137 void OTimePicker::setMinute(int m) {
00138 
00139   QString minute;
00140   minute.sprintf("%.2d",m);
00141 
00142   QValueListIterator<OClickableLabel *> it;
00143   for (it=minuteLst.begin(); it!=minuteLst.end(); it++) {
00144     if ((*it)->text() == minute) (*it)->setOn(true);
00145     else (*it)->setOn(false);
00146   }
00147 
00148   tm.setHMS(tm.hour(),m,0);
00149 }
00150 
00154 void OTimePicker::setHour(int h) {
00155 
00156   QString hour;
00157   hour.sprintf("%.2d",h);
00158 
00159   QValueListIterator<OClickableLabel *> it;
00160   for (it=hourLst.begin(); it!=hourLst.end(); it++) {
00161     if ((*it)->text() == hour) (*it)->setOn(true);
00162     else (*it)->setOn(false);
00163   }
00164   tm.setHMS(h,tm.minute(),0);
00165 }
00166 
00167 
00175 OTimePickerDialog::OTimePickerDialog ( QWidget* parent, const char* name, WFlags fl )
00176     : OTimePickerDialogBase (parent , name, true , fl)
00177 {
00178 
00179     connect ( m_timePicker, SIGNAL( timeChanged( const QTime& ) ),
00180           this, SLOT( setTime ( const QTime& ) ) );
00181     connect ( minuteField, SIGNAL( textChanged ( const QString& ) ),
00182           this, SLOT ( setMinute ( const QString& ) ) );
00183     connect ( hourField, SIGNAL( textChanged ( const QString& ) ),
00184           this, SLOT ( setHour ( const QString& ) ) );
00185 
00186 }
00187 
00191 QTime OTimePickerDialog::time()const
00192 {
00193     return m_time;
00194 }
00195 
00200 void OTimePickerDialog::setTime( const QTime& time )
00201 {
00202     m_time = time;
00203 
00204     m_timePicker->setHour ( time.hour() );
00205     m_timePicker->setMinute( time.minute() );
00206 
00207     // Set Textfields
00208     if ( time.hour() < 10 )
00209         hourField->setText( "0" + QString::number( time.hour() ) );
00210     else
00211         hourField->setText( QString::number( time.hour() ) );
00212 
00213     if ( time.minute() < 10 )
00214         minuteField->setText( "0" + QString::number( time.minute() ) );
00215     else
00216         minuteField->setText( QString::number( time.minute() ) );
00217 
00218 }
00219 
00225 void OTimePickerDialog::setHour ( const QString& hour )
00226 {
00227     if ( QTime::isValid ( hour.toInt(),  m_time.minute() , 00 ) ){
00228         m_time.setHMS ( hour.toInt(),  m_time.minute() , 00 );
00229         setTime ( m_time );
00230     }
00231 
00232 }
00233 
00239 void OTimePickerDialog::setMinute ( const QString& minute )
00240 {
00241     if ( QTime::isValid ( m_time.hour(), minute.toInt(), 00 ) ){
00242         m_time.setHMS ( m_time.hour(), minute.toInt(), 00 );
00243         setTime ( m_time );
00244     }
00245 }
KDE Logo
This file is part of the documentation for OPIE Version 1.1.
Documentation copyright © 1997-2003 the KDE developers. 2003 OPIE developers
Generated on Tue Feb 10 20:24:45 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001