2019-07-23 22:18:36 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "widgets/BaseWidget.hpp"
|
|
|
|
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QPoint>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QWidget>
|
|
|
|
|
2023-10-08 18:50:48 +02:00
|
|
|
#include <optional>
|
|
|
|
|
2019-10-07 15:46:08 +02:00
|
|
|
namespace chatterino {
|
2019-07-23 22:18:36 +02:00
|
|
|
|
|
|
|
class Button : public BaseWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
struct ClickEffect {
|
|
|
|
double progress = 0.0;
|
|
|
|
QPoint position;
|
|
|
|
|
|
|
|
ClickEffect(QPoint _position)
|
|
|
|
: position(_position)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
2019-09-01 13:06:56 +02:00
|
|
|
enum class Dim { None, Some, Lots };
|
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
Button(BaseWidget *parent = nullptr);
|
|
|
|
|
2023-10-08 18:50:48 +02:00
|
|
|
void setMouseEffectColor(std::optional<QColor> color);
|
2019-07-23 22:18:36 +02:00
|
|
|
void setPixmap(const QPixmap &pixmap_);
|
|
|
|
const QPixmap &getPixmap() const;
|
|
|
|
|
2019-09-01 13:06:56 +02:00
|
|
|
void setDim(Dim value);
|
|
|
|
Dim getDim() const;
|
2019-07-23 22:18:36 +02:00
|
|
|
qreal getCurrentDimAmount() const;
|
|
|
|
|
|
|
|
void setEnable(bool value);
|
|
|
|
bool getEnable() const;
|
|
|
|
|
|
|
|
void setEnableMargin(bool value);
|
|
|
|
bool getEnableMargin() const;
|
|
|
|
|
|
|
|
void setBorderColor(const QColor &color);
|
|
|
|
const QColor &getBorderColor() const;
|
|
|
|
|
|
|
|
void setMenu(std::unique_ptr<QMenu> menu);
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void leftClicked();
|
|
|
|
void clicked(Qt::MouseButton button);
|
|
|
|
void leftMousePress();
|
|
|
|
|
|
|
|
protected:
|
2023-10-01 07:13:37 +02:00
|
|
|
void paintEvent(QPaintEvent * /*event*/) override;
|
|
|
|
|
|
|
|
/// Paint this button.
|
|
|
|
/// This is intended for child classes that may want to paint the overlay.
|
|
|
|
/// This function should be used after rendering the custom button,
|
|
|
|
/// because the painter's state will be modified by this function.
|
|
|
|
void paintButton(QPainter &painter);
|
2023-02-11 18:13:29 +01:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
void enterEvent(QEnterEvent * /*event*/) override;
|
|
|
|
#else
|
|
|
|
void enterEvent(QEvent * /*event*/) override;
|
|
|
|
#endif
|
2019-07-23 22:18:36 +02:00
|
|
|
virtual void leaveEvent(QEvent *) override;
|
|
|
|
virtual void mousePressEvent(QMouseEvent *event) override;
|
|
|
|
virtual void mouseReleaseEvent(QMouseEvent *event) override;
|
|
|
|
virtual void mouseMoveEvent(QMouseEvent *event) override;
|
|
|
|
|
|
|
|
void fancyPaint(QPainter &painter);
|
|
|
|
|
|
|
|
bool enabled_{true};
|
|
|
|
bool selected_{false};
|
|
|
|
bool mouseOver_{false};
|
|
|
|
bool mouseDown_{false};
|
|
|
|
bool menuVisible_{false};
|
|
|
|
|
|
|
|
private:
|
|
|
|
void onMouseEffectTimeout();
|
|
|
|
void showMenu();
|
|
|
|
|
|
|
|
QColor borderColor_{};
|
|
|
|
QPixmap pixmap_{};
|
2020-09-26 15:40:43 +02:00
|
|
|
QPixmap resizedPixmap_{};
|
2019-09-01 13:06:56 +02:00
|
|
|
Dim dimPixmap_{Dim::Some};
|
2019-07-23 22:18:36 +02:00
|
|
|
bool enableMargin_{true};
|
|
|
|
QPoint mousePos_{};
|
|
|
|
double hoverMultiplier_{0.0};
|
|
|
|
QTimer effectTimer_{};
|
|
|
|
std::vector<ClickEffect> clickEffects_{};
|
2023-10-08 18:50:48 +02:00
|
|
|
std::optional<QColor> mouseEffectColor_{};
|
2019-07-23 22:18:36 +02:00
|
|
|
std::unique_ptr<QMenu> menu_{};
|
|
|
|
};
|
|
|
|
|
2019-10-07 15:46:08 +02:00
|
|
|
} // namespace chatterino
|