2 * Carla Style, based on Qt5 fusion style
3 * Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies)
4 * Copyright (C) 2013-2014 Filipe Coelho <falktx@falktx.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
15 * For a full copy of the license see the doc/LGPL.txt file
18 #ifndef CARLA_STYLE_ANIMATIONS_HPP_INCLUDED
19 #define CARLA_STYLE_ANIMATIONS_HPP_INCLUDED
21 #include "CarlaStyle.hpp"
23 #include <QtCore/QAbstractAnimation>
24 #include <QtCore/QCoreApplication>
25 #include <QtCore/QDateTime>
26 #include <QtGui/QImage>
28 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
29 # include <QtWidgets/QWidget>
31 # include <QtGui/QWidget>
34 class CarlaStyleAnimation
: public QAbstractAnimation
36 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) && defined(__clang_major__) && __clang_major__ >= 4
37 # pragma clang diagnostic push
38 # pragma clang diagnostic ignored "-Winconsistent-missing-override"
41 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) && defined(__clang_major__) && __clang_major__ >= 4
42 # pragma clang diagnostic pop
46 CarlaStyleAnimation(QObject
* target
)
47 : QAbstractAnimation(),
50 _startTime(QTime::currentTime())
52 if (target
!= nullptr)
54 moveToThread(target
->thread());
58 connect(this, SIGNAL(finished()), SLOT(deleteLater()));
61 QObject
* target() const
66 int duration() const override
71 void setDuration(int duration
)
81 void setDelay(int delay
)
86 QTime
startTime() const
91 void setStartTime(const QTime
& time
)
98 QEvent
event(QEvent::HoverEnter
);
99 QCoreApplication::sendEvent(target(), &event
);
103 virtual bool isUpdateNeeded() const
105 return currentTime() > _delay
;
108 virtual void updateCurrentTime(int /*time*/) override
110 if (QObject
* tgt
= target())
112 if (tgt
->isWidgetType())
114 QWidget
* widget
= static_cast<QWidget
*>(tgt
);
115 if (widget
->window()->isMinimized() || ! widget
->isVisible())
119 if (isUpdateNeeded())
130 class CarlaProgressStyleAnimation
: public CarlaStyleAnimation
132 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) && defined(__clang_major__) && __clang_major__ >= 4
133 # pragma clang diagnostic push
134 # pragma clang diagnostic ignored "-Winconsistent-missing-override"
137 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) && defined(__clang_major__) && __clang_major__ >= 4
138 # pragma clang diagnostic pop
142 CarlaProgressStyleAnimation(int speed
, QObject
* target
)
143 : CarlaStyleAnimation(target
),
149 int animationStep() const
151 return currentTime() / (1000.0 / _speed
);
154 int progressStep(int width
) const
156 int step
= animationStep();
157 int progress
= (step
* width
/ _speed
) % width
;
158 if (((step
* width
/ _speed
) % (2 * width
)) >= width
)
159 progress
= width
- progress
;
168 void setSpeed(int speed
)
174 bool isUpdateNeeded() const override
176 if (CarlaStyleAnimation::isUpdateNeeded())
178 int current
= animationStep();
179 if (_step
== -1 || _step
!= current
)
193 #endif // CARLA_STYLE_ANIMATIONS_HPP_INCLUDED