korganizer Library API Documentation

datenavigatorcontainer.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 <kdebug.h>
00026 #include <klocale.h>
00027 
00028 #include "koglobals.h"
00029 #include "navigatorbar.h"
00030 #include "kdatenavigator.h"
00031 
00032 #include <kcalendarsystem.h>
00033 
00034 #include "datenavigatorcontainer.h"
00035 
00036 DateNavigatorContainer::DateNavigatorContainer( QWidget *parent,
00037                                                 const char *name )
00038   : QWidget( parent, name ), mCalendar( 0 ), 
00039     mHorizontalCount( 1 ), mVerticalCount( 1 )
00040 {
00041   mExtraViews.setAutoDelete( true );
00042 
00043   mNavigatorView = new KDateNavigator( this, name );
00044 
00045   connectNavigatorView( mNavigatorView );
00046 }
00047 
00048 DateNavigatorContainer::~DateNavigatorContainer()
00049 {
00050 }
00051 
00052 void DateNavigatorContainer::connectNavigatorView( KDateNavigator *v )
00053 {
00054   connect( v, SIGNAL( datesSelected( const KCal::DateList & ) ),
00055            SIGNAL( datesSelected( const KCal::DateList & ) ) );
00056   connect( v, SIGNAL( incidenceDropped( Incidence * ) ),
00057            SIGNAL( incidenceDropped( Incidence * ) ) );
00058   connect( v, SIGNAL( incidenceDroppedMove( Incidence *, Incidence * ) ),
00059            SIGNAL( incidenceDroppedMove( Incidence *, Incidence * ) ) );
00060   connect( v, SIGNAL( weekClicked( const QDate & ) ),
00061            SIGNAL( weekClicked( const QDate & ) ) );
00062 
00063   connect( v, SIGNAL( goPrevious() ), SIGNAL( goPrevious() ) );
00064   connect( v, SIGNAL( goNext() ), SIGNAL( goNext() ) );
00065 
00066   connect( v, SIGNAL( goNextMonth() ), SIGNAL( goNextMonth() ) );
00067   connect( v, SIGNAL( goPrevMonth() ), SIGNAL( goPrevMonth() ) );
00068   connect( v, SIGNAL( goNextYear() ), SIGNAL( goNextYear() ) );
00069   connect( v, SIGNAL( goPrevYear() ), SIGNAL( goPrevYear() ) );
00070 
00071   connect( v, SIGNAL( goMonth( int ) ), SIGNAL( goMonth( int ) ) );
00072 }
00073 
00074 void DateNavigatorContainer::setCalendar( Calendar *cal )
00075 {
00076   mCalendar = cal;
00077   mNavigatorView->setCalendar( cal );
00078   KDateNavigator *n;
00079   for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
00080     n->setCalendar( cal );
00081   }
00082 }
00083 
00084 void DateNavigatorContainer::updateDayMatrix()
00085 {
00086   mNavigatorView->updateDayMatrix();
00087   KDateNavigator *n;
00088   for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
00089     n->updateDayMatrix();
00090   }
00091 }
00092 
00093 void DateNavigatorContainer::updateToday()
00094 {
00095   mNavigatorView->updateToday();
00096   KDateNavigator *n;
00097   for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
00098     n->updateToday();
00099   }
00100 }
00101 
00102 void DateNavigatorContainer::updateView()
00103 {
00104   mNavigatorView->updateView();
00105   KDateNavigator *n;
00106   for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
00107     n->updateView();
00108   }
00109 }
00110 
00111 void DateNavigatorContainer::updateConfig()
00112 {
00113   mNavigatorView->updateConfig();
00114   KDateNavigator *n;
00115   for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
00116     n->updateConfig();
00117   }
00118 }
00119 
00120 void DateNavigatorContainer::selectDates( const DateList &dateList )
00121 {
00122   mNavigatorView->selectDates( dateList );
00123   setBaseDates();
00124 }
00125 
00126 void DateNavigatorContainer::setBaseDates()
00127 {
00128   KCal::DateList dateList = mNavigatorView->selectedDates();
00129   if ( dateList.isEmpty() ) {
00130     kdError() << "DateNavigatorContainer::selectDates() empty list." << endl;
00131   }
00132   QDate baseDate = dateList.first();
00133   KDateNavigator *n;
00134   for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
00135     baseDate = KOGlobals::self()->calendarSystem()->addMonths( baseDate, 1 );
00136     n->setBaseDate( baseDate );
00137   }
00138 }
00139 
00140 void DateNavigatorContainer::resizeEvent( QResizeEvent * )
00141 {
00142 #if 0
00143   kdDebug() << "DateNavigatorContainer::resizeEvent()" << endl;
00144   kdDebug() << "  CURRENT SIZE: " << size() << endl;
00145   kdDebug() << "  MINIMUM SIZEHINT: " << minimumSizeHint() << endl;
00146   kdDebug() << "  SIZEHINT: " << sizeHint() << endl;
00147   kdDebug() << "  MINIMUM SIZE: " << minimumSize() << endl;
00148 #endif
00149 
00150   QSize minSize = mNavigatorView->minimumSizeHint();
00151 
00152 //  kdDebug() << "  NAVIGATORVIEW minimumSizeHint: " << minSize << endl;
00153 
00154   int verticalCount = size().height() / minSize.height();
00155   int horizontalCount = size().width() / minSize.width();
00156 
00157   if ( horizontalCount != mHorizontalCount ||
00158        verticalCount != mVerticalCount ) {
00159     uint count = horizontalCount * verticalCount;
00160     if ( count == 0 ) return;
00161 
00162     while ( count > ( mExtraViews.count() + 1 ) ) {
00163       KDateNavigator *n = new KDateNavigator( this );
00164       mExtraViews.append( n );
00165       n->setCalendar( mCalendar );
00166       setBaseDates();
00167       connectNavigatorView( n );
00168       n->show();
00169     }
00170 
00171     while ( count < ( mExtraViews.count() + 1 ) ) {
00172       mExtraViews.removeLast();
00173     }
00174 
00175     mHorizontalCount = horizontalCount;
00176     mVerticalCount = verticalCount;
00177   }
00178   
00179   int height = size().height() / verticalCount;
00180   int width = size().width() / horizontalCount;
00181 
00182   NavigatorBar *bar = mNavigatorView->navigatorBar();
00183   if ( horizontalCount > 1 ) bar->showButtons( true, false );
00184   else bar->showButtons( true, true );
00185   
00186   mNavigatorView->setGeometry( 
00187       ( (KOGlobals::self()->reverseLayout())?(horizontalCount-1):0) * width, 
00188       0, width, height );
00189   for( uint i = 0; i < mExtraViews.count(); ++i ) {
00190     int x = ( i + 1 ) % horizontalCount;
00191     int y = ( i + 1 ) / horizontalCount;
00192 
00193     KDateNavigator *view = mExtraViews.at( i );
00194     bar = view->navigatorBar();
00195     if ( y > 0 ) bar->showButtons( false, false );
00196     else {
00197         if ( x + 1 == horizontalCount ) bar->showButtons( false, true );
00198         else bar->showButtons( false, false );
00199     }
00200     view->setGeometry( 
00201         ( (KOGlobals::self()->reverseLayout())?(horizontalCount-1-x):x) * width, 
00202         y * height, width, height );
00203   }
00204 }
00205 
00206 QSize DateNavigatorContainer::minimumSizeHint() const
00207 {
00208   return mNavigatorView->minimumSizeHint();
00209 }
00210 
00211 QSize DateNavigatorContainer::sizeHint() const
00212 {
00213   return mNavigatorView->sizeHint();
00214 }
00215 
00216 #include "datenavigatorcontainer.moc"
KDE Logo
This file is part of the documentation for korganizer Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Apr 4 04:49:26 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003