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

korganizer

  • sources
  • kde-4.12
  • kdepim
  • korganizer
datenavigatorcontainer.cpp
Go to the documentation of this file.
1 /*
2  This file is part of KOrganizer.
3 
4  Copyright (c) 2001,2002,2003 Cornelius Schumacher <schumacher@kde.org>
5  Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
6 
7  Copyright (C) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
8  Author: Sergio Martins <sergio@kdab.com>
9 
10  This program is free software; you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation; either version 2 of the License, or
13  (at your option) any later version.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License along
21  with this program; if not, write to the Free Software Foundation, Inc.,
22  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 
24  As a special exception, permission is given to link this program
25  with any edition of Qt, and distribute the resulting executable,
26  without including the source code for Qt in the source distribution.
27 */
28 
29 #include "datenavigatorcontainer.h"
30 #include "kdatenavigator.h"
31 #include "kodaymatrix.h"
32 #include "koglobals.h"
33 #include "navigatorbar.h"
34 
35 #include <KCalendarSystem>
36 
37 #include <QTimer>
38 
39 DateNavigatorContainer::DateNavigatorContainer( QWidget *parent )
40  : QFrame( parent ),
41  mHorizontalCount( 1 ), mVerticalCount( 1 ),
42  mIgnoreNavigatorUpdates( false )
43 {
44  mNavigatorView = new KDateNavigator( this );
45  mNavigatorView->setWhatsThis(
46  i18n( "<qt><p>Select the dates you want to "
47  "display in KOrganizer's main view here. Hold the "
48  "mouse button to select more than one day.</p>"
49  "<p>Press the top buttons to browse to the next "
50  "/ previous months or years.</p>"
51  "<p>Each line shows a week. The number in the left "
52  "column is the number of the week in the year. "
53  "Press it to select the whole week.</p>"
54  "</qt>" ) );
55 
56  connectNavigatorView( mNavigatorView );
57 }
58 
59 DateNavigatorContainer::~DateNavigatorContainer()
60 {
61  qDeleteAll( mExtraViews );
62 }
63 
64 void DateNavigatorContainer::connectNavigatorView( KDateNavigator *v )
65 {
66  connect( v, SIGNAL(datesSelected(KCalCore::DateList)),
67  SLOT(handleDatesSelectedSignal(KCalCore::DateList)) );
68 
69  connect( v, SIGNAL(incidenceDropped(Akonadi::Item,QDate)),
70  SIGNAL(incidenceDropped(Akonadi::Item,QDate)) );
71  connect( v, SIGNAL(incidenceDroppedMove(Akonadi::Item,QDate)),
72  SIGNAL(incidenceDroppedMove(Akonadi::Item,QDate)) );
73 
74  connect( v, SIGNAL(newEventSignal(QDate)),
75  SIGNAL(newEventSignal(QDate)) );
76  connect( v, SIGNAL(newTodoSignal(QDate)),
77  SIGNAL(newTodoSignal(QDate)) );
78  connect( v, SIGNAL(newJournalSignal(QDate)),
79  SIGNAL(newJournalSignal(QDate)) );
80 
81  connect( v, SIGNAL(weekClicked(QDate,QDate)),
82  SLOT(handleWeekClickedSignal(QDate,QDate)) );
83 
84  connect( v, SIGNAL(goPrevious()), SIGNAL(goPrevious()) );
85  connect( v, SIGNAL(goNext()), SIGNAL(goNext()) );
86 
87  connect( v, SIGNAL(nextYearClicked()), SIGNAL(nextYearClicked()) );
88  connect( v, SIGNAL(prevYearClicked()), SIGNAL(prevYearClicked()) );
89 
90  connect( v, SIGNAL(prevMonthClicked()), SLOT(goPrevMonth()) );
91  connect( v, SIGNAL(nextMonthClicked()), SLOT(goNextMonth()) );
92 
93  connect( v, SIGNAL(monthSelected(int)), SIGNAL(monthSelected(int)) );
94  connect( v, SIGNAL(yearSelected(int)), SIGNAL(yearSelected(int)) );
95 }
96 
97 void DateNavigatorContainer::setCalendar( const Akonadi::ETMCalendar::Ptr &calendar )
98 {
99  mCalendar = calendar;
100  mNavigatorView->setCalendar( calendar );
101  foreach ( KDateNavigator *n, mExtraViews ) {
102  if ( n ) {
103  n->setCalendar( calendar );
104  }
105  }
106 }
107 
108 // TODO_Recurrence: let the navigators update just once, and tell them that
109 // if data has changed or just the selection (because then the list of dayss
110 // with events doesn't have to be updated if the month stayed the same
111 void DateNavigatorContainer::updateDayMatrix()
112 {
113  mNavigatorView->updateDayMatrix();
114  foreach ( KDateNavigator *n, mExtraViews ) {
115  if ( n ) {
116  n->updateDayMatrix();
117  }
118  }
119 }
120 
121 void DateNavigatorContainer::updateToday()
122 {
123  mNavigatorView->updateToday();
124  foreach ( KDateNavigator *n, mExtraViews ) {
125  if ( n ) {
126  n->updateToday();
127  }
128  }
129 }
130 
131 void DateNavigatorContainer::setUpdateNeeded()
132 {
133  mNavigatorView->setUpdateNeeded();
134  foreach ( KDateNavigator *n, mExtraViews ) {
135  if ( n ) {
136  n->setUpdateNeeded();
137  }
138  }
139 }
140 
141 void DateNavigatorContainer::updateView()
142 {
143  mNavigatorView->updateView();
144  foreach ( KDateNavigator *n, mExtraViews ) {
145  if ( n ) {
146  n->setUpdateNeeded();
147  }
148  }
149 }
150 
151 void DateNavigatorContainer::updateConfig()
152 {
153  mNavigatorView->updateConfig();
154  foreach ( KDateNavigator *n, mExtraViews ) {
155  if ( n ) {
156  n->updateConfig();
157  }
158  }
159 }
160 
161 void DateNavigatorContainer::selectDates( const KCalCore::DateList &dateList,
162  const QDate &preferredMonth )
163 {
164  if ( !dateList.isEmpty() ) {
165  QDate start( dateList.first() );
166  QDate end( dateList.last() );
167  QDate navfirst( mNavigatorView->startDate() );
168  QDate navsecond; // start of the second shown month if existent
169  QDate navlast;
170  if ( !mExtraViews.isEmpty() ) {
171  navlast = mExtraViews.last()->endDate();
172  navsecond = mExtraViews.first()->startDate();
173  } else {
174  navlast = mNavigatorView->endDate();
175  navsecond = navfirst;
176  }
177 
178  const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
179 
180  // If the datelist crosses months we won't know which month to show
181  // so we read what's in preferredMonth
182  const bool changingMonth =
183  ( preferredMonth.isValid() &&
184  calSys->month( mNavigatorView->month() ) != calSys->month( preferredMonth ) );
185 
186  if ( start < navfirst || // <- start should always be visible
187  // end is not visible and we have a spare month at the beginning:
188  ( end > navlast && start >= navsecond ) ||
189  changingMonth ) {
190 
191  if ( preferredMonth.isValid() ) {
192  setBaseDates( preferredMonth );
193  } else {
194  setBaseDates( start );
195  }
196  }
197 
198  if ( !mIgnoreNavigatorUpdates ) {
199  mNavigatorView->selectDates( dateList );
200  foreach ( KDateNavigator *n, mExtraViews ) {
201  if ( n ) {
202  n->selectDates( dateList );
203  }
204  }
205  }
206  }
207 }
208 
209 void DateNavigatorContainer::setBaseDates( const QDate &start )
210 {
211  QDate baseDate = start;
212  if ( !mIgnoreNavigatorUpdates ) {
213  mNavigatorView->setBaseDate( baseDate );
214  }
215 
216  foreach ( KDateNavigator *n, mExtraViews ) {
217  baseDate = KOGlobals::self()->calendarSystem()->addMonths( baseDate, 1 );
218  if ( !mIgnoreNavigatorUpdates ) {
219  n->setBaseDate( baseDate );
220  }
221  }
222 }
223 
224 void DateNavigatorContainer::resizeEvent( QResizeEvent * )
225 {
226 #if 0
227  kDebug() << "DateNavigatorContainer::resizeEvent()";
228  kDebug() << " CURRENT SIZE:" << size();
229  kDebug() << " MINIMUM SIZEHINT:" << minimumSizeHint();
230  kDebug() << " SIZEHINT:" << sizeHint();
231  kDebug() << " MINIMUM SIZE:" << minimumSize();
232 #endif
233  QTimer::singleShot( 0, this, SLOT(resizeAllContents()) );
234 }
235 
236 void DateNavigatorContainer::resizeAllContents()
237 {
238  QSize minSize = mNavigatorView->minimumSizeHint();
239 
240 // kDebug() << " NAVIGATORVIEW minimumSizeHint:" << minSize;
241 
242  int verticalCount = size().height() / minSize.height();
243  int horizontalCount = size().width() / minSize.width();
244 
245  if ( horizontalCount != mHorizontalCount || verticalCount != mVerticalCount ) {
246  int count = horizontalCount * verticalCount;
247  if ( count == 0 ) {
248  return;
249  }
250 
251  while ( count > ( mExtraViews.count() + 1 ) ) {
252  KDateNavigator *n = new KDateNavigator( this );
253  mExtraViews.append( n );
254  n->setCalendar( mCalendar );
255  connectNavigatorView( n );
256  }
257 
258  while ( count < ( mExtraViews.count() + 1 ) ) {
259  delete ( mExtraViews.last() );
260  mExtraViews.removeLast();
261  }
262 
263  mHorizontalCount = horizontalCount;
264  mVerticalCount = verticalCount;
265  setBaseDates( mNavigatorView->selectedDates().first() );
266  selectDates( mNavigatorView->selectedDates() );
267  foreach ( KDateNavigator *n, mExtraViews ) {
268  if ( n ) {
269  n->show();
270  }
271  }
272  }
273 
274  int height = size().height() / verticalCount;
275  int width = size().width() / horizontalCount;
276 
277  NavigatorBar *bar = mNavigatorView->navigatorBar();
278  if ( horizontalCount > 1 ) {
279  bar->showButtons( true, false );
280  } else {
281  bar->showButtons( true, true );
282  }
283 
284  mNavigatorView->setGeometry( ( ( ( KOGlobals::self()->reverseLayout() ) ?
285  ( horizontalCount - 1 ) : 0 ) * width ),
286  0, width, height );
287  for ( int i = 0; i < mExtraViews.count(); ++i ) {
288  int x = ( i + 1 ) % horizontalCount;
289  int y = ( i + 1 ) / horizontalCount;
290 
291  KDateNavigator *view = mExtraViews.at( i );
292  bar = view->navigatorBar();
293  if ( y > 0 ) {
294  bar->showButtons( false, false );
295  } else {
296  if ( x + 1 == horizontalCount ) {
297  bar->showButtons( false, true );
298  } else {
299  bar->showButtons( false, false );
300  }
301  }
302  view->setGeometry( ( ( ( KOGlobals::self()->reverseLayout() ) ?
303  ( horizontalCount - 1 - x ) : x ) * width ),
304  y * height, width, height );
305 
306  }
307 }
308 
309 QSize DateNavigatorContainer::minimumSizeHint() const
310 {
311  return mNavigatorView->minimumSizeHint();
312 }
313 
314 QSize DateNavigatorContainer::sizeHint() const
315 {
316  return mNavigatorView->sizeHint();
317 }
318 
319 void DateNavigatorContainer::setHighlightMode( bool highlightEvents,
320  bool highlightTodos,
321  bool highlightJournals ) const {
322 
323  mNavigatorView->setHighlightMode( highlightEvents, highlightTodos, highlightJournals );
324 
325  foreach ( KDateNavigator *n, mExtraViews ) {
326  if ( n ) {
327  n->setHighlightMode( highlightEvents, highlightTodos, highlightJournals );
328  }
329  }
330 
331 }
332 
333 void DateNavigatorContainer::goNextMonth()
334 {
335  const QPair<QDate,QDate> p = dateLimits( 1 );
336 
337  emit nextMonthClicked( mNavigatorView->month(),
338  p.first,
339  p.second );
340 }
341 
342 void DateNavigatorContainer::goPrevMonth()
343 {
344  const QPair<QDate,QDate> p = dateLimits( -1 );
345 
346  emit prevMonthClicked( mNavigatorView->month(),
347  p.first,
348  p.second );
349 }
350 
351 QPair<QDate,QDate> DateNavigatorContainer::dateLimits( int offset ) const
352 {
353  const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
354  QDate firstMonth, lastMonth;
355  if ( mExtraViews.isEmpty() ) {
356  lastMonth = mNavigatorView->month();
357  } else {
358  lastMonth = mExtraViews.last()->month();
359  }
360 
361  firstMonth = calSys->addMonths( mNavigatorView->month(), offset );
362  lastMonth = calSys->addMonths( lastMonth, offset );
363 
364  QPair<QDate,QDate> firstMonthBoundary = KODayMatrix::matrixLimits( firstMonth );
365  QPair<QDate,QDate> lastMonthBoundary = KODayMatrix::matrixLimits( lastMonth );
366 
367  return qMakePair( firstMonthBoundary.first, lastMonthBoundary.second );
368 }
369 
370 QDate DateNavigatorContainer::monthOfNavigator( int navigatorIndex ) const
371 {
372  if ( navigatorIndex == 0 ) {
373  return mNavigatorView->month();
374  }
375 
376  if ( navigatorIndex <= mExtraViews.count() && navigatorIndex >= 0 ) {
377  return mExtraViews[navigatorIndex-1]->month();
378  } else {
379  return QDate();
380  }
381 }
382 
383 void DateNavigatorContainer::handleDatesSelectedSignal( const KCalCore::DateList &dateList )
384 {
385  Q_ASSERT( sender() );
386  // When we have more than one KDateNavigator, both can have the
387  // same selection ( because they can share weeks )
388  // The month that we send in the datesSelected() signal should be
389  // the one belonging to the KDatenavigator with the earliest month
390  const QDate firstDate = dateList.first();
391  KDateNavigator *navigator = firstNavigatorForDate( firstDate );
392  navigator = navigator ? navigator : qobject_cast<KDateNavigator*>( sender() );
393 
394  emit datesSelected( dateList, navigator->month() );
395 }
396 
397 void DateNavigatorContainer::handleWeekClickedSignal( const QDate &week, const QDate & )
398 {
399  Q_ASSERT( sender() );
400  KDateNavigator *navigator = firstNavigatorForDate( week );
401  navigator = navigator ? navigator : qobject_cast<KDateNavigator*>( sender() );
402 
403  emit weekClicked( week, navigator->month() );
404 }
405 
406 KDateNavigator *DateNavigatorContainer::firstNavigatorForDate( const QDate &date ) const
407 {
408  KDateNavigator *navigator = 0;
409  if ( date.isValid() ) {
410  QPair<QDate,QDate> limits = KODayMatrix::matrixLimits( mNavigatorView->month() );
411 
412  if ( date >= limits.first && date <= limits.second ) {
413  // The date is in the first navigator
414  navigator = mNavigatorView;
415  } else {
416  foreach ( KDateNavigator *nav, mExtraViews ) {
417  if ( nav ) {
418  limits = KODayMatrix::matrixLimits( nav->month() );
419  if ( date >= limits.first && date <= limits.second ) {
420  navigator = nav;
421  break;
422  }
423  }
424  }
425  }
426  }
427 
428  return navigator;
429 }
430 
431 #include "datenavigatorcontainer.moc"
DateNavigatorContainer::goNextMonth
void goNextMonth()
Definition: datenavigatorcontainer.cpp:333
KDateNavigator::selectDates
void selectDates(const KCalCore::DateList &)
Definition: kdatenavigator.cpp:308
KDateNavigator::updateConfig
void updateConfig()
Definition: kdatenavigator.cpp:248
DateNavigatorContainer::DateNavigatorContainer
DateNavigatorContainer(QWidget *parent=0)
Definition: datenavigatorcontainer.cpp:39
KDateNavigator::startDate
QDate startDate() const
Definition: kdatenavigator.cpp:148
koglobals.h
DateNavigatorContainer::monthOfNavigator
QDate monthOfNavigator(int navigatorIndex=0) const
Returns the month of the specified KDateNavigator.
Definition: datenavigatorcontainer.cpp:370
DateNavigatorContainer::resizeEvent
void resizeEvent(QResizeEvent *)
Definition: datenavigatorcontainer.cpp:224
KODayMatrix::matrixLimits
static QPair< QDate, QDate > matrixLimits(const QDate &month)
returns the first and last date of the 6*7 matrix that displays month
Definition: kodaymatrix.cpp:886
DateNavigatorContainer::datesSelected
void datesSelected(const KCalCore::DateList &, const QDate &preferredMonth)
KDateNavigator::navigatorBar
NavigatorBar * navigatorBar() const
Definition: kdatenavigator.h:64
datenavigatorcontainer.h
navigatorbar.h
DateNavigatorContainer::setUpdateNeeded
void setUpdateNeeded()
Definition: datenavigatorcontainer.cpp:131
DateNavigatorContainer::setHighlightMode
void setHighlightMode(bool highlightEvents, bool highlightTodos, bool highlightJournals) const
Definition: datenavigatorcontainer.cpp:319
DateNavigatorContainer::incidenceDropped
void incidenceDropped(const Akonadi::Item &, const QDate &)
KDateNavigator::selectedDates
KCalCore::DateList selectedDates() const
Definition: kdatenavigator.h:57
QWidget
DateNavigatorContainer::goNext
void goNext()
DateNavigatorContainer::newEventSignal
void newEventSignal(const QDate &)
kodaymatrix.h
kdatenavigator.h
KDateNavigator::updateView
void updateView()
Definition: kdatenavigator.cpp:242
KDateNavigator::endDate
QDate endDate() const
Definition: kdatenavigator.cpp:171
DateNavigatorContainer::setCalendar
void setCalendar(const Akonadi::ETMCalendar::Ptr &)
Associate date navigator with a calendar.
Definition: datenavigatorcontainer.cpp:97
DateNavigatorContainer::incidenceDroppedMove
void incidenceDroppedMove(const Akonadi::Item &, const QDate &)
DateNavigatorContainer::newJournalSignal
void newJournalSignal(const QDate &)
KDateNavigator
Definition: kdatenavigator.h:43
DateNavigatorContainer::nextMonthClicked
void nextMonthClicked(const QDate &currentMonth, const QDate &selectionLowerLimit, const QDate &selectionUpperLimit)
DateNavigatorContainer::~DateNavigatorContainer
~DateNavigatorContainer()
Definition: datenavigatorcontainer.cpp:59
DateNavigatorContainer::connectNavigatorView
void connectNavigatorView(KDateNavigator *v)
Definition: datenavigatorcontainer.cpp:64
DateNavigatorContainer::prevMonthClicked
void prevMonthClicked(const QDate &currentMonth, const QDate &selectionLowerLimit, const QDate &selectionUpperLimit)
Signals that the previous month button has been clicked.
KDateNavigator::setBaseDate
void setBaseDate(const QDate &)
Definition: kdatenavigator.cpp:118
KDateNavigator::updateToday
void updateToday()
Definition: kdatenavigator.cpp:142
DateNavigatorContainer::minimumSizeHint
QSize minimumSizeHint() const
Definition: datenavigatorcontainer.cpp:309
DateNavigatorContainer::yearSelected
void yearSelected(int year)
DateNavigatorContainer::weekClicked
void weekClicked(const QDate &week, const QDate &preferredMonth)
DateNavigatorContainer::monthSelected
void monthSelected(int month)
KOGlobals::calendarSystem
const KCalendarSystem * calendarSystem() const
Definition: koglobals.cpp:65
KOGlobals::self
static KOGlobals * self()
Definition: koglobals.cpp:43
NavigatorBar
Definition: navigatorbar.h:33
DateNavigatorContainer::updateToday
void updateToday()
Definition: datenavigatorcontainer.cpp:121
DateNavigatorContainer::sizeHint
QSize sizeHint() const
Definition: datenavigatorcontainer.cpp:314
KDateNavigator::month
QDate month() const
Returns the current displayed month.
Definition: kdatenavigator.cpp:228
NavigatorBar::showButtons
void showButtons(bool left, bool right)
Definition: navigatorbar.cpp:105
DateNavigatorContainer::goPrevious
void goPrevious()
DateNavigatorContainer::selectDates
void selectDates(const KCalCore::DateList &, const QDate &preferredMonth=QDate())
preferredMonth is useful when the datelist crosses months, if different from -1, it has the month tha...
Definition: datenavigatorcontainer.cpp:161
KDateNavigator::setHighlightMode
void setHighlightMode(bool highlightEvents, bool highlightTodos, bool highlightJournals) const
Definition: kdatenavigator.cpp:176
DateNavigatorContainer::updateView
void updateView()
Definition: datenavigatorcontainer.cpp:141
DateNavigatorContainer::setBaseDates
void setBaseDates(const QDate &start)
Definition: datenavigatorcontainer.cpp:209
DateNavigatorContainer::goPrevMonth
void goPrevMonth()
Definition: datenavigatorcontainer.cpp:342
KDateNavigator::setUpdateNeeded
void setUpdateNeeded()
Definition: kdatenavigator.cpp:223
DateNavigatorContainer::updateDayMatrix
void updateDayMatrix()
Definition: datenavigatorcontainer.cpp:111
DateNavigatorContainer::newTodoSignal
void newTodoSignal(const QDate &)
DateNavigatorContainer::prevYearClicked
void prevYearClicked()
DateNavigatorContainer::nextYearClicked
void nextYearClicked()
QFrame
DateNavigatorContainer::resizeAllContents
void resizeAllContents()
Resizes all the child elements after the size of the widget changed.
Definition: datenavigatorcontainer.cpp:236
DateNavigatorContainer::updateConfig
void updateConfig()
Definition: datenavigatorcontainer.cpp:151
KDateNavigator::updateDayMatrix
void updateDayMatrix()
Definition: kdatenavigator.cpp:217
KDateNavigator::setCalendar
void setCalendar(const Akonadi::ETMCalendar::Ptr &)
Associate date navigator with a calendar.
Definition: kdatenavigator.cpp:105
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:19 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

korganizer

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

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal