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 "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
00098
00099
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;
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 ||
00156
00157 ( end > navlast && start >= navsecond ) ) {
00158
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
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"