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 /*
00002                              This file is part of the Opie Project
00003                              Copyright (C) Stefan Eilers <eilers.stefan@epost.de>
00004               =.             Copyright (C) The Opie Team <opie-devel@handhelds.org>
00005             .=l.
00006            .>+-=
00007  _;:,     .>    :=|.         This program is free software; you can
00008 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00009 :`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
00010 .="- .-=="i,     .._         License as published by the Free Software
00011  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00012      ._= =}       :          or (at your option) any later version.
00013     .%`+i>       _;_.
00014     .i_,=:_.      -<s.       This program is distributed in the hope that
00015      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00016     : ..    .:,     . . .    without even the implied warranty of
00017     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00018   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00019 ..}^=.=       =       ;      Library General Public License for more
00020 ++=   -.     .`     .:       details.
00021  :     =  ...= . :.=-
00022  -.   .:....=;==+<;          You should have received a copy of the GNU
00023   -_. . .   )=.  =           Library General Public License along with
00024     --        :-=`           this library; see the file COPYING.LIB.
00025                              If not, write to the Free Software Foundation,
00026                              Inc., 59 Temple Place - Suite 330,
00027                              Boston, MA 02111-1307, USA.
00028 */
00029 
00030 /* OPIE */
00031 #include "otimepicker.h"
00032 
00033 /* QT */
00034 #include <qgroupbox.h>
00035 #include <qlayout.h>
00036 #include <qlineedit.h>
00037 
00038 
00039 
00040 namespace Opie {
00041 namespace Ui {
00042 
00049 OTimePicker::OTimePicker(QWidget* parent, const char* name, Qt::WFlags fl)
00050             :QWidget(parent,name,fl)
00051 {
00052     QVBoxLayout *vbox=new QVBoxLayout(this);
00053 
00054     OClickableLabel *r;
00055     QString s;
00056 
00057     // Hour Row
00058     QWidget *row=new QWidget(this);
00059     QHBoxLayout *l=new QHBoxLayout(row);
00060     vbox->addWidget(row);
00061 
00062     for (int i=0; i<24; i++)
00063     {
00064         r=new OClickableLabel(row);
00065         hourLst.append(r);
00066         s.sprintf("%.2d",i);
00067         r->setText(s);
00068         r->setToggleButton(true);
00069         r->setAlignment(AlignHCenter | AlignVCenter);
00070         l->addWidget(r);
00071         connect(r, SIGNAL(toggled(bool)),
00072                 this, SLOT(slotHour(bool)));
00073 
00074         if (i==11)
00075         { // Second row
00076             row=new QWidget(this);
00077             l=new QHBoxLayout(row);
00078             vbox->addWidget(row);
00079         }
00080     }
00081 
00082     // Minute Row
00083     row=new QWidget(this);
00084     l=new QHBoxLayout(row);
00085     vbox->addWidget(row);
00086 
00087     for (int i=0; i<60; i+=5)
00088     {
00089         r=new OClickableLabel(row);
00090         minuteLst.append(r);
00091         s.sprintf("%.2d",i);
00092         r->setText(s);
00093         r->setToggleButton(true);
00094         r->setAlignment(AlignHCenter | AlignVCenter);
00095         l->addWidget(r);
00096         connect(r, SIGNAL(toggled(bool)),
00097                 this, SLOT(slotMinute(bool)));
00098     }
00099 }
00100 
00105 QTime OTimePicker::time()const
00106 {
00107     return tm;
00108 }
00109 
00110 void OTimePicker::slotHour(bool b)
00111 {
00112 
00113     OClickableLabel *r = (OClickableLabel *) sender();
00114 
00115     if (b)
00116     {
00117         QValueListIterator<OClickableLabel *> it;
00118         for (it=hourLst.begin(); it!=hourLst.end(); it++)
00119         {
00120             if (*it != r) (*it)->setOn(false);
00121             else tm.setHMS((*it)->text().toInt(), tm.minute(), 0);
00122         }
00123         emit timeChanged(tm);
00124     }
00125     else
00126     {
00127         r->setOn(true);
00128     }
00129 
00130 }
00131 
00132 void OTimePicker::slotMinute(bool b)
00133 {
00134 
00135     OClickableLabel *r = (OClickableLabel *) sender();
00136 
00137     if (b)
00138     {
00139         QValueListIterator<OClickableLabel *> it;
00140         for (it=minuteLst.begin(); it!=minuteLst.end(); it++)
00141         {
00142             if (*it != r) (*it)->setOn(false);
00143             else tm.setHMS(tm.hour(),(*it)->text().toInt(), 0);
00144         }
00145         emit timeChanged(tm);
00146     }
00147     else
00148     {
00149         r->setOn(true);
00150     }
00151 
00152 }
00153 
00159 void OTimePicker::setTime( const QTime& t)
00160 {
00161     setTime( t.hour(), t.minute() );
00162 }
00163 
00169 void OTimePicker::setTime( int h,  int m )
00170 {
00171     setHour(h);
00172     setMinute(m);
00173 }
00174 
00175 /*
00176  * FIXME round minutes to the 5 minute arrangement -zecke
00177  */
00182 void OTimePicker::setMinute(int m)
00183 {
00184 
00185     QString minute;
00186     minute.sprintf("%.2d",m);
00187 
00188     QValueListIterator<OClickableLabel *> it;
00189     for (it=minuteLst.begin(); it!=minuteLst.end(); it++)
00190     {
00191         if ((*it)->text() == minute) (*it)->setOn(true);
00192         else (*it)->setOn(false);
00193     }
00194 
00195     tm.setHMS(tm.hour(),m,0);
00196 }
00197 
00201 void OTimePicker::setHour(int h)
00202 {
00203 
00204     QString hour;
00205     hour.sprintf("%.2d",h);
00206 
00207     QValueListIterator<OClickableLabel *> it;
00208     for (it=hourLst.begin(); it!=hourLst.end(); it++)
00209     {
00210         if ((*it)->text() == hour) (*it)->setOn(true);
00211         else (*it)->setOn(false);
00212     }
00213     tm.setHMS(h,tm.minute(),0);
00214 }
00215 
00216 
00224 OTimePickerDialog::OTimePickerDialog ( QWidget* parent, const char* name, WFlags fl )
00225         : OTimePickerDialogBase (parent , name, true , fl)
00226 {
00227     m_timePicker = new OTimePicker(  GroupBox1, "m_timePicker" );
00228     GroupBox1Layout->addWidget( m_timePicker, 0, 0 );
00229 
00230     connect ( m_timePicker, SIGNAL( timeChanged(const QTime&) ),
00231               this, SLOT( setTime(const QTime&) ) );
00232     connect ( minuteField, SIGNAL( textChanged(const QString&) ),
00233               this, SLOT ( setMinute(const QString&) ) );
00234     connect ( hourField, SIGNAL( textChanged(const QString&) ),
00235               this, SLOT ( setHour(const QString&) ) );
00236 
00237 }
00238 
00242 QTime OTimePickerDialog::time()const
00243 {
00244     return m_time;
00245 }
00246 
00251 void OTimePickerDialog::setTime( const QTime& time )
00252 {
00253     m_time = time;
00254 
00255     m_timePicker->setHour ( time.hour() );
00256     m_timePicker->setMinute( time.minute() );
00257 
00258     // Set Textfields
00259     if ( time.hour() < 10 )
00260         hourField->setText( "0" + QString::number( time.hour() ) );
00261     else
00262         hourField->setText( QString::number( time.hour() ) );
00263 
00264     if ( time.minute() < 10 )
00265         minuteField->setText( "0" + QString::number( time.minute() ) );
00266     else
00267         minuteField->setText( QString::number( time.minute() ) );
00268 
00269 }
00270 
00276 void OTimePickerDialog::setHour ( const QString& hour )
00277 {
00278     if ( QTime::isValid ( hour.toInt(),  m_time.minute() , 00 ) )
00279     {
00280         m_time.setHMS ( hour.toInt(),  m_time.minute() , 00 );
00281         setTime ( m_time );
00282     }
00283 
00284 }
00285 
00291 void OTimePickerDialog::setMinute ( const QString& minute )
00292 {
00293     if ( QTime::isValid ( m_time.hour(), minute.toInt(), 00 ) )
00294     {
00295         m_time.setHMS ( m_time.hour(), minute.toInt(), 00 );
00296         setTime ( m_time );
00297     }
00298 }
00299 
00300 }
00301 }

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