2019-07-23 22:18:36 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "widgets/BaseWidget.hpp"
|
|
|
|
|
Sort and force grouping of includes (#4172)
This change enforces strict include grouping using IncludeCategories
In addition to adding this to the .clang-format file and applying it in the tests/src and src directories, I also did the following small changes:
In ChatterSet.hpp, I changed lrucache to a <>include
In Irc2.hpp, I change common/SignalVector.hpp to a "project-include"
In AttachedWindow.cpp, NativeMessaging.cpp, WindowsHelper.hpp, BaseWindow.cpp, and StreamerMode.cpp, I disabled clang-format for the windows-includes
In WindowDescriptors.hpp, I added the missing vector include. It was previously not needed because the include was handled by another file that was previously included first.
clang-format minimum version has been bumped, so Ubuntu version used in the check-formatting job has been bumped to 22.04 (which is the latest LTS)
2022-11-27 19:32:53 +01:00
|
|
|
#include <boost/optional.hpp>
|
2019-07-23 22:18:36 +02:00
|
|
|
#include <QMenu>
|
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QPoint>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QWidget>
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
void setMouseEffectColor(boost::optional<QColor> color);
|
|
|
|
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:
|
|
|
|
virtual void paintEvent(QPaintEvent *) override;
|
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_{};
|
|
|
|
boost::optional<QColor> mouseEffectColor_{};
|
|
|
|
std::unique_ptr<QMenu> menu_{};
|
|
|
|
};
|
|
|
|
|
2019-10-07 15:46:08 +02:00
|
|
|
} // namespace chatterino
|