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>
|
|
|
|
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "widgets/BaseWidget.hpp"
|
2017-06-26 16:41:20 +02:00
|
|
|
|
2018-08-07 23:46:00 +02:00
|
|
|
#include <QMenu>
|
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 {
|
2017-06-07 10:09:24 +02:00
|
|
|
|
2018-08-08 15:35:54 +02:00
|
|
|
class Button : 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:
|
2018-08-08 15:35:54 +02:00
|
|
|
Button(BaseWidget *parent = nullptr);
|
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;
|
|
|
|
|
2018-07-04 13:13:21 +02:00
|
|
|
void setDim(bool value);
|
|
|
|
bool getDim() const;
|
|
|
|
qreal getCurrentDimAmount() const;
|
2018-07-04 13:05:54 +02:00
|
|
|
|
2018-07-04 19:43:41 +02:00
|
|
|
void setEnable(bool value);
|
|
|
|
bool getEnable() const;
|
|
|
|
|
2018-09-04 21:39:54 +02:00
|
|
|
void setEnableMargin(bool value);
|
|
|
|
bool getEnableMargin() const;
|
|
|
|
|
2018-06-06 10:46:23 +02:00
|
|
|
void setBorderColor(const QColor &color);
|
|
|
|
const QColor &getBorderColor() const;
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2018-08-07 23:46:00 +02:00
|
|
|
void setMenu(std::unique_ptr<QMenu> menu);
|
|
|
|
|
2017-09-15 17:23:49 +02:00
|
|
|
signals:
|
|
|
|
void clicked();
|
2018-07-04 19:43:41 +02:00
|
|
|
void leftMousePress();
|
2017-09-15 17:23:49 +02:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
protected:
|
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);
|
|
|
|
|
2018-08-07 23:46:00 +02:00
|
|
|
bool enabled_{true};
|
|
|
|
bool selected_{false};
|
|
|
|
bool mouseOver_{false};
|
|
|
|
bool mouseDown_{false};
|
|
|
|
bool menuVisible_{false};
|
2018-07-06 19:23:47 +02:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
private:
|
2018-07-06 19:23:47 +02:00
|
|
|
void onMouseEffectTimeout();
|
2018-08-07 23:46:00 +02:00
|
|
|
void showMenu();
|
|
|
|
|
|
|
|
QColor borderColor_{};
|
|
|
|
QPixmap pixmap_{};
|
|
|
|
bool dimPixmap_{true};
|
2018-09-04 21:39:54 +02:00
|
|
|
bool enableMargin_{true};
|
2018-08-07 23:46:00 +02:00
|
|
|
QPoint mousePos_{};
|
|
|
|
double hoverMultiplier_{0.0};
|
|
|
|
QTimer effectTimer_{};
|
|
|
|
std::vector<ClickEffect> clickEffects_{};
|
|
|
|
boost::optional<QColor> mouseEffectColor_{};
|
|
|
|
std::unique_ptr<QMenu> menu_{};
|
2017-04-12 17:46:44 +02:00
|
|
|
};
|
|
|
|
|
2017-06-07 10:09:24 +02:00
|
|
|
} // namespace chatterino
|