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()));
38 mFontMetrics = new QFontMetrics(QLabel().font());
41 void DayNavigatorWidget::setDates(const QDate &aStartDate, const QDate &aEndDate)
43 Q_ASSERT(aStartDate<=aEndDate);
45 mStartDate = aStartDate;
47 mCurDate = aStartDate;
49 // QRect rect = mFontMetrics->boundingRect(mCurDate.toString("MMM dd yyyy"));
51 if(mStartDate==mEndDate) // only one day conference
53 prevDayButton->setDisabled(true);
54 nextDayButton->setDisabled(true);
55 emit(dateChanged(mCurDate));
59 // at least 2-days conference
60 prevDayButton->setDisabled(true);
61 nextDayButton->setDisabled(false);
62 emit(dateChanged(mCurDate));
66 void DayNavigatorWidget::prevDayButtonClicked()
68 if(mCurDate>mStartDate)
70 mCurDate = mCurDate.addDays(-1);
72 if(mCurDate==mStartDate || mStartDate==mEndDate)
73 prevDayButton->setDisabled(true);
75 prevDayButton->setDisabled(false);
77 if(mCurDate==mEndDate || mStartDate==mEndDate)
78 nextDayButton->setDisabled(true);
80 nextDayButton->setDisabled(false);
82 emit(dateChanged(mCurDate));
83 selectedDate->update();
87 void DayNavigatorWidget::nextDayButtonClicked()
91 mCurDate = mCurDate.addDays(1);
93 if(mCurDate==mStartDate || mStartDate==mEndDate)
94 prevDayButton->setDisabled(true);
96 prevDayButton->setDisabled(false);
98 if(mCurDate==mEndDate || mStartDate==mEndDate)
99 nextDayButton->setDisabled(true);
101 nextDayButton->setDisabled(false);
103 emit(dateChanged(mCurDate));
104 selectedDate->update();
108 void DayNavigatorWidget::paintEvent(QPaintEvent *aEvent)
112 QString selectedDateStr = mCurDate.toString("MMM dd yyyy");
114 QPainter painter(this);
116 QRect r = selectedDate->geometry();
117 QRect s = mFontMetrics->boundingRect(selectedDateStr);
119 r.x() + r.width()/2 - s.height()/2 - mFontMetrics->descent(),
123 painter.translate(r.width()/2, r.height()/2);
125 painter.drawText(p.y(), p.x(), selectedDateStr); // y,x,string