31 #include <KCalendarSystem>
32 #include <KGlobalSettings>
35 #include <QGridLayout>
37 #include <QWheelEvent>
40 :
QFrame( parent ), mBaseDate( 1970, 1, 1 )
42 QGridLayout *topLayout =
new QGridLayout(
this );
43 topLayout->setMargin( 0 );
44 topLayout->setSpacing( 0 );
47 topLayout->addWidget( mNavigatorBar, 0, 0, 1, 8 );
56 QString generalFont = KGlobalSettings::generalFont().family();
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 );
64 topLayout->addWidget( mHeadings[i], 1, i + 1 );
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 );
74 topLayout->addWidget( mWeeknos[i], i + 2, 0 );
78 mDayMatrix->setObjectName( QLatin1String(
"KDateNavigator::dayMatrix") );
80 connect( mDayMatrix, SIGNAL(selected(KCalCore::DateList)),
95 topLayout->addWidget( mDayMatrix, 2, 1, 6, 7 );
108 disconnect(mCalendar.data(), 0,
this, 0);
110 mCalendar = calendar;
113 connect(mCalendar.data(), SIGNAL(calendarChanged()), SLOT(
setUpdateNeeded()));
120 if ( date != mBaseDate ) {
127 KCalCore::DateList dates;
128 dates.append( date );
132 mDayMatrix->update();
138 return QSizePolicy( QSizePolicy::MinimumExpanding,
139 QSizePolicy::MinimumExpanding );
145 mDayMatrix->update();
151 QDate dayone( mBaseDate.year(), mBaseDate.month(), mBaseDate.day() );
153 dayone = dayone.addDays( -d2 + 1 );
156 int m_fstDayOfWkCalsys = calsys->dayOfWeek( dayone );
157 int weekstart = KGlobal::locale()->weekStartDay();
161 int nextLine = m_fstDayOfWkCalsys <= weekstart ? 7 : 0;
164 int index = weekstart - m_fstDayOfWkCalsys - nextLine;
166 dayone = dayone.addDays( index );
178 bool highlightJournals )
const {
180 mDayMatrix->
setHighlightMode( highlightEvents, highlightTodos, highlightJournals );
192 for (
int i=0; i < 6; ++i ) {
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 );
200 if ( weeknumstart != weeknumend ) {
201 weeknum = i18nc(
"start/end week number of line in date picker",
"%1/%2",
202 weeknumstart, weeknumend );
204 weeknum.setNum( weeknumstart );
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 ) );
220 mDayMatrix->update();
233 if ( calSys->day( firstCell ) == 1 ) {
236 calSys->setDate( firstCell, calSys->year( firstCell ),
237 calSys->month( firstCell ), 1 );
238 return calSys->addMonths( firstCell, 1 );
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;
255 QString 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 ) );
271 for (
int i=0; i < 6; ++i ) {
280 void KDateNavigator::selectMonthHelper(
int monthDifference )
283 mBaseDate, monthDifference );
285 KCalCore::DateList newSelection = mSelectedDates;
286 for (
int i=0; i < mSelectedDates.count(); ++i ) {
292 mSelectedDates = newSelection;
294 *( --newSelection.end() ) );
300 selectMonthHelper( 1 );
305 selectMonthHelper( -1 );
310 if ( dateList.count() > 0 ) {
311 mSelectedDates = dateList;
316 *( --dateList.end() ) );
324 if ( e->delta() > 0 ) {
334 if ( e->type() == QEvent::MouseButtonPress ) {
336 for ( i=0; i < 6; ++i ) {
337 if ( o == mWeeknos[i] ) {
338 const QDate weekstart = mDayMatrix->
getDate( i * 7 );
349 #include "kdatenavigator.moc"
void selectDates(const KCalCore::DateList &)
void incidenceDroppedMove(const Akonadi::Item &, const QDate &)
const QDate & getDate(int offset) const
Returns the QDate object associated with day indexed by the supplied offset.
void wheelEvent(QWheelEvent *)
void datesSelected(const KCalCore::DateList &)
QSizePolicy sizePolicy() const
void selectPreviousMonth()
void setShowWeekNums(bool enabled)
void selectDates(const KCalCore::DateList &)
void setHighlightMode(bool highlightEvents, bool highlightTodos, bool highlightJournals)
Sets which incidences should be highlighted.
KDateNavigator(QWidget *parent=0)
void incidenceDropped(const Akonadi::Item &, const QDate &)
void updateView(const QDate &actdate)
updates the day matrix to start with the given date.
void yearSelected(int year)
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...
bool eventFilter(QObject *, QEvent *)
void setBaseDate(const QDate &)
void newJournalSignal(const QDate &)
void monthSelected(int month)
const KCalendarSystem * calendarSystem() const
static KOGlobals * self()
void setCalendar(const Akonadi::ETMCalendar::Ptr &)
Associate a calendar with this day matrix.
void newTodoSignal(const QDate &)
QDate month() const
Returns the current displayed month.
void setHighlightMode(bool highlightEvents, bool highlightTodos, bool highlightJournals) const
Replacement for kdpdatebuton.cpp that used 42 widgets for the day matrix to be displayed.
void newEventSignal(const QDate &)
void recalculateToday()
Calculates which square in the matrix should be hiighted to indicate the square is on "today"...
void weekClicked(const QDate &week, const QDate &month)
void setCalendar(const Akonadi::ETMCalendar::Ptr &)
Associate date navigator with a calendar.