2017-06-07 10:09:24 +02:00
|
|
|
#pragma once
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2017-12-19 02:23:17 +01:00
|
|
|
#include <boost/optional.hpp>
|
|
|
|
|
2017-06-26 16:41:20 +02:00
|
|
|
#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 {
|
2017-06-07 10:09:24 +02:00
|
|
|
|
2017-09-21 17:34:41 +02:00
|
|
|
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 {
|
2017-06-26 16:41:20 +02:00
|
|
|
double progress = 0.0;
|
2017-04-12 17:46:44 +02:00
|
|
|
QPoint position;
|
|
|
|
|
2017-06-26 16:41:20 +02:00
|
|
|
ClickEffect(QPoint _position)
|
|
|
|
: position(_position)
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
2017-09-21 17:34:41 +02:00
|
|
|
RippleEffectButton(BaseWidget *parent);
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2017-12-19 02:23:17 +01:00
|
|
|
void setMouseEffectColor(boost::optional<QColor> color);
|
2018-06-06 10:46:23 +02:00
|
|
|
void setPixmap(const QPixmap &pixmap_);
|
|
|
|
const QPixmap &getPixmap() const;
|
|
|
|
|
|
|
|
void setBorderColor(const QColor &color);
|
|
|
|
const QColor &getBorderColor() 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:
|
2018-06-06 10:46:23 +02:00
|
|
|
bool selected_ = false;
|
|
|
|
bool mouseOver_ = false;
|
|
|
|
bool mouseDown_ = false;
|
2017-08-05 17:01:02 +02:00
|
|
|
|
2017-06-26 16:41:20 +02:00
|
|
|
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-06-06 10:46:23 +02:00
|
|
|
QColor borderColor_;
|
|
|
|
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();
|
|
|
|
};
|
|
|
|
|
2017-06-07 10:09:24 +02:00
|
|
|
} // namespace widgets
|
|
|
|
} // namespace chatterino
|