Explorar el Código

Fix ctkRangeSliderTest when run with different styles

The test was written using QCleanlooks style and it fails with GTK style.
Julien Finet hace 12 años
padre
commit
4e98d9a064

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

@@ -20,6 +20,7 @@
 
 
 // Qt includes
 // Qt includes
 #include <QApplication>
 #include <QApplication>
+#include <QCleanlooksStyle>
 #include <QString>
 #include <QString>
 #include <QStyle>
 #include <QStyle>
 #include <QStyleOptionSlider>
 #include <QStyleOptionSlider>
@@ -34,6 +35,7 @@ class ctkRangeSliderTester: public QObject
 {
 {
   Q_OBJECT
   Q_OBJECT
 private slots:
 private slots:
+  void initTestCase();
   void testGUIEvents();
   void testGUIEvents();
   void testTooltips();
   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()
 void ctkRangeSliderTester::testGUIEvents()
 {
 {
   ctkRangeSlider rangeSlider;
   ctkRangeSlider rangeSlider;
@@ -149,6 +158,9 @@ void ctkRangeSliderTester::testHandleMouseEvents()
     QStyle::CC_Slider, &option, QStyle::SC_SliderHandle, &rangeSlider );
     QStyle::CC_Slider, &option, QStyle::SC_SliderHandle, &rangeSlider );
   rangeSlider.resize(100 + sliderHandleSize.width(), 20);
   rangeSlider.resize(100 + sliderHandleSize.width(), 20);
 
 
+  rangeSlider.show();
+  QTest::qWaitForWindowShown(&rangeSlider);
+
   QFETCH(bool, minHandle);
   QFETCH(bool, minHandle);
   QFETCH(bool, symmetricMoves);
   QFETCH(bool, symmetricMoves);
   QFETCH(int, moveInPx);
   QFETCH(int, moveInPx);
@@ -168,6 +180,9 @@ void ctkRangeSliderTester::testHandleMouseEvents()
 
 
   QTest::mouseMove(&rangeSlider, currentCursorPos);
   QTest::mouseMove(&rangeSlider, currentCursorPos);
   QTest::mousePress(&rangeSlider, Qt::LeftButton, 0, currentCursorPos);
   QTest::mousePress(&rangeSlider, Qt::LeftButton, 0, currentCursorPos);
+  const bool isHandleDown = minHandle ? rangeSlider.isMinimumSliderDown() :
+    rangeSlider.isMaximumSliderDown();
+  QVERIFY(isHandleDown);
   currentCursorPos += QPoint(moveInPx, 0);
   currentCursorPos += QPoint(moveInPx, 0);
   ctkTest::mouseMove(&rangeSlider, Qt::LeftButton, 0, currentCursorPos);
   ctkTest::mouseMove(&rangeSlider, Qt::LeftButton, 0, currentCursorPos);
   QTest::mouseRelease(&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;
   QString handleToolTip()const;
   void setHandleToolTip(const QString& toolTip);
   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:
 Q_SIGNALS:
   ///
   ///
   /// This signal is emitted when the slider minimum value has changed, 
   /// This signal is emitted when the slider minimum value has changed, 
@@ -183,9 +190,6 @@ protected:
   virtual void mouseMoveEvent(QMouseEvent* ev);
   virtual void mouseMoveEvent(QMouseEvent* ev);
   virtual void mouseReleaseEvent(QMouseEvent* ev);
   virtual void mouseReleaseEvent(QMouseEvent* ev);
 
 
-  bool isMinimumSliderDown()const;
-  bool isMaximumSliderDown()const;
-
   // Description:
   // Description:
   // Rendering is done here.
   // Rendering is done here.
   virtual void paintEvent(QPaintEvent* ev);
   virtual void paintEvent(QPaintEvent* ev);