source: src/gui/daynavigatorwidget.cpp @ 5992909

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

day navigator widget changes

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