1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
36 #include <QtCore/QPointer>
37 #include <QtCore/QTime>
38 #include <QtCore/QBasicTimer>
39 #include <QtGui/QStyle>
40 #include <QtGui/QPainter>
41 #include <QtGui/QWidget>
44 * This is a set of helper classes to allow for widget animations in
45 * the style. Its mostly taken from Vista style so it should be fully documented
53 Animation() : m_running(true) { }
54 virtual ~Animation() { }
55 QWidget * widget() const { return m_widget; }
56 bool running() const { return m_running; }
57 const QTime &startTime() const { return m_startTime; }
58 void setRunning(bool val) { m_running = val; }
59 void setWidget(QWidget *widget) { m_widget = widget; }
60 void setStartTime(const QTime &startTime) { m_startTime = startTime; }
61 virtual void paint(QPainter *painter, const QStyleOption *option);
64 void drawBlendedImage(QPainter *painter, QRect rect, float value);
66 QPointer<QWidget> m_widget;
67 QImage m_primaryImage;
68 QImage m_secondaryImage;
73 // Handles state transition animations
74 class Transition : public Animation
77 Transition() : Animation() {}
78 virtual ~Transition() {}
79 void setDuration(int duration) { m_duration = duration; }
80 void setStartImage(const QImage &image) { m_primaryImage = image; }
81 void setEndImage(const QImage &image) { m_secondaryImage = image; }
82 virtual void paint(QPainter *painter, const QStyleOption *option);
83 int duration() const { return m_duration; }
84 int m_duration; //set time in ms to complete a state transition
87 class StyleAnimator : public QObject
92 StyleAnimator(QObject *parent = 0) : QObject(parent) {}
94 void timerEvent(QTimerEvent *);
95 void startAnimation(Animation *);
96 void stopAnimation(const QWidget *);
97 Animation* widgetAnimation(const QWidget *) const;
100 QBasicTimer animationTimer;
101 QList <Animation*> animations;
104 #endif // ANIMATION_H