diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-03-14 17:42:18 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-03-16 19:04:01 +0000 |
commit | db558fe10bf4f609b26f9da1ef3ff0d4a16d4699 (patch) | |
tree | d3afd5b28877cb207e1d794b7669c42d0878d759 | |
parent | a62b8a3ad9880713fd20b33cfea17ca1d3150c52 (diff) |
Enable tests to turn off Windows Vista animations
Animations in that style depend on the current time, which makes it
impossible to run baseline tests. Introduce a dynamic property that
allows us to set the time that animations use.
This way, tests can turn the animation off, or control which time should
be used.
To keep performance overhead low, check only once whether the dynamic
property is set at all.
Change-Id: I9bc57b9867fb0d852e101570eca4c7609e7fe1a8
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
(cherry picked from commit 58a14d943353f02bfbee0a65f5e31c40358c8c53)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/plugins/styles/windowsvista/qwindowsvistastyle.cpp | 30 | ||||
-rw-r--r-- | src/plugins/styles/windowsvista/qwindowsvistastyle_p_p.h | 1 | ||||
-rw-r--r-- | tests/baseline/shared/qwidgetbaselinetest.cpp | 1 |
3 files changed, 25 insertions, 7 deletions
diff --git a/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp b/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp index 73be33b278..01e1529aa2 100644 --- a/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp +++ b/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp @@ -86,6 +86,22 @@ bool QWindowsVistaStylePrivate::useVista() return QWindowsVistaStylePrivate::useXP(); } +/*! + \internal + + Animations are started at a frame that is based on the current time, + which makes it impossible to run baseline tests with this style. Allow + overriding through a dynamic property. +*/ +QTime QWindowsVistaStylePrivate::animationTime() const +{ + Q_Q(const QWindowsVistaStyle); + static bool animationTimeOverride = q->dynamicPropertyNames().contains("_qt_animation_time"); + if (animationTimeOverride) + return q->property("_qt_animation_time").toTime(); + return QTime::currentTime(); +} + /* \internal Checks and returns the style object */ @@ -391,7 +407,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt TMT_TRANSITIONDURATIONS, &duration))) { t->setDuration(int(duration)); } - t->setStartTime(QTime::currentTime()); + t->setStartTime(d->animationTime()); deleteClonedAnimationStyleOption(styleOption); d->startAnimation(t); @@ -899,7 +915,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption t->setDuration(int(duration)); else t->setDuration(0); - t->setStartTime(QTime::currentTime()); + t->setStartTime(d->animationTime()); styleObject->setProperty("_q_no_animation", false); deleteClonedAnimationStyleOption(styleOption); @@ -961,7 +977,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption d->drawBackground(theme); pulse->setStartImage(startImage); pulse->setEndImage(alternateImage); - pulse->setStartTime(QTime::currentTime()); + pulse->setStartTime(d->animationTime()); pulse->setDuration(2000); d->startAnimation(pulse); anim = pulse; @@ -1022,7 +1038,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption vertical ? PP_FILLVERT : PP_FILL); theme.rect = option->rect; bool reverse = (bar->direction == Qt::LeftToRight && inverted) || (bar->direction == Qt::RightToLeft && !inverted); - QTime current = QTime::currentTime(); + QTime current = d->animationTime(); if (isIndeterminate) { if (QProgressStyleAnimation *a = qobject_cast<QProgressStyleAnimation *>(d->animation(styleObject(option)))) { @@ -1030,7 +1046,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption int animationWidth = glowSize * 2 + (vertical ? theme.rect.height() : theme.rect.width()); int animOffset = a->startTime().msecsTo(current) / 4; if (animOffset > animationWidth) - a->setStartTime(QTime::currentTime()); + a->setStartTime(d->animationTime()); painter->save(); painter->setClipRect(theme.rect); QRect animRect; @@ -1102,7 +1118,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption theme.partId = vertical ? PP_MOVEOVERLAYVERT : PP_MOVEOVERLAY; if (animOffset > animationWidth) { if (bar->progress < bar->maximum) - a->setStartTime(QTime::currentTime()); + a->setStartTime(d->animationTime()); else d->stopAnimation(styleObject(option)); //we stop the glow motion only after it has //moved out of view @@ -1577,7 +1593,7 @@ void QWindowsVistaStyle::drawComplexControl(ComplexControl control, const QStyle styleObject->setProperty("_q_no_animation", false); t->setEndImage(endImage); - t->setStartTime(QTime::currentTime()); + t->setStartTime(d->animationTime()); if (option->state & State_MouseOver || option->state & State_Sunken) t->setDuration(150); diff --git a/src/plugins/styles/windowsvista/qwindowsvistastyle_p_p.h b/src/plugins/styles/windowsvista/qwindowsvistastyle_p_p.h index 4fd4740ffe..5382d8c46c 100644 --- a/src/plugins/styles/windowsvista/qwindowsvistastyle_p_p.h +++ b/src/plugins/styles/windowsvista/qwindowsvistastyle_p_p.h @@ -194,6 +194,7 @@ class QWindowsVistaStylePrivate : public QWindowsXPStylePrivate public: static int fixedPixelMetric(QStyle::PixelMetric pm); static inline bool useVista(); + QTime animationTime() const; bool transitionsEnabled() const; }; diff --git a/tests/baseline/shared/qwidgetbaselinetest.cpp b/tests/baseline/shared/qwidgetbaselinetest.cpp index 41771cf669..3be8ae7893 100644 --- a/tests/baseline/shared/qwidgetbaselinetest.cpp +++ b/tests/baseline/shared/qwidgetbaselinetest.cpp @@ -53,6 +53,7 @@ QWidgetBaselineTest::QWidgetBaselineTest() #else QApplication::style()->name(); #endif + QApplication::style()->setProperty("_qt_animation_time", QTime()); QByteArray appearanceBytes; { QDataStream appearanceStream(&appearanceBytes, QIODevice::WriteOnly); |