2018-06-26 14:09:39 +02:00
|
|
|
#include "widgets/helper/NotebookButton.hpp"
|
2018-06-28 19:46:45 +02:00
|
|
|
#include "singletons/Themes.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "widgets/Notebook.hpp"
|
2018-06-26 17:20:03 +02:00
|
|
|
#include "widgets/helper/RippleEffectButton.hpp"
|
2018-06-26 14:39:22 +02:00
|
|
|
#include "widgets/splits/SplitContainer.hpp"
|
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
|
|
|
|
2018-01-24 22:09:26 +01:00
|
|
|
#define nuuls nullptr
|
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
namespace chatterino {
|
2017-01-18 21:30:23 +01:00
|
|
|
|
2017-06-26 16:41:20 +02:00
|
|
|
NotebookButton::NotebookButton(BaseWidget *parent)
|
2017-09-21 17:34:41 +02:00
|
|
|
: RippleEffectButton(parent)
|
2016-12-30 12:19:31 +01:00
|
|
|
{
|
2018-01-24 22:09:26 +01:00
|
|
|
this->setAcceptDrops(true);
|
2016-12-30 12:19:31 +01:00
|
|
|
}
|
2016-12-30 12:20:26 +01:00
|
|
|
|
2018-04-05 23:44:46 +02:00
|
|
|
void NotebookButton::themeRefreshEvent()
|
|
|
|
{
|
2018-04-27 22:11:19 +02:00
|
|
|
this->setMouseEffectColor(this->themeManager->tabs.regular.text);
|
2018-04-05 23:44:46 +02: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;
|
|
|
|
|
2018-06-06 10:46:23 +02:00
|
|
|
if (mouseDown_ || mouseOver_) {
|
2018-04-27 22:11:19 +02:00
|
|
|
background = this->themeManager->tabs.regular.backgrounds.hover.color();
|
|
|
|
foreground = this->themeManager->tabs.regular.text;
|
2017-01-11 18:52:09 +01:00
|
|
|
} else {
|
2018-04-27 22:11:19 +02:00
|
|
|
background = this->themeManager->tabs.regular.backgrounds.regular.color();
|
|
|
|
foreground = this->themeManager->tabs.regular.text;
|
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
|
|
|
|
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) {
|
2018-06-01 14:46:41 +02:00
|
|
|
painter.setPen([&] {
|
|
|
|
QColor tmp = foreground;
|
2018-06-06 10:46:23 +02:00
|
|
|
if (!this->mouseOver_) {
|
2018-06-01 14:46:41 +02:00
|
|
|
tmp.setAlpha(180);
|
|
|
|
}
|
|
|
|
return tmp;
|
|
|
|
}());
|
|
|
|
QRect rect = this->rect();
|
|
|
|
int s = h * 4 / 9;
|
|
|
|
|
|
|
|
painter.drawLine(rect.left() + rect.width() / 2 - (s / 2), rect.top() + rect.height() / 2,
|
|
|
|
rect.left() + rect.width() / 2 + (s / 2), rect.top() + rect.height() / 2);
|
|
|
|
painter.drawLine(rect.left() + rect.width() / 2, rect.top() + rect.height() / 2 - (s / 2),
|
|
|
|
rect.left() + rect.width() / 2, rect.top() + rect.height() / 2 + (s / 2));
|
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) {
|
2018-06-06 10:46:23 +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-09-21 17:34:41 +02:00
|
|
|
RippleEffectButton::mouseReleaseEvent(event);
|
2016-12-30 12:20:26 +01:00
|
|
|
}
|
2017-06-07 10:09:24 +02:00
|
|
|
|
2018-01-24 22:09:26 +01:00
|
|
|
void NotebookButton::dragEnterEvent(QDragEnterEvent *event)
|
|
|
|
{
|
2018-06-11 21:57:17 +02:00
|
|
|
if (!event->mimeData()->hasFormat("chatterino/split")) {
|
2018-01-24 22:09:26 +01:00
|
|
|
return;
|
2018-06-11 21:57:17 +02:00
|
|
|
}
|
2018-01-24 22:09:26 +01:00
|
|
|
|
|
|
|
event->acceptProposedAction();
|
|
|
|
|
|
|
|
auto e = new QMouseEvent(QMouseEvent::MouseButtonPress,
|
|
|
|
QPointF(this->width() / 2, this->height() / 2), Qt::LeftButton,
|
|
|
|
Qt::LeftButton, 0);
|
|
|
|
RippleEffectButton::mousePressEvent(e);
|
|
|
|
delete e;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NotebookButton::dragLeaveEvent(QDragLeaveEvent *)
|
|
|
|
{
|
2018-06-06 10:46:23 +02:00
|
|
|
this->mouseDown_ = true;
|
2018-01-24 22:09:26 +01:00
|
|
|
this->update();
|
|
|
|
|
|
|
|
auto e = new QMouseEvent(QMouseEvent::MouseButtonRelease,
|
|
|
|
QPointF(this->width() / 2, this->height() / 2), Qt::LeftButton,
|
|
|
|
Qt::LeftButton, 0);
|
|
|
|
RippleEffectButton::mouseReleaseEvent(e);
|
|
|
|
delete e;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NotebookButton::dropEvent(QDropEvent *event)
|
|
|
|
{
|
|
|
|
if (SplitContainer::isDraggingSplit) {
|
|
|
|
event->acceptProposedAction();
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
Notebook *notebook = dynamic_cast<Notebook *>(this->parentWidget());
|
2018-01-24 22:09:26 +01:00
|
|
|
|
|
|
|
if (notebook != nuuls) {
|
2018-05-23 04:22:17 +02:00
|
|
|
SplitContainer *page = new SplitContainer(notebook);
|
|
|
|
auto *tab = notebook->addPage(page);
|
|
|
|
page->setTab(tab);
|
2018-01-24 22:09:26 +01:00
|
|
|
|
2018-05-10 19:50:31 +02:00
|
|
|
SplitContainer::draggingSplit->setParent(page);
|
|
|
|
page->appendSplit(SplitContainer::draggingSplit);
|
2018-01-24 22:09:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-04-03 02:55:32 +02:00
|
|
|
|
2017-06-07 10:09:24 +02:00
|
|
|
} // namespace chatterino
|