Преглед на файлове

Add pageStep property to ctkDoubleSlider and ctkSliderWidget

Julien Finet преди 14 години
родител
ревизия
affe04903b

+ 14 - 2
Libs/Widgets/Testing/Cpp/ctkDoubleSliderTest1.cpp

@@ -21,6 +21,7 @@
 // Qt includes
 #include <QApplication>
 #include <QString>
+#include <QTimer>
 
 // CTK includes
 #include "ctkDoubleSlider.h"
@@ -185,7 +186,18 @@ int ctkDoubleSliderTest1(int argc, char * argv [] )
   //             << " pos: " << slider.sliderPosition() << std::endl;
   //   return EXIT_FAILURE;
   //   }
-
-  return EXIT_SUCCESS;
+  slider.setPageStep(1.);
+  if (slider.pageStep() != 1.)
+    {
+    std::cerr << "ctkDoubleSlider::setPageStep(1.) failed"
+              << " val: " << slider.pageStep() << std::endl;
+    return EXIT_FAILURE;
+    }
+  slider.show();
+  if (argc < 2 || QString(argv[1]) != "-I" )
+    {
+    QTimer::singleShot(100, &app, SLOT(quit()));
+    }
+  return app.exec();
 }
 

+ 14 - 2
Libs/Widgets/Testing/Cpp/ctkSliderWidgetTest1.cpp

@@ -20,6 +20,7 @@
 
 // Qt includes
 #include <QApplication>
+#include <QTimer>
 
 // CTK includes
 #include "ctkSliderWidget.h"
@@ -196,8 +197,19 @@ int ctkSliderWidgetTest1(int argc, char * argv [] )
               << sliderSpinBox.maximum() << std::endl;
     return EXIT_FAILURE;
     }
-
+  sliderSpinBox.setPageStep(1.);
+  if (sliderSpinBox.pageStep() != 1.)
+    {
+    std::cerr << "ctkSliderWidget::setPageStep(1.) failed"
+              << " val: " << sliderSpinBox.pageStep() << std::endl;
+    return EXIT_FAILURE;
+    }
   // FIXME check that the correct signals are sent.
-  return EXIT_SUCCESS;
+  sliderSpinBox.show();
+  if (argc < 2 || QString(argv[1]) != "-I" )
+    {
+    QTimer::singleShot(100, &app, SLOT(quit()));
+    }
+  return app.exec();
 }
 

+ 20 - 0
Libs/Widgets/ctkDoubleSlider.cpp

@@ -48,6 +48,7 @@ public:
   // we should have a Offset and SliderPositionOffset (and MinimumOffset?)
   double      Offset;
   double      SingleStep;
+  double      PageStep;
   double      Value;
 };
 
@@ -61,6 +62,7 @@ ctkDoubleSliderPrivate::ctkDoubleSliderPrivate(ctkDoubleSlider& object)
   this->SettingRange = false;
   this->Offset = 0.;
   this->SingleStep = 1.;
+  this->PageStep = 10.;
   this->Value = 0.;
 }
 
@@ -75,7 +77,9 @@ void ctkDoubleSliderPrivate::init()
   
   this->Minimum = this->Slider->minimum();
   this->Maximum = this->Slider->maximum();
+  // this->Slider->singleStep is always 1
   this->SingleStep = this->Slider->singleStep();
+  this->PageStep = this->Slider->pageStep();
   this->Value = this->Slider->value();
 
   q->connect(this->Slider, SIGNAL(valueChanged(int)), q, SLOT(onValueChanged(int)));
@@ -275,10 +279,26 @@ void ctkDoubleSlider::setSingleStep(double newStep)
   this->setRange(d->Minimum, d->Maximum);
   d->Slider->setValue(d->toInt(_value));
   d->Value = _value;
+  d->Slider->setPageStep(d->toInt(d->PageStep));
   this->blockSignals(oldBlockSignals);
 }
 
 // --------------------------------------------------------------------------
+double ctkDoubleSlider::pageStep()const
+{
+  Q_D(const ctkDoubleSlider);
+  return d->PageStep;
+}
+
+// --------------------------------------------------------------------------
+void ctkDoubleSlider::setPageStep(double newStep)
+{
+  Q_D(ctkDoubleSlider);
+  d->PageStep = newStep;
+  d->Slider->setPageStep(d->toInt(d->PageStep));
+}
+
+// --------------------------------------------------------------------------
 double ctkDoubleSlider::tickInterval()const
 {
   Q_D(const ctkDoubleSlider);

+ 10 - 0
Libs/Widgets/ctkDoubleSlider.h

@@ -45,6 +45,7 @@ class CTK_WIDGETS_EXPORT ctkDoubleSlider : public QWidget
   Q_PROPERTY(double value READ value WRITE setValue)
   Q_PROPERTY(double sliderPosition READ sliderPosition WRITE setSliderPosition)
   Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep)
+  Q_PROPERTY(double pageStep READ pageStep WRITE setPageStep)
   Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
   Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
   Q_PROPERTY(double tickInterval READ tickInterval WRITE setTickInterval)
@@ -96,10 +97,19 @@ public:
   /// This property holds the single step.
   /// The smaller of two natural steps that an abstract sliders provides and
   /// typically corresponds to the user pressing an arrow key
+  /// Default value is 1.
   void setSingleStep(double step);
   double singleStep()const;
 
   /// 
+  /// This property holds the page step.
+  /// The larger of two natural steps that an abstract slider provides and
+  /// typically corresponds to the user pressing PageUp or PageDown.
+  /// Default value is 10.
+  void setPageStep(double step);
+  double pageStep()const;
+
+  /// 
   /// This property holds the interval between tickmarks.
   /// This is a value interval, not a pixel interval. If it is 0, the slider
   /// will choose between lineStep() and pageStep().

+ 14 - 0
Libs/Widgets/ctkSliderWidget.cpp

@@ -321,6 +321,20 @@ void ctkSliderWidget::setSingleStep(double step)
 }
 
 // --------------------------------------------------------------------------
+double ctkSliderWidget::pageStep()const
+{
+  Q_D(const ctkSliderWidget);
+  return d->Slider->pageStep();
+}
+
+// --------------------------------------------------------------------------
+void ctkSliderWidget::setPageStep(double step)
+{
+  Q_D(ctkSliderWidget);
+  d->Slider->setPageStep(step);
+}
+
+// --------------------------------------------------------------------------
 int ctkSliderWidget::decimals()const
 {
   Q_D(const ctkSliderWidget);

+ 8 - 0
Libs/Widgets/ctkSliderWidget.h

@@ -40,6 +40,7 @@ class CTK_WIDGETS_EXPORT ctkSliderWidget : public QWidget
   Q_OBJECT
   Q_PROPERTY(int decimals READ decimals WRITE setDecimals)
   Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep)
+  Q_PROPERTY(double pageStep READ pageStep WRITE setPageStep)
   Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
   Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
   Q_PROPERTY(double value READ value WRITE setValue)
@@ -100,6 +101,13 @@ public:
   void setSingleStep(double step);
 
   /// 
+  /// This property holds the page step.
+  /// The larger of two natural steps that an abstract slider provides and
+  /// typically corresponds to the user pressing PageUp or PageDown.
+  double pageStep()const;
+  void setPageStep(double step);
+
+  /// 
   /// This property holds the precision of the spin box, in decimals.
   /// Sets how many decimals the spinbox will use for displaying and interpreting doubles.
   int decimals()const;