summary refs log tree commit diff
path: root/src/ui/Ripple.cc
blob: 2869bf7ba81a753953ab96ed7248a5441b4cae3c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "Ripple.h"
#include "RippleOverlay.h"

Ripple::Ripple(const QPoint &center, QObject *parent)
  : QParallelAnimationGroup(parent)
  , overlay_(0)
  , radius_anim_(animate("radius"))
  , opacity_anim_(animate("opacity"))
  , radius_(0)
  , opacity_(0)
  , center_(center)
{
        init();
}

Ripple::Ripple(const QPoint &center, RippleOverlay *overlay, QObject *parent)
  : QParallelAnimationGroup(parent)
  , overlay_(overlay)
  , radius_anim_(animate("radius"))
  , opacity_anim_(animate("opacity"))
  , radius_(0)
  , opacity_(0)
  , center_(center)
{
        init();
}

Ripple::~Ripple()
{
}

void
Ripple::setRadius(qreal radius)
{
        Q_ASSERT(overlay_);

        if (radius_ == radius)
                return;

        radius_ = radius;
        overlay_->update();
}

void
Ripple::setOpacity(qreal opacity)
{
        Q_ASSERT(overlay_);

        if (opacity_ == opacity)
                return;

        opacity_ = opacity;
        overlay_->update();
}

void
Ripple::setColor(const QColor &color)
{
        if (brush_.color() == color)
                return;

        brush_.setColor(color);

        if (overlay_)
                overlay_->update();
}

void
Ripple::setBrush(const QBrush &brush)
{
        brush_ = brush;

        if (overlay_)
                overlay_->update();
}

void
Ripple::destroy()
{
        Q_ASSERT(overlay_);

        overlay_->removeRipple(this);
}

QPropertyAnimation *
Ripple::animate(const QByteArray &property, const QEasingCurve &easing, int duration)
{
        QPropertyAnimation *animation = new QPropertyAnimation;
        animation->setTargetObject(this);
        animation->setPropertyName(property);
        animation->setEasingCurve(easing);
        animation->setDuration(duration);

        addAnimation(animation);

        return animation;
}

void
Ripple::init()
{
        setOpacityStartValue(0.5);
        setOpacityEndValue(0);
        setRadiusStartValue(0);
        setRadiusEndValue(300);

        brush_.setColor(Qt::black);
        brush_.setStyle(Qt::SolidPattern);

        connect(this, SIGNAL(finished()), this, SLOT(destroy()));
}