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 086f7a6..c64f986 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 07d13bc..bf1f17a 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 da5846d..d4ddcea 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 cd4f9dc..1436100 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 8f472ed..193c23f 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