source: src/gui/daynavigatorwidget.cpp @ c7da828

qt5
Last change on this file since c7da828 was c7da828, checked in by gregor herrmann <gregoa@…>, 12 years ago

Shift date text up by icon/2 in order to re-center the text. More or less at least.

  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2 * Copyright (C) 2010 Ixonos Plc.
3 * Copyright (C) 2011 Philipp Spitzer, gregor herrmann
4 *
5 * This file is part of ConfClerk.
6 *
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)
10 * any later version.
11 *
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
15 * more details.
16 *
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/>.
19 */
20#include "daynavigatorwidget.h"
21
22#include <QPainter>
23#include <QFontMetrics>
24#include <QLabel>
25
26#include <QDebug>
27
28DayNavigatorWidget::DayNavigatorWidget(QWidget *aParent)
29    : QWidget(aParent)
30    , mStartDate(QDate())
31    , mEndDate(QDate())
32    , mCurDate(QDate())
33{
34    setupUi(this);
35    connect(prevDayButton, SIGNAL(clicked()), SLOT(prevDayButtonClicked()));
36    connect(nextDayButton, SIGNAL(clicked()), SLOT(nextDayButtonClicked()));
37    connect(todayButton, SIGNAL(clicked()), SLOT(todayButtonClicked()));
38
39    mFontMetrics = new QFontMetrics(QLabel().font());
40}
41
42void DayNavigatorWidget::setDates(const QDate &aStartDate, const QDate &aEndDate)
43{
44    Q_ASSERT(aStartDate<=aEndDate);
45
46    mStartDate = aStartDate;
47    mEndDate = aEndDate;
48    mCurDate = aStartDate;
49
50    // QRect rect = mFontMetrics->boundingRect(mCurDate.toString("MMM dd yyyy"));
51
52    if(mStartDate==mEndDate) // only one day conference
53    {
54        prevDayButton->setDisabled(true);
55        nextDayButton->setDisabled(true);
56        emit(dateChanged(mCurDate));
57    }
58    else
59    {
60        // at least 2-days conference
61        prevDayButton->setDisabled(true);
62        nextDayButton->setDisabled(false);
63        emit(dateChanged(mCurDate));
64    }
65}
66
67void DayNavigatorWidget::configureNavigation()
68{
69    // check start date
70    if(mCurDate==mStartDate || mStartDate==mEndDate)
71        prevDayButton->setDisabled(true);
72    else
73        prevDayButton->setDisabled(false);
74    // check end date
75    if(mCurDate==mEndDate || mStartDate==mEndDate)
76        nextDayButton->setDisabled(true);
77    else
78        nextDayButton->setDisabled(false);
79}
80
81void DayNavigatorWidget::prevDayButtonClicked()
82{
83    if(mCurDate>mStartDate)
84    {
85        mCurDate = mCurDate.addDays(-1);
86        configureNavigation();
87        emit(dateChanged(mCurDate));
88        selectedDate->update();
89    }
90}
91
92void DayNavigatorWidget::nextDayButtonClicked()
93{
94    if(mCurDate<mEndDate)
95    {
96        mCurDate = mCurDate.addDays(1);
97        configureNavigation();
98        emit(dateChanged(mCurDate));
99        selectedDate->update();
100    }
101}
102
103void DayNavigatorWidget::todayButtonClicked()
104{
105    QDate targetDate = QDate::currentDate();
106    if (targetDate>mStartDate && targetDate<mEndDate)
107    {
108        mCurDate = targetDate;
109        configureNavigation();
110        emit(dateChanged(mCurDate));
111        selectedDate->update();
112    }
113}
114
115void DayNavigatorWidget::paintEvent(QPaintEvent *aEvent)
116{
117    Q_UNUSED(aEvent);
118
119    QString selectedDateStr = mCurDate.toString("dddd\nyyyy-MM-dd");
120    QPainter painter(this);
121    painter.save();
122    QRect q(y()-height()+16, x(), height(), width()); // today icon size = 32x32
123    painter.rotate(270);
124    painter.drawText(q, Qt::AlignCenter, selectedDateStr);
125    painter.restore();
126}
127
Note: See TracBrowser for help on using the repository browser.