Add today button to date navigator.
authorgregor herrmann <gregoa@debian.org>
Sun, 24 Jul 2011 11:41:14 +0000 (11:41 +0000)
committergregor herrmann <gregoa@debian.org>
Sun, 24 Jul 2011 11:41:14 +0000 (11:41 +0000)
TODO: date is not centered between prev/next arrows anymore.

Cf. #29

NEWS
src/gui/daynavigatorwidget.cpp
src/gui/daynavigatorwidget.h
src/gui/daynavigatorwidget.ui
src/icons.qrc
src/icons/today.png [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 086f7a6cdbe10191c244fbb1be49d65b656cc71b..c64f986f01832b552d7fe9ebad68a48155e46cb1 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,8 @@ fosdem-schedule; cf. docs/fosdem-schedule for the historic documentation.
 
 Version 0.5.3
 //! TODO
+* Add "jump to today" button to date navigator.
+  Thanks to Michael Schutte for the patch.
 
 Version 0.5.2, 2011-07-23
 * Show close button in conference dialog also if there are no conferences
index 07d13bc5fc5873829fa2d773c0ad706289ab4730..bf1f17a60aff7b0d2d1ae290e4aad3b81856d04f 100644 (file)
@@ -34,6 +34,7 @@ DayNavigatorWidget::DayNavigatorWidget(QWidget *aParent)
     setupUi(this);
     connect(prevDayButton, SIGNAL(clicked()), SLOT(prevDayButtonClicked()));
     connect(nextDayButton, SIGNAL(clicked()), SLOT(nextDayButtonClicked()));
+    connect(todayButton, SIGNAL(clicked()), SLOT(todayButtonClicked()));
 
     mFontMetrics = new QFontMetrics(QLabel().font());
 }
@@ -63,22 +64,26 @@ void DayNavigatorWidget::setDates(const QDate &aStartDate, const QDate &aEndDate
     }
 }
 
+void DayNavigatorWidget::configureNavigation()
+{
+    // check start date
+    if(mCurDate==mStartDate || mStartDate==mEndDate)
+        prevDayButton->setDisabled(true);
+    else
+        prevDayButton->setDisabled(false);
+    // check end date
+    if(mCurDate==mEndDate || mStartDate==mEndDate)
+        nextDayButton->setDisabled(true);
+    else
+        nextDayButton->setDisabled(false);
+}
+
 void DayNavigatorWidget::prevDayButtonClicked()
 {
     if(mCurDate>mStartDate)
     {
         mCurDate = mCurDate.addDays(-1);
-        // check start date
-        if(mCurDate==mStartDate || mStartDate==mEndDate)
-            prevDayButton->setDisabled(true);
-        else
-            prevDayButton->setDisabled(false);
-        // check end date
-        if(mCurDate==mEndDate || mStartDate==mEndDate)
-            nextDayButton->setDisabled(true);
-        else
-            nextDayButton->setDisabled(false);
-
+        configureNavigation();
         emit(dateChanged(mCurDate));
         selectedDate->update();
     }
@@ -89,17 +94,19 @@ void DayNavigatorWidget::nextDayButtonClicked()
     if(mCurDate<mEndDate)
     {
         mCurDate = mCurDate.addDays(1);
-        // check start date
-        if(mCurDate==mStartDate || mStartDate==mEndDate)
-            prevDayButton->setDisabled(true);
-        else
-            prevDayButton->setDisabled(false);
-        // check end date
-        if(mCurDate==mEndDate || mStartDate==mEndDate)
-            nextDayButton->setDisabled(true);
-        else
-            nextDayButton->setDisabled(false);
+        configureNavigation();
+        emit(dateChanged(mCurDate));
+        selectedDate->update();
+    }
+}
 
+void DayNavigatorWidget::todayButtonClicked()
+{
+    QDate targetDate = QDate::currentDate();
+    if (targetDate>mStartDate && targetDate<mEndDate)
+    {
+        mCurDate = targetDate;
+        configureNavigation();
         emit(dateChanged(mCurDate));
         selectedDate->update();
     }
index da5846dcd5e028d978020ceff2c9ef68877a9056..d4ddcea0ad2da1d06ec1bd9bdf08e9ed20259749 100644 (file)
@@ -79,7 +79,9 @@ class DayNavigatorWidget : public QWidget, private Ui::DayNavigatorWidget
         void setDates(const QDate &aStartDate, const QDate &aEndDate);
     protected:
         void paintEvent(QPaintEvent *);
+        void configureNavigation();
     private slots:
+        void todayButtonClicked();
         void prevDayButtonClicked();
         void nextDayButtonClicked();
     signals:
index cd4f9dc5ee601e1acf18bd6d453c57f95613de54..1436100761b8ee9c90338376ab0958b65349f9bb 100644 (file)
        </property>
       </widget>
      </item>
+     <item>
+      <widget class="QToolButton" name="todayButton">
+       <property name="text">
+        <string>...</string>
+       </property>
+       <property name="icon">
+        <iconset resource="../icons.qrc">
+         <normaloff>:/icons/today.png</normaloff>:/icons/today.png</iconset>
+       </property>
+       <property name="autoRaise">
+        <bool>true</bool>
+       </property>
+      </widget>
+     </item>
     </layout>
    </item>
   </layout>
  </widget>
- <resources/>
+ <resources>
+  <include location="../icons.qrc"/>
+ </resources>
  <connections/>
  <slots>
   <slot>prevDayButtonClicked()</slot>
   <slot>nextDayButtonClicked()</slot>
+  <slot>todayButtonClicked()</slot>
  </slots>
 </ui>
index 8f472eda7afcbeed7b2c380fe82900eca5aea53e..193c23f36379a2eacd2158a12037d3acbff17b1f 100644 (file)
@@ -9,5 +9,6 @@
     <file>icons/emblem-new.png</file>
     <file>icons/dialog-warning.png</file>
     <file>icons/search.png</file>
+    <file>icons/today.png</file>
   </qresource>
 </RCC>
diff --git a/src/icons/today.png b/src/icons/today.png
new file mode 100644 (file)
index 0000000..cec3de3
Binary files /dev/null and b/src/icons/today.png differ