浏览代码

Merge branch 'ctkRangeSlider-fix-style'

* ctkRangeSlider-fix-style:
  Improve mac style rendering of ctkRangeSlider
  ctkDoubleRangeSlider better support of large double values
Julien Finet 12 年之前
父节点
当前提交
6e310e38d6
共有 3 个文件被更改,包括 32 次插入3 次删除
  1. 12 0
      Libs/Widgets/ctkDoubleRangeSlider.cpp
  2. 3 1
      Libs/Widgets/ctkDoubleSlider.cpp
  3. 17 2
      Libs/Widgets/ctkRangeSlider.cpp

+ 12 - 0
Libs/Widgets/ctkDoubleRangeSlider.cpp

@@ -125,7 +125,19 @@ void ctkDoubleRangeSliderPrivate::connectSlider()
 int ctkDoubleRangeSliderPrivate::toInt(double doubleValue)const
 int ctkDoubleRangeSliderPrivate::toInt(double doubleValue)const
 {
 {
   double tmp = doubleValue / this->SingleStep;
   double tmp = doubleValue / this->SingleStep;
+  static const double minInt = std::numeric_limits<int>::min();
+  static const double maxInt = std::numeric_limits<int>::max();
+#ifndef QT_NO_DEBUG
+  if (tmp < minInt || tmp > maxInt)
+    {
+    qWarning() << __FUNCTION__ << ": value " << doubleValue
+               << " for singleStep " << this->SingleStep
+               << " is out of integer bounds !";
+    }
+#endif
+  tmp = qBound(minInt, tmp, maxInt);
   int intValue = qRound(tmp);
   int intValue = qRound(tmp);
+  //qDebug() << __FUNCTION__ << doubleValue << tmp << intValue;
   return intValue;
   return intValue;
 }
 }
 
 

+ 3 - 1
Libs/Widgets/ctkDoubleSlider.cpp

@@ -122,7 +122,9 @@ int ctkDoubleSliderPrivate::toInt(double doubleValue)const
 #ifndef QT_NO_DEBUG
 #ifndef QT_NO_DEBUG
   if (tmp < minInt || tmp > maxInt)
   if (tmp < minInt || tmp > maxInt)
     {
     {
-    qWarning("ctkDoubleSliderPrivate::toInt value out of bounds !");
+    qWarning() << __FUNCTION__ << ": value " << doubleValue
+              << " for singleStep " << this->SingleStep
+              << " is out of integer bounds !";
     }
     }
 #endif
 #endif
   tmp = qBound(minInt, tmp, maxInt);
   tmp = qBound(minInt, tmp, maxInt);

+ 17 - 2
Libs/Widgets/ctkRangeSlider.cpp

@@ -277,7 +277,12 @@ void ctkRangeSliderPrivate::drawMinimumSlider( QStylePainter* painter ) const
     option.activeSubControls = QStyle::SC_SliderHandle;
     option.activeSubControls = QStyle::SC_SliderHandle;
     option.state |= QStyle::State_Sunken;
     option.state |= QStyle::State_Sunken;
     }
     }
-
+#ifdef Q_OS_MAC
+  // On mac style, drawing just the handle actually draws also the groove.
+  QRect clip = q->style()->subControlRect(QStyle::CC_Slider, &option,
+                                          QStyle::SC_SliderHandle, q);
+  painter->setClipRect(clip);
+#endif
   painter->drawComplexControl(QStyle::CC_Slider, option);
   painter->drawComplexControl(QStyle::CC_Slider, option);
 }
 }
 
 
@@ -297,6 +302,12 @@ void ctkRangeSliderPrivate::drawMaximumSlider( QStylePainter* painter ) const
     option.activeSubControls = QStyle::SC_SliderHandle;
     option.activeSubControls = QStyle::SC_SliderHandle;
     option.state |= QStyle::State_Sunken;
     option.state |= QStyle::State_Sunken;
     }
     }
+#ifdef Q_OS_MAC
+  // On mac style, drawing just the handle actually draws also the groove.
+  QRect clip = q->style()->subControlRect(QStyle::CC_Slider, &option,
+                                          QStyle::SC_SliderHandle, q);
+  painter->setClipRect(clip);
+#endif
   painter->drawComplexControl(QStyle::CC_Slider, option);
   painter->drawComplexControl(QStyle::CC_Slider, option);
 }
 }
 
 
@@ -534,7 +545,11 @@ void ctkRangeSlider::paintEvent( QPaintEvent* )
 
 
   QStylePainter painter(this);
   QStylePainter painter(this);
   option.subControls = QStyle::SC_SliderGroove;
   option.subControls = QStyle::SC_SliderGroove;
-  option.sliderPosition = this->minimum(); // don't highlight the SliderGroove
+  // Move to minimum to not highlight the SliderGroove.
+  // On mac style, drawing just the slider groove also draws the handles,
+  // therefore we give a negative (outside of view) position.
+  option.sliderValue = this->minimum() - this->maximum();
+  option.sliderPosition = this->minimum() - this->maximum();
   painter.drawComplexControl(QStyle::CC_Slider, option);
   painter.drawComplexControl(QStyle::CC_Slider, option);
 
 
   option.sliderPosition = d->m_MinimumPosition;
   option.sliderPosition = d->m_MinimumPosition;