Prevent easing example warnings.
authorThomas Hartmann <Thomas.Hartmann@digia.com>
Wed, 21 Nov 2012 10:53:45 +0000 (11:53 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Fri, 23 Nov 2012 16:04:00 +0000 (17:04 +0100)
examples/widgets/animation/easing was spitting out a lot of
"QEasingCurve: Invalid tcb curve" warnings.
The reason was that in case of the TCP curve we do not provide
defaults.

The function createEasingCurve() now provides reasonable values
for the custom curves to show what is possible and how to use them.

Change-Id: I880d8d0f0ce2872ce2019f7d2e000f4c4ce136e2
Reviewed-by: Mitch Curtis <mitch.curtis@digia.com>
Reviewed-by: Alessandro Portale <alessandro.portale@digia.com>
examples/widgets/animation/easing/window.cpp

index f5ff439..0a9df0f 100644 (file)
@@ -75,6 +75,23 @@ Window::Window(QWidget *parent)
     startAnimation();
 }
 
+QEasingCurve createEasingCurve(QEasingCurve::Type curveType)
+{
+    QEasingCurve curve(curveType);
+
+    if (curveType == QEasingCurve::BezierSpline) {
+        curve.addCubicBezierSegment(QPointF(0.4, 0.1), QPointF(0.6, 0.9), QPointF(1.0, 1.0));
+
+    } else if (curveType == QEasingCurve::TCBSpline) {
+        curve.addTCBSegment(QPointF(0.0, 0.0), 0, 0, 0);
+        curve.addTCBSegment(QPointF(0.3, 0.4), 0.2, 1, -0.2);
+        curve.addTCBSegment(QPointF(0.7, 0.6), -0.2, 1, 0.2);
+        curve.addTCBSegment(QPointF(1.0, 1.0), 0, 0, 0);
+    }
+
+    return curve;
+}
+
 void Window::createCurveIcons()
 {
     QPixmap pix(m_iconSize);
@@ -88,7 +105,7 @@ void Window::createCurveIcons()
     // Skip QEasingCurve::Custom
     for (int i = 0; i < QEasingCurve::NCurveTypes - 1; ++i) {
         painter.fillRect(QRect(QPoint(0, 0), m_iconSize), brush);
-        QEasingCurve curve((QEasingCurve::Type)i);
+        QEasingCurve curve = createEasingCurve((QEasingCurve::Type) i);
         painter.setPen(QColor(0, 0, 255, 64));
         qreal xAxis = m_iconSize.height()/1.5;
         qreal yAxis = m_iconSize.width()/3;
@@ -139,7 +156,7 @@ void Window::startAnimation()
 void Window::curveChanged(int row)
 {
     QEasingCurve::Type curveType = (QEasingCurve::Type)row;
-    m_anim->setEasingCurve(curveType);
+    m_anim->setEasingCurve(createEasingCurve(curveType));
     m_anim->setCurrentTime(0);
 
     bool isElastic = curveType >= QEasingCurve::InElastic && curveType <= QEasingCurve::OutInElastic;