navigatorbar.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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( QWidget *parent, const char *name )
00060 : QWidget( parent, name ), mHasMinWidth( false )
00061 {
00062 QBoxLayout *topLayout = new QHBoxLayout( this );
00063
00064
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
00078 mMonth = new ActiveLabel( mCtrlFrame );
00079 mMonth->setFont( tfont );
00080 mMonth->setAlignment( AlignCenter );
00081 QToolTip::add( mMonth, i18n("Select a month") );
00082
00083 QPixmap pix;
00084
00085 mPrevYear = new QPushButton( mCtrlFrame );
00086 pix = KOGlobals::self()->smallIcon( isRTL ? "2rightarrow" : "2leftarrow" );
00087 mPrevYear->setPixmap( pix );
00088 mPrevYear->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
00089 QToolTip::add( mPrevYear, i18n("Previous year") );
00090
00091 pix = KOGlobals::self()->smallIcon( isRTL ? "1rightarrow" : "1leftarrow");
00092 mPrevMonth = new QPushButton( mCtrlFrame );
00093 mPrevMonth->setPixmap( pix );
00094 mPrevMonth->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
00095 QToolTip::add( mPrevMonth, i18n("Previous month") );
00096
00097
00098 pix = KOGlobals::self()->smallIcon( isRTL ? "1leftarrow" : "1rightarrow");
00099 mNextMonth = new QPushButton( mCtrlFrame );
00100 mNextMonth->setPixmap( pix );
00101 mNextMonth->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
00102 QToolTip::add( mNextMonth, i18n("Next month") );
00103
00104 pix = KOGlobals::self()->smallIcon( isRTL ? "2leftarrow" : "2rightarrow");
00105 mNextYear = new QPushButton( mCtrlFrame );
00106 mNextYear->setPixmap( pix );
00107 mNextYear->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
00108 QToolTip::add( mNextYear, i18n("Next year") );
00109
00110
00111 QBoxLayout *ctrlLayout = new QHBoxLayout( mCtrlFrame, 1 );
00112 ctrlLayout->addWidget( mPrevYear, 3 );
00113 ctrlLayout->addWidget( mPrevMonth, 3 );
00114 ctrlLayout->addSpacing( 2 );
00115 ctrlLayout->addWidget( mMonth, 3 );
00116 ctrlLayout->addSpacing( 2 );
00117 ctrlLayout->addWidget( mNextMonth, 3 );
00118 ctrlLayout->addWidget( mNextYear, 3 );
00119
00120 connect( mPrevYear, SIGNAL( clicked() ), SIGNAL( goPrevYear() ) );
00121 connect( mPrevMonth, SIGNAL( clicked() ), SIGNAL( goPrevMonth() ) );
00122 connect( mNextMonth, SIGNAL( clicked() ), SIGNAL( goNextMonth() ) );
00123 connect( mNextYear, SIGNAL( clicked() ), SIGNAL( goNextYear() ) );
00124 connect( mMonth, SIGNAL( clicked() ), SLOT( selectMonth() ) );
00125 }
00126
00127 NavigatorBar::~NavigatorBar()
00128 {
00129 }
00130
00131 void NavigatorBar::showButtons( bool left, bool right )
00132 {
00133 if ( left ) {
00134 mPrevYear->show();
00135 mPrevMonth->show();
00136 } else {
00137 mPrevYear->hide();
00138 mPrevMonth->hide();
00139 }
00140
00141 if ( right ) {
00142 mNextYear->show();
00143 mNextMonth->show();
00144 } else {
00145 mNextYear->hide();
00146 mNextMonth->hide();
00147 }
00148
00149 }
00150
00151 void NavigatorBar::selectDates( const KCal::DateList &dateList )
00152 {
00153 if ( dateList.count() > 0 ) {
00154 mDate = dateList.first();
00155
00156 const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
00157
00158 if ( !mHasMinWidth ) {
00159
00160 int i;
00161 int maxwidth = 0;
00162
00163 for( i = 1; i <= calSys->monthsInYear( mDate ); ++i ) {
00164 int w = QFontMetrics( mMonth->font() ).width( QString("%1 8888")
00165 .arg( calSys->monthName( i, calSys->year( mDate ) ) ) );
00166 if ( w > maxwidth ) maxwidth = w;
00167 }
00168 mMonth->setMinimumWidth( maxwidth );
00169
00170 mHasMinWidth = true;
00171 }
00172
00173
00174 mMonth->setText( QString("%1 %2").arg( calSys->monthName( mDate ) )
00175 .arg( calSys->year( mDate ) ) );
00176 }
00177 }
00178
00179 void NavigatorBar::selectMonth()
00180 {
00181
00182 const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
00183
00184 int i, month, months = calSys->monthsInYear( mDate );
00185
00186 QPopupMenu *popup = new QPopupMenu( mMonth );
00187
00188 for ( i = 1; i <= months; i++ )
00189 popup->insertItem( calSys->monthName( i, calSys->year( mDate ) ), i );
00190
00191 popup->setActiveItem( calSys->month( mDate ) - 1 );
00192 popup->setMinimumWidth( mMonth->width() );
00193
00194 if ( ( month = popup->exec( mMonth->mapToGlobal( QPoint( 0, 0 ) ),
00195 calSys->month( mDate ) - 1 ) ) == -1 ) {
00196 delete popup;
00197 return;
00198 }
00199
00200 emit goMonth( month );
00201
00202 delete popup;
00203 }
00204
00205 #include "navigatorbar.moc"
This file is part of the documentation for korganizer Library Version 3.3.2.