2 * Copyright (C) 2010 Ixonos Plc.
3 * Copyright (C) 2011 Philipp Spitzer, gregor herrmann
5 * This file is part of ConfClerk.
7 * ConfClerk is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation, either version 2 of the License, or (at your option)
12 * ConfClerk is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * ConfClerk. If not, see <http://www.gnu.org/licenses/>.
20 #include "daynavigatorwidget.h"
23 #include <QFontMetrics>
28 DayNavigatorWidget::DayNavigatorWidget(QWidget *aParent)
35 connect(prevDayButton, SIGNAL(clicked()), SLOT(prevDayButtonClicked()));
36 connect(nextDayButton, SIGNAL(clicked()), SLOT(nextDayButtonClicked()));
37 connect(todayButton, SIGNAL(clicked()), SLOT(todayButtonClicked()));
39 mFontMetrics = new QFontMetrics(QLabel().font());
42 void DayNavigatorWidget::setDates(const QDate &aStartDate, const QDate &aEndDate)
44 Q_ASSERT(aStartDate<=aEndDate);
46 mStartDate = aStartDate;
48 mCurDate = aStartDate;
50 // QRect rect = mFontMetrics->boundingRect(mCurDate.toString("MMM dd yyyy"));
52 if(mStartDate==mEndDate) // only one day conference
54 prevDayButton->setDisabled(true);
55 nextDayButton->setDisabled(true);
56 emit(dateChanged(mCurDate));
60 // at least 2-days conference
61 prevDayButton->setDisabled(true);
62 nextDayButton->setDisabled(false);
63 emit(dateChanged(mCurDate));
67 void DayNavigatorWidget::configureNavigation()
70 if(mCurDate==mStartDate || mStartDate==mEndDate)
71 prevDayButton->setDisabled(true);
73 prevDayButton->setDisabled(false);
75 if(mCurDate==mEndDate || mStartDate==mEndDate)
76 nextDayButton->setDisabled(true);
78 nextDayButton->setDisabled(false);
81 void DayNavigatorWidget::prevDayButtonClicked()
83 if(mCurDate>mStartDate)
85 mCurDate = mCurDate.addDays(-1);
86 configureNavigation();
87 emit(dateChanged(mCurDate));
88 selectedDate->update();
92 void DayNavigatorWidget::nextDayButtonClicked()
96 mCurDate = mCurDate.addDays(1);
97 configureNavigation();
98 emit(dateChanged(mCurDate));
99 selectedDate->update();
103 void DayNavigatorWidget::todayButtonClicked()
105 QDate targetDate = QDate::currentDate();
106 if (targetDate>mStartDate && targetDate<mEndDate)
108 mCurDate = targetDate;
109 configureNavigation();
110 emit(dateChanged(mCurDate));
111 selectedDate->update();
115 void DayNavigatorWidget::paintEvent(QPaintEvent *aEvent)
119 QString selectedDateStr = mCurDate.toString("dddd\nyyyy-MM-dd");
120 QPainter painter(this);
122 QRect q(y()-height()+16, x(), height(), width()); // today icon size = 32x32
124 painter.drawText(q, Qt::AlignCenter, selectedDateStr);