source: src/gui/daynavigatorwidget.cpp @ d49254d

qt5
Last change on this file since d49254d was ea638ef, checked in by pavelpa <pavelpa@…>, 12 years ago

implemented 'conflicts' dialog

  • displays rooms instead of conflicts for now
    • needs to implement additional methods in Event, ...
  • Property mode set to 100644
File size: 3.1 KB
Line 
1#include "daynavigatorwidget.h"
2
3#include <QPainter>
4#include <QFontMetrics>
5#include <QLabel>
6
7#include <QDebug>
8
9DayNavigatorWidget::DayNavigatorWidget(QWidget *aParent)
10    : QWidget(aParent)
11    , mStartDate(QDate())
12    , mEndDate(QDate())
13    , mCurDate(QDate())
14{
15    setupUi(this);
16    connect(prevDayButton, SIGNAL(clicked()), SLOT(prevDayButtonClicked()));
17    connect(nextDayButton, SIGNAL(clicked()), SLOT(nextDayButtonClicked()));
18
19    mFontMetrics = new QFontMetrics(QLabel().font());
20}
21
22void DayNavigatorWidget::setDates(const QDate &aStartDate, const QDate &aEndDate)
23{
24    Q_ASSERT(aStartDate<=aEndDate);
25
26    //qDebug() << "DayNavigatorWidget::setDates(): " << aStartDate << ", " << aEndDate;
27    mStartDate = aStartDate;
28    mEndDate = aEndDate;
29    mCurDate = aStartDate;
30
31    QRect rect = mFontMetrics->boundingRect(mCurDate.toString("MMM dd yyyy"));
32
33    if(mStartDate==mEndDate) // only one day conference
34    {
35        prevDayButton->setDisabled(true);
36        nextDayButton->setDisabled(true);
37        emit(dateChanged(mCurDate));
38    }
39    else
40    {
41        // at least 2-days conference
42        prevDayButton->setDisabled(true);
43        nextDayButton->setDisabled(false);
44        emit(dateChanged(mCurDate));
45    }
46}
47
48void DayNavigatorWidget::prevDayButtonClicked()
49{
50    //qDebug() << mStartDate << ":" << mCurDate << ":" << mEndDate;
51    if(mCurDate>mStartDate)
52    {
53        mCurDate = mCurDate.addDays(-1);
54        // check start date
55        if(mCurDate==mStartDate || mStartDate==mEndDate)
56            prevDayButton->setDisabled(true);
57        else
58            prevDayButton->setDisabled(false);
59        // check end date
60        if(mCurDate==mEndDate || mStartDate==mEndDate)
61            nextDayButton->setDisabled(true);
62        else
63            nextDayButton->setDisabled(false);
64
65        emit(dateChanged(mCurDate));
66        selectedDate->update();
67    }
68}
69
70void DayNavigatorWidget::nextDayButtonClicked()
71{
72    //qDebug() << mStartDate << ":" << mCurDate << ":" << mEndDate;
73    if(mCurDate<mEndDate)
74    {
75        mCurDate = mCurDate.addDays(1);
76        // check start date
77        if(mCurDate==mStartDate || mStartDate==mEndDate)
78            prevDayButton->setDisabled(true);
79        else
80            prevDayButton->setDisabled(false);
81        // check end date
82        if(mCurDate==mEndDate || mStartDate==mEndDate)
83            nextDayButton->setDisabled(true);
84        else
85            nextDayButton->setDisabled(false);
86
87        emit(dateChanged(mCurDate));
88        selectedDate->update();
89    }
90}
91
92QDate DayNavigatorWidget::getCurrentDate()
93{
94    return mCurDate;
95}
96
97void DayNavigatorWidget::paintEvent(QPaintEvent *aEvent)
98{
99    QString selectedDateStr = mCurDate.toString("MMM dd yyyy");
100
101    QPainter painter(this);
102    painter.save();
103    QRect r = selectedDate->geometry();
104    QRect s = mFontMetrics->boundingRect(selectedDateStr);
105    QPoint p = QPoint(
106            r.x() + r.width()/2 - s.height()/2 - mFontMetrics->descent(),
107            - 130
108            );
109
110    painter.translate(r.width()/2, r.height()/2);
111    painter.rotate(270);
112    painter.drawText(p.y(), p.x(), selectedDateStr); // y,x,string
113    painter.restore();
114}
115
Note: See TracBrowser for help on using the repository browser.