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

89 lines
2 KiB
C++
Raw Normal View History

#pragma once
2017-04-12 17:46:44 +02:00
#include <boost/optional.hpp>
2018-06-26 14:09:39 +02:00
#include "widgets/BaseWidget.hpp"
#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 {
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 {
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:
2018-08-08 15:35:54 +02:00
Button(BaseWidget *parent = nullptr);
2017-04-12 17:46:44 +02: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 setDim(bool value);
bool getDim() const;
qreal getCurrentDimAmount() const;
2018-07-04 13:05:54 +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
void setMenu(std::unique_ptr<QMenu> menu);
2017-09-15 17:23:49 +02:00
signals:
void clicked();
void leftMousePress();
2017-09-15 17:23:49 +02:00
2017-04-12 17:46:44 +02:00
protected:
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);
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();
void showMenu();
QColor borderColor_{};
QPixmap pixmap_{};
bool dimPixmap_{true};
2018-09-04 21:39:54 +02:00
bool enableMargin_{true};
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
};
} // namespace chatterino