Selaa lähdekoodia

Always show the date range of ctkDateRangeWidget

except when "Any" is current.
Automatically select the right option based on the date.
Julien Finet 14 vuotta sitten
vanhempi
commit
c1f8f7a329

+ 9 - 12
Libs/Widgets/Resources/UI/ctkDateRangeWidget.ui

@@ -6,7 +6,7 @@
    <rect>
    <rect>
     <x>0</x>
     <x>0</x>
     <y>0</y>
     <y>0</y>
-    <width>100</width>
+    <width>167</width>
     <height>186</height>
     <height>186</height>
    </rect>
    </rect>
   </property>
   </property>
@@ -17,7 +17,7 @@
    </sizepolicy>
    </sizepolicy>
   </property>
   </property>
   <property name="windowTitle">
   <property name="windowTitle">
-   <string>ctkSliderSpinBoxWidget</string>
+   <string>Date Range</string>
   </property>
   </property>
   <layout class="QVBoxLayout" name="verticalLayout">
   <layout class="QVBoxLayout" name="verticalLayout">
    <property name="margin">
    <property name="margin">
@@ -28,9 +28,6 @@
      <property name="text">
      <property name="text">
       <string>Any Date</string>
       <string>Any Date</string>
      </property>
      </property>
-     <property name="checked">
-      <bool>true</bool>
-     </property>
     </widget>
     </widget>
    </item>
    </item>
    <item>
    <item>
@@ -66,6 +63,9 @@
      <property name="text">
      <property name="text">
       <string>Select Range</string>
       <string>Select Range</string>
      </property>
      </property>
+     <property name="checked">
+      <bool>true</bool>
+     </property>
     </widget>
     </widget>
    </item>
    </item>
    <item>
    <item>
@@ -86,9 +86,6 @@
       <property name="topMargin">
       <property name="topMargin">
        <number>0</number>
        <number>0</number>
       </property>
       </property>
-      <property name="rightMargin">
-       <number>0</number>
-      </property>
       <property name="bottomMargin">
       <property name="bottomMargin">
        <number>0</number>
        <number>0</number>
       </property>
       </property>
@@ -114,14 +111,14 @@
  <resources/>
  <resources/>
  <connections>
  <connections>
   <connection>
   <connection>
-   <sender>SelectRangeRadioButton</sender>
+   <sender>AnyDateRadioButton</sender>
    <signal>toggled(bool)</signal>
    <signal>toggled(bool)</signal>
    <receiver>DateRangeWidget</receiver>
    <receiver>DateRangeWidget</receiver>
-   <slot>setVisible(bool)</slot>
+   <slot>setHidden(bool)</slot>
    <hints>
    <hints>
     <hint type="sourcelabel">
     <hint type="sourcelabel">
-     <x>31</x>
-     <y>119</y>
+     <x>83</x>
+     <y>8</y>
     </hint>
     </hint>
     <hint type="destinationlabel">
     <hint type="destinationlabel">
      <x>43</x>
      <x>43</x>

+ 10 - 0
Libs/Widgets/ctkDateRangeWidget.cpp

@@ -137,6 +137,10 @@ ctkDateRangeWidget::ctkDateRangeWidget(QWidget* _parent) : Superclass(_parent)
                    this, SIGNAL(startDateTimeChanged(const QDateTime&)));
                    this, SIGNAL(startDateTimeChanged(const QDateTime&)));
   QObject::connect(d->EndDate, SIGNAL(dateTimeChanged(const QDateTime&)),
   QObject::connect(d->EndDate, SIGNAL(dateTimeChanged(const QDateTime&)),
                    this, SIGNAL(endDateTimeChanged(const QDateTime&)));
                    this, SIGNAL(endDateTimeChanged(const QDateTime&)));
+  QObject::connect(d->StartDate, SIGNAL(dateTimeChanged(const QDateTime&)),
+                   this, SLOT(onDateTimeChanged()));
+  QObject::connect(d->EndDate, SIGNAL(dateTimeChanged(const QDateTime&)),
+                   this, SLOT(onDateTimeChanged()));
 }
 }
 
 
 // --------------------------------------------------------------------------
 // --------------------------------------------------------------------------
@@ -277,3 +281,9 @@ bool ctkDateRangeWidget::displayTime()const
   return d->DisplayTime;
   return d->DisplayTime;
 }
 }
 
 
+// -------------------------------------------------------------------------
+void ctkDateRangeWidget::onDateTimeChanged()
+{
+  Q_D(ctkDateRangeWidget);
+  d->autoselectRadioButton();
+}

+ 3 - 0
Libs/Widgets/ctkDateRangeWidget.h

@@ -106,6 +106,9 @@ signals:
   /// Fired when the end date is changed
   /// Fired when the end date is changed
   void endDateTimeChanged(const QDateTime& value);
   void endDateTimeChanged(const QDateTime& value);
 
 
+protected slots:
+  void onDateTimeChanged();
+
 protected:
 protected:
   QScopedPointer<ctkDateRangeWidgetPrivate> d_ptr;
   QScopedPointer<ctkDateRangeWidgetPrivate> d_ptr;