mirror-chatterino2/widgets/notebookbutton.cpp

107 lines
2.8 KiB
C++
Raw Normal View History

2017-01-18 21:30:23 +01:00
#include "widgets/notebookbutton.h"
2017-01-01 02:30:42 +01:00
#include "colorscheme.h"
2017-04-12 17:46:44 +02:00
#include "widgets/fancybutton.h"
2016-12-30 12:19:31 +01:00
2017-01-18 04:52:47 +01:00
#include <QMouseEvent>
#include <QPainter>
#include <QPainterPath>
2017-04-12 17:46:44 +02:00
#include <QRadialGradient>
2017-01-18 04:52:47 +01:00
2017-01-18 21:30:23 +01:00
namespace chatterino {
namespace widgets {
2016-12-30 12:20:26 +01:00
NotebookButton::NotebookButton(QWidget *parent)
2017-04-12 17:46:44 +02:00
: FancyButton(parent)
2016-12-30 12:19:31 +01:00
{
2017-04-12 17:46:44 +02:00
setMouseEffectColor(QColor(0, 0, 0));
2016-12-30 12:19:31 +01:00
}
2016-12-30 12:20:26 +01:00
2017-04-12 17:46:44 +02:00
void NotebookButton::paintEvent(QPaintEvent *)
2016-12-30 12:20:26 +01:00
{
QPainter painter(this);
QColor background;
QColor foreground;
2017-02-02 01:23:26 +01:00
auto &colorScheme = ColorScheme::getInstance();
2017-01-01 02:30:42 +01:00
2017-04-12 17:46:44 +02:00
if (_mouseDown) {
2017-01-01 02:30:42 +01:00
background = colorScheme.TabSelectedBackground;
foreground = colorScheme.TabSelectedText;
2017-04-12 17:46:44 +02:00
} else if (_mouseOver) {
2017-01-01 02:30:42 +01:00
background = colorScheme.TabHoverBackground;
foreground = colorScheme.TabSelectedBackground;
2017-01-11 18:52:09 +01:00
} else {
2017-01-01 02:30:42 +01:00
background = colorScheme.TabPanelBackground;
2017-04-12 17:46:44 +02:00
// foreground = colorScheme.TabSelectedBackground;
foreground = QColor(230, 230, 230);
2016-12-30 12:20:26 +01:00
}
2017-01-01 02:30:42 +01:00
painter.setPen(Qt::NoPen);
2016-12-30 12:20:26 +01:00
painter.fillRect(this->rect(), background);
2017-04-12 17:46:44 +02:00
float h = height(), w = width();
2016-12-30 12:20:26 +01:00
2017-01-11 18:52:09 +01:00
if (icon == IconPlus) {
2017-04-12 17:46:44 +02:00
painter.fillRect(
QRectF((h / 12) * 2 + 1, (h / 12) * 5 + 1, w - ((h / 12) * 5), (h / 12) * 1),
foreground);
painter.fillRect(
QRectF((h / 12) * 5 + 1, (h / 12) * 2 + 1, (h / 12) * 1, w - ((h / 12) * 5)),
foreground);
2017-01-11 18:52:09 +01:00
} else if (icon == IconUser) {
2017-01-01 02:30:42 +01:00
painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::HighQualityAntialiasing);
2017-01-11 18:52:09 +01:00
auto a = w / 8;
2017-01-01 02:30:42 +01:00
QPainterPath path;
path.arcMoveTo(a, 4 * a, 6 * a, 6 * a, 0);
path.arcTo(a, 4 * a, 6 * a, 6 * a, 0, 180);
painter.fillPath(path, foreground);
painter.setBrush(background);
2017-01-11 18:52:09 +01:00
painter.drawEllipse(2 * a, 1 * a, 4 * a, 4 * a);
2016-12-30 12:20:26 +01:00
2017-01-01 02:30:42 +01:00
painter.setBrush(foreground);
2017-01-11 18:52:09 +01:00
painter.drawEllipse(2.5 * a, 1.5 * a, 3 * a + 1, 3 * a);
} else // IconSettings
2016-12-30 12:20:26 +01:00
{
2017-01-01 02:30:42 +01:00
painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::HighQualityAntialiasing);
2017-01-11 18:52:09 +01:00
auto a = w / 8;
2017-01-01 02:30:42 +01:00
QPainterPath path;
2017-01-11 18:52:09 +01:00
path.arcMoveTo(a, a, 6 * a, 6 * a, 0 - (360 / 32.0));
2017-01-01 02:30:42 +01:00
2017-01-11 18:52:09 +01:00
for (int i = 0; i < 8; i++) {
2017-04-12 17:46:44 +02:00
path.arcTo(a, a, 6 * a, 6 * a, i * (360 / 8.0) - (360 / 32.0), (360 / 32.0));
path.arcTo(2 * a, 2 * a, 4 * a, 4 * a, i * (360 / 8.0) + (360 / 32.0), (360 / 32.0));
2017-01-01 02:30:42 +01:00
}
painter.fillPath(path, foreground);
2016-12-30 12:20:26 +01:00
2017-01-01 02:30:42 +01:00
painter.setBrush(background);
2017-01-11 18:52:09 +01:00
painter.drawEllipse(3 * a, 3 * a, 2 * a, 2 * a);
2016-12-30 12:20:26 +01:00
}
2017-04-12 17:46:44 +02:00
fancyPaint(painter);
2016-12-30 12:20:26 +01:00
}
2017-04-12 17:46:44 +02:00
void NotebookButton::mouseReleaseEvent(QMouseEvent *event)
2016-12-30 12:20:26 +01:00
{
2017-01-11 18:52:09 +01:00
if (event->button() == Qt::LeftButton) {
2017-04-12 17:46:44 +02:00
_mouseDown = false;
2016-12-30 12:20:26 +01:00
2017-04-12 17:46:44 +02:00
update();
2017-01-01 18:43:52 +01:00
emit clicked();
}
2016-12-30 12:20:26 +01:00
2017-04-12 17:46:44 +02:00
FancyButton::mouseReleaseEvent(event);
2016-12-30 12:20:26 +01:00
}
2017-01-18 21:30:23 +01:00
}
}