Changeset 701240f
- Timestamp:
- 09/21/11 21:29:43 (11 years ago)
- Branches:
- master, qt5
- Children:
- 66ec7cb
- Parents:
- 788182f
- Location:
- src/gui
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/gui/daynavigatorwidget.cpp
r788182f r701240f 21 21 22 22 #include <QPainter> 23 #include <QFontMetrics>24 23 #include <QLabel> 25 24 26 #include <QDebug>27 25 28 DayNavigatorWidget::DayNavigatorWidget(QWidget *aParent) 29 : QWidget(aParent) 30 , mStartDate(QDate()) 31 , mEndDate(QDate()) 32 , mCurDate(QDate()) 33 { 34 setupUi(this); 26 DayNavigatorWidget::DayNavigatorWidget(QWidget *aParent): QWidget(aParent) { 27 setupUi(this); 28 35 29 connect(prevDayButton, SIGNAL(clicked()), SLOT(prevDayButtonClicked())); 36 30 connect(nextDayButton, SIGNAL(clicked()), SLOT(nextDayButtonClicked())); 37 31 connect(todayButton, SIGNAL(clicked()), SLOT(todayButtonClicked())); 38 39 mFontMetrics = new QFontMetrics(QLabel().font());40 32 } 41 33 42 void DayNavigatorWidget::setDates(const QDate &aStartDate, const QDate &aEndDate) 43 {44 Q_ASSERT(aStartDate <=aEndDate);34 35 void DayNavigatorWidget::setDates(const QDate &aStartDate, const QDate &aEndDate) { 36 Q_ASSERT(aStartDate.isValid() && aEndDate.isValid() && aStartDate<=aEndDate); 45 37 46 38 mStartDate = aStartDate; 47 39 mEndDate = aEndDate; 40 48 41 if (!mCurDate.isValid()) mCurDate = mStartDate; 49 42 // if mCurDate is out of range, set it to mstartDate 50 43 else if (mCurDate < mStartDate || mCurDate > mEndDate) mCurDate = mStartDate; 51 44 52 prevDayButton->setDisabled(mCurDate == mStartDate); 53 nextDayButton->setDisabled(mCurDate == mEndDate); 45 configureNavigation(); 54 46 emit(dateChanged(mCurDate)); 55 47 this->update(); 56 48 } 57 49 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 51 void 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(); 70 69 } 71 70 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 72 void DayNavigatorWidget::configureNavigation() { 73 prevDayButton->setDisabled(mCurDate == mStartDate); 74 nextDayButton->setDisabled(mCurDate == mEndDate); 81 75 } 82 76 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 78 void DayNavigatorWidget::prevDayButtonClicked() { 79 if(mCurDate <= mStartDate) return; 80 mCurDate = mCurDate.addDays(-1); 81 configureNavigation(); 82 emit(dateChanged(mCurDate)); 83 this->update(); 92 84 } 93 85 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 87 void DayNavigatorWidget::nextDayButtonClicked() { 88 if(mCurDate >= mEndDate) return; 89 mCurDate = mCurDate.addDays(1); 90 configureNavigation(); 91 emit(dateChanged(mCurDate)); 92 this->update(); 104 93 } 94 95 96 void DayNavigatorWidget::todayButtonClicked() { 97 setCurDate(QDate::currentDate()); 98 } 99 105 100 106 101 void DayNavigatorWidget::paintEvent(QPaintEvent *aEvent) … … 135 130 painter.restore(); 136 131 } 137 -
src/gui/daynavigatorwidget.h
r788182f r701240f 25 25 #include <QDate> 26 26 27 /*#include <QPainter>*/ 28 /*#include <QLabel>*/ 29 30 /*class QFontMetrics;*/ 31 32 /*class VerticalLabel : public QWidget*/ 33 /*{*/ 34 35 /*public:*/ 36 /*VerticalLabel(QWidget *aParent = NULL)*/ 37 /*: QWidget(aParent)*/ 38 /*, mText("")*/ 39 /*{*/ 40 /*mFont = QLabel().font();*/ 41 /*} */ 42 43 /*void paintEvent(QPaintEvent *)*/ 44 /*{ */ 45 /*QPainter p(this);*/ 46 /*drawRotatedText(&p, 270, width()/2, height()/2, mText);*/ 47 /*} */ 48 49 /*void drawRotatedText(QPainter *aPainter, qreal aDegrees, int x, int y, const QString &aText)*/ 50 /*{ */ 51 52 /*aPainter->save();*/ 53 /*aPainter->setFont(mFont);*/ 54 /*aPainter->translate(x, y); */ 55 /*aPainter->rotate(aDegrees);*/ 56 /*QFontMetrics fm(mFont);*/ 57 /*QRect r = fm.boundingRect(aText);*/ 58 /*aPainter->drawText(-r.width()/2, fm.descent()/2, aText);*/ 59 /*aPainter->restore();*/ 60 /*} */ 61 62 /*void setText(const QString &aText)*/ 63 /*{*/ 64 /*mText = aText;*/ 65 /*update();*/ 66 /*}*/ 67 68 /*private:*/ 69 /*QString mText;*/ 70 /*QFont mFont;*/ 71 /*};*/ 72 73 class DayNavigatorWidget : public QWidget, private Ui::DayNavigatorWidget 74 { 27 /** The DayNavigator widget manages three dates, the startDate, curDate and endDate. 28 Either startDate, curDate and endDate all have to be valid and startDate <= curDate <= endDate, 29 OR all three dates are invalid (representing "no date range", e.g. no conference). */ 30 class DayNavigatorWidget : public QWidget, private Ui::DayNavigatorWidget { 75 31 Q_OBJECT 76 32 public: … … 78 34 ~DayNavigatorWidget() {} 79 35 void setDates(const QDate &aStartDate, const QDate &aEndDate); 36 void setCurDate(const QDate& curDate); 80 37 QDate curDate() const {return mCurDate;} 81 38 protected: … … 92 49 QDate mEndDate; 93 50 QDate mCurDate; 94 QFontMetrics *mFontMetrics;95 51 }; 96 52
Note: See TracChangeset
for help on using the changeset viewer.