dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
styleanimator.h
Go to the documentation of this file.
1 
13 /*
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.
18  *
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.
23  *
24  * You should have received a copy of the GNU General Public License along
25  * with this program; if not, see <http://www.gnu.org/licenses/>
26  */
27 
28 #ifndef ANIMATION_H
29 #define ANIMATION_H
30 
31 #include <QtCore/QPointer>
32 #include <QtCore/QTime>
33 #include <QtCore/QBasicTimer>
34 #include <QStyle>
35 #include <QPainter>
36 #include <QWidget>
37 
38 /*
39  * This is a set of helper classes to allow for widget animations in
40  * the style. Its mostly taken from Vista style so it should be fully documented
41  * there.
42  *
43  */
44 
45 class Animation
46 {
47 public:
49  : m_running(true)
50  {
51  }
52  virtual ~Animation() {}
53  QWidget *widget() const { return m_widget; }
54  bool running() const { return m_running; }
55  const QTime &startTime() const { return m_startTime; }
56  void setRunning(bool val) { m_running = val; }
57  void setWidget(QWidget *widget) { m_widget = widget; }
58  void setStartTime(const QTime &startTime) { m_startTime = startTime; }
59  virtual void paint(QPainter *painter, const QStyleOption *option);
60 
61 protected:
62  void drawBlendedImage(QPainter *painter, QRect rect, float value);
63  QTime m_startTime;
64  QPointer<QWidget> m_widget;
67  QImage m_tempImage;
68  bool m_running;
69 };
70 
71 // Handles state transition animations
72 class Transition : public Animation
73 {
74 public:
76  : Animation()
77  {
78  }
79  virtual ~Transition() {}
81  void setStartImage(const QImage &image) { m_primaryImage = image; }
82  void setEndImage(const QImage &image) { m_secondaryImage = image; }
83  virtual void paint(QPainter *painter, const QStyleOption *option);
84  int duration() const { return m_duration; }
85  int m_duration; // set time in ms to complete a state transition
86 };
87 
88 class StyleAnimator : public QObject
89 {
90  Q_OBJECT
91 
92 public:
93  StyleAnimator(QObject *parent = nullptr)
94  : QObject(parent)
95  {
96  }
97 
98  void timerEvent(QTimerEvent *);
99  void startAnimation(Animation *);
100  void stopAnimation(const QWidget *);
101  Animation *widgetAnimation(const QWidget *) const;
102 
103 private:
104  QBasicTimer animationTimer;
105  QList<Animation *> animations;
106 };
107 
108 #endif // ANIMATION_H
bool running() const
Definition: styleanimator.h:54
virtual ~Transition()
Definition: styleanimator.h:79
QImage m_primaryImage
Definition: styleanimator.h:65
QImage m_secondaryImage
Definition: styleanimator.h:66
void setRunning(bool val)
Definition: styleanimator.h:56
const QTime & startTime() const
Definition: styleanimator.h:55
bool m_running
Definition: styleanimator.h:68
void drawBlendedImage(QPainter *painter, QRect rect, float value)
virtual ~Animation()
Definition: styleanimator.h:52
virtual void paint(QPainter *painter, const QStyleOption *option)
Animation * widgetAnimation(const QWidget *) const
int duration() const
Definition: styleanimator.h:84
virtual void paint(QPainter *painter, const QStyleOption *option)
StyleAnimator(QObject *parent=nullptr)
Definition: styleanimator.h:93
void setEndImage(const QImage &image)
Definition: styleanimator.h:82
void setStartTime(const QTime &startTime)
Definition: styleanimator.h:58
void setWidget(QWidget *widget)
Definition: styleanimator.h:57
QImage m_tempImage
Definition: styleanimator.h:67
void timerEvent(QTimerEvent *)
QWidget * widget() const
Definition: styleanimator.h:53
void stopAnimation(const QWidget *)
QPointer< QWidget > m_widget
Definition: styleanimator.h:64
QTime m_startTime
Definition: styleanimator.h:63
void setStartImage(const QImage &image)
Definition: styleanimator.h:81
void setDuration(int duration)
Definition: styleanimator.h:80
void startAnimation(Animation *)