Kaynağa Gözat

Always show the date range of ctkDateRangeWidget

except when "Any" is current.
Automatically select the right option based on the date.
Julien Finet 14 yıl önce
ebeveyn
işleme
c1f8f7a329

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

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

+ 10 - 0
Libs/Widgets/ctkDateRangeWidget.cpp

@@ -137,6 +137,10 @@ ctkDateRangeWidget::ctkDateRangeWidget(QWidget* _parent) : Superclass(_parent)
                    this, SIGNAL(startDateTimeChanged(const QDateTime&)));
   QObject::connect(d->EndDate, SIGNAL(dateTimeChanged(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;
 }
 
+// -------------------------------------------------------------------------
+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
   void endDateTimeChanged(const QDateTime& value);
 
+protected slots:
+  void onDateTimeChanged();
+
 protected:
   QScopedPointer<ctkDateRangeWidgetPrivate> d_ptr;