7df7da70cb
Remove unused constructor of messages::Message Fixed LimitedQueueSnapshot _-prefixes Changed LimitedQueueSnapshot's usage of int to std::size_t ColorScheme is no longer a singleton Created a "BaseWidget" class which is pretty much a QWidget except it has a reference of ColorScheme since most widgets will need a reference to the style they should use. BaseWidget can be implemented either with a BaseWidget parent (which will copy the ColorScheme reference from the parent) or with a normal QWidget parent and an explicit ColorScheme reference. Save main window geometry on close Fix font changing in the Settings Dialog Update settings library version
99 lines
2.0 KiB
C++
99 lines
2.0 KiB
C++
#include "widgets/chatwidgetheaderbutton.hpp"
|
|
#include "colorscheme.hpp"
|
|
#include "widgets/chatwidgetheader.hpp"
|
|
|
|
#include <QBrush>
|
|
#include <QPainter>
|
|
|
|
namespace chatterino {
|
|
namespace widgets {
|
|
|
|
ChatWidgetHeaderButton::ChatWidgetHeaderButton(BaseWidget *parent, int spacing)
|
|
: BaseWidget(parent)
|
|
, mouseOver(false)
|
|
, mouseDown(false)
|
|
{
|
|
setLayout(&this->ui.hbox);
|
|
|
|
this->ui.label.setAlignment(Qt::AlignCenter);
|
|
|
|
this->ui.hbox.setMargin(0);
|
|
this->ui.hbox.addSpacing(spacing);
|
|
this->ui.hbox.addWidget(&this->ui.label);
|
|
this->ui.hbox.addSpacing(spacing);
|
|
|
|
QObject::connect(&this->ui.label, &SignalLabel::mouseUp, this,
|
|
&ChatWidgetHeaderButton::labelMouseUp);
|
|
QObject::connect(&this->ui.label, &SignalLabel::mouseDown, this,
|
|
&ChatWidgetHeaderButton::labelMouseDown);
|
|
}
|
|
|
|
void ChatWidgetHeaderButton::paintEvent(QPaintEvent *)
|
|
{
|
|
QPainter painter(this);
|
|
|
|
QBrush brush(this->colorScheme.isLightTheme() ? QColor(0, 0, 0, 32)
|
|
: QColor(255, 255, 255, 32));
|
|
|
|
if (mouseDown) {
|
|
painter.fillRect(rect(), brush);
|
|
}
|
|
|
|
if (mouseOver) {
|
|
painter.fillRect(rect(), brush);
|
|
}
|
|
}
|
|
|
|
void ChatWidgetHeaderButton::mousePressEvent(QMouseEvent *event)
|
|
{
|
|
if (event->button() == Qt::LeftButton) {
|
|
mouseDown = true;
|
|
|
|
update();
|
|
}
|
|
}
|
|
|
|
void ChatWidgetHeaderButton::mouseReleaseEvent(QMouseEvent *event)
|
|
{
|
|
if (event->button() == Qt::LeftButton) {
|
|
mouseDown = false;
|
|
|
|
update();
|
|
|
|
emit clicked();
|
|
}
|
|
}
|
|
|
|
void ChatWidgetHeaderButton::enterEvent(QEvent *)
|
|
{
|
|
mouseOver = true;
|
|
|
|
update();
|
|
}
|
|
|
|
void ChatWidgetHeaderButton::leaveEvent(QEvent *)
|
|
{
|
|
mouseOver = false;
|
|
|
|
update();
|
|
}
|
|
|
|
void ChatWidgetHeaderButton::labelMouseUp()
|
|
{
|
|
mouseDown = false;
|
|
|
|
update();
|
|
|
|
emit clicked();
|
|
}
|
|
|
|
void ChatWidgetHeaderButton::labelMouseDown()
|
|
{
|
|
mouseDown = true;
|
|
|
|
update();
|
|
}
|
|
|
|
} // namespace widgets
|
|
} // namespace chatterino
|