summary refs log tree commit diff
path: root/src/ui/RippleOverlay.h
blob: 7ae3e4f10a541d2d57d507ce2634f287a72b942d (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
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later

#pragma once

#include <QPainterPath>

#include "OverlayWidget.h"

class Ripple;

class RippleOverlay : public OverlayWidget
{
        Q_OBJECT

public:
        explicit RippleOverlay(QWidget *parent = nullptr);

        void addRipple(Ripple *ripple);
        void addRipple(const QPoint &position, qreal radius = 300);

        void removeRipple(Ripple *ripple);

        inline void setClipping(bool enable);
        inline bool hasClipping() const;

        inline void setClipPath(const QPainterPath &path);

protected:
        void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;

private:
        Q_DISABLE_COPY(RippleOverlay)

        void paintRipple(QPainter *painter, Ripple *ripple);

        QList<Ripple *> ripples_;
        QPainterPath clip_path_;
        bool use_clip_;
};

inline void
RippleOverlay::setClipping(bool enable)
{
        use_clip_ = enable;
        update();
}

inline bool
RippleOverlay::hasClipping() const
{
        return use_clip_;
}

inline void
RippleOverlay::setClipPath(const QPainterPath &path)
{
        clip_path_ = path;
        update();
}