2018-06-26 14:09:39 +02:00
|
|
|
#include "widgets/helper/NotebookButton.hpp"
|
Sort and force grouping of includes (#4172)
This change enforces strict include grouping using IncludeCategories
In addition to adding this to the .clang-format file and applying it in the tests/src and src directories, I also did the following small changes:
In ChatterSet.hpp, I changed lrucache to a <>include
In Irc2.hpp, I change common/SignalVector.hpp to a "project-include"
In AttachedWindow.cpp, NativeMessaging.cpp, WindowsHelper.hpp, BaseWindow.cpp, and StreamerMode.cpp, I disabled clang-format for the windows-includes
In WindowDescriptors.hpp, I added the missing vector include. It was previously not needed because the include was handled by another file that was previously included first.
clang-format minimum version has been bumped, so Ubuntu version used in the check-formatting job has been bumped to 22.04 (which is the latest LTS)
2022-11-27 19:32:53 +01:00
|
|
|
|
2022-12-25 12:09:25 +01:00
|
|
|
#include "common/QLogging.hpp"
|
2018-06-28 20:03:04 +02:00
|
|
|
#include "singletons/Theme.hpp"
|
2018-08-08 15:35:54 +02:00
|
|
|
#include "widgets/helper/Button.hpp"
|
Sort and force grouping of includes (#4172)
This change enforces strict include grouping using IncludeCategories
In addition to adding this to the .clang-format file and applying it in the tests/src and src directories, I also did the following small changes:
In ChatterSet.hpp, I changed lrucache to a <>include
In Irc2.hpp, I change common/SignalVector.hpp to a "project-include"
In AttachedWindow.cpp, NativeMessaging.cpp, WindowsHelper.hpp, BaseWindow.cpp, and StreamerMode.cpp, I disabled clang-format for the windows-includes
In WindowDescriptors.hpp, I added the missing vector include. It was previously not needed because the include was handled by another file that was previously included first.
clang-format minimum version has been bumped, so Ubuntu version used in the check-formatting job has been bumped to 22.04 (which is the latest LTS)
2022-11-27 19:32:53 +01:00
|
|
|
#include "widgets/Notebook.hpp"
|
2022-12-25 12:09:25 +01:00
|
|
|
#include "widgets/splits/DraggedSplit.hpp"
|
2018-08-11 22:23:06 +02:00
|
|
|
#include "widgets/splits/Split.hpp"
|
2018-06-26 14:39:22 +02:00
|
|
|
#include "widgets/splits/SplitContainer.hpp"
|
2016-12-30 12:19:31 +01:00
|
|
|
|
Sort and force grouping of includes (#4172)
This change enforces strict include grouping using IncludeCategories
In addition to adding this to the .clang-format file and applying it in the tests/src and src directories, I also did the following small changes:
In ChatterSet.hpp, I changed lrucache to a <>include
In Irc2.hpp, I change common/SignalVector.hpp to a "project-include"
In AttachedWindow.cpp, NativeMessaging.cpp, WindowsHelper.hpp, BaseWindow.cpp, and StreamerMode.cpp, I disabled clang-format for the windows-includes
In WindowDescriptors.hpp, I added the missing vector include. It was previously not needed because the include was handled by another file that was previously included first.
clang-format minimum version has been bumped, so Ubuntu version used in the check-formatting job has been bumped to 22.04 (which is the latest LTS)
2022-11-27 19:32:53 +01:00
|
|
|
#include <QMimeData>
|
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
|
|
|
|
2018-07-05 13:25:10 +02:00
|
|
|
NotebookButton::NotebookButton(Notebook *parent)
|
2018-08-08 15:35:54 +02:00
|
|
|
: Button(parent)
|
2018-07-05 13:25:10 +02:00
|
|
|
, parent_(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-07-05 13:25:10 +02:00
|
|
|
void NotebookButton::setIcon(Icon icon)
|
|
|
|
{
|
|
|
|
this->icon_ = icon;
|
|
|
|
|
|
|
|
this->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
NotebookButton::Icon NotebookButton::getIcon() const
|
|
|
|
{
|
|
|
|
return this->icon_;
|
|
|
|
}
|
|
|
|
|
2018-07-06 17:11:37 +02:00
|
|
|
void NotebookButton::themeChangedEvent()
|
2018-04-05 23:44:46 +02:00
|
|
|
{
|
2018-07-06 17:11:37 +02:00
|
|
|
this->setMouseEffectColor(this->theme->tabs.regular.text);
|
2018-04-05 23:44:46 +02:00
|
|
|
}
|
|
|
|
|
2018-07-05 13:25:10 +02:00
|
|
|
void NotebookButton::paintEvent(QPaintEvent *event)
|
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_)
|
|
|
|
{
|
2023-03-17 20:53:03 +01:00
|
|
|
background = this->theme->tabs.regular.backgrounds.hover;
|
2018-07-06 17:11:37 +02:00
|
|
|
foreground = this->theme->tabs.regular.text;
|
2017-01-11 18:52:09 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-03-17 20:53:03 +01:00
|
|
|
background = this->theme->tabs.regular.backgrounds.regular;
|
2018-07-06 17:11:37 +02:00
|
|
|
foreground = this->theme->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
|
|
|
|
2018-07-05 13:25:10 +02:00
|
|
|
switch (icon_)
|
|
|
|
{
|
2019-09-26 00:51:05 +02:00
|
|
|
case Plus: {
|
2018-07-05 13:25:10 +02:00
|
|
|
painter.setPen([&] {
|
|
|
|
QColor tmp = foreground;
|
2022-12-25 12:09:25 +01:00
|
|
|
if (isDraggingSplit())
|
2018-10-09 19:22:07 +02:00
|
|
|
{
|
|
|
|
tmp = this->theme->tabs.selected.line.regular;
|
|
|
|
}
|
|
|
|
else if (!this->mouseOver_)
|
|
|
|
{
|
2018-07-05 13:25:10 +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));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-09-26 00:51:05 +02:00
|
|
|
case User: {
|
2018-07-05 13:25:10 +02:00
|
|
|
painter.setRenderHint(QPainter::Antialiasing);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2020-02-28 19:48:04 +01:00
|
|
|
QPainterPath remove;
|
|
|
|
remove.addEllipse(2 * a, 1 * a, 4 * a, 4 * a);
|
|
|
|
path = path.subtracted(remove);
|
2018-07-05 13:25:10 +02:00
|
|
|
|
2020-02-28 19:52:15 +01:00
|
|
|
path.addEllipse(2.5 * a, 1.5 * a, 3 * a, 3 * a);
|
2018-07-05 13:25:10 +02:00
|
|
|
|
2020-02-28 19:48:04 +01:00
|
|
|
painter.fillPath(path, foreground);
|
2018-07-05 13:25:10 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-09-26 00:51:05 +02:00
|
|
|
case Settings: {
|
2018-07-05 13:25:10 +02:00
|
|
|
painter.setRenderHint(QPainter::Antialiasing);
|
|
|
|
|
|
|
|
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));
|
2018-06-01 14:46:41 +02:00
|
|
|
}
|
2017-01-01 02:30:42 +01:00
|
|
|
|
2020-02-28 19:48:04 +01:00
|
|
|
QPainterPath remove;
|
|
|
|
remove.addEllipse(3 * a, 3 * a, 2 * a, 2 * a);
|
2016-12-30 12:20:26 +01:00
|
|
|
|
2020-02-28 19:48:04 +01:00
|
|
|
painter.fillPath(path.subtracted(remove), foreground);
|
2018-07-05 13:25:10 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-01-01 02:30:42 +01:00
|
|
|
|
2018-07-05 13:25:10 +02:00
|
|
|
default:;
|
2016-12-30 12:20:26 +01:00
|
|
|
}
|
|
|
|
|
2018-08-08 15:35:54 +02:00
|
|
|
Button::paintEvent(event);
|
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
|
|
|
|
2018-10-21 16:13:26 +02:00
|
|
|
emit leftClicked();
|
2017-01-01 18:43:52 +01:00
|
|
|
}
|
2016-12-30 12:20:26 +01:00
|
|
|
|
2018-08-08 15:35:54 +02:00
|
|
|
Button::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;
|
|
|
|
|
|
|
|
event->acceptProposedAction();
|
|
|
|
|
|
|
|
auto e = new QMouseEvent(QMouseEvent::MouseButtonPress,
|
|
|
|
QPointF(this->width() / 2, this->height() / 2),
|
2021-03-13 16:27:13 +01:00
|
|
|
Qt::LeftButton, Qt::LeftButton, {});
|
2018-08-08 15:35:54 +02:00
|
|
|
Button::mousePressEvent(e);
|
2018-01-24 22:09:26 +01:00
|
|
|
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),
|
2021-03-13 16:27:13 +01:00
|
|
|
Qt::LeftButton, Qt::LeftButton, {});
|
2018-08-08 15:35:54 +02:00
|
|
|
Button::mouseReleaseEvent(e);
|
2018-01-24 22:09:26 +01:00
|
|
|
delete e;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NotebookButton::dropEvent(QDropEvent *event)
|
|
|
|
{
|
2022-12-25 12:09:25 +01:00
|
|
|
auto *draggedSplit = dynamic_cast<Split *>(event->source());
|
|
|
|
if (!draggedSplit)
|
2018-01-24 22:09:26 +01:00
|
|
|
{
|
2022-12-25 12:09:25 +01:00
|
|
|
qCDebug(chatterinoWidget)
|
|
|
|
<< "Dropped something that wasn't a split onto a notebook button";
|
|
|
|
return;
|
|
|
|
}
|
2018-01-24 22:09:26 +01:00
|
|
|
|
2022-12-25 12:09:25 +01:00
|
|
|
auto *notebook = dynamic_cast<Notebook *>(this->parentWidget());
|
|
|
|
if (!notebook)
|
|
|
|
{
|
|
|
|
qCDebug(chatterinoWidget) << "Dropped a split onto a notebook button "
|
|
|
|
"without a parent notebook";
|
|
|
|
return;
|
|
|
|
}
|
2018-01-24 22:09:26 +01:00
|
|
|
|
2022-12-25 12:09:25 +01:00
|
|
|
event->acceptProposedAction();
|
2018-01-24 22:09:26 +01:00
|
|
|
|
2022-12-25 12:09:25 +01:00
|
|
|
auto *page = new SplitContainer(notebook);
|
|
|
|
auto *tab = notebook->addPage(page);
|
|
|
|
page->setTab(tab);
|
|
|
|
|
|
|
|
draggedSplit->setParent(page);
|
|
|
|
page->insertSplit(draggedSplit);
|
2018-01-24 22:09:26 +01:00
|
|
|
}
|
2018-04-03 02:55:32 +02:00
|
|
|
|
2018-07-05 13:25:10 +02:00
|
|
|
void NotebookButton::hideEvent(QHideEvent *)
|
|
|
|
{
|
2023-06-11 11:34:28 +02:00
|
|
|
this->parent_->refresh();
|
2018-07-05 13:25:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void NotebookButton::showEvent(QShowEvent *)
|
|
|
|
{
|
2023-06-11 11:34:28 +02:00
|
|
|
this->parent_->refresh();
|
2018-07-05 13:25:10 +02:00
|
|
|
}
|
|
|
|
|
2017-06-07 10:09:24 +02:00
|
|
|
} // namespace chatterino
|