korganizer Library API Documentation

kdatenavigator.cpp

00001 /* 00002 This file is part of KOrganizer. 00003 00004 Copyright (c) 2001,2002,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 <qkeycode.h> 00027 #include <qlayout.h> 00028 #include <qtimer.h> 00029 #include <qframe.h> 00030 #include <qlabel.h> 00031 00032 #include <kdebug.h> 00033 #include <klocale.h> 00034 #include <kglobal.h> 00035 #include <kglobalsettings.h> 00036 00037 #include "koglobals.h" 00038 #include "koprefs.h" 00039 #ifndef KORG_NOPLUGINS 00040 #include "kocore.h" 00041 #endif 00042 #include "kodaymatrix.h" 00043 00044 #include <kcalendarsystem.h> 00045 00046 #include "navigatorbar.h" 00047 00048 #include "kdatenavigator.h" 00049 00050 KDateNavigator::KDateNavigator( QWidget *parent, const char *name ) 00051 : QFrame( parent, name ) 00052 { 00053 setFrameStyle( QFrame::NoFrame ); 00054 00055 QGridLayout *topLayout = new QGridLayout( this, 8, 8 ); 00056 00057 mNavigatorBar = new NavigatorBar( this ); 00058 topLayout->addMultiCellWidget( mNavigatorBar, 0, 0, 0, 7 ); 00059 00060 connect( mNavigatorBar, SIGNAL( goPrevYear() ), SIGNAL( goPrevYear() ) ); 00061 connect( mNavigatorBar, SIGNAL( goPrevMonth() ), SIGNAL( goPrevMonth() ) ); 00062 connect( mNavigatorBar, SIGNAL( goNextMonth() ), SIGNAL( goNextMonth() ) ); 00063 connect( mNavigatorBar, SIGNAL( goNextYear() ), SIGNAL( goNextYear() ) ); 00064 connect( mNavigatorBar, SIGNAL( goMonth( int ) ), SIGNAL( goMonth( int ) ) ); 00065 00066 int i; 00067 QString generalFont = KGlobalSettings::generalFont().family(); 00068 00069 // Set up the heading fields. 00070 for( i = 0; i < 7; i++ ) { 00071 headings[i] = new QLabel( this ); 00072 headings[i]->setFont( QFont( generalFont, 10, QFont::Bold ) ); 00073 headings[i]->setAlignment( AlignCenter ); 00074 00075 topLayout->addWidget( headings[i], 1, i + 1 ); 00076 } 00077 00078 // Create the weeknumber labels 00079 for( i = 0; i < 6; i++ ) { 00080 weeknos[i] = new QLabel( this ); 00081 weeknos[i]->setAlignment( AlignCenter ); 00082 weeknos[i]->setFont( QFont( generalFont, 10 ) ); 00083 weeknos[i]->installEventFilter( this ); 00084 00085 topLayout->addWidget( weeknos[i], i + 2, 0 ); 00086 } 00087 00088 mDayMatrix = new KODayMatrix( this, "KDateNavigator::dayMatrix" ); 00089 mDayMatrix->setFrameStyle( QFrame::Panel | QFrame::Sunken ); 00090 mDayMatrix->setLineWidth( 1 ); 00091 00092 connect( mDayMatrix, SIGNAL( selected( const KCal::DateList & ) ), 00093 SIGNAL( datesSelected( const KCal::DateList & ) ) ); 00094 00095 connect( mDayMatrix, SIGNAL( incidenceDropped( Incidence * ) ), 00096 SIGNAL( incidenceDropped( Incidence * ) ) ); 00097 connect( mDayMatrix, SIGNAL( incidenceDroppedMove( Incidence * , Incidence * ) ), 00098 SIGNAL( incidenceDroppedMove( Incidence *, Incidence * ) ) ); 00099 00100 00101 topLayout->addMultiCellWidget( mDayMatrix, 2, 7, 1, 7 ); 00102 00103 // read settings from configuration file. 00104 updateConfig(); 00105 } 00106 00107 KDateNavigator::~KDateNavigator() 00108 { 00109 } 00110 00111 void KDateNavigator::setCalendar( Calendar *cal ) 00112 { 00113 mDayMatrix->setCalendar( cal ); 00114 } 00115 00116 void KDateNavigator::setBaseDate( const QDate &date ) 00117 { 00118 mBaseDate = date; 00119 00120 updateDates(); 00121 updateView(); 00122 00123 KCal::DateList dates; 00124 dates.append( date ); 00125 mNavigatorBar->selectDates( dates ); 00126 00127 mDayMatrix->clearSelection(); 00128 mDayMatrix->repaint(); 00129 } 00130 00131 QSizePolicy KDateNavigator::sizePolicy () const 00132 { 00133 return QSizePolicy( QSizePolicy::MinimumExpanding, 00134 QSizePolicy::MinimumExpanding ); 00135 } 00136 00137 void KDateNavigator::updateToday() 00138 { 00139 if ( mDayMatrix->isEndOfMonth() ) { 00140 goNextMonth(); 00141 } 00142 mDayMatrix->recalculateToday(); 00143 mDayMatrix->repaint(); 00144 } 00145 00146 void KDateNavigator::updateDates() 00147 { 00148 // Find the first day of the week of the current month. 00149 //int d1 = KOGlobals::self()->calendarSystem()->day( mBaseDate ); 00150 QDate dayone( mBaseDate.year(), mBaseDate.month(), mBaseDate.day() ); 00151 int d2 = KOGlobals::self()->calendarSystem()->day( dayone ); 00152 //int di = d1 - d2 + 1; 00153 dayone = dayone.addDays( -d2 + 1 ); 00154 00155 int m_fstDayOfWkCalsys = KOGlobals::self()->calendarSystem()->dayOfWeek( 00156 dayone ); 00157 00158 // If month begins on Monday and Monday is first day of week, 00159 // month should begin on second line. Sunday doesn't have this problem. 00160 int nextLine = ( ( m_fstDayOfWkCalsys == 1) && 00161 ( KGlobal::locale()->weekStartDay() == 1 ) ) ? 7 : 0; 00162 00163 // update the matrix dates 00164 int index = ( KGlobal::locale()->weekStartDay() == 1 ? 1 : 0 ) - 00165 m_fstDayOfWkCalsys - nextLine; 00166 00167 mDayMatrix->updateView( dayone.addDays( index ) ); 00168 00169 // each updateDates is followed by an updateView -> repaint is issued there ! 00170 // mDayMatrix->repaint(); 00171 } 00172 00173 void KDateNavigator::updateDayMatrix() 00174 { 00175 mDayMatrix->updateView(); 00176 mDayMatrix->repaint(); 00177 } 00178 00179 00180 void KDateNavigator::updateView() 00181 { 00182 // kdDebug() << "KDateNavigator::updateView()" << endl; 00183 00184 setUpdatesEnabled( false ); 00185 00186 int i; 00187 00188 // kdDebug(5850) << "updateView() -> mDayMatrix->updateView()" << endl; 00189 mDayMatrix->updateView(); 00190 00191 // set the week numbers. 00192 for( i = 0; i < 6; i++ ) { 00193 QString weeknum; 00194 // remember, according to ISO 8601, the first week of the year is the 00195 // first week that contains a thursday. Thus we must subtract off 4, 00196 // not just 1. 00197 00198 //ET int dayOfYear = buttons[(i + 1) * 7 - 4]->date().dayOfYear(); 00199 int dayOfYear = KOGlobals::self()->calendarSystem()->dayOfYear( 00200 ( mDayMatrix->getDate( ( i + 1 ) * 7 - 4 ) ) ); 00201 00202 if ( dayOfYear % 7 != 0 ) 00203 weeknum.setNum( dayOfYear / 7 + 1 ); 00204 else 00205 weeknum.setNum( dayOfYear / 7 ); 00206 weeknos[i]->setText( weeknum ); 00207 } 00208 00209 setUpdatesEnabled( true ); 00210 00211 // kdDebug(5850) << "updateView() -> repaint()" << endl; 00212 repaint(); 00213 mDayMatrix->repaint(); 00214 } 00215 00216 void KDateNavigator::updateConfig() 00217 { 00218 int day; 00219 for( int i = 0; i < 7; i++ ) { 00220 // take the first letter of the day name to be the abbreviation 00221 if ( KGlobal::locale()->weekStartDay() == 1 ) { 00222 day = i + 1; 00223 } else { 00224 if ( i == 0 ) day = 7; 00225 else day = i; 00226 } 00227 QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( day, 00228 true ); 00229 if ( KOPrefs::instance()->mCompactDialogs ) dayName = dayName.left( 1 ); 00230 headings[i]->setText( dayName ); 00231 } 00232 00233 // FIXME: Use actual config setting here 00234 // setShowWeekNums( true ); 00235 } 00236 00237 void KDateNavigator::setShowWeekNums( bool enabled ) 00238 { 00239 for( int i = 0; i < 6; i++ ) { 00240 if( enabled ) 00241 weeknos[i]->show(); 00242 else 00243 weeknos[i]->hide(); 00244 } 00245 } 00246 00247 void KDateNavigator::selectDates( const DateList &dateList ) 00248 { 00249 if ( dateList.count() > 0 ) { 00250 mNavigatorBar->selectDates( dateList ); 00251 00252 mSelectedDates = dateList; 00253 00254 // set our record of the month and year that this datetbl is 00255 // displaying. 00256 mBaseDate = mSelectedDates.first(); 00257 00258 updateDates(); 00259 00260 mDayMatrix->setSelectedDaysFrom( *( dateList.begin() ), 00261 *( --dateList.end() ) ); 00262 00263 updateView(); 00264 } 00265 } 00266 00267 void KDateNavigator::wheelEvent ( QWheelEvent *e ) 00268 { 00269 if( e->delta() > 0 ) emit goPrevious(); 00270 else emit goNext(); 00271 00272 e->accept(); 00273 } 00274 00275 bool KDateNavigator::eventFilter ( QObject *o, QEvent *e ) 00276 { 00277 if ( e->type() == QEvent::MouseButtonPress ) { 00278 int i; 00279 for( i = 0; i < 6; ++i ) { 00280 if ( o == weeknos[ i ] ) { 00281 QDate weekstart = mDayMatrix->getDate( i * 7 ); 00282 emit weekClicked( weekstart ); 00283 break; 00284 } 00285 } 00286 return true; 00287 } else { 00288 return false; 00289 } 00290 } 00291 00292 #include "kdatenavigator.moc"
KDE Logo
This file is part of the documentation for korganizer Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Oct 1 15:19:30 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003