• 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
kdatenavigator.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  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License along
18  with this program; if not, write to the Free Software Foundation, Inc.,
19  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 
21  As a special exception, permission is given to link this program
22  with any edition of Qt, and distribute the resulting executable,
23  without including the source code for Qt in the source distribution.
24 */
25 
26 #include "kdatenavigator.h"
27 #include "kodaymatrix.h"
28 #include "koglobals.h"
29 #include "navigatorbar.h"
30 
31 #include <KCalendarSystem>
32 #include <KGlobalSettings>
33 
34 #include <QEvent>
35 #include <QGridLayout>
36 #include <QLabel>
37 #include <QWheelEvent>
38 
39 KDateNavigator::KDateNavigator( QWidget *parent )
40  : QFrame( parent ), mBaseDate( 1970, 1, 1 )
41 {
42  QGridLayout *topLayout = new QGridLayout( this );
43  topLayout->setMargin( 0 );
44  topLayout->setSpacing( 0 );
45 
46  mNavigatorBar = new NavigatorBar( this );
47  topLayout->addWidget( mNavigatorBar, 0, 0, 1, 8 );
48 
49  connect( mNavigatorBar, SIGNAL(prevYearClicked()), SIGNAL(prevYearClicked()) );
50  connect( mNavigatorBar, SIGNAL(prevMonthClicked()), SIGNAL(prevMonthClicked()) );
51  connect( mNavigatorBar, SIGNAL(nextMonthClicked()), SIGNAL(nextMonthClicked()) );
52  connect( mNavigatorBar, SIGNAL(nextYearClicked()), SIGNAL(nextYearClicked()) );
53  connect( mNavigatorBar, SIGNAL(monthSelected(int)), SIGNAL(monthSelected(int)) );
54  connect( mNavigatorBar, SIGNAL(yearSelected(int)), SIGNAL(yearSelected(int)));
55 
56  QString generalFont = KGlobalSettings::generalFont().family();
57 
58  // Set up the heading fields.
59  for ( int i = 0; i < 7; ++i ) {
60  mHeadings[i] = new QLabel( this );
61  mHeadings[i]->setFont( QFont( generalFont, 10, QFont::Bold ) );
62  mHeadings[i]->setAlignment( Qt::AlignCenter );
63 
64  topLayout->addWidget( mHeadings[i], 1, i + 1 );
65  }
66 
67  // Create the weeknumber labels
68  for ( int i = 0; i < 6; ++i ) {
69  mWeeknos[i] = new QLabel( this );
70  mWeeknos[i]->setAlignment( Qt::AlignCenter );
71  mWeeknos[i]->setFont( QFont( generalFont, 10 ) );
72  mWeeknos[i]->installEventFilter( this );
73 
74  topLayout->addWidget( mWeeknos[i], i + 2, 0 );
75  }
76 
77  mDayMatrix = new KODayMatrix( this );
78  mDayMatrix->setObjectName( QLatin1String("KDateNavigator::dayMatrix") );
79 
80  connect( mDayMatrix, SIGNAL(selected(KCalCore::DateList)),
81  SIGNAL(datesSelected(KCalCore::DateList)) );
82 
83  connect( mDayMatrix, SIGNAL(incidenceDropped(Akonadi::Item,QDate)),
84  SIGNAL(incidenceDropped(Akonadi::Item,QDate)) );
85  connect( mDayMatrix, SIGNAL(incidenceDroppedMove(Akonadi::Item,QDate)),
86  SIGNAL(incidenceDroppedMove(Akonadi::Item,QDate)) );
87 
88  connect( mDayMatrix, SIGNAL(newEventSignal(QDate)),
89  SIGNAL(newEventSignal(QDate)) );
90  connect( mDayMatrix, SIGNAL(newTodoSignal(QDate)),
91  SIGNAL(newTodoSignal(QDate)) );
92  connect( mDayMatrix, SIGNAL(newJournalSignal(QDate)),
93  SIGNAL(newJournalSignal(QDate)) );
94 
95  topLayout->addWidget( mDayMatrix, 2, 1, 6, 7 );
96 
97  // read settings from configuration file.
98  updateConfig();
99 }
100 
101 KDateNavigator::~KDateNavigator()
102 {
103 }
104 
105 void KDateNavigator::setCalendar( const Akonadi::ETMCalendar::Ptr &calendar )
106 {
107  if (mCalendar)
108  disconnect(mCalendar.data(), 0, this, 0);
109 
110  mCalendar = calendar;
111 
112  if (mCalendar)
113  connect(mCalendar.data(), SIGNAL(calendarChanged()), SLOT(setUpdateNeeded()));
114 
115  mDayMatrix->setCalendar( calendar );
116 }
117 
118 void KDateNavigator::setBaseDate( const QDate &date )
119 {
120  if ( date != mBaseDate ) {
121  mBaseDate = date;
122 
123  updateDates();
124  updateView();
125 
126  // Use the base date to show the monthname and year in the header
127  KCalCore::DateList dates;
128  dates.append( date );
129  mNavigatorBar->selectDates( dates );
130 
131  update();
132  mDayMatrix->update();
133  }
134 }
135 
136 QSizePolicy KDateNavigator::sizePolicy () const
137 {
138  return QSizePolicy( QSizePolicy::MinimumExpanding,
139  QSizePolicy::MinimumExpanding );
140 }
141 
142 void KDateNavigator::updateToday()
143 {
144  mDayMatrix->recalculateToday();
145  mDayMatrix->update();
146 }
147 
148 QDate KDateNavigator::startDate() const
149 {
150  // Find the first day of the week of the current month.
151  QDate dayone( mBaseDate.year(), mBaseDate.month(), mBaseDate.day() );
152  int d2 = KOGlobals::self()->calendarSystem()->day( dayone );
153  dayone = dayone.addDays( -d2 + 1 );
154 
155  const KCalendarSystem *calsys = KOGlobals::self()->calendarSystem();
156  int m_fstDayOfWkCalsys = calsys->dayOfWeek( dayone );
157  int weekstart = KGlobal::locale()->weekStartDay();
158 
159  // If month begins on Monday and Monday is first day of week,
160  // month should begin on second line. Sunday doesn't have this problem.
161  int nextLine = m_fstDayOfWkCalsys <= weekstart ? 7 : 0;
162 
163  // update the matrix dates
164  int index = weekstart - m_fstDayOfWkCalsys - nextLine;
165 
166  dayone = dayone.addDays( index );
167 
168  return dayone;
169 }
170 
171 QDate KDateNavigator::endDate() const
172 {
173  return startDate().addDays( 6 * 7 );
174 }
175 
176 void KDateNavigator::setHighlightMode( bool highlightEvents,
177  bool highlightTodos,
178  bool highlightJournals ) const {
179 
180  mDayMatrix->setHighlightMode( highlightEvents, highlightTodos, highlightJournals );
181 }
182 
183 void KDateNavigator::updateDates()
184 {
185  QDate dayone = startDate();
186 
187  mDayMatrix->updateView( dayone );
188 
189  const KCalendarSystem *calsys = KOGlobals::self()->calendarSystem();
190 
191  // set the week numbers.
192  for ( int i=0; i < 6; ++i ) {
193  // Use QDate's weekNumber method to determine the week number!
194  QDate dtStart = mDayMatrix->getDate( i * 7 );
195  QDate dtEnd = mDayMatrix->getDate( ( i + 1 ) * 7 - 1 );
196  const int weeknumstart = calsys->week( dtStart );
197  const int weeknumend = calsys->week( dtEnd );
198  QString weeknum;
199 
200  if ( weeknumstart != weeknumend ) {
201  weeknum = i18nc( "start/end week number of line in date picker", "%1/%2",
202  weeknumstart, weeknumend );
203  } else {
204  weeknum.setNum( weeknumstart );
205  }
206  mWeeknos[i]->setText( weeknum );
207  mWeeknos[i]->setToolTip( i18n( "Scroll to week number %1", weeknum ) );
208  mWeeknos[i]->setWhatsThis(
209  i18n( "Click here to scroll the display to week number %1 "
210  "of the currently displayed year.", weeknum ) );
211  }
212 
213 // each updateDates is followed by an updateView -> repaint is issued there !
214 // mDayMatrix->repaint();
215 }
216 
217 void KDateNavigator::updateDayMatrix()
218 {
219  mDayMatrix->updateView();
220  mDayMatrix->update();
221 }
222 
223 void KDateNavigator::setUpdateNeeded()
224 {
225  mDayMatrix->setUpdateNeeded();
226 }
227 
228 QDate KDateNavigator::month() const
229 {
230  QDate firstCell = startDate();
231  const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
232 
233  if ( calSys->day( firstCell ) == 1 ) {
234  return firstCell;
235  } else {
236  calSys->setDate( firstCell, calSys->year( firstCell ),
237  calSys->month( firstCell ), 1 );
238  return calSys->addMonths( firstCell, 1 );
239  }
240 }
241 
242 void KDateNavigator::updateView()
243 {
244  updateDayMatrix();
245  update();
246 }
247 
248 void KDateNavigator::updateConfig()
249 {
250  int weekstart = KGlobal::locale()->weekStartDay();
251  for ( int i=0; i < 7; ++i ) {
252  const int day = weekstart + i <= 7 ? weekstart + i : ( weekstart + i ) % 7;
253  QString dayName =
254  KOGlobals::self()->calendarSystem()->weekDayName( day, KCalendarSystem::ShortDayName );
255  QString longDayName =
256  KOGlobals::self()->calendarSystem()->weekDayName( day, KCalendarSystem::LongDayName );
257  mHeadings[i]->setText( dayName );
258  mHeadings[i]->setToolTip( i18n( "%1", longDayName ) );
259  mHeadings[i]->setWhatsThis(
260  i18n( "A column header of the %1 dates in the month.", longDayName ) );
261  }
262  mDayMatrix->setUpdateNeeded();
263  updateDayMatrix();
264  update();
265  // FIXME: Use actual config setting here
266 // setShowWeekNums( true );
267 }
268 
269 void KDateNavigator::setShowWeekNums( bool enabled )
270 {
271  for ( int i=0; i < 6; ++i ) {
272  if( enabled ) {
273  mWeeknos[i]->show();
274  } else {
275  mWeeknos[i]->hide();
276  }
277  }
278 }
279 
280 void KDateNavigator::selectMonthHelper( int monthDifference )
281 {
282  QDate baseDateNextMonth = KOGlobals::self()->calendarSystem()->addMonths(
283  mBaseDate, monthDifference );
284 
285  KCalCore::DateList newSelection = mSelectedDates;
286  for ( int i=0; i < mSelectedDates.count(); ++i ) {
287  newSelection[i] =
288  KOGlobals::self()->calendarSystem()->addMonths( newSelection[i], monthDifference );
289  }
290 
291  setBaseDate( baseDateNextMonth );
292  mSelectedDates = newSelection;
293  mDayMatrix->setSelectedDaysFrom( *( newSelection.begin() ),
294  *( --newSelection.end() ) );
295  updateView();
296 }
297 
298 void KDateNavigator::selectNextMonth()
299 {
300  selectMonthHelper( 1 );
301 }
302 
303 void KDateNavigator::selectPreviousMonth()
304 {
305  selectMonthHelper( -1 );
306 }
307 
308 void KDateNavigator::selectDates( const KCalCore::DateList &dateList )
309 {
310  if ( dateList.count() > 0 ) {
311  mSelectedDates = dateList;
312 
313  updateDates();
314 
315  mDayMatrix->setSelectedDaysFrom( *( dateList.begin() ),
316  *( --dateList.end() ) );
317 
318  updateView();
319  }
320 }
321 
322 void KDateNavigator::wheelEvent ( QWheelEvent *e )
323 {
324  if ( e->delta() > 0 ) {
325  emit goPrevious();
326  } else {
327  emit goNext();
328  }
329  e->accept();
330 }
331 
332 bool KDateNavigator::eventFilter ( QObject *o, QEvent *e )
333 {
334  if ( e->type() == QEvent::MouseButtonPress ) {
335  int i;
336  for ( i=0; i < 6; ++i ) {
337  if ( o == mWeeknos[i] ) {
338  const QDate weekstart = mDayMatrix->getDate( i * 7 );
339  emit weekClicked( weekstart, month() );
340  break;
341  }
342  }
343  return true;
344  } else {
345  return false;
346  }
347 }
348 
349 #include "kdatenavigator.moc"
KDateNavigator::updateDates
void updateDates()
Definition: kdatenavigator.cpp:183
KDateNavigator::~KDateNavigator
~KDateNavigator()
Definition: kdatenavigator.cpp:101
KDateNavigator::selectNextMonth
void selectNextMonth()
Definition: kdatenavigator.cpp:298
KDateNavigator::selectDates
void selectDates(const KCalCore::DateList &)
Definition: kdatenavigator.cpp:308
KDateNavigator::updateConfig
void updateConfig()
Definition: kdatenavigator.cpp:248
KDateNavigator::nextYearClicked
void nextYearClicked()
KDateNavigator::startDate
QDate startDate() const
Definition: kdatenavigator.cpp:148
koglobals.h
navigatorbar.h
KDateNavigator::incidenceDroppedMove
void incidenceDroppedMove(const Akonadi::Item &, const QDate &)
KODayMatrix::getDate
const QDate & getDate(int offset) const
Returns the QDate object associated with day indexed by the supplied offset.
Definition: kodaymatrix.cpp:412
KDateNavigator::wheelEvent
void wheelEvent(QWheelEvent *)
Definition: kdatenavigator.cpp:322
QWidget
KDateNavigator::datesSelected
void datesSelected(const KCalCore::DateList &)
kodaymatrix.h
KDateNavigator::sizePolicy
QSizePolicy sizePolicy() const
Definition: kdatenavigator.cpp:136
KDateNavigator::goPrevious
void goPrevious()
kdatenavigator.h
KDateNavigator::updateView
void updateView()
Definition: kdatenavigator.cpp:242
KDateNavigator::endDate
QDate endDate() const
Definition: kdatenavigator.cpp:171
QObject
KDateNavigator::selectPreviousMonth
void selectPreviousMonth()
Definition: kdatenavigator.cpp:303
KDateNavigator::setShowWeekNums
void setShowWeekNums(bool enabled)
Definition: kdatenavigator.cpp:269
NavigatorBar::selectDates
void selectDates(const KCalCore::DateList &)
Definition: navigatorbar.cpp:124
KODayMatrix::setHighlightMode
void setHighlightMode(bool highlightEvents, bool highlightTodos, bool highlightJournals)
Sets which incidences should be highlighted.
Definition: kodaymatrix.cpp:453
KDateNavigator::KDateNavigator
KDateNavigator(QWidget *parent=0)
Definition: kdatenavigator.cpp:39
KDateNavigator::incidenceDropped
void incidenceDropped(const Akonadi::Item &, const QDate &)
KODayMatrix::updateView
void updateView(const QDate &actdate)
updates the day matrix to start with the given date.
Definition: kodaymatrix.cpp:182
KDateNavigator::goNext
void goNext()
KDateNavigator::yearSelected
void yearSelected(int year)
KODayMatrix::setSelectedDaysFrom
void setSelectedDaysFrom(const QDate &start, const QDate &end)
Sets the actual to be displayed selection in the day matrix starting from start and ending with end...
Definition: kodaymatrix.cpp:139
KDateNavigator::nextMonthClicked
void nextMonthClicked()
KDateNavigator::eventFilter
bool eventFilter(QObject *, QEvent *)
Definition: kdatenavigator.cpp:332
KDateNavigator::setBaseDate
void setBaseDate(const QDate &)
Definition: kdatenavigator.cpp:118
KDateNavigator::updateToday
void updateToday()
Definition: kdatenavigator.cpp:142
KDateNavigator::newJournalSignal
void newJournalSignal(const QDate &)
KDateNavigator::monthSelected
void monthSelected(int month)
KOGlobals::calendarSystem
const KCalendarSystem * calendarSystem() const
Definition: koglobals.cpp:65
KOGlobals::self
static KOGlobals * self()
Definition: koglobals.cpp:43
KODayMatrix::setCalendar
void setCalendar(const Akonadi::ETMCalendar::Ptr &)
Associate a calendar with this day matrix.
Definition: kodaymatrix.cpp:70
NavigatorBar
Definition: navigatorbar.h:33
KDateNavigator::newTodoSignal
void newTodoSignal(const QDate &)
KDateNavigator::month
QDate month() const
Returns the current displayed month.
Definition: kdatenavigator.cpp:228
KDateNavigator::setHighlightMode
void setHighlightMode(bool highlightEvents, bool highlightTodos, bool highlightJournals) const
Definition: kdatenavigator.cpp:176
KDateNavigator::prevMonthClicked
void prevMonthClicked()
KODayMatrix
Replacement for kdpdatebuton.cpp that used 42 widgets for the day matrix to be displayed.
Definition: kodaymatrix.h:69
KDateNavigator::setUpdateNeeded
void setUpdateNeeded()
Definition: kdatenavigator.cpp:223
KODayMatrix::setUpdateNeeded
void setUpdateNeeded()
Definition: kodaymatrix.cpp:177
KDateNavigator::newEventSignal
void newEventSignal(const QDate &)
QFrame
KODayMatrix::recalculateToday
void recalculateToday()
Calculates which square in the matrix should be hiighted to indicate the square is on "today"...
Definition: kodaymatrix.cpp:152
KDateNavigator::weekClicked
void weekClicked(const QDate &week, const QDate &month)
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
KDateNavigator::prevYearClicked
void prevYearClicked()
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