2017-01-18 21:30:23 +01:00
|
|
|
#include "widgets/chatwidgetheaderbutton.h"
|
2017-01-15 16:38:30 +01:00
|
|
|
#include "colorscheme.h"
|
|
|
|
|
|
|
|
#include <QBrush>
|
|
|
|
#include <QPainter>
|
|
|
|
|
2017-01-18 21:30:23 +01:00
|
|
|
namespace chatterino {
|
|
|
|
namespace widgets {
|
|
|
|
|
2017-01-15 16:38:30 +01:00
|
|
|
ChatWidgetHeaderButton::ChatWidgetHeaderButton()
|
|
|
|
: QWidget()
|
|
|
|
, hbox()
|
2017-01-18 04:33:30 +01:00
|
|
|
, label()
|
|
|
|
, mouseOver(false)
|
|
|
|
, mouseDown(false)
|
2017-01-15 16:38:30 +01:00
|
|
|
{
|
|
|
|
setLayout(&hbox);
|
|
|
|
|
|
|
|
hbox.setMargin(0);
|
|
|
|
hbox.addSpacing(6);
|
2017-01-18 04:33:30 +01:00
|
|
|
hbox.addWidget(&this->label);
|
2017-01-15 16:38:30 +01:00
|
|
|
hbox.addSpacing(6);
|
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
QObject::connect(&this->label, &ChatWidgetHeaderButtonLabel::mouseUp, this,
|
2017-01-15 17:12:19 +01:00
|
|
|
&ChatWidgetHeaderButton::labelMouseUp);
|
2017-01-18 04:33:30 +01:00
|
|
|
QObject::connect(&this->label, &ChatWidgetHeaderButtonLabel::mouseDown,
|
|
|
|
this, &ChatWidgetHeaderButton::labelMouseDown);
|
2017-01-15 16:38:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ChatWidgetHeaderButton::paintEvent(QPaintEvent *)
|
|
|
|
{
|
|
|
|
QPainter painter(this);
|
|
|
|
|
|
|
|
QBrush brush(ColorScheme::instance().IsLightTheme
|
|
|
|
? QColor(0, 0, 0, 32)
|
|
|
|
: QColor(255, 255, 255, 32));
|
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
if (this->mouseDown) {
|
2017-01-15 16:38:30 +01:00
|
|
|
painter.fillRect(rect(), brush);
|
|
|
|
}
|
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
if (this->mouseOver) {
|
2017-01-15 16:38:30 +01:00
|
|
|
painter.fillRect(rect(), brush);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ChatWidgetHeaderButton::mousePressEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (event->button() == Qt::LeftButton) {
|
2017-01-18 04:33:30 +01:00
|
|
|
this->mouseDown = true;
|
2017-01-15 16:38:30 +01:00
|
|
|
|
|
|
|
repaint();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ChatWidgetHeaderButton::mouseReleaseEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (event->button() == Qt::LeftButton) {
|
2017-01-18 04:33:30 +01:00
|
|
|
this->mouseDown = false;
|
2017-01-15 16:38:30 +01:00
|
|
|
|
|
|
|
repaint();
|
|
|
|
|
|
|
|
emit clicked();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ChatWidgetHeaderButton::enterEvent(QEvent *)
|
|
|
|
{
|
2017-01-18 04:33:30 +01:00
|
|
|
this->mouseOver = true;
|
2017-01-15 16:38:30 +01:00
|
|
|
|
|
|
|
repaint();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ChatWidgetHeaderButton::leaveEvent(QEvent *)
|
|
|
|
{
|
2017-01-18 04:33:30 +01:00
|
|
|
this->mouseOver = false;
|
2017-01-15 16:38:30 +01:00
|
|
|
|
|
|
|
repaint();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ChatWidgetHeaderButton::labelMouseUp()
|
|
|
|
{
|
2017-01-18 04:33:30 +01:00
|
|
|
this->mouseDown = false;
|
2017-01-15 16:38:30 +01:00
|
|
|
|
|
|
|
repaint();
|
|
|
|
|
|
|
|
emit clicked();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ChatWidgetHeaderButton::labelMouseDown()
|
|
|
|
{
|
2017-01-18 04:33:30 +01:00
|
|
|
this->mouseDown = true;
|
2017-01-15 16:38:30 +01:00
|
|
|
|
|
|
|
repaint();
|
|
|
|
}
|
2017-01-18 21:30:23 +01:00
|
|
|
}
|
|
|
|
}
|