korganizer

datenavigatorcontainer.cpp

00001 /*
00002     This file is part of KOrganizer.
00003 
00004     Copyright (c) 2001,2002,2003 Cornelius Schumacher <schumacher@kde.org>
00005     Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00006 
00007     This program is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020 
00021     As a special exception, permission is given to link this program
00022     with any edition of Qt, and distribute the resulting executable,
00023     without including the source code for Qt in the source distribution.
00024 */
00025 
00026 #include <kdebug.h>
00027 #include <klocale.h>
00028 
00029 #include "koglobals.h"
00030 #include "navigatorbar.h"
00031 #include "kdatenavigator.h"
00032 
00033 #include <kcalendarsystem.h>
00034 #include <kdialog.h>
00035 
00036 #include "datenavigatorcontainer.h"
00037 
00038 #include <qwhatsthis.h>
00039 #include <qtimer.h>
00040 
00041 DateNavigatorContainer::DateNavigatorContainer( QWidget *parent,
00042                                                 const char *name )
00043   : QFrame( parent, name ), mCalendar( 0 ),
00044     mHorizontalCount( 1 ), mVerticalCount( 1 )
00045 {
00046   mExtraViews.setAutoDelete( true );
00047   setFrameStyle( QFrame::Sunken | QFrame::StyledPanel );
00048 
00049   mNavigatorView = new KDateNavigator( this, name );
00050   QWhatsThis::add( mNavigatorView,
00051                    i18n( "<qt><p>Select the dates you want to "
00052                          "display in KOrganizer's main view here. Hold down the "
00053                          "mouse button to select more than one day.</p>"
00054                          "<p>Press the top buttons to browse to the next "
00055                          "/ previous months or years.</p>"
00056                          "<p>Each line shows a week. The number in the left "
00057                          "column is the number of the week in the year. "
00058                          "Press it to select the whole week.</p>"
00059                          "</qt>" ) );
00060 
00061   connectNavigatorView( mNavigatorView );
00062 }
00063 
00064 DateNavigatorContainer::~DateNavigatorContainer()
00065 {
00066 }
00067 
00068 void DateNavigatorContainer::connectNavigatorView( KDateNavigator *v )
00069 {
00070   connect( v, SIGNAL( datesSelected( const KCal::DateList & ) ),
00071            SIGNAL( datesSelected( const KCal::DateList & ) ) );
00072   connect( v, SIGNAL( incidenceDropped( Incidence *, const QDate & ) ),
00073            SIGNAL( incidenceDropped( Incidence *, const QDate & ) ) );
00074   connect( v, SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ),
00075            SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ) );
00076   connect( v, SIGNAL( weekClicked( const QDate & ) ),
00077            SIGNAL( weekClicked( const QDate & ) ) );
00078 
00079   connect( v, SIGNAL( goPrevious() ), SIGNAL( goPrevious() ) );
00080   connect( v, SIGNAL( goNext() ), SIGNAL( goNext() ) );
00081 
00082   connect( v, SIGNAL( goNextMonth() ), SIGNAL( goNextMonth() ) );
00083   connect( v, SIGNAL( goPrevMonth() ), SIGNAL( goPrevMonth() ) );
00084   connect( v, SIGNAL( goNextYear() ), SIGNAL( goNextYear() ) );
00085   connect( v, SIGNAL( goPrevYear() ), SIGNAL( goPrevYear() ) );
00086 
00087   connect( v, SIGNAL( goMonth( int ) ), SIGNAL( goMonth( int ) ) );
00088 }
00089 
00090 void DateNavigatorContainer::setCalendar( Calendar *cal )
00091 {
00092   mCalendar = cal;
00093   mNavigatorView->setCalendar( cal );
00094   KDateNavigator *n;
00095   for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
00096     n->setCalendar( cal );
00097   }
00098 }
00099 
00100 // TODO_Recurrence: let the navigators update just once, and tell them that
00101 // if data has changed or just the selection (because then the list of dayss
00102 // with events doesn't have to be updated if the month stayed the same
00103 void DateNavigatorContainer::updateDayMatrix()
00104 {
00105   mNavigatorView->updateDayMatrix();
00106   KDateNavigator *n;
00107   for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
00108     n->updateDayMatrix();
00109   }
00110 }
00111 
00112 void DateNavigatorContainer::updateToday()
00113 {
00114   mNavigatorView->updateToday();
00115   KDateNavigator *n;
00116   for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
00117     n->updateToday();
00118   }
00119 }
00120 
00121 void DateNavigatorContainer::updateView()
00122 {
00123   mNavigatorView->updateView();
00124   KDateNavigator *n;
00125   for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
00126     n->updateView();
00127   }
00128 }
00129 
00130 void DateNavigatorContainer::updateConfig()
00131 {
00132   mNavigatorView->updateConfig();
00133   KDateNavigator *n;
00134   for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
00135     n->updateConfig();
00136   }
00137 }
00138 
00139 void DateNavigatorContainer::selectDates( const DateList &dateList )
00140 {
00141   if ( !dateList.isEmpty() ) {
00142     QDate start( dateList.first() );
00143     QDate end( dateList.last() );
00144     QDate navfirst( mNavigatorView->startDate() );
00145     QDate navsecond; // start of the second shown month if existant
00146     QDate navlast;
00147     if ( !mExtraViews.isEmpty() ) {
00148       navlast = mExtraViews.last()->endDate();
00149       navsecond = mExtraViews.first()->startDate();
00150     } else {
00151       navlast = mNavigatorView->endDate();
00152       navsecond = navfirst;
00153     }
00154     if ( start < navfirst // <- start should always be visible
00155          // end is not visible and we have a spare month at the beginning:
00156          || ( end > navlast && start >= navsecond ) ) {
00157       // Change the shown months so that the beginning of the date list is visible
00158       setBaseDates( start );
00159     }
00160 
00161     mNavigatorView->selectDates( dateList );
00162     KDateNavigator *n = mExtraViews.first();
00163     while ( n ) {
00164       n->selectDates( dateList );
00165       n = mExtraViews.next();
00166     }
00167   }
00168 }
00169 
00170 void DateNavigatorContainer::setBaseDates( const QDate &start )
00171 {
00172   QDate baseDate = start;
00173   mNavigatorView->setBaseDate( baseDate );
00174   for( KDateNavigator *n = mExtraViews.first(); n; n = mExtraViews.next() ) {
00175     baseDate = KOGlobals::self()->calendarSystem()->addMonths( baseDate, 1 );
00176     n->setBaseDate( baseDate );
00177   }
00178 }
00179 
00180 void DateNavigatorContainer::resizeEvent( QResizeEvent * )
00181 {
00182 #if 0
00183   kdDebug(5850) << "DateNavigatorContainer::resizeEvent()" << endl;
00184   kdDebug(5850) << "  CURRENT SIZE: " << size() << endl;
00185   kdDebug(5850) << "  MINIMUM SIZEHINT: " << minimumSizeHint() << endl;
00186   kdDebug(5850) << "  SIZEHINT: " << sizeHint() << endl;
00187   kdDebug(5850) << "  MINIMUM SIZE: " << minimumSize() << endl;
00188 #endif
00189   QTimer::singleShot( 0, this, SLOT( resizeAllContents() ) );
00190 }
00191 
00192 void DateNavigatorContainer::resizeAllContents()
00193 {
00194   QSize minSize = mNavigatorView->minimumSizeHint();
00195 
00196 //  kdDebug(5850) << "  NAVIGATORVIEW minimumSizeHint: " << minSize << endl;
00197 
00198   int margin = KDialog::spacingHint();
00199   int verticalCount = ( size().height() - margin*2 ) / minSize.height();
00200   int horizontalCount = ( size().width() - margin*2 ) / minSize.width();
00201 
00202   if ( horizontalCount != mHorizontalCount ||
00203        verticalCount != mVerticalCount ) {
00204     uint count = horizontalCount * verticalCount;
00205     if ( count == 0 ) return;
00206 
00207     while ( count > ( mExtraViews.count() + 1 ) ) {
00208       KDateNavigator *n = new KDateNavigator( this );
00209       mExtraViews.append( n );
00210       n->setCalendar( mCalendar );
00211       connectNavigatorView( n );
00212     }
00213 
00214     while ( count < ( mExtraViews.count() + 1 ) ) {
00215       mExtraViews.removeLast();
00216     }
00217 
00218     mHorizontalCount = horizontalCount;
00219     mVerticalCount = verticalCount;
00220     selectDates( mNavigatorView->selectedDates() );
00221     for( KDateNavigator *n = mExtraViews.first(); n; n = mExtraViews.next() ) {
00222       n->show();
00223     }
00224   }
00225 
00226   int height = (size().height() - margin*2) / verticalCount;
00227   int width = (size().width() - margin*2) / horizontalCount;
00228 
00229   NavigatorBar *bar = mNavigatorView->navigatorBar();
00230   if ( horizontalCount > 1 ) bar->showButtons( true, false );
00231   else bar->showButtons( true, true );
00232 
00233   mNavigatorView->setGeometry(
00234       ( ( (KOGlobals::self()->reverseLayout())?(horizontalCount-1):0) * width ) + margin,
00235         margin, width, height );
00236   for( uint i = 0; i < mExtraViews.count(); ++i ) {
00237     int x = ( i + 1 ) % horizontalCount;
00238     int y = ( i + 1 ) / horizontalCount;
00239 
00240     KDateNavigator *view = mExtraViews.at( i );
00241     bar = view->navigatorBar();
00242     if ( y > 0 ) bar->showButtons( false, false );
00243     else {
00244         if ( x + 1 == horizontalCount ) bar->showButtons( false, true );
00245         else bar->showButtons( false, false );
00246     }
00247     view->setGeometry(
00248         ( ( (KOGlobals::self()->reverseLayout())?(horizontalCount-1-x):x) * width ) + margin,
00249           ( y * height ) + margin, width, height );
00250   }
00251 }
00252 
00253 QSize DateNavigatorContainer::minimumSizeHint() const
00254 {
00255   int margin = KDialog::spacingHint() * 2;
00256   return mNavigatorView->minimumSizeHint() + QSize( margin, margin );
00257 }
00258 
00259 QSize DateNavigatorContainer::sizeHint() const
00260 {
00261   int margin = KDialog::spacingHint() * 2;
00262   return mNavigatorView->sizeHint() + QSize( margin, margin );
00263 }
00264 
00265 #include "datenavigatorcontainer.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys