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)
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, AnimationRule rule)
41{
42 bool animate = rule == AnimationRule::Run;
43 QRect r = widget->geometry();
44 if (r.right() < 0 || r.bottom() < 0)
45 r = QRect();
46
47 animate = animate && !r.isNull() && !_final_geometry.isNull();
48
49 // might make the widget go away by sending it to negative space
50 const QRect final_geometry = _final_geometry.isValid() || widget->isWindow() ? _final_geometry :
51 QRect(QPoint(-500 - widget->width(), -500 - widget->height()), widget->size());
52
53#if QT_CONFIG(animation)
54 //If the QStyle has animations, animate
55 if (const int animationDuration = widget->style()->styleHint(QStyle::SH_Widget_Animation_Duration, nullptr, widget)) {
56 AnimationMap::const_iterator it = m_animation_map.constFind(widget);
57 if (it != m_animation_map.constEnd() && *it && (*it)->endValue().toRect() == final_geometry)
58 return;
59
60 QPropertyAnimation *anim = new QPropertyAnimation(widget, "geometry", widget);
61 anim->setDuration(animate ? animationDuration : 0);
62 anim->setEasingCurve(QEasingCurve::InOutQuad);
63 anim->setEndValue(final_geometry);
64 m_animation_map[widget] = anim;
65 connect(anim, &QPropertyAnimation::destroyed, this, [this, widget]() { abort(widget); });
66 anim->start(QPropertyAnimation::DeleteWhenStopped);
67 } else
68#endif // animation
69 {
70 //we do it in one shot
71 widget->setGeometry(final_geometry);
72#if QT_CONFIG(mainwindow)
73 m_mainWindowLayout->animationFinished(widget);
74#endif // QT_CONFIG(mainwindow)
75 }
76}
77
79{
80 auto isActiveAnimation = [](const QPointer<QPropertyAnimation> &p) { return !p.isNull(); };
81 return !std::all_of(m_animation_map.begin(), m_animation_map.end(), isActiveAnimation);
82}
83
84QT_END_NAMESPACE
85
86#include "moc_qwidgetanimator_p.cpp"
friend class QWidget
Definition qpainter.h:432
void animate(QWidget *widget, const QRect &final_geometry, AnimationRule rule)
void abort(QWidget *widget)
bool animating() const
Combined button and popup list for selecting options.