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

datebookdayheaderimpl.cpp

Go to the documentation of this file.
00001 /*
00002                              This file is part of the Opie Project
00003 
00004                              Copyright (C) Opie Team <opie-devel@handhelds.org>
00005               =.
00006             .=l.
00007            .>+-=
00008  _;:,     .>    :=|.         This program is free software; you can
00009 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00010 :`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
00011 .="- .-=="i,     .._         License as published by the Free Software
00012  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00013      ._= =}       :          or (at your option) any later version.
00014     .%`+i>       _;_.
00015     .i_,=:_.      -<s.       This program is distributed in the hope that
00016      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00017     : ..    .:,     . . .    without even the implied warranty of
00018     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00019   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00020 ..}^=.=       =       ;      Library General Public License for more
00021 ++=   -.     .`     .:       details.
00022 :     =  ...= . :.=-
00023  -.   .:....=;==+<;          You should have received a copy of the GNU
00024   -_. . .   )=.  =           Library General Public License along with
00025     --        :-=`           this library; see the file COPYING.LIB.
00026                              If not, write to the Free Software Foundation,
00027                              Inc., 59 Temple Place - Suite 330,
00028                              Boston, MA 02111-1307, USA.
00029 */
00030 
00031 #include "datebookdayheaderimpl.h"
00032 
00033 #include <opie2/oresource.h>
00034 
00035 #include <qpe/datebookmonth.h>
00036 
00037 #include <qbuttongroup.h>
00038 #include <qtoolbutton.h>
00039 
00040 
00041 /*
00042  *  Constructs a DateBookDayHeader which is a child of 'parent', with the
00043  *  name 'name' and widget flags set to 'f'
00044  *
00045  *  The dialog will by default be modeless, unless you set 'modal' to
00046  *  TRUE to construct a modal dialog.
00047  */
00048 DateBookDayHeader::DateBookDayHeader( bool useMonday,
00049                                       QWidget* parent,  const char* name )
00050     : DateBookDayHeaderBase( parent, name ),
00051       bUseMonday( useMonday )
00052 {
00053     connect(date,SIGNAL(pressed()),this,SLOT(pickDate()));
00054 
00055     setupNames();
00056 
00057     forward->setPixmap(  Opie::Core::OResource::loadPixmap( "forward" ) );
00058     back->setPixmap(  Opie::Core::OResource::loadPixmap( "back" ) );
00059     forwardweek->setPixmap(  Opie::Core::OResource::loadPixmap( "fastforward" ) );
00060     backweek->setPixmap(  Opie::Core::OResource::loadPixmap( "fastback" ) );
00061 
00062     setBackgroundMode( PaletteButton );
00063     grpDays->setBackgroundMode( PaletteButton );
00064 }
00065 
00066 /*
00067  *  Destroys the object and frees any allocated resources
00068  */
00069 DateBookDayHeader::~DateBookDayHeader()
00070 {
00071     // no need to delete child widgets, Qt does it all for us
00072 }
00073 
00074 void DateBookDayHeader::setStartOfWeek( bool onMonday )
00075 {
00076     bUseMonday = onMonday;
00077     setupNames();
00078     setDate( currDate.year(), currDate.month(), currDate.day() );
00079 }
00080 
00081 void DateBookDayHeader::setupNames()
00082 {
00083     if ( bUseMonday ) {
00084         cmdDay1->setText( DateBookDayHeaderBase::tr("Monday").left(1) );
00085         cmdDay2->setText( DateBookDayHeaderBase::tr("Tuesday").left(1) );
00086         cmdDay3->setText( DateBookDayHeaderBase::tr("Wednesday").left(1) );
00087         cmdDay4->setText( DateBookDayHeaderBase::tr("Thursday").left(1) );
00088         cmdDay5->setText( DateBookDayHeaderBase::tr("Friday").left(1) );
00089         cmdDay6->setText( DateBookDayHeaderBase::tr("Saturday").left(1) );
00090         cmdDay7->setText( DateBookDayHeaderBase::tr("Sunday").left(1) );
00091     } else {
00092         cmdDay1->setText( DateBookDayHeaderBase::tr("Sunday").left(1) );
00093         cmdDay2->setText( DateBookDayHeaderBase::tr("Monday").left(1) );
00094         cmdDay3->setText( DateBookDayHeaderBase::tr("Tuesday").left(1) );
00095         cmdDay4->setText( DateBookDayHeaderBase::tr("Wednesday").left(1) );
00096         cmdDay5->setText( DateBookDayHeaderBase::tr("Thursday").left(1) );
00097         cmdDay6->setText( DateBookDayHeaderBase::tr("Friday").left(1) );
00098         cmdDay7->setText( DateBookDayHeaderBase::tr("Saturday").left(1) );
00099     }
00100 }
00101 
00102 
00103 void DateBookDayHeader::pickDate()
00104 {
00105     static QPopupMenu *m1 = 0;
00106     static DateBookMonth *picker = 0;
00107     if ( !m1 ) {
00108         m1 = new QPopupMenu( this );
00109         picker = new DateBookMonth( m1, 0, TRUE );
00110         m1->insertItem( picker );
00111         connect( picker, SIGNAL( dateClicked(int,int,int) ),
00112                  this, SLOT( setDate(int,int,int) ) );
00113         connect( m1, SIGNAL( aboutToHide() ),
00114                  this, SLOT( gotHide() ) );
00115     }
00116     picker->setDate( currDate.year(), currDate.month(), currDate.day() );
00117     m1->popup(mapToGlobal(date->pos()+QPoint(0,date->height())));
00118     picker->setFocus();
00119 }
00120 
00121 void DateBookDayHeader::gotHide()
00122 {
00123     // we have to redo the button...
00124     date->setDown( false );
00125 }
00126 
00127 /*
00128  * public slot
00129  */
00130 void DateBookDayHeader::goBack()
00131 {
00132     currDate = currDate.addDays( -1 );
00133     setDate( currDate.year(), currDate.month(), currDate.day() );
00134 }
00135 /*
00136  * public slot
00137  */
00138 void DateBookDayHeader::goForward()
00139 {
00140     currDate = currDate.addDays( 1 );
00141     setDate( currDate.year(), currDate.month(), currDate.day() );
00142 }
00143 /*
00144  * public slot
00145  */
00146 void DateBookDayHeader::goBackWeek()
00147 {
00148     currDate = currDate.addDays( -7 );
00149     setDate( currDate.year(), currDate.month(), currDate.day() );
00150 }
00151 /*
00152  * public slot
00153  */
00154 void DateBookDayHeader::goForwardWeek()
00155 {
00156     currDate = currDate.addDays( 7 );
00157     setDate( currDate.year(), currDate.month(), currDate.day() );
00158 }
00159 
00160 
00161 /*
00162  * public slot
00163  */
00164 void DateBookDayHeader::setDate( int y, int m, int d )
00165 {
00166     currDate.setYMD( y, m, d );
00167     date->setText( TimeString::shortDate( currDate ) );
00168 
00169     int iDayOfWeek = currDate.dayOfWeek();
00170     // cleverly adjust the day depending on how we start the week
00171     if ( bUseMonday )
00172         iDayOfWeek--;
00173     else {
00174         if ( iDayOfWeek == 7 )  // Sunday
00175             iDayOfWeek = 0;
00176     }
00177     grpDays->setButton( iDayOfWeek );
00178     emit dateChanged( y, m, d );
00179 }
00180 
00181 /*
00182  * public slot
00183  */
00184 void DateBookDayHeader::setDay( int day )
00185 {
00186     int realDay;
00187     int dayOfWeek = currDate.dayOfWeek();
00188 
00189     // a little adjustment is needed...
00190     if ( bUseMonday )
00191         realDay = day + 1 ;
00192     else if ( !bUseMonday && day == 0 ) // sunday
00193         realDay = 7;
00194     else
00195         realDay = day;
00196     // special cases first...
00197     if ( realDay == 7 && !bUseMonday )  {
00198         while ( currDate.dayOfWeek() != realDay )
00199             currDate = currDate.addDays( -1 );
00200     } else if ( !bUseMonday && dayOfWeek == 7 && dayOfWeek > realDay ) {
00201         while ( currDate.dayOfWeek() != realDay )
00202             currDate = currDate.addDays( 1 );
00203     } else if ( dayOfWeek < realDay ) {
00204         while ( currDate.dayOfWeek() < realDay )
00205             currDate = currDate.addDays( 1 );
00206     } else if ( dayOfWeek > realDay ) {
00207         while ( currDate.dayOfWeek() > realDay )
00208             currDate = currDate.addDays( -1 );
00209     }
00210     // update the date...
00211     setDate( currDate.year(), currDate.month(), currDate.day() );
00212 }

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