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 }
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
00101
00102
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;
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
00155
00156 || ( end > navlast && start >= navsecond ) ) {
00157
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
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 setBaseDates( mNavigatorView->selectedDates().first() );
00221 selectDates( mNavigatorView->selectedDates() );
00222 for( KDateNavigator *n = mExtraViews.first(); n; n = mExtraViews.next() ) {
00223 n->show();
00224 }
00225 }
00226
00227 int height = (size().height() - margin*2) / verticalCount;
00228 int width = (size().width() - margin*2) / horizontalCount;
00229
00230 NavigatorBar *bar = mNavigatorView->navigatorBar();
00231 if ( horizontalCount > 1 ) bar->showButtons( true, false );
00232 else bar->showButtons( true, true );
00233
00234 mNavigatorView->setGeometry(
00235 ( ( (KOGlobals::self()->reverseLayout())?(horizontalCount-1):0) * width ) + margin,
00236 margin, width, height );
00237 for( uint i = 0; i < mExtraViews.count(); ++i ) {
00238 int x = ( i + 1 ) % horizontalCount;
00239 int y = ( i + 1 ) / horizontalCount;
00240
00241 KDateNavigator *view = mExtraViews.at( i );
00242 bar = view->navigatorBar();
00243 if ( y > 0 ) bar->showButtons( false, false );
00244 else {
00245 if ( x + 1 == horizontalCount ) bar->showButtons( false, true );
00246 else bar->showButtons( false, false );
00247 }
00248 view->setGeometry(
00249 ( ( (KOGlobals::self()->reverseLayout())?(horizontalCount-1-x):x) * width ) + margin,
00250 ( y * height ) + margin, width, height );
00251 }
00252 }
00253
00254 QSize DateNavigatorContainer::minimumSizeHint() const
00255 {
00256 int margin = KDialog::spacingHint() * 2;
00257 return mNavigatorView->minimumSizeHint() + QSize( margin, margin );
00258 }
00259
00260 QSize DateNavigatorContainer::sizeHint() const
00261 {
00262 int margin = KDialog::spacingHint() * 2;
00263 return mNavigatorView->sizeHint() + QSize( margin, margin );
00264 }
00265
00266 #include "datenavigatorcontainer.moc"