Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
4#include "qwidgetanimator_p.h"
5
6#if QT_CONFIG(animation)
7#include <QtCore/qpropertyanimation.h>
8#endif
9#include <QtWidgets/qwidget.h>
10#include <QtWidgets/qstyle.h>
11#if QT_CONFIG(mainwindow)
12#include <private/qmainwindowlayout_p.h>
13#endif
14
16
18#if QT_CONFIG(mainwindow)
19: m_mainWindowLayout(layout)
20#endif
21{
23}
24
26{
27#if QT_CONFIG(animation)
28 const auto it = m_animation_map.constFind(w);
29 if (it == m_animation_map.cend())
30 return;
31 QPropertyAnimation *anim = *it;
32 m_animation_map.erase(it);
33 if (anim) {
34 anim->stop();
35 }
36#if QT_CONFIG(mainwindow)
37 m_mainWindowLayout->animationFinished(w);
38#endif
39#else
40 Q_UNUSED(w); //there is no animation to abort
41#endif // animation
42}
43
44#if QT_CONFIG(animation)
45void QWidgetAnimator::animationFinished()
46{
47 QPropertyAnimation *anim = qobject_cast<QPropertyAnimation*>(sender());
48 abort(static_cast<QWidget*>(anim->targetObject()));
49}
50#endif // animation
51
52void QWidgetAnimator::animate(QWidget *widget, const QRect &_final_geometry, bool animate)
53{
55 if (r.right() < 0 || r.bottom() < 0)
56 r = QRect();
57
58 animate = animate && !r.isNull() && !_final_geometry.isNull();
59
60 // might make the widget go away by sending it to negative space
61 const QRect final_geometry = _final_geometry.isValid() || widget->isWindow() ? _final_geometry :
62 QRect(QPoint(-500 - widget->width(), -500 - widget->height()), widget->size());
63
64#if QT_CONFIG(animation)
65 //If the QStyle has animations, animate
66 if (const int animationDuration = widget->style()->styleHint(QStyle::SH_Widget_Animation_Duration, nullptr, widget)) {
68 if (it != m_animation_map.constEnd() && (*it)->endValue().toRect() == final_geometry)
69 return;
70
71 QPropertyAnimation *anim = new QPropertyAnimation(widget, "geometry", widget);
72 anim->setDuration(animate ? animationDuration : 0);
74 anim->setEndValue(final_geometry);
75 m_animation_map[widget] = anim;
77 this, &QWidgetAnimator::animationFinished);
79 } else
80#endif // animation
81 {
82 //we do it in one shot
83 widget->setGeometry(final_geometry);
84#if QT_CONFIG(mainwindow)
85 m_mainWindowLayout->animationFinished(widget);
86#endif // QT_CONFIG(mainwindow)
87 }
88}
89
91{
92 return !m_animation_map.isEmpty();
93}
94
96
97#include "moc_qwidgetanimator_p.cpp"
void stop()
Stops the animation.
void start(QAbstractAnimation::DeletionPolicy policy=KeepWhenStopped)
Starts the animation.
void finished()
QAbstractAnimation emits this signal after the animation has stopped and has reached the end.
const_iterator constFind(const Key &key) const noexcept
Definition qhash.h:1299
const_iterator constEnd() const noexcept
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the ...
Definition qhash.h:1219
iterator erase(const_iterator it)
Definition qhash.h:1233
const_iterator cend() const noexcept
Definition qhash.h:1218
bool isEmpty() const noexcept
Returns true if the hash contains no items; otherwise returns false.
Definition qhash.h:928
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
QObject * sender() const
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; othe...
Definition qobject.cpp:2658
\inmodule QtCore\reentrant
Definition qpoint.h:25
QObject * targetObject
the target QObject for this animation.
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr bool isValid() const noexcept
Returns true if the rectangle is valid, otherwise returns false.
Definition qrect.h:170
@ SH_Widget_Animation_Duration
Definition qstyle.h:700
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=nullptr, const QWidget *widget=nullptr, QStyleHintReturn *returnData=nullptr) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
void setEasingCurve(const QEasingCurve &easing)
void setDuration(int msecs)
void setEndValue(const QVariant &value)
void animate(QWidget *widget, const QRect &final_geometry, bool animate)
void abort(QWidget *widget)
QWidgetAnimator(QMainWindowLayout *layout)
bool animating() const
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
void setGeometry(int x, int y, int w, int h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qwidget.h:886
QSize size
the size of the widget excluding any window frame
Definition qwidget.h:113
QRect geometry
the geometry of the widget relative to its parent and excluding the window frame
Definition qwidget.h:106
int width
the width of the widget excluding any window frame
Definition qwidget.h:114
int height
the height of the widget excluding any window frame
Definition qwidget.h:115
QStyle * style() const
Definition qwidget.cpp:2600
bool isWindow() const
Returns true if the widget is an independent window, otherwise returns false.
Definition qwidget.h:811
QOpenGLWidget * widget
[1]
QSet< QString >::iterator it
Combined button and popup list for selecting options.
GLfloat GLfloat GLfloat w
[0]
GLboolean r
[2]
#define Q_UNUSED(x)
QVBoxLayout * layout