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::setUpdateNeeded()
00122 {
00123   mNavigatorView->setUpdateNeeded();
00124   KDateNavigator *n;
00125   for ( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
00126     n->setUpdateNeeded();
00127   }
00128 }
00129 
00130 void DateNavigatorContainer::updateView()
00131 {
00132   mNavigatorView->updateView();
00133   KDateNavigator *n;
00134   for ( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
00135     n->setUpdateNeeded();
00136   }
00137 }
00138 
00139 void DateNavigatorContainer::updateConfig()
00140 {
00141   mNavigatorView->updateConfig();
00142   KDateNavigator *n;
00143   for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
00144     n->updateConfig();
00145   }
00146 }
00147 
00148 void DateNavigatorContainer::selectDates( const DateList &dateList )
00149 {
00150   if ( !dateList.isEmpty() ) {
00151     QDate start( dateList.first() );
00152     QDate end( dateList.last() );
00153     QDate navfirst( mNavigatorView->startDate() );
00154     QDate navsecond; // start of the second shown month if existant
00155     QDate navlast;
00156     if ( !mExtraViews.isEmpty() ) {
00157       navlast = mExtraViews.last()->endDate();
00158       navsecond = mExtraViews.first()->startDate();
00159     } else {
00160       navlast = mNavigatorView->endDate();
00161       navsecond = navfirst;
00162     }
00163     if ( start < navfirst // <- start should always be visible
00164          // end is not visible and we have a spare month at the beginning:
00165          || ( end > navlast && start >= navsecond ) ) {
00166       // Change the shown months so that the beginning of the date list is visible
00167       setBaseDates( start );
00168     }
00169 
00170     mNavigatorView->selectDates( dateList );
00171     KDateNavigator *n = mExtraViews.first();
00172     while ( n ) {
00173       n->selectDates( dateList );
00174       n = mExtraViews.next();
00175     }
00176   }
00177 }
00178 
00179 void DateNavigatorContainer::setBaseDates( const QDate &start )
00180 {
00181   QDate baseDate = start;
00182   mNavigatorView->setBaseDate( baseDate );
00183   for( KDateNavigator *n = mExtraViews.first(); n; n = mExtraViews.next() ) {
00184     baseDate = KOGlobals::self()->calendarSystem()->addMonths( baseDate, 1 );
00185     n->setBaseDate( baseDate );
00186   }
00187 }
00188 
00189 void DateNavigatorContainer::resizeEvent( QResizeEvent * )
00190 {
00191 #if 0
00192   kdDebug(5850) << "DateNavigatorContainer::resizeEvent()" << endl;
00193   kdDebug(5850) << "  CURRENT SIZE: " << size() << endl;
00194   kdDebug(5850) << "  MINIMUM SIZEHINT: " << minimumSizeHint() << endl;
00195   kdDebug(5850) << "  SIZEHINT: " << sizeHint() << endl;
00196   kdDebug(5850) << "  MINIMUM SIZE: " << minimumSize() << endl;
00197 #endif
00198   QTimer::singleShot( 0, this, SLOT( resizeAllContents() ) );
00199 }
00200 
00201 void DateNavigatorContainer::resizeAllContents()
00202 {
00203   QSize minSize = mNavigatorView->minimumSizeHint();
00204 
00205 //  kdDebug(5850) << "  NAVIGATORVIEW minimumSizeHint: " << minSize << endl;
00206 
00207   int margin = KDialog::spacingHint();
00208   int verticalCount = ( size().height() - margin*2 ) / minSize.height();
00209   int horizontalCount = ( size().width() - margin*2 ) / minSize.width();
00210 
00211   if ( horizontalCount != mHorizontalCount ||
00212        verticalCount != mVerticalCount ) {
00213     uint count = horizontalCount * verticalCount;
00214     if ( count == 0 ) return;
00215 
00216     while ( count > ( mExtraViews.count() + 1 ) ) {
00217       KDateNavigator *n = new KDateNavigator( this );
00218       mExtraViews.append( n );
00219       n->setCalendar( mCalendar );
00220       connectNavigatorView( n );
00221     }
00222 
00223     while ( count < ( mExtraViews.count() + 1 ) ) {
00224       mExtraViews.removeLast();
00225     }
00226 
00227     mHorizontalCount = horizontalCount;
00228     mVerticalCount = verticalCount;
00229     setBaseDates( mNavigatorView->selectedDates().first() );
00230     selectDates( mNavigatorView->selectedDates() );
00231     for( KDateNavigator *n = mExtraViews.first(); n; n = mExtraViews.next() ) {
00232       n->show();
00233     }
00234   }
00235 
00236   int height = (size().height() - margin*2) / verticalCount;
00237   int width = (size().width() - margin*2) / horizontalCount;
00238 
00239   NavigatorBar *bar = mNavigatorView->navigatorBar();
00240   if ( horizontalCount > 1 ) bar->showButtons( true, false );
00241   else bar->showButtons( true, true );
00242 
00243   mNavigatorView->setGeometry(
00244       ( ( (KOGlobals::self()->reverseLayout())?(horizontalCount-1):0) * width ) + margin,
00245         margin, width, height );
00246   for( uint i = 0; i < mExtraViews.count(); ++i ) {
00247     int x = ( i + 1 ) % horizontalCount;
00248     int y = ( i + 1 ) / horizontalCount;
00249 
00250     KDateNavigator *view = mExtraViews.at( i );
00251     bar = view->navigatorBar();
00252     if ( y > 0 ) bar->showButtons( false, false );
00253     else {
00254         if ( x + 1 == horizontalCount ) bar->showButtons( false, true );
00255         else bar->showButtons( false, false );
00256     }
00257     view->setGeometry(
00258         ( ( (KOGlobals::self()->reverseLayout())?(horizontalCount-1-x):x) * width ) + margin,
00259           ( y * height ) + margin, width, height );
00260   }
00261 }
00262 
00263 QSize DateNavigatorContainer::minimumSizeHint() const
00264 {
00265   int margin = KDialog::spacingHint() * 2;
00266   return mNavigatorView->minimumSizeHint() + QSize( margin, margin );
00267 }
00268 
00269 QSize DateNavigatorContainer::sizeHint() const
00270 {
00271   int margin = KDialog::spacingHint() * 2;
00272   return mNavigatorView->sizeHint() + QSize( margin, margin );
00273 }
00274 
00275 #include "datenavigatorcontainer.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys