Changeset 701240f in confclerk_git for src/gui/daynavigatorwidget.cpp


Ignore:
Timestamp:
09/21/11 21:29:43 (11 years ago)
Author:
Philipp Spitzer <philipp@…>
Branches:
master, qt5
Children:
66ec7cb
Parents:
788182f
Message:

Cleanup daynavigatorwidget.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/gui/daynavigatorwidget.cpp

    r788182f r701240f  
    2121
    2222#include <QPainter>
    23 #include <QFontMetrics>
    2423#include <QLabel>
    2524
    26 #include <QDebug>
    2725
    28 DayNavigatorWidget::DayNavigatorWidget(QWidget *aParent)
    29     : QWidget(aParent)
    30     , mStartDate(QDate())
    31     , mEndDate(QDate())
    32     , mCurDate(QDate())
    33 {
    34     setupUi(this);
     26DayNavigatorWidget::DayNavigatorWidget(QWidget *aParent): QWidget(aParent) {
     27    setupUi(this);   
     28
    3529    connect(prevDayButton, SIGNAL(clicked()), SLOT(prevDayButtonClicked()));
    3630    connect(nextDayButton, SIGNAL(clicked()), SLOT(nextDayButtonClicked()));
    3731    connect(todayButton, SIGNAL(clicked()), SLOT(todayButtonClicked()));
    38 
    39     mFontMetrics = new QFontMetrics(QLabel().font());
    4032}
    4133
    42 void DayNavigatorWidget::setDates(const QDate &aStartDate, const QDate &aEndDate)
    43 {
    44     Q_ASSERT(aStartDate<=aEndDate);
     34
     35void DayNavigatorWidget::setDates(const QDate &aStartDate, const QDate &aEndDate) {
     36    Q_ASSERT(aStartDate.isValid() && aEndDate.isValid() && aStartDate<=aEndDate);
    4537
    4638    mStartDate = aStartDate;
    4739    mEndDate = aEndDate;
     40
    4841    if (!mCurDate.isValid()) mCurDate = mStartDate;
    4942    // if mCurDate is out of range, set it to mstartDate
    5043    else if (mCurDate < mStartDate || mCurDate > mEndDate) mCurDate = mStartDate;
    5144
    52     prevDayButton->setDisabled(mCurDate == mStartDate);
    53     nextDayButton->setDisabled(mCurDate == mEndDate);
     45    configureNavigation();
    5446    emit(dateChanged(mCurDate));
    5547    this->update();
    5648}
    5749
    58 void DayNavigatorWidget::configureNavigation()
    59 {
    60     // check start date
    61     if(mCurDate==mStartDate || mStartDate==mEndDate)
    62         prevDayButton->setDisabled(true);
    63     else
    64         prevDayButton->setDisabled(false);
    65     // check end date
    66     if(mCurDate==mEndDate || mStartDate==mEndDate)
    67         nextDayButton->setDisabled(true);
    68     else
    69         nextDayButton->setDisabled(false);
     50
     51void DayNavigatorWidget::setCurDate(const QDate& curDate) {
     52    Q_ASSERT(curDate.isValid());
     53    if (curDate == mCurDate) return;
     54
     55    if (!mStartDate.isValid()) {
     56        // the start and end date have not been set
     57        mStartDate = curDate;
     58        mEndDate = curDate;
     59        mCurDate = curDate;
     60    }
     61
     62    else if (curDate < mStartDate) mCurDate = mStartDate;
     63    else if (curDate > mEndDate) mCurDate = mEndDate;
     64    else mCurDate = curDate;
     65
     66    configureNavigation();
     67    emit(dateChanged(mCurDate));
     68    this->update();
    7069}
    7170
    72 void DayNavigatorWidget::prevDayButtonClicked()
    73 {
    74     if(mCurDate>mStartDate)
    75     {
    76         mCurDate = mCurDate.addDays(-1);
    77         configureNavigation();
    78         emit(dateChanged(mCurDate));
    79         this->update();
    80     }
     71
     72void DayNavigatorWidget::configureNavigation() {
     73    prevDayButton->setDisabled(mCurDate == mStartDate);
     74    nextDayButton->setDisabled(mCurDate == mEndDate);
    8175}
    8276
    83 void DayNavigatorWidget::nextDayButtonClicked()
    84 {
    85     if(mCurDate<mEndDate)
    86     {
    87         mCurDate = mCurDate.addDays(1);
    88         configureNavigation();
    89         emit(dateChanged(mCurDate));
    90         this->update();
    91     }
     77
     78void DayNavigatorWidget::prevDayButtonClicked() {
     79    if(mCurDate <= mStartDate) return;
     80    mCurDate = mCurDate.addDays(-1);
     81    configureNavigation();
     82    emit(dateChanged(mCurDate));
     83    this->update();
    9284}
    9385
    94 void DayNavigatorWidget::todayButtonClicked()
    95 {
    96     QDate targetDate = QDate::currentDate();
    97     if (targetDate>mStartDate && targetDate<mEndDate)
    98     {
    99         mCurDate = targetDate;
    100         configureNavigation();
    101         emit(dateChanged(mCurDate));
    102         this->update();
    103     }
     86
     87void DayNavigatorWidget::nextDayButtonClicked() {
     88    if(mCurDate >= mEndDate) return;
     89    mCurDate = mCurDate.addDays(1);
     90    configureNavigation();
     91    emit(dateChanged(mCurDate));
     92    this->update();
    10493}
     94
     95
     96void DayNavigatorWidget::todayButtonClicked() {
     97    setCurDate(QDate::currentDate());
     98}
     99
    105100
    106101void DayNavigatorWidget::paintEvent(QPaintEvent *aEvent)
     
    135130    painter.restore();
    136131}
    137 
Note: See TracChangeset for help on using the changeset viewer.