瀏覽代碼

Fix ctkRangeSliderTest when run with different styles

The test was written using QCleanlooks style and it fails with GTK style.
Julien Finet 11 年之前
父節點
當前提交
4e98d9a064
共有 2 個文件被更改,包括 22 次插入3 次删除
  1. 15 0
      Libs/Widgets/Testing/Cpp/ctkRangeSliderTest.cpp
  2. 7 3
      Libs/Widgets/ctkRangeSlider.h

+ 15 - 0
Libs/Widgets/Testing/Cpp/ctkRangeSliderTest.cpp

@@ -20,6 +20,7 @@
 
 // Qt includes
 #include <QApplication>
+#include <QCleanlooksStyle>
 #include <QString>
 #include <QStyle>
 #include <QStyleOptionSlider>
@@ -34,6 +35,7 @@ class ctkRangeSliderTester: public QObject
 {
   Q_OBJECT
 private slots:
+  void initTestCase();
   void testGUIEvents();
   void testTooltips();
 
@@ -47,6 +49,13 @@ private slots:
 };
 
 // ----------------------------------------------------------------------------
+void ctkRangeSliderTester::initTestCase()
+{
+  // Mouse position on handles does not with with gtk style.
+  QApplication::setStyle(new QCleanlooksStyle());
+}
+
+// ----------------------------------------------------------------------------
 void ctkRangeSliderTester::testGUIEvents()
 {
   ctkRangeSlider rangeSlider;
@@ -149,6 +158,9 @@ void ctkRangeSliderTester::testHandleMouseEvents()
     QStyle::CC_Slider, &option, QStyle::SC_SliderHandle, &rangeSlider );
   rangeSlider.resize(100 + sliderHandleSize.width(), 20);
 
+  rangeSlider.show();
+  QTest::qWaitForWindowShown(&rangeSlider);
+
   QFETCH(bool, minHandle);
   QFETCH(bool, symmetricMoves);
   QFETCH(int, moveInPx);
@@ -168,6 +180,9 @@ void ctkRangeSliderTester::testHandleMouseEvents()
 
   QTest::mouseMove(&rangeSlider, currentCursorPos);
   QTest::mousePress(&rangeSlider, Qt::LeftButton, 0, currentCursorPos);
+  const bool isHandleDown = minHandle ? rangeSlider.isMinimumSliderDown() :
+    rangeSlider.isMaximumSliderDown();
+  QVERIFY(isHandleDown);
   currentCursorPos += QPoint(moveInPx, 0);
   ctkTest::mouseMove(&rangeSlider, Qt::LeftButton, 0, currentCursorPos);
   QTest::mouseRelease(&rangeSlider, Qt::LeftButton, 0, currentCursorPos);

+ 7 - 3
Libs/Widgets/ctkRangeSlider.h

@@ -112,6 +112,13 @@ public:
   QString handleToolTip()const;
   void setHandleToolTip(const QString& toolTip);
 
+  /// Returns true if the minimum value handle is down, false if it is up.
+  /// \sa isMaximumSliderDown()
+  bool isMinimumSliderDown()const;
+  /// Returns true if the maximum value handle is down, false if it is up.
+  /// \sa isMinimumSliderDown()
+  bool isMaximumSliderDown()const;
+
 Q_SIGNALS:
   ///
   /// This signal is emitted when the slider minimum value has changed, 
@@ -183,9 +190,6 @@ protected:
   virtual void mouseMoveEvent(QMouseEvent* ev);
   virtual void mouseReleaseEvent(QMouseEvent* ev);
 
-  bool isMinimumSliderDown()const;
-  bool isMaximumSliderDown()const;
-
   // Description:
   // Rendering is done here.
   virtual void paintEvent(QPaintEvent* ev);