OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / coreplugin / styleanimator.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
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.
18 **
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.
22 **
23 ** Other Usage
24 **
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.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #ifndef ANIMATION_H
34 #define ANIMATION_H
35
36 #include <QtCore/QPointer>
37 #include <QtCore/QTime>
38 #include <QtCore/QBasicTimer>
39 #include <QtGui/QStyle>
40 #include <QtGui/QPainter>
41 #include <QtGui/QWidget>
42
43 /*
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
46  * there.
47  *
48  */
49
50 class Animation
51 {
52 public :
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);
62
63 protected:
64     void drawBlendedImage(QPainter *painter, QRect rect, float value);
65     QTime m_startTime;
66     QPointer<QWidget> m_widget;
67     QImage m_primaryImage;
68     QImage m_secondaryImage;
69     QImage m_tempImage;
70     bool m_running;
71 };
72
73 // Handles state transition animations
74 class Transition : public Animation
75 {
76 public :
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
85 };
86
87 class StyleAnimator : public QObject
88 {
89     Q_OBJECT
90
91 public:
92     StyleAnimator(QObject *parent = 0) : QObject(parent) {}
93
94     void timerEvent(QTimerEvent *);
95     void startAnimation(Animation *);
96     void stopAnimation(const QWidget *);
97     Animation* widgetAnimation(const QWidget *) const;
98
99 private:
100     QBasicTimer animationTimer;
101     QList <Animation*> animations;
102 };
103
104 #endif // ANIMATION_H