summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2018-09-26 15:39:35 +0200
committerLiang Qi <liang.qi@qt.io>2018-10-12 14:26:15 +0000
commitc593492d1678a2ec08f1bfffcb572459b3bc6c00 (patch)
treea9427b13e0f3aa252d68decc862de5acb4dc3b17 /src/widgets/widgets
parent0509383cf2852f2aebd1efd75413835747c8f341 (diff)
Modernize the "animation" feature
Change-Id: Ibc164b3df3cf87db569ef4813de458a9067b7f7d Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
Diffstat (limited to 'src/widgets/widgets')
-rw-r--r--src/widgets/widgets/qlineedit_p.cpp4
-rw-r--r--src/widgets/widgets/qlineedit_p.h4
-rw-r--r--src/widgets/widgets/qtabbar.cpp6
-rw-r--r--src/widgets/widgets/qtabbar_p.h10
-rw-r--r--src/widgets/widgets/qwidgetanimator.cpp18
-rw-r--r--src/widgets/widgets/qwidgetanimator_p.h2
6 files changed, 25 insertions, 19 deletions
diff --git a/src/widgets/widgets/qlineedit_p.cpp b/src/widgets/widgets/qlineedit_p.cpp
index 0eeff196a8..cccb44c4ef 100644
--- a/src/widgets/widgets/qlineedit_p.cpp
+++ b/src/widgets/widgets/qlineedit_p.cpp
@@ -57,7 +57,9 @@
#include "qlist.h"
#endif
#include <qpainter.h>
+#if QT_CONFIG(animation)
#include <qpropertyanimation.h>
+#endif
#include <qstylehints.h>
#include <qvalidator.h>
@@ -390,7 +392,7 @@ void QLineEditIconButton::setOpacity(qreal value)
}
}
-#ifndef QT_NO_ANIMATION
+#if QT_CONFIG(animation)
void QLineEditIconButton::startOpacityAnimation(qreal endValue)
{
QPropertyAnimation *animation = new QPropertyAnimation(this, QByteArrayLiteral("opacity"));
diff --git a/src/widgets/widgets/qlineedit_p.h b/src/widgets/widgets/qlineedit_p.h
index 71a67e3d10..7cd91dfc29 100644
--- a/src/widgets/widgets/qlineedit_p.h
+++ b/src/widgets/widgets/qlineedit_p.h
@@ -89,7 +89,7 @@ public:
qreal opacity() const { return m_opacity; }
void setOpacity(qreal value);
-#ifndef QT_NO_ANIMATION
+#if QT_CONFIG(animation)
void animateShow(bool visible) { startOpacityAnimation(visible ? 1.0 : 0.0); }
#endif
@@ -101,7 +101,7 @@ private slots:
void updateCursor();
private:
-#ifndef QT_NO_ANIMATION
+#if QT_CONFIG(animation)
void startOpacityAnimation(qreal endValue);
#endif
QLineEditPrivate *lineEditPrivate() const;
diff --git a/src/widgets/widgets/qtabbar.cpp b/src/widgets/widgets/qtabbar.cpp
index 8af70d0f9c..98e15c8f17 100644
--- a/src/widgets/widgets/qtabbar.cpp
+++ b/src/widgets/widgets/qtabbar.cpp
@@ -2109,13 +2109,13 @@ void QTabBarPrivate::moveTabFinished(int index)
Q_Q(QTabBar);
bool cleanup = (pressedIndex == index) || (pressedIndex == -1) || !validIndex(index);
bool allAnimationsFinished = true;
-#ifndef QT_NO_ANIMATION
+#if QT_CONFIG(animation)
for(int i = 0; allAnimationsFinished && i < tabList.count(); ++i) {
const Tab &t = tabList.at(i);
if (t.animation && t.animation->state() == QAbstractAnimation::Running)
allAnimationsFinished = false;
}
-#endif //QT_NO_ANIMATION
+#endif // animation
if (allAnimationsFinished && cleanup) {
if(movingTab)
movingTab->setVisible(false); // We might not get a mouse release
@@ -2680,7 +2680,7 @@ void CloseButton::paintEvent(QPaintEvent *)
style()->drawPrimitive(QStyle::PE_IndicatorTabClose, &opt, &p, this);
}
-#ifndef QT_NO_ANIMATION
+#if QT_CONFIG(animation)
void QTabBarPrivate::Tab::TabBarAnimation::updateCurrentValue(const QVariant &current)
{
priv->moveTab(priv->tabList.indexOf(*tab), current.toInt());
diff --git a/src/widgets/widgets/qtabbar_p.h b/src/widgets/widgets/qtabbar_p.h
index 1092878f2c..04f07c7cec 100644
--- a/src/widgets/widgets/qtabbar_p.h
+++ b/src/widgets/widgets/qtabbar_p.h
@@ -58,7 +58,9 @@
#include <qicon.h>
#include <qtoolbutton.h>
#include <qdebug.h>
+#if QT_CONFIG(animation)
#include <qvariantanimation.h>
+#endif
#define ANIMATION_DURATION 250
@@ -107,9 +109,9 @@ public:
inline Tab(const QIcon &ico, const QString &txt)
: enabled(true) , shortcutId(0), text(txt), icon(ico),
leftWidget(0), rightWidget(0), lastTab(-1), dragOffset(0)
-#ifndef QT_NO_ANIMATION
+#if QT_CONFIG(animation)
, animation(0)
-#endif //QT_NO_ANIMATION
+#endif // animation
{}
bool operator==(const Tab &other) const { return &other == this; }
bool enabled;
@@ -136,7 +138,7 @@ public:
QString accessibleName;
#endif
-#ifndef QT_NO_ANIMATION
+#if QT_CONFIG(animation)
~Tab() { delete animation; }
struct TabBarAnimation : public QVariantAnimation {
TabBarAnimation(Tab *t, QTabBarPrivate *_priv) : tab(t), priv(_priv)
@@ -166,7 +168,7 @@ public:
#else
void startAnimation(QTabBarPrivate *priv, int duration)
{ Q_UNUSED(duration); priv->moveTabFinished(priv->tabList.indexOf(*this)); }
-#endif //QT_NO_ANIMATION
+#endif // animation
};
QList<Tab> tabList;
mutable QHash<QString, QSize> textSizes;
diff --git a/src/widgets/widgets/qwidgetanimator.cpp b/src/widgets/widgets/qwidgetanimator.cpp
index b6828a14ef..b1e527e3b6 100644
--- a/src/widgets/widgets/qwidgetanimator.cpp
+++ b/src/widgets/widgets/qwidgetanimator.cpp
@@ -37,15 +37,17 @@
**
****************************************************************************/
+#include "qwidgetanimator_p.h"
+
+#if QT_CONFIG(animation)
#include <QtCore/qpropertyanimation.h>
+#endif
#include <QtWidgets/qwidget.h>
#include <QtWidgets/qstyle.h>
#if QT_CONFIG(mainwindow)
#include <private/qmainwindowlayout_p.h>
#endif
-#include "qwidgetanimator_p.h"
-
QT_BEGIN_NAMESPACE
QWidgetAnimator::QWidgetAnimator(QMainWindowLayout *layout) : m_mainWindowLayout(layout)
@@ -54,7 +56,7 @@ QWidgetAnimator::QWidgetAnimator(QMainWindowLayout *layout) : m_mainWindowLayout
void QWidgetAnimator::abort(QWidget *w)
{
-#ifndef QT_NO_ANIMATION
+#if QT_CONFIG(animation)
const auto it = m_animation_map.constFind(w);
if (it == m_animation_map.cend())
return;
@@ -68,16 +70,16 @@ void QWidgetAnimator::abort(QWidget *w)
#endif
#else
Q_UNUSED(w); //there is no animation to abort
-#endif //QT_NO_ANIMATION
+#endif // animation
}
-#ifndef QT_NO_ANIMATION
+#if QT_CONFIG(animation)
void QWidgetAnimator::animationFinished()
{
QPropertyAnimation *anim = qobject_cast<QPropertyAnimation*>(sender());
abort(static_cast<QWidget*>(anim->targetObject()));
}
-#endif //QT_NO_ANIMATION
+#endif // animation
void QWidgetAnimator::animate(QWidget *widget, const QRect &_final_geometry, bool animate)
{
@@ -91,7 +93,7 @@ void QWidgetAnimator::animate(QWidget *widget, const QRect &_final_geometry, boo
const QRect final_geometry = _final_geometry.isValid() || widget->isWindow() ? _final_geometry :
QRect(QPoint(-500 - widget->width(), -500 - widget->height()), widget->size());
-#ifndef QT_NO_ANIMATION
+#if QT_CONFIG(animation)
//If the QStyle has animations, animate
if (const int animationDuration = widget->style()->styleHint(QStyle::SH_Widget_Animation_Duration, 0, widget)) {
AnimationMap::const_iterator it = m_animation_map.constFind(widget);
@@ -106,7 +108,7 @@ void QWidgetAnimator::animate(QWidget *widget, const QRect &_final_geometry, boo
connect(anim, SIGNAL(finished()), SLOT(animationFinished()));
anim->start(QPropertyAnimation::DeleteWhenStopped);
} else
-#endif //QT_NO_ANIMATION
+#endif // animation
{
//we do it in one shot
widget->setGeometry(final_geometry);
diff --git a/src/widgets/widgets/qwidgetanimator_p.h b/src/widgets/widgets/qwidgetanimator_p.h
index 90be22c271..920cc3ffc8 100644
--- a/src/widgets/widgets/qwidgetanimator_p.h
+++ b/src/widgets/widgets/qwidgetanimator_p.h
@@ -73,7 +73,7 @@ public:
void abort(QWidget *widget);
-#ifndef QT_NO_ANIMATION
+#if QT_CONFIG(animation)
private Q_SLOTS:
void animationFinished();
#endif