source: confclerk_git/src/gui/daynavigatorwidget.cpp @ 04ea240

qt5
Last change on this file since 04ea240 was 04ea240, checked in by Philipp Spitzer <philipp@…>, 12 years ago

Changed the placement of the date label again.
Changed the date format to show the day-of-week.

  • Property mode set to 100644
File size: 3.4 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
38    mFontMetrics = new QFontMetrics(QLabel().font());
39}
40
41void DayNavigatorWidget::setDates(const QDate &aStartDate, const QDate &aEndDate)
42{
43    Q_ASSERT(aStartDate<=aEndDate);
44
45    mStartDate = aStartDate;
46    mEndDate = aEndDate;
47    mCurDate = aStartDate;
48
49    // QRect rect = mFontMetrics->boundingRect(mCurDate.toString("MMM dd yyyy"));
50
51    if(mStartDate==mEndDate) // only one day conference
52    {
53        prevDayButton->setDisabled(true);
54        nextDayButton->setDisabled(true);
55        emit(dateChanged(mCurDate));
56    }
57    else
58    {
59        // at least 2-days conference
60        prevDayButton->setDisabled(true);
61        nextDayButton->setDisabled(false);
62        emit(dateChanged(mCurDate));
63    }
64}
65
66void DayNavigatorWidget::prevDayButtonClicked()
67{
68    if(mCurDate>mStartDate)
69    {
70        mCurDate = mCurDate.addDays(-1);
71        // check start date
72        if(mCurDate==mStartDate || mStartDate==mEndDate)
73            prevDayButton->setDisabled(true);
74        else
75            prevDayButton->setDisabled(false);
76        // check end date
77        if(mCurDate==mEndDate || mStartDate==mEndDate)
78            nextDayButton->setDisabled(true);
79        else
80            nextDayButton->setDisabled(false);
81
82        emit(dateChanged(mCurDate));
83        selectedDate->update();
84    }
85}
86
87void DayNavigatorWidget::nextDayButtonClicked()
88{
89    if(mCurDate<mEndDate)
90    {
91        mCurDate = mCurDate.addDays(1);
92        // check start date
93        if(mCurDate==mStartDate || mStartDate==mEndDate)
94            prevDayButton->setDisabled(true);
95        else
96            prevDayButton->setDisabled(false);
97        // check end date
98        if(mCurDate==mEndDate || mStartDate==mEndDate)
99            nextDayButton->setDisabled(true);
100        else
101            nextDayButton->setDisabled(false);
102
103        emit(dateChanged(mCurDate));
104        selectedDate->update();
105    }
106}
107
108void DayNavigatorWidget::paintEvent(QPaintEvent *aEvent)
109{
110    Q_UNUSED(aEvent);
111
112    QString selectedDateStr = mCurDate.toString("dddd\nyyyy-MM-dd");
113    QPainter painter(this);
114    painter.save();
115    QRect q(y()-height(), x(), height(), width());
116    painter.rotate(270);
117    painter.drawText(q, Qt::AlignCenter, selectedDateStr);
118    painter.restore();
119}
120
Note: See TracBrowser for help on using the repository browser.