mirror-chatterino2/src/widgets/helper/rippleeffectbutton.hpp

67 lines
1.4 KiB
C++
Raw Normal View History

#pragma once
2017-04-12 17:46:44 +02:00
#include <boost/optional.hpp>
#include "widgets/basewidget.hpp"
2017-04-12 17:46:44 +02:00
#include <QMouseEvent>
#include <QPainter>
#include <QPoint>
#include <QTimer>
#include <QWidget>
2017-04-14 17:52:22 +02:00
namespace chatterino {
namespace widgets {
class RippleEffectButton : public BaseWidget
2017-04-12 17:46:44 +02:00
{
2017-09-15 17:23:49 +02:00
Q_OBJECT
2017-04-12 17:46:44 +02:00
struct ClickEffect {
double progress = 0.0;
2017-04-12 17:46:44 +02:00
QPoint position;
ClickEffect(QPoint _position)
: position(_position)
2017-04-12 17:46:44 +02:00
{
}
};
public:
RippleEffectButton(BaseWidget *parent);
2017-04-12 17:46:44 +02:00
void setMouseEffectColor(boost::optional<QColor> color);
2018-01-17 16:52:51 +01:00
void setPixmap(const QPixmap *pixmap);
const QPixmap *getPixmap() const;
2017-04-12 17:46:44 +02:00
2017-09-15 17:23:49 +02:00
signals:
void clicked();
2017-04-12 17:46:44 +02:00
protected:
2017-08-05 17:01:02 +02:00
bool selected = false;
bool mouseOver = false;
bool mouseDown = false;
virtual void paintEvent(QPaintEvent *) override;
virtual void enterEvent(QEvent *) override;
virtual void leaveEvent(QEvent *) override;
virtual void mousePressEvent(QMouseEvent *event) override;
virtual void mouseReleaseEvent(QMouseEvent *event) override;
virtual void mouseMoveEvent(QMouseEvent *event) override;
2017-04-12 17:46:44 +02:00
void fancyPaint(QPainter &painter);
private:
2018-01-17 16:52:51 +01:00
QPixmap *pixmap;
QPoint mousePos;
double hoverMultiplier = 0.0;
QTimer effectTimer;
std::vector<ClickEffect> clickEffects;
boost::optional<QColor> mouseEffectColor = boost::none;
2017-04-12 17:46:44 +02:00
void onMouseEffectTimeout();
};
} // namespace widgets
} // namespace chatterino