matrixion/include/ui/Ripple.h

147 lines
3 KiB
C
Raw Permalink Normal View History

#pragma once
2017-04-06 02:06:42 +03:00
#include <QBrush>
#include <QEasingCurve>
#include <QParallelAnimationGroup>
#include <QPoint>
#include <QPropertyAnimation>
class RippleOverlay;
class Ripple : public QParallelAnimationGroup
{
2017-09-10 12:59:21 +03:00
Q_OBJECT
2017-04-06 02:06:42 +03:00
2017-09-10 12:59:21 +03:00
Q_PROPERTY(qreal radius WRITE setRadius READ radius)
Q_PROPERTY(qreal opacity WRITE setOpacity READ opacity)
2017-04-06 02:06:42 +03:00
public:
2017-09-10 12:59:21 +03:00
explicit Ripple(const QPoint &center, QObject *parent = 0);
Ripple(const QPoint &center, RippleOverlay *overlay, QObject *parent = 0);
~Ripple();
2017-04-06 02:06:42 +03:00
2017-09-10 12:59:21 +03:00
inline void setOverlay(RippleOverlay *overlay);
2017-04-06 02:06:42 +03:00
2017-09-10 12:59:21 +03:00
void setRadius(qreal radius);
void setOpacity(qreal opacity);
void setColor(const QColor &color);
void setBrush(const QBrush &brush);
2017-04-06 02:06:42 +03:00
2017-09-10 12:59:21 +03:00
inline qreal radius() const;
inline qreal opacity() const;
inline QColor color() const;
inline QBrush brush() const;
inline QPoint center() const;
2017-04-06 02:06:42 +03:00
2017-09-10 12:59:21 +03:00
inline QPropertyAnimation *radiusAnimation() const;
inline QPropertyAnimation *opacityAnimation() const;
2017-04-06 02:06:42 +03:00
2017-09-10 12:59:21 +03:00
inline void setOpacityStartValue(qreal value);
inline void setOpacityEndValue(qreal value);
inline void setRadiusStartValue(qreal value);
inline void setRadiusEndValue(qreal value);
inline void setDuration(int msecs);
2017-04-06 02:06:42 +03:00
protected slots:
2017-09-10 12:59:21 +03:00
void destroy();
2017-04-06 02:06:42 +03:00
private:
2017-09-10 12:59:21 +03:00
Q_DISABLE_COPY(Ripple)
2017-04-06 02:06:42 +03:00
2017-09-10 12:59:21 +03:00
QPropertyAnimation *animate(const QByteArray &property,
const QEasingCurve &easing = QEasingCurve::OutQuad,
int duration = 800);
2017-04-06 02:06:42 +03:00
2017-09-10 12:59:21 +03:00
void init();
2017-04-06 02:06:42 +03:00
2017-09-10 12:59:21 +03:00
RippleOverlay *overlay_;
2017-04-06 02:06:42 +03:00
2017-09-10 12:59:21 +03:00
QPropertyAnimation *const radius_anim_;
QPropertyAnimation *const opacity_anim_;
2017-04-06 02:06:42 +03:00
2017-09-10 12:59:21 +03:00
qreal radius_;
qreal opacity_;
2017-04-06 02:06:42 +03:00
2017-09-10 12:59:21 +03:00
QPoint center_;
QBrush brush_;
2017-04-06 02:06:42 +03:00
};
2017-08-20 13:47:22 +03:00
inline void
Ripple::setOverlay(RippleOverlay *overlay)
2017-04-06 02:06:42 +03:00
{
2017-09-10 12:59:21 +03:00
overlay_ = overlay;
2017-04-06 02:06:42 +03:00
}
2017-08-20 13:47:22 +03:00
inline qreal
Ripple::radius() const
2017-04-06 02:06:42 +03:00
{
2017-09-10 12:59:21 +03:00
return radius_;
2017-04-06 02:06:42 +03:00
}
2017-08-20 13:47:22 +03:00
inline qreal
Ripple::opacity() const
2017-04-06 02:06:42 +03:00
{
2017-09-10 12:59:21 +03:00
return opacity_;
2017-04-06 02:06:42 +03:00
}
2017-08-20 13:47:22 +03:00
inline QColor
Ripple::color() const
2017-04-06 02:06:42 +03:00
{
2017-09-10 12:59:21 +03:00
return brush_.color();
2017-04-06 02:06:42 +03:00
}
2017-08-20 13:47:22 +03:00
inline QBrush
Ripple::brush() const
2017-04-06 02:06:42 +03:00
{
2017-09-10 12:59:21 +03:00
return brush_;
2017-04-06 02:06:42 +03:00
}
2017-08-20 13:47:22 +03:00
inline QPoint
Ripple::center() const
2017-04-06 02:06:42 +03:00
{
2017-09-10 12:59:21 +03:00
return center_;
2017-04-06 02:06:42 +03:00
}
2017-08-20 13:47:22 +03:00
inline QPropertyAnimation *
Ripple::radiusAnimation() const
2017-04-06 02:06:42 +03:00
{
2017-09-10 12:59:21 +03:00
return radius_anim_;
2017-04-06 02:06:42 +03:00
}
2017-08-20 13:47:22 +03:00
inline QPropertyAnimation *
Ripple::opacityAnimation() const
2017-04-06 02:06:42 +03:00
{
2017-09-10 12:59:21 +03:00
return opacity_anim_;
2017-04-06 02:06:42 +03:00
}
2017-08-20 13:47:22 +03:00
inline void
Ripple::setOpacityStartValue(qreal value)
2017-04-06 02:06:42 +03:00
{
2017-09-10 12:59:21 +03:00
opacity_anim_->setStartValue(value);
2017-04-06 02:06:42 +03:00
}
2017-08-20 13:47:22 +03:00
inline void
Ripple::setOpacityEndValue(qreal value)
2017-04-06 02:06:42 +03:00
{
2017-09-10 12:59:21 +03:00
opacity_anim_->setEndValue(value);
2017-04-06 02:06:42 +03:00
}
2017-08-20 13:47:22 +03:00
inline void
Ripple::setRadiusStartValue(qreal value)
2017-04-06 02:06:42 +03:00
{
2017-09-10 12:59:21 +03:00
radius_anim_->setStartValue(value);
2017-04-06 02:06:42 +03:00
}
2017-08-20 13:47:22 +03:00
inline void
Ripple::setRadiusEndValue(qreal value)
2017-04-06 02:06:42 +03:00
{
2017-09-10 12:59:21 +03:00
radius_anim_->setEndValue(value);
2017-04-06 02:06:42 +03:00
}
2017-08-20 13:47:22 +03:00
inline void
Ripple::setDuration(int msecs)
2017-04-06 02:06:42 +03:00
{
2017-09-10 12:59:21 +03:00
radius_anim_->setDuration(msecs);
opacity_anim_->setDuration(msecs);
2017-04-06 02:06:42 +03:00
}