LP-56 - Better txpid option namings, fix tabs-spaces, tooltips. headers, variable...
[librepilot.git] / ground / openpilotgcs / src / plugins / coreplugin / styleanimator.h
blob48c9fe8e91ce8373a91de71b0b0a6773febfaa14
1 /**
2 ******************************************************************************
4 * @file styleanimator.h
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
7 * @addtogroup GCSPlugins GCS Plugins
8 * @{
9 * @addtogroup CorePlugin Core Plugin
10 * @{
11 * @brief The Core GCS plugin
12 *****************************************************************************/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #ifndef ANIMATION_H
30 #define ANIMATION_H
32 #include <QtCore/QPointer>
33 #include <QtCore/QTime>
34 #include <QtCore/QBasicTimer>
35 #include <QStyle>
36 #include <QPainter>
37 #include <QWidget>
40 * This is a set of helper classes to allow for widget animations in
41 * the style. Its mostly taken from Vista style so it should be fully documented
42 * there.
46 class Animation {
47 public:
48 Animation() : m_running(true) {}
49 virtual ~Animation() {}
50 QWidget *widget() const
52 return m_widget;
54 bool running() const
56 return m_running;
58 const QTime &startTime() const
60 return m_startTime;
62 void setRunning(bool val)
64 m_running = val;
66 void setWidget(QWidget *widget)
68 m_widget = widget;
70 void setStartTime(const QTime &startTime)
72 m_startTime = startTime;
74 virtual void paint(QPainter *painter, const QStyleOption *option);
76 protected:
77 void drawBlendedImage(QPainter *painter, QRect rect, float value);
78 QTime m_startTime;
79 QPointer<QWidget> m_widget;
80 QImage m_primaryImage;
81 QImage m_secondaryImage;
82 QImage m_tempImage;
83 bool m_running;
86 // Handles state transition animations
87 class Transition : public Animation {
88 public:
89 Transition() : Animation() {}
90 virtual ~Transition() {}
91 void setDuration(int duration)
93 m_duration = duration;
95 void setStartImage(const QImage &image)
97 m_primaryImage = image;
99 void setEndImage(const QImage &image)
101 m_secondaryImage = image;
103 virtual void paint(QPainter *painter, const QStyleOption *option);
104 int duration() const
106 return m_duration;
108 int m_duration; // set time in ms to complete a state transition
111 class StyleAnimator : public QObject {
112 Q_OBJECT
114 public:
115 StyleAnimator(QObject *parent = 0) : QObject(parent) {}
117 void timerEvent(QTimerEvent *);
118 void startAnimation(Animation *);
119 void stopAnimation(const QWidget *);
120 Animation *widgetAnimation(const QWidget *) const;
122 private:
123 QBasicTimer animationTimer;
124 QList <Animation *> animations;
127 #endif // ANIMATION_H