Qt 4.8
qwidgetanimator.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include <QtCore/qpropertyanimation.h>
43 #include <QtGui/qwidget.h>
44 #include <QtGui/private/qmainwindowlayout_p.h>
45 
46 #include "qwidgetanimator_p.h"
47 
49 
51 {
52 }
53 
55 {
56 #ifndef QT_NO_ANIMATION
58  if (it == m_animation_map.end())
59  return;
60  QPropertyAnimation *anim = *it;
62  if (anim) {
63  anim->stop();
64  }
65 #ifndef QT_NO_MAINWINDOW
67 #endif
68 #else
69  Q_UNUSED(w); //there is no animation to abort
70 #endif //QT_NO_ANIMATION
71 }
72 
73 #ifndef QT_NO_ANIMATION
75 {
77  abort(static_cast<QWidget*>(anim->targetObject()));
78 }
79 #endif //QT_NO_ANIMATION
80 
81 void QWidgetAnimator::animate(QWidget *widget, const QRect &_final_geometry, bool animate)
82 {
83  QRect r = widget->geometry();
84  if (r.right() < 0 || r.bottom() < 0)
85  r = QRect();
86 
87  animate = animate && !r.isNull() && !_final_geometry.isNull();
88 
89  // might make the wigdet go away by sending it to negative space
90  const QRect final_geometry = _final_geometry.isValid() || widget->isWindow() ? _final_geometry :
91  QRect(QPoint(-500 - widget->width(), -500 - widget->height()), widget->size());
92 
93 #ifndef QT_NO_ANIMATION
95  if (it != m_animation_map.constEnd() && (*it)->endValue().toRect() == final_geometry)
96  return;
97 
98  QPropertyAnimation *anim = new QPropertyAnimation(widget, "geometry", widget);
99  anim->setDuration(animate ? 200 : 0);
101  anim->setEndValue(final_geometry);
102  m_animation_map[widget] = anim;
103  connect(anim, SIGNAL(finished()), SLOT(animationFinished()));
105 #else
106  //we do it in one shot
107  widget->setGeometry(final_geometry);
108 #ifndef QT_NO_MAINWINDOW
110 #endif //QT_NO_MAINWINDOW
111 #endif //QT_NO_ANIMATION
112 }
113 
115 {
116  return !m_animation_map.isEmpty();
117 }
118 
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:231
The QPropertyAnimation class animates Qt properties.
QWidgetAnimator(QMainWindowLayout *layout)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QPointer< QWidget > widget
int width
the width of the widget excluding any window frame
Definition: qwidget.h:166
#define it(className, varName)
bool isWindow() const
Returns true if the widget is an independent window, otherwise returns false.
Definition: qwidget.h:945
#define SLOT(a)
Definition: qobjectdefs.h:226
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
void setEasingCurve(const QEasingCurve &easing)
void start(QAbstractAnimation::DeletionPolicy policy=KeepWhenStopped)
Starts the animation.
iterator find(const Key &key)
Returns an iterator pointing to the item with key key in the map.
Definition: qmap.h:618
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:1017
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
T * qobject_cast(QObject *object)
Definition: qobject.h:375
void setEndValue(const QVariant &value)
QObject * targetObject
the target QObject for this animation.
QMainWindowLayout * m_mainWindowLayout
void stop()
Stops the animation.
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:2327
void setDuration(int msecs)
#define SIGNAL(a)
Definition: qobjectdefs.h:227
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
int height
the height of the widget excluding any window frame
Definition: qwidget.h:167
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
const char * layout
QSize size
the size of the widget excluding any window frame
Definition: qwidget.h:165
bool animating() const
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:380
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:375
void abort(QWidget *widget)
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
bool isEmpty() const
Returns true if the map contains no items; otherwise returns false.
Definition: qmap.h:203
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
const_iterator constFind(const Key &key) const
Returns an const iterator pointing to the item with key key in the map.
Definition: qmap.h:612
iterator erase(iterator it)
Removes the (key, value) pair pointed to by the iterator pos from the map, and returns an iterator to...
Definition: qmap.h:717
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
Definition: qrect.h:237
void animationFinished(QWidget *widget)
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
QRect geometry
the geometry of the widget relative to its parent and excluding the window frame
Definition: qwidget.h:158
void animate(QWidget *widget, const QRect &final_geometry, bool animate)
AnimationMap m_animation_map