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 //qDebug() << "DayNavigatorWidget::setDates(): " << 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::prevDayButtonClicked()
69 //qDebug() << mStartDate << ":" << mCurDate << ":" << mEndDate;
70 if(mCurDate>mStartDate)
72 mCurDate = mCurDate.addDays(-1);
74 if(mCurDate==mStartDate || mStartDate==mEndDate)
75 prevDayButton->setDisabled(true);
77 prevDayButton->setDisabled(false);
79 if(mCurDate==mEndDate || mStartDate==mEndDate)
80 nextDayButton->setDisabled(true);
82 nextDayButton->setDisabled(false);
84 emit(dateChanged(mCurDate));
85 selectedDate->update();
89 void DayNavigatorWidget::nextDayButtonClicked()
91 //qDebug() << mStartDate << ":" << mCurDate << ":" << mEndDate;
94 mCurDate = mCurDate.addDays(1);
96 if(mCurDate==mStartDate || mStartDate==mEndDate)
97 prevDayButton->setDisabled(true);
99 prevDayButton->setDisabled(false);
101 if(mCurDate==mEndDate || mStartDate==mEndDate)
102 nextDayButton->setDisabled(true);
104 nextDayButton->setDisabled(false);
106 emit(dateChanged(mCurDate));
107 selectedDate->update();
111 void DayNavigatorWidget::paintEvent(QPaintEvent *aEvent)
115 QString selectedDateStr = mCurDate.toString("MMM dd yyyy");
117 QPainter painter(this);
119 QRect r = selectedDate->geometry();
120 QRect s = mFontMetrics->boundingRect(selectedDateStr);
122 r.x() + r.width()/2 - s.height()/2 - mFontMetrics->descent(),
126 painter.translate(r.width()/2, r.height()/2);
128 painter.drawText(p.y(), p.x(), selectedDateStr); // y,x,string