source: src/gui/daynavigatorwidget.cpp @ 68b2df2

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

Add copyright to source.

  • Property mode set to 100644
File size: 3.8 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    //qDebug() << "DayNavigatorWidget::setDates(): " << aStartDate << ", " << aEndDate;
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::prevDayButtonClicked()
68{
69    //qDebug() << mStartDate << ":" << mCurDate << ":" << mEndDate;
70    if(mCurDate>mStartDate)
71    {
72        mCurDate = mCurDate.addDays(-1);
73        // check start date
74        if(mCurDate==mStartDate || mStartDate==mEndDate)
75            prevDayButton->setDisabled(true);
76        else
77            prevDayButton->setDisabled(false);
78        // check end date
79        if(mCurDate==mEndDate || mStartDate==mEndDate)
80            nextDayButton->setDisabled(true);
81        else
82            nextDayButton->setDisabled(false);
83
84        emit(dateChanged(mCurDate));
85        selectedDate->update();
86    }
87}
88
89void DayNavigatorWidget::nextDayButtonClicked()
90{
91    //qDebug() << mStartDate << ":" << mCurDate << ":" << mEndDate;
92    if(mCurDate<mEndDate)
93    {
94        mCurDate = mCurDate.addDays(1);
95        // check start date
96        if(mCurDate==mStartDate || mStartDate==mEndDate)
97            prevDayButton->setDisabled(true);
98        else
99            prevDayButton->setDisabled(false);
100        // check end date
101        if(mCurDate==mEndDate || mStartDate==mEndDate)
102            nextDayButton->setDisabled(true);
103        else
104            nextDayButton->setDisabled(false);
105
106        emit(dateChanged(mCurDate));
107        selectedDate->update();
108    }
109}
110
111void DayNavigatorWidget::paintEvent(QPaintEvent *aEvent)
112{
113    Q_UNUSED(aEvent);
114
115    QString selectedDateStr = mCurDate.toString("MMM dd yyyy");
116
117    QPainter painter(this);
118    painter.save();
119    QRect r = selectedDate->geometry();
120    QRect s = mFontMetrics->boundingRect(selectedDateStr);
121    QPoint p = QPoint(
122            r.x() + r.width()/2 - s.height()/2 - mFontMetrics->descent(),
123            - 130
124            );
125
126    painter.translate(r.width()/2, r.height()/2);
127    painter.rotate(270);
128    painter.drawText(p.y(), p.x(), selectedDateStr); // y,x,string
129    painter.restore();
130}
131
Note: See TracBrowser for help on using the repository browser.