Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwidgetanimator.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
6
7#if QT_CONFIG(animation)
8#include <QtCore/qpropertyanimation.h>
9#endif
10#include <QtWidgets/qwidget.h>
11#include <QtWidgets/qstyle.h>
12#if QT_CONFIG(mainwindow)
13#include <private/qmainwindowlayout_p.h>
14#endif
15
17
19#if QT_CONFIG(mainwindow)
20: m_mainWindowLayout(layout)
21#endif
22{
23 Q_UNUSED(layout);
24}
25
27{
28#if QT_CONFIG(animation)
29 QPropertyAnimation *anim = m_animation_map.take(w);
30 if (anim)
31 anim->stop();
32#if QT_CONFIG(mainwindow)
33 m_mainWindowLayout->animationFinished(w);
34#endif
35#else
36 Q_UNUSED(w); //there is no animation to abort
37#endif // animation
38}
39
40void QWidgetAnimator::animate(QWidget *widget, const QRect &_final_geometry, bool animate)
41{
42 QRect r = widget->geometry();
43 if (r.right() < 0 || r.bottom() < 0)
44 r = QRect();
45
46 animate = animate && !r.isNull() && !_final_geometry.isNull();
47
48 // might make the widget go away by sending it to negative space
49 const QRect final_geometry = _final_geometry.isValid() || widget->isWindow() ? _final_geometry :
50 QRect(QPoint(-500 - widget->width(), -500 - widget->height()), widget->size());
51
52#if QT_CONFIG(animation)
53 //If the QStyle has animations, animate
54 if (const int animationDuration = widget->style()->styleHint(QStyle::SH_Widget_Animation_Duration, nullptr, widget)) {
55 AnimationMap::const_iterator it = m_animation_map.constFind(widget);
56 if (it != m_animation_map.constEnd() && (*it)->endValue().toRect() == final_geometry)
57 return;
58
59 QPropertyAnimation *anim = new QPropertyAnimation(widget, "geometry", widget);
60 anim->setDuration(animate ? animationDuration : 0);
61 anim->setEasingCurve(QEasingCurve::InOutQuad);
62 anim->setEndValue(final_geometry);
63 m_animation_map[widget] = anim;
64 connect(anim, &QPropertyAnimation::destroyed, this, [this, widget]() { abort(widget); });
65 anim->start(QPropertyAnimation::DeleteWhenStopped);
66 } else
67#endif // animation
68 {
69 //we do it in one shot
70 widget->setGeometry(final_geometry);
71#if QT_CONFIG(mainwindow)
72 m_mainWindowLayout->animationFinished(widget);
73#endif // QT_CONFIG(mainwindow)
74 }
75}
76
78{
79 return !m_animation_map.isEmpty();
80}
81
82QT_END_NAMESPACE
83
84#include "moc_qwidgetanimator_p.cpp"
friend class QWidget
Definition qpainter.h:431
void animate(QWidget *widget, const QRect &final_geometry, bool animate)
void abort(QWidget *widget)
bool animating() const