00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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 connect( v, SIGNAL( goYear( int ) ), SIGNAL( goYear( int ) ) );
00089 }
00090
00091 void DateNavigatorContainer::setCalendar( Calendar *cal )
00092 {
00093 mCalendar = cal;
00094 mNavigatorView->setCalendar( cal );
00095 KDateNavigator *n;
00096 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
00097 n->setCalendar( cal );
00098 }
00099 }
00100
00101
00102
00103
00104 void DateNavigatorContainer::updateDayMatrix()
00105 {
00106 mNavigatorView->updateDayMatrix();
00107 KDateNavigator *n;
00108 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
00109 n->updateDayMatrix();
00110 }
00111 }
00112
00113 void DateNavigatorContainer::updateToday()
00114 {
00115 mNavigatorView->updateToday();
00116 KDateNavigator *n;
00117 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
00118 n->updateToday();
00119 }
00120 }
00121
00122 void DateNavigatorContainer::setUpdateNeeded()
00123 {
00124 mNavigatorView->setUpdateNeeded();
00125 KDateNavigator *n;
00126 for ( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
00127 n->setUpdateNeeded();
00128 }
00129 }
00130
00131 void DateNavigatorContainer::updateView()
00132 {
00133 mNavigatorView->updateView();
00134 KDateNavigator *n;
00135 for ( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
00136 n->setUpdateNeeded();
00137 }
00138 }
00139
00140 void DateNavigatorContainer::updateConfig()
00141 {
00142 mNavigatorView->updateConfig();
00143 KDateNavigator *n;
00144 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
00145 n->updateConfig();
00146 }
00147 }
00148
00149 void DateNavigatorContainer::selectDates( const DateList &dateList )
00150 {
00151 if ( !dateList.isEmpty() ) {
00152 QDate start( dateList.first() );
00153 QDate end( dateList.last() );
00154 QDate navfirst( mNavigatorView->startDate() );
00155 QDate navsecond;
00156 QDate navlast;
00157 if ( !mExtraViews.isEmpty() ) {
00158 navlast = mExtraViews.last()->endDate();
00159 navsecond = mExtraViews.first()->startDate();
00160 } else {
00161 navlast = mNavigatorView->endDate();
00162 navsecond = navfirst;
00163 }
00164 if ( start < navfirst
00165
00166 || ( end > navlast && start >= navsecond ) ) {
00167
00168 setBaseDates( start );
00169 }
00170
00171 mNavigatorView->selectDates( dateList );
00172 KDateNavigator *n = mExtraViews.first();
00173 while ( n ) {
00174 n->selectDates( dateList );
00175 n = mExtraViews.next();
00176 }
00177 }
00178 }
00179
00180 void DateNavigatorContainer::setBaseDates( const QDate &start )
00181 {
00182 QDate baseDate = start;
00183 mNavigatorView->setBaseDate( baseDate );
00184 for( KDateNavigator *n = mExtraViews.first(); n; n = mExtraViews.next() ) {
00185 baseDate = KOGlobals::self()->calendarSystem()->addMonths( baseDate, 1 );
00186 n->setBaseDate( baseDate );
00187 }
00188 }
00189
00190 void DateNavigatorContainer::resizeEvent( QResizeEvent * )
00191 {
00192 #if 0
00193 kdDebug(5850) << "DateNavigatorContainer::resizeEvent()" << endl;
00194 kdDebug(5850) << " CURRENT SIZE: " << size() << endl;
00195 kdDebug(5850) << " MINIMUM SIZEHINT: " << minimumSizeHint() << endl;
00196 kdDebug(5850) << " SIZEHINT: " << sizeHint() << endl;
00197 kdDebug(5850) << " MINIMUM SIZE: " << minimumSize() << endl;
00198 #endif
00199 QTimer::singleShot( 0, this, SLOT( resizeAllContents() ) );
00200 }
00201
00202 void DateNavigatorContainer::resizeAllContents()
00203 {
00204 QSize minSize = mNavigatorView->minimumSizeHint();
00205
00206
00207
00208 int margin = KDialog::spacingHint();
00209 int verticalCount = ( size().height() - margin*2 ) / minSize.height();
00210 int horizontalCount = ( size().width() - margin*2 ) / minSize.width();
00211
00212 if ( horizontalCount != mHorizontalCount ||
00213 verticalCount != mVerticalCount ) {
00214 uint count = horizontalCount * verticalCount;
00215 if ( count == 0 ) return;
00216
00217 while ( count > ( mExtraViews.count() + 1 ) ) {
00218 KDateNavigator *n = new KDateNavigator( this );
00219 mExtraViews.append( n );
00220 n->setCalendar( mCalendar );
00221 connectNavigatorView( n );
00222 }
00223
00224 while ( count < ( mExtraViews.count() + 1 ) ) {
00225 mExtraViews.removeLast();
00226 }
00227
00228 mHorizontalCount = horizontalCount;
00229 mVerticalCount = verticalCount;
00230 setBaseDates( mNavigatorView->selectedDates().first() );
00231 selectDates( mNavigatorView->selectedDates() );
00232 for( KDateNavigator *n = mExtraViews.first(); n; n = mExtraViews.next() ) {
00233 n->show();
00234 }
00235 }
00236
00237 int height = (size().height() - margin*2) / verticalCount;
00238 int width = (size().width() - margin*2) / horizontalCount;
00239
00240 NavigatorBar *bar = mNavigatorView->navigatorBar();
00241 if ( horizontalCount > 1 ) bar->showButtons( true, false );
00242 else bar->showButtons( true, true );
00243
00244 mNavigatorView->setGeometry(
00245 ( ( (KOGlobals::self()->reverseLayout())?(horizontalCount-1):0) * width ) + margin,
00246 margin, width, height );
00247 for( uint i = 0; i < mExtraViews.count(); ++i ) {
00248 int x = ( i + 1 ) % horizontalCount;
00249 int y = ( i + 1 ) / horizontalCount;
00250
00251 KDateNavigator *view = mExtraViews.at( i );
00252 bar = view->navigatorBar();
00253 if ( y > 0 ) bar->showButtons( false, false );
00254 else {
00255 if ( x + 1 == horizontalCount ) bar->showButtons( false, true );
00256 else bar->showButtons( false, false );
00257 }
00258 view->setGeometry(
00259 ( ( (KOGlobals::self()->reverseLayout())?(horizontalCount-1-x):x) * width ) + margin,
00260 ( y * height ) + margin, width, height );
00261 }
00262 }
00263
00264 QSize DateNavigatorContainer::minimumSizeHint() const
00265 {
00266 int margin = KDialog::spacingHint() * 2;
00267 return mNavigatorView->minimumSizeHint() + QSize( margin, margin );
00268 }
00269
00270 QSize DateNavigatorContainer::sizeHint() const
00271 {
00272 int margin = KDialog::spacingHint() * 2;
00273 return mNavigatorView->sizeHint() + QSize( margin, margin );
00274 }
00275
00276 #include "datenavigatorcontainer.moc"