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

datebookweekheaderimpl.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 "datebookweekheaderimpl.h"
00032 #include "datebookweek.h"
00033 
00034 #include <opie2/odebug.h>
00035 #include <opie2/oresource.h>
00036 
00037 #include <qpe/datebookmonth.h>
00038 
00039 #include <qtoolbutton.h>
00040 
00041 /*
00042  *  Constructs a DateBookWeekHeader which is a child of 'parent', with the
00043  *  name 'name' and widget flags set to 'f'
00044  */
00045 DateBookWeekHeader::DateBookWeekHeader( bool startOnMonday, QWidget* parent, const char* name, WFlags fl )
00046     : DateBookWeekHeaderBase( parent, name, fl ),
00047       bStartOnMonday( startOnMonday )
00048 {
00049         setBackgroundMode( PaletteButton );
00050         labelDate->setBackgroundMode( PaletteButton );
00051         backmonth->setPixmap( Opie::Core::OResource::loadPixmap( "fastback", Opie::Core::OResource::SmallIcon ) );
00052         backweek->setPixmap( Opie::Core::OResource::loadPixmap( "back", Opie::Core::OResource::SmallIcon ) );
00053         forwardweek->setPixmap( Opie::Core::OResource::loadPixmap( "forward", Opie::Core::OResource::SmallIcon ) );
00054         forwardmonth->setPixmap( Opie::Core::OResource::loadPixmap( "fastforward", Opie::Core::OResource::SmallIcon ) );
00055 }
00056 
00057 /*
00058  *  Destroys the object and frees any allocated resources
00059  */
00060 DateBookWeekHeader::~DateBookWeekHeader()
00061 {
00062     // no need to delete child widgets, Qt does it all for us
00063 }
00064 
00065 void DateBookWeekHeader::pickDate()
00066 {
00067         static QPopupMenu *m1 = 0;
00068         static DateBookMonth *picker = 0;
00069         if ( !m1 ) {
00070                 m1 = new QPopupMenu( this );
00071                 picker = new DateBookMonth( m1, 0, TRUE );
00072                 m1->insertItem( picker );
00073                 connect( picker, SIGNAL( dateClicked(int,int,int) ), this, SLOT( setDate(int,int,int) ) );
00074 //              connect( m1, SIGNAL( aboutToHide() ), this, SLOT( gotHide() ) );
00075         }
00076         picker->setDate( date.year(), date.month(), date.day() );
00077         m1->popup(mapToGlobal(labelDate->pos()+QPoint(0,labelDate->height())));
00078         picker->setFocus();
00079 }
00080 
00081 void DateBookWeekHeader::nextMonth()
00082 {
00083         owarn << "nextMonth()" << oendl;
00084         setDate(date.addDays(28));
00085 }
00086 void DateBookWeekHeader::prevMonth()
00087 {
00088         owarn << "prevMonth()" << oendl;
00089         setDate(date.addDays(-28));
00090 }
00091 void DateBookWeekHeader::nextWeek()
00092 {
00093         owarn << "nextWeek()" << oendl;
00094         setDate(date.addDays(7));
00095 }
00096 void DateBookWeekHeader::prevWeek()
00097 {
00098         owarn << "prevWeek()" << oendl;
00099         setDate(date.addDays(-7));
00100 }
00101 
00102 void DateBookWeekHeader::setDate( int y, int m, int d )
00103 {
00104         setDate(QDate(y,m,d));
00105 }
00106 
00107 void DateBookWeekHeader::setDate(const QDate &d) {
00108         int year,week,dayofweek;
00109         date=d;
00110         dayofweek=d.dayOfWeek();
00111         if(bStartOnMonday)
00112             dayofweek--;
00113         else if( dayofweek == 7 )
00114             // we already have the right day -7 would lead to the current week..
00115             dayofweek = 0;
00116 
00117         date=date.addDays(-dayofweek);
00118         calcWeek(date,week,year,bStartOnMonday);
00119         QDate start=date;
00120         QDate stop=start.addDays(6);
00121         labelDate->setText( QString::number(start.day()) + "." +
00122                         Calendar::nameOfMonth( start.month()) + "-" +
00123                         QString::number(stop.day()) + "." +
00124                         Calendar::nameOfMonth( stop.month()) +" ("+
00125                         tr("w")+":"+QString::number( week ) +")");
00126         date = d; // bugfix: 0001126 - date has to be the selected date, not monday!
00127         emit dateChanged(date);
00128 }
00129 
00130 void DateBookWeekHeader::setStartOfWeek( bool onMonday )
00131 {
00132         bStartOnMonday = onMonday;
00133         setDate( date );
00134 }

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