2016-12-30 12:19:31 +01:00
|
|
|
#include "notebookbutton.h"
|
2016-12-30 12:20:26 +01:00
|
|
|
#include "QPainter"
|
2017-01-01 02:30:42 +01:00
|
|
|
#include "QPainterPath"
|
2017-01-01 18:43:52 +01:00
|
|
|
#include "QMouseEvent"
|
2017-01-01 02:30:42 +01:00
|
|
|
#include "colorscheme.h"
|
2016-12-30 12:19:31 +01:00
|
|
|
|
2016-12-30 12:20:26 +01:00
|
|
|
NotebookButton::NotebookButton(QWidget *parent)
|
|
|
|
: QWidget(parent)
|
2016-12-30 12:19:31 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2016-12-30 12:20:26 +01:00
|
|
|
|
|
|
|
void NotebookButton::paintEvent(QPaintEvent *)
|
|
|
|
{
|
|
|
|
QPainter painter(this);
|
|
|
|
|
|
|
|
QColor background;
|
|
|
|
QColor foreground;
|
|
|
|
|
2017-01-06 23:28:48 +01:00
|
|
|
auto colorScheme = ColorScheme::instance();
|
2017-01-01 02:30:42 +01:00
|
|
|
|
2016-12-30 12:20:26 +01:00
|
|
|
if (mouseDown)
|
|
|
|
{
|
2017-01-01 02:30:42 +01:00
|
|
|
background = colorScheme.TabSelectedBackground;
|
|
|
|
foreground = colorScheme.TabSelectedText;
|
2016-12-30 12:20:26 +01:00
|
|
|
}
|
|
|
|
else if (mouseOver)
|
|
|
|
{
|
2017-01-01 02:30:42 +01:00
|
|
|
background = colorScheme.TabHoverBackground;
|
|
|
|
foreground = colorScheme.TabSelectedBackground;
|
2016-12-30 12:20:26 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-01-01 02:30:42 +01:00
|
|
|
background = colorScheme.TabPanelBackground;
|
|
|
|
foreground = colorScheme.TabSelectedBackground;
|
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);
|
|
|
|
|
|
|
|
float h = this->height(), w = this->width();
|
|
|
|
|
|
|
|
if (icon == IconPlus)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
else if (icon == IconUser)
|
|
|
|
{
|
2017-01-01 02:30:42 +01:00
|
|
|
painter.setRenderHint(QPainter::Antialiasing);
|
|
|
|
painter.setRenderHint(QPainter::HighQualityAntialiasing);
|
|
|
|
|
|
|
|
auto a = w/8;
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
painter.drawEllipse(2.5*a, 1.5*a, 3*a + 1, 3*a);
|
2016-12-30 12:20:26 +01:00
|
|
|
}
|
|
|
|
else // IconSettings
|
|
|
|
{
|
2017-01-01 02:30:42 +01:00
|
|
|
painter.setRenderHint(QPainter::Antialiasing);
|
|
|
|
painter.setRenderHint(QPainter::HighQualityAntialiasing);
|
|
|
|
|
|
|
|
auto a = w/8;
|
|
|
|
QPainterPath path;
|
|
|
|
|
|
|
|
path.arcMoveTo(a, a, 6*a, 6*a, 0 - (360 / 32.0));
|
|
|
|
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
painter.fillPath(path, foreground);
|
2016-12-30 12:20:26 +01:00
|
|
|
|
2017-01-01 02:30:42 +01:00
|
|
|
painter.setBrush(background);
|
|
|
|
painter.drawEllipse(3*a, 3*a, 2*a, 2*a);
|
2016-12-30 12:20:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-01 18:43:52 +01:00
|
|
|
void NotebookButton::mousePressEvent(QMouseEvent *event)
|
2016-12-30 12:20:26 +01:00
|
|
|
{
|
2017-01-01 18:43:52 +01:00
|
|
|
if (event->button() == Qt::LeftButton)
|
|
|
|
{
|
|
|
|
mouseDown = true;
|
2016-12-30 12:20:26 +01:00
|
|
|
|
2017-01-01 18:43:52 +01:00
|
|
|
this->repaint();
|
|
|
|
}
|
2016-12-30 12:20:26 +01:00
|
|
|
}
|
|
|
|
|
2017-01-01 18:43:52 +01:00
|
|
|
void NotebookButton::mouseReleaseEvent(QMouseEvent *event)
|
2016-12-30 12:20:26 +01:00
|
|
|
{
|
2017-01-01 18:43:52 +01:00
|
|
|
if (event->button() == Qt::LeftButton)
|
|
|
|
{
|
|
|
|
mouseDown = false;
|
2016-12-30 12:20:26 +01:00
|
|
|
|
2017-01-01 18:43:52 +01:00
|
|
|
this->repaint();
|
|
|
|
|
|
|
|
emit clicked();
|
|
|
|
}
|
2016-12-30 12:20:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void NotebookButton::enterEvent(QEvent *)
|
|
|
|
{
|
|
|
|
mouseOver = true;
|
|
|
|
|
|
|
|
this->repaint();
|
|
|
|
}
|
|
|
|
|
|
|
|
void NotebookButton::leaveEvent(QEvent *)
|
|
|
|
{
|
|
|
|
mouseOver = false;
|
|
|
|
|
|
|
|
this->repaint();
|
|
|
|
}
|