• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

korganizer

datenavigatorcontainer.cpp

Go to the documentation of this file.
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 along
00018   with this program; if not, write to the Free Software Foundation, Inc.,
00019   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 "datenavigatorcontainer.h"
00027 #include "koglobals.h"
00028 #include "navigatorbar.h"
00029 #include "kdatenavigator.h"
00030 
00031 #include <kdebug.h>
00032 #include <klocale.h>
00033 #include <kcalendarsystem.h>
00034 #include <kdialog.h>
00035 
00036 #include <QTimer>
00037 #include <QFrame>
00038 #include <QResizeEvent>
00039 
00040 DateNavigatorContainer::DateNavigatorContainer( QWidget *parent )
00041   : QFrame( parent ), mCalendar( 0 ),
00042     mHorizontalCount( 1 ), mVerticalCount( 1 )
00043 {
00044   mNavigatorView = new KDateNavigator( this );
00045   mNavigatorView->setWhatsThis(
00046                    i18n( "<qt><p>Select the dates you want to "
00047                          "display in KOrganizer's main view here. Hold the "
00048                          "mouse button to select more than one day.</p>"
00049                          "<p>Press the top buttons to browse to the next "
00050                          "/ previous months or years.</p>"
00051                          "<p>Each line shows a week. The number in the left "
00052                          "column is the number of the week in the year. "
00053                          "Press it to select the whole week.</p>"
00054                          "</qt>" ) );
00055 
00056   connectNavigatorView( mNavigatorView );
00057 }
00058 
00059 DateNavigatorContainer::~DateNavigatorContainer()
00060 {
00061   qDeleteAll( mExtraViews );
00062 }
00063 
00064 void DateNavigatorContainer::connectNavigatorView( KDateNavigator *v )
00065 {
00066   connect( v, SIGNAL(datesSelected(const KCal::DateList &)),
00067            SIGNAL(datesSelected(const KCal::DateList &)) );
00068   connect( v, SIGNAL(incidenceDropped(Incidence *,const QDate &)),
00069            SIGNAL(incidenceDropped(Incidence *,const QDate &)) );
00070   connect( v, SIGNAL(incidenceDroppedMove(Incidence *,const QDate &)),
00071            SIGNAL(incidenceDroppedMove(Incidence *,const QDate &)) );
00072   connect( v, SIGNAL(weekClicked(const QDate &)),
00073            SIGNAL(weekClicked(const QDate &)) );
00074 
00075   connect( v, SIGNAL(goPrevious()), SIGNAL(goPrevious()) );
00076   connect( v, SIGNAL(goNext()), SIGNAL(goNext()) );
00077 
00078   connect( v, SIGNAL(goNextMonth()), SIGNAL(goNextMonth()) );
00079   connect( v, SIGNAL(goPrevMonth()), SIGNAL(goPrevMonth()) );
00080   connect( v, SIGNAL(goNextYear()), SIGNAL(goNextYear()) );
00081   connect( v, SIGNAL(goPrevYear()), SIGNAL(goPrevYear()) );
00082   connect( v, SIGNAL(goMonth(int)), SIGNAL(goMonth(int)) );
00083   connect( v, SIGNAL(goYear(int)), SIGNAL(goYear(int)) );
00084 }
00085 
00086 void DateNavigatorContainer::setCalendar( Calendar *cal )
00087 {
00088   mCalendar = cal;
00089   mNavigatorView->setCalendar( cal );
00090   foreach ( KDateNavigator *n, mExtraViews ) {
00091     if ( n ) {
00092       n->setCalendar( cal );
00093     }
00094   }
00095 }
00096 
00097 // TODO_Recurrence: let the navigators update just once, and tell them that
00098 // if data has changed or just the selection (because then the list of dayss
00099 // with events doesn't have to be updated if the month stayed the same
00100 void DateNavigatorContainer::updateDayMatrix()
00101 {
00102   mNavigatorView->updateDayMatrix();
00103   foreach ( KDateNavigator *n, mExtraViews ) {
00104     if ( n ) {
00105       n->updateDayMatrix();
00106     }
00107   }
00108 }
00109 
00110 void DateNavigatorContainer::updateToday()
00111 {
00112   mNavigatorView->updateToday();
00113   foreach ( KDateNavigator *n, mExtraViews ) {
00114     if ( n ) {
00115       n->updateToday();
00116     }
00117   }
00118 }
00119 
00120 void DateNavigatorContainer::updateView()
00121 {
00122   mNavigatorView->updateView();
00123   foreach ( KDateNavigator *n, mExtraViews ) {
00124     if ( n ) {
00125       n->updateView();
00126     }
00127   }
00128 }
00129 
00130 void DateNavigatorContainer::updateConfig()
00131 {
00132   mNavigatorView->updateConfig();
00133   foreach ( KDateNavigator *n, mExtraViews ) {
00134     if ( n ) {
00135       n->updateConfig();
00136     }
00137   }
00138 }
00139 
00140 void DateNavigatorContainer::selectDates( const DateList &dateList )
00141 {
00142   if ( !dateList.isEmpty() ) {
00143     QDate start( dateList.first() );
00144     QDate end( dateList.last() );
00145     QDate navfirst( mNavigatorView->startDate() );
00146     QDate navsecond; // start of the second shown month if existent
00147     QDate navlast;
00148     if ( !mExtraViews.isEmpty() ) {
00149       navlast = mExtraViews.last()->endDate();
00150       navsecond = mExtraViews.first()->startDate();
00151     } else {
00152       navlast = mNavigatorView->endDate();
00153       navsecond = navfirst;
00154     }
00155     if ( start < navfirst || // <- start should always be visible
00156          // end is not visible and we have a spare month at the beginning:
00157          ( end > navlast && start >= navsecond ) ) {
00158       // Change the shown months so that the beginning of the date list is visible
00159       setBaseDates( start );
00160     }
00161 
00162     mNavigatorView->selectDates( dateList );
00163     foreach ( KDateNavigator *n, mExtraViews ) {
00164       if ( n ) {
00165         n->selectDates( dateList );
00166       }
00167     }
00168   }
00169 }
00170 
00171 void DateNavigatorContainer::setBaseDates( const QDate &start )
00172 {
00173   QDate baseDate = start;
00174   mNavigatorView->setBaseDate( baseDate );
00175   foreach ( KDateNavigator *n, mExtraViews ) {
00176     baseDate = KOGlobals::self()->calendarSystem()->addMonths( baseDate, 1 );
00177     n->setBaseDate( baseDate );
00178   }
00179 }
00180 
00181 void DateNavigatorContainer::resizeEvent( QResizeEvent * )
00182 {
00183 #if 0
00184   kDebug() << "DateNavigatorContainer::resizeEvent()";
00185   kDebug() << "  CURRENT SIZE:" << size();
00186   kDebug() << "  MINIMUM SIZEHINT:" << minimumSizeHint();
00187   kDebug() << "  SIZEHINT:" << sizeHint();
00188   kDebug() << "  MINIMUM SIZE:" << minimumSize();
00189 #endif
00190   QTimer::singleShot( 0, this, SLOT(resizeAllContents()) );
00191 }
00192 
00193 void DateNavigatorContainer::resizeAllContents()
00194 {
00195   QSize minSize = mNavigatorView->minimumSizeHint();
00196 
00197 //  kDebug() << "  NAVIGATORVIEW minimumSizeHint:" << minSize;
00198 
00199   int margin = KDialog::spacingHint();
00200   int verticalCount = ( size().height() - margin * 2 ) / minSize.height();
00201   int horizontalCount = ( size().width() - margin * 2 ) / minSize.width();
00202 
00203   if ( horizontalCount != mHorizontalCount || verticalCount != mVerticalCount ) {
00204     int count = horizontalCount * verticalCount;
00205     if ( count == 0 ) {
00206       return;
00207     }
00208 
00209     while ( count > ( mExtraViews.count() + 1 ) ) {
00210       KDateNavigator *n = new KDateNavigator( this );
00211       mExtraViews.append( n );
00212       n->setCalendar( mCalendar );
00213       connectNavigatorView( n );
00214     }
00215 
00216     while ( count < ( mExtraViews.count() + 1 ) ) {
00217       delete ( mExtraViews.last() );
00218       mExtraViews.removeLast();
00219     }
00220 
00221     mHorizontalCount = horizontalCount;
00222     mVerticalCount = verticalCount;
00223     setBaseDates( mNavigatorView->selectedDates().first() );
00224     selectDates( mNavigatorView->selectedDates() );
00225     foreach ( KDateNavigator *n, mExtraViews ) {
00226       if ( n ) {
00227         n->show();
00228       }
00229     }
00230   }
00231 
00232   int height = ( size().height() - margin * 2 ) / verticalCount;
00233   int width = ( size().width() - margin * 2 ) / horizontalCount;
00234 
00235   NavigatorBar *bar = mNavigatorView->navigatorBar();
00236   if ( horizontalCount > 1 ) {
00237     bar->showButtons( true, false );
00238   } else {
00239     bar->showButtons( true, true );
00240   }
00241 
00242   mNavigatorView->setGeometry( ( ( ( KOGlobals::self()->reverseLayout() ) ?
00243                                    ( horizontalCount - 1 ) : 0 ) * width ) + margin,
00244                                margin, width, height );
00245   for ( int i = 0; i < mExtraViews.count(); ++i ) {
00246     int x = ( i + 1 ) % horizontalCount;
00247     int y = ( i + 1 ) / horizontalCount;
00248 
00249     KDateNavigator *view = mExtraViews.at( i );
00250     bar = view->navigatorBar();
00251     if ( y > 0 ) {
00252       bar->showButtons( false, false );
00253     } else {
00254       if ( x + 1 == horizontalCount ) {
00255         bar->showButtons( false, true );
00256       } else {
00257         bar->showButtons( false, false );
00258       }
00259     }
00260     view->setGeometry( ( ( ( KOGlobals::self()->reverseLayout() ) ?
00261                            ( horizontalCount - 1 - x ) : x ) * width ) + margin,
00262                        ( y * height ) + margin, width, height );
00263   }
00264 }
00265 
00266 QSize DateNavigatorContainer::minimumSizeHint() const
00267 {
00268   int margin = KDialog::spacingHint() * 2;
00269   return mNavigatorView->minimumSizeHint() + QSize( margin, margin );
00270 }
00271 
00272 QSize DateNavigatorContainer::sizeHint() const
00273 {
00274   int margin = KDialog::spacingHint() * 2;
00275   return mNavigatorView->sizeHint() + QSize( margin, margin );
00276 }
00277 
00278 #include "datenavigatorcontainer.moc"

korganizer

Skip menu "korganizer"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  •   doc
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal