korganizer Library API Documentation

navigatorbar.cpp

00001 /*
00002     This file is part of KOrganizer.
00003 
00004     Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 
00020     As a special exception, permission is given to link this program
00021     with any edition of Qt, and distribute the resulting executable,
00022     without including the source code for Qt in the source distribution.
00023 */
00024 
00025 #include <qstring.h>
00026 #include <qtooltip.h>
00027 #include <qpushbutton.h>
00028 #include <qlayout.h>
00029 #include <qframe.h>
00030 #include <qpopupmenu.h>
00031 #include <qlabel.h>
00032 
00033 #include <kdebug.h>
00034 #include <klocale.h>
00035 #include <kglobal.h>
00036 #include <kiconloader.h>
00037 
00038 #include "koglobals.h"
00039 #include "koprefs.h"
00040 #ifndef KORG_NOPLUGINS
00041 #include "kocore.h"
00042 #endif
00043 
00044 #include <kcalendarsystem.h>
00045 
00046 #include "navigatorbar.h"
00047 
00048 ActiveLabel::ActiveLabel( QWidget *parent, const char *name )
00049   : QLabel( parent, name )
00050 {
00051 }
00052 
00053 void ActiveLabel::mouseReleaseEvent( QMouseEvent * )
00054 {
00055   emit clicked();
00056 }
00057 
00058 
00059 NavigatorBar::NavigatorBar( const QDate & date, QWidget *parent, const char *name )
00060   : QWidget( parent, name ), mDate(date)
00061 {
00062   QBoxLayout *topLayout = new QHBoxLayout( this );
00063 
00064   // Set up the control buttons and date label
00065   mCtrlFrame = new QFrame( this );
00066   mCtrlFrame->setFrameStyle( QFrame::Panel | QFrame::Raised );
00067   mCtrlFrame->setLineWidth( 1 );
00068 
00069   topLayout->addWidget( mCtrlFrame );
00070 
00071   QFont tfont = font();
00072   tfont.setPointSize( 10 );
00073   tfont.setBold( false );
00074 
00075   bool isRTL = KOGlobals::self()->reverseLayout();
00076 
00077   // Create month name button
00078   mMonth = new ActiveLabel( mCtrlFrame );
00079   mMonth->setFont( tfont );
00080   mMonth->setAlignment( AlignCenter );
00081   QToolTip::add( mMonth, i18n("Select a Month") );
00082 
00083   // Set minimum width to width of widest month name label
00084   int i;
00085   int maxwidth = 0;
00086 
00087   const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
00088   for( i = 1; i <= calSys->monthsInYear(date); ++i ) {
00089     int w = QFontMetrics(tfont).width( QString("%1 8888").arg(calSys->monthName( i, calSys->year(date) )) );
00090     if ( w > maxwidth ) maxwidth = w;
00091   }
00092   mMonth->setMinimumWidth( maxwidth );
00093 
00094   // Create backward navigation buttons
00095   mPrevYear = new QPushButton( mCtrlFrame );
00096   mPrevYear->setPixmap( KOGlobals::self()->smallIcon( isRTL ? "2rightarrow" : "2leftarrow" ) );
00097   mPrevYear->setMinimumHeight(mMonth->height());
00098   QToolTip::add( mPrevYear, i18n("Previous year") );
00099 
00100   mPrevMonth = new QPushButton( mCtrlFrame );
00101   mPrevMonth->setPixmap( KOGlobals::self()->smallIcon( isRTL ? "1rightarrow" : "1leftarrow") );
00102   mPrevMonth->setMinimumHeight(mMonth->height());
00103   QToolTip::add( mPrevMonth, i18n("Previous month") );
00104 
00105   // Create forward navigation buttons
00106   mNextMonth = new QPushButton( mCtrlFrame );
00107   mNextMonth->setPixmap( KOGlobals::self()->smallIcon( isRTL ? "1leftarrow" : "1rightarrow") );
00108   mNextMonth->setMinimumHeight(mMonth->height());
00109   QToolTip::add( mNextMonth, i18n("Next month") );
00110 
00111   mNextYear = new QPushButton( mCtrlFrame );
00112   mNextYear->setPixmap( KOGlobals::self()->smallIcon( isRTL ? "2leftarrow" : "2rightarrow") );
00113   mNextYear->setMinimumHeight(mMonth->height());
00114   QToolTip::add( mNextYear, i18n("Next year") );
00115 
00116   // set up control frame layout
00117   QBoxLayout *ctrlLayout = new QHBoxLayout( mCtrlFrame, 1 );
00118   ctrlLayout->addWidget( mPrevYear, 3 );
00119   ctrlLayout->addWidget( mPrevMonth, 3 );
00120   ctrlLayout->addSpacing( 2 );
00121   ctrlLayout->addWidget( mMonth, 3 );
00122   ctrlLayout->addSpacing( 2 );
00123   ctrlLayout->addWidget( mNextMonth, 3 );
00124   ctrlLayout->addWidget( mNextYear, 3 );
00125 
00126   connect( mPrevYear, SIGNAL( clicked() ), SIGNAL( goPrevYear() ) );
00127   connect( mPrevMonth, SIGNAL( clicked() ), SIGNAL( goPrevMonth() ) );
00128   connect( mNextMonth, SIGNAL( clicked() ), SIGNAL( goNextMonth() ) );
00129   connect( mNextYear, SIGNAL( clicked() ), SIGNAL( goNextYear() ) );
00130   connect( mMonth, SIGNAL( clicked() ), SLOT( selectMonth() ) );
00131 }
00132 
00133 NavigatorBar::~NavigatorBar()
00134 {
00135 }
00136 
00137 void NavigatorBar::selectDates( const KCal::DateList &dateList )
00138 {
00139   if (dateList.count() > 0) {
00140     mDate = dateList.first();
00141 
00142     const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
00143 
00144     // compute the label at the top of the navigator
00145     mMonth->setText( QString("%1 %2").arg(calSys->monthName( mDate )).arg(calSys->year(mDate)) );
00146   }
00147 }
00148 
00149 void NavigatorBar::selectMonth()
00150 {
00151   // every year can have different month names (in some calendar systems)
00152   const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
00153 
00154   int i, month, months = calSys->monthsInYear( mDate );
00155 
00156   QPopupMenu *popup = new QPopupMenu( mMonth );
00157 
00158   for ( i = 1; i <= months; i++ )
00159     popup->insertItem( calSys->monthName( i, calSys->year( mDate ) ), i );
00160 
00161   popup->setActiveItem( calSys->month( mDate ) - 1 );
00162   popup->setMinimumWidth( mMonth->width() );
00163 
00164   if ( ( month = popup->exec( mMonth->mapToGlobal( QPoint( 0, 0 ) ),
00165                               calSys->month( mDate ) - 1 ) ) == -1 ) {
00166     delete popup;
00167     return;  // canceled
00168   }
00169 
00170   emit goMonth( month );
00171 
00172   delete popup;
00173 }
00174 
00175 #include "navigatorbar.moc"
KDE Logo
This file is part of the documentation for korganizer Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:38:31 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003