27 #include <tdelocale.h>
29 #include "koglobals.h"
30 #include "navigatorbar.h"
31 #include "kdatenavigator.h"
32 #include "kodaymatrix.h"
34 #include <kcalendarsystem.h>
37 #include "datenavigatorcontainer.h"
39 #include <tqwhatsthis.h>
42 DateNavigatorContainer::DateNavigatorContainer( TQWidget *parent,
44 : TQFrame( parent, name ), mCalendar( 0 ),
45 mHorizontalCount( 1 ), mVerticalCount( 1 )
47 mExtraViews.setAutoDelete(
true );
48 setFrameStyle( TQFrame::Sunken | TQFrame::StyledPanel );
50 mNavigatorView =
new KDateNavigator(
this, name );
51 TQWhatsThis::add( mNavigatorView,
52 i18n(
"<qt><p>Select the dates you want to "
53 "display in KOrganizer's main view here. Hold down the "
54 "mouse button to select more than one day.</p>"
55 "<p>Press the top buttons to browse to the next "
56 "/ previous months or years.</p>"
57 "<p>Each line shows a week. The number in the left "
58 "column is the number of the week in the year. "
59 "Press it to select the whole week.</p>"
62 connectNavigatorView( mNavigatorView );
65 DateNavigatorContainer::~DateNavigatorContainer()
69 void DateNavigatorContainer::connectNavigatorView( KDateNavigator *v )
71 connect( v, TQ_SIGNAL( datesSelected(
const KCal::DateList & ) ),
72 TQ_SIGNAL( datesSelected(
const KCal::DateList & ) ) );
73 connect( v, TQ_SIGNAL( incidenceDropped(
Incidence *,
const TQDate & ) ),
74 TQ_SIGNAL( incidenceDropped(
Incidence *,
const TQDate & ) ) );
75 connect( v, TQ_SIGNAL( incidenceDroppedMove(
Incidence *,
const TQDate & ) ),
76 TQ_SIGNAL( incidenceDroppedMove(
Incidence *,
const TQDate & ) ) );
77 connect( v, TQ_SIGNAL( weekClicked(
const TQDate & ) ),
78 TQ_SIGNAL( weekClicked(
const TQDate & ) ) );
80 connect( v, TQ_SIGNAL( goPrevious() ), TQ_SIGNAL( goPrevious() ) );
81 connect( v, TQ_SIGNAL( goNext() ), TQ_SIGNAL( goNext() ) );
83 connect( v, TQ_SIGNAL( nextYearClicked() ), TQ_SIGNAL( nextYearClicked() ) );
84 connect( v, TQ_SIGNAL( prevYearClicked() ), TQ_SIGNAL( prevYearClicked() ) );
86 connect( v, TQ_SIGNAL( prevMonthClicked() ),
this, TQ_SLOT( goPrevMonth() ) );
87 connect( v, TQ_SIGNAL( nextMonthClicked() ),
this, TQ_SLOT( goNextMonth() ) );
89 connect( v, TQ_SIGNAL( monthSelected(
int ) ), TQ_SIGNAL( monthSelected(
int ) ) );
90 connect( v, TQ_SIGNAL( yearSelected(
int ) ), TQ_SIGNAL( yearSelected(
int ) ) );
93 void DateNavigatorContainer::setCalendar(
Calendar *cal )
96 mNavigatorView->setCalendar( cal );
98 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
99 n->setCalendar( cal );
106 void DateNavigatorContainer::updateDayMatrix()
108 mNavigatorView->updateDayMatrix();
110 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
111 n->updateDayMatrix();
115 void DateNavigatorContainer::updateToday()
117 mNavigatorView->updateToday();
119 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
124 void DateNavigatorContainer::setUpdateNeeded()
126 mNavigatorView->setUpdateNeeded();
128 for ( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
129 n->setUpdateNeeded();
133 void DateNavigatorContainer::updateView()
135 mNavigatorView->updateView();
137 for ( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
138 n->setUpdateNeeded();
142 void DateNavigatorContainer::updateConfig()
144 mNavigatorView->updateConfig();
146 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
151 void DateNavigatorContainer::selectDates(
const DateList &dateList,
const TQDate &preferredMonth )
153 if ( !dateList.isEmpty() ) {
154 TQDate start( dateList.first() );
155 TQDate end( dateList.last() );
156 TQDate navfirst( mNavigatorView->startDate() );
159 if ( !mExtraViews.isEmpty() ) {
160 navlast = mExtraViews.last()->endDate();
161 navsecond = mExtraViews.first()->startDate();
163 navlast = mNavigatorView->endDate();
164 navsecond = navfirst;
167 const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
171 const bool changingMonth = ( preferredMonth.isValid() &&
172 calSys->month( mNavigatorView->month() ) != calSys->month( preferredMonth ) );
174 if ( start < navfirst
176 || ( end > navlast && start >= navsecond )
179 if ( preferredMonth.isValid() ) {
180 setBaseDates( preferredMonth );
182 setBaseDates( start );
186 mNavigatorView->selectDates( dateList );
187 KDateNavigator *n = mExtraViews.first();
189 n->selectDates( dateList );
190 n = mExtraViews.next();
195 void DateNavigatorContainer::setBaseDates(
const TQDate &start )
197 TQDate baseDate = start;
198 mNavigatorView->setBaseDate( baseDate );
199 for( KDateNavigator *n = mExtraViews.first(); n; n = mExtraViews.next() ) {
200 baseDate = KOGlobals::self()->calendarSystem()->addMonths( baseDate, 1 );
201 n->setBaseDate( baseDate );
205 void DateNavigatorContainer::resizeEvent( TQResizeEvent * )
208 kdDebug(5850) <<
"DateNavigatorContainer::resizeEvent()" << endl;
209 kdDebug(5850) <<
" CURRENT SIZE: " << size() << endl;
210 kdDebug(5850) <<
" MINIMUM SIZEHINT: " << minimumSizeHint() << endl;
211 kdDebug(5850) <<
" SIZEHINT: " << sizeHint() << endl;
212 kdDebug(5850) <<
" MINIMUM SIZE: " << minimumSize() << endl;
214 TQTimer::singleShot( 0,
this, TQ_SLOT( resizeAllContents() ) );
217 void DateNavigatorContainer::resizeAllContents()
219 TQSize minSize = mNavigatorView->minimumSizeHint();
223 int margin = KDialog::spacingHint();
224 int verticalCount = ( size().height() - margin*2 ) / minSize.height();
225 int horizontalCount = ( size().width() - margin*2 ) / minSize.width();
227 if ( horizontalCount != mHorizontalCount ||
228 verticalCount != mVerticalCount ) {
229 uint count = horizontalCount * verticalCount;
234 while ( count > ( mExtraViews.count() + 1 ) ) {
235 KDateNavigator *n =
new KDateNavigator(
this );
236 mExtraViews.append( n );
237 n->setCalendar( mCalendar );
238 connectNavigatorView( n );
241 while ( count < ( mExtraViews.count() + 1 ) ) {
242 mExtraViews.removeLast();
245 mHorizontalCount = horizontalCount;
246 mVerticalCount = verticalCount;
247 setBaseDates( mNavigatorView->selectedDates().first() );
248 selectDates( mNavigatorView->selectedDates() );
249 for( KDateNavigator *n = mExtraViews.first(); n; n = mExtraViews.next() ) {
254 int height = (size().height() - margin*2) / verticalCount;
255 int width = (size().width() - margin*2) / horizontalCount;
257 NavigatorBar *bar = mNavigatorView->navigatorBar();
258 if ( horizontalCount > 1 ) {
259 bar->showButtons(
true,
false );
261 bar->showButtons(
true,
true );
264 mNavigatorView->setGeometry(
265 ( ( (KOGlobals::self()->reverseLayout())?(horizontalCount-1):0) * width ) + margin,
266 margin, width, height );
268 for( uint i = 0; i < mExtraViews.count(); ++i ) {
269 int x = ( i + 1 ) % horizontalCount;
270 int y = ( i + 1 ) / horizontalCount;
272 KDateNavigator *
view = mExtraViews.at( i );
273 bar =
view->navigatorBar();
275 bar->showButtons(
false,
false );
277 if ( x + 1 == horizontalCount ) {
278 bar->showButtons(
false,
true );
280 bar->showButtons(
false,
false );
284 ( ( (KOGlobals::self()->reverseLayout())?(horizontalCount-1-x):x) * width ) + margin,
285 ( y * height ) + margin, width, height );
289 TQSize DateNavigatorContainer::minimumSizeHint()
const
291 int margin = KDialog::spacingHint() * 2;
292 return mNavigatorView->minimumSizeHint() + TQSize( margin, margin );
295 TQSize DateNavigatorContainer::sizeHint()
const
297 int margin = KDialog::spacingHint() * 2;
298 return mNavigatorView->sizeHint() + TQSize( margin, margin );
301 void DateNavigatorContainer::goNextMonth()
303 const TQPair<TQDate,TQDate> p = dateLimits( 1 );
305 emit nextMonthClicked( mNavigatorView->month(),
310 void DateNavigatorContainer::goPrevMonth()
312 const TQPair<TQDate,TQDate> p = dateLimits( -1 );
314 emit prevMonthClicked( mNavigatorView->month(),
319 TQPair<TQDate,TQDate> DateNavigatorContainer::dateLimits(
int offset )
321 const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
322 TQDate firstMonth, lastMonth;
323 if ( mExtraViews.isEmpty() ) {
324 lastMonth = mNavigatorView->month();
326 lastMonth = mExtraViews.last()->month();
329 firstMonth = calSys->addMonths( mNavigatorView->month(), offset );
330 lastMonth = calSys->addMonths( lastMonth, offset );
335 return qMakePair( firstMonthBoundary.first, lastMonthBoundary.second );
338 #include "datenavigatorcontainer.moc"
static TQPair< TQDate, TQDate > matrixLimits(const TQDate &month)
returns the first and last date of the 6*7 matrix that displays month
bool view(TQWidget *parent, Attachment *attachment)