2019-07-23 22:18:36 +02:00
|
|
|
#include "TitlebarButton.hpp"
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2022-11-10 10:07:50 +01:00
|
|
|
#include "singletons/Theme.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 <QPainterPath>
|
|
|
|
|
2019-10-07 15:46:08 +02:00
|
|
|
namespace chatterino {
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
TitleBarButton::TitleBarButton()
|
|
|
|
: Button(nullptr)
|
|
|
|
{
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
TitleBarButtonStyle TitleBarButton::getButtonStyle() const
|
|
|
|
{
|
|
|
|
return this->style_;
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
void TitleBarButton::setButtonStyle(TitleBarButtonStyle _style)
|
|
|
|
{
|
|
|
|
this->style_ = _style;
|
|
|
|
this->update();
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
void TitleBarButton::paintEvent(QPaintEvent *event)
|
|
|
|
{
|
|
|
|
QPainter painter(this);
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
painter.setOpacity(this->getCurrentDimAmount());
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
QColor color = this->theme->window.text;
|
|
|
|
QColor background = this->theme->window.background;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
int xD = this->height() / 3;
|
|
|
|
int centerX = this->width() / 2;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
painter.setRenderHint(QPainter::Antialiasing, false);
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
switch (this->style_)
|
|
|
|
{
|
2019-11-02 12:36:42 +01:00
|
|
|
case TitleBarButtonStyle::Minimize: {
|
2019-07-23 22:18:36 +02:00
|
|
|
painter.fillRect(centerX - xD / 2, xD * 3 / 2, xD, 1, color);
|
|
|
|
break;
|
|
|
|
}
|
2019-11-02 12:36:42 +01:00
|
|
|
case TitleBarButtonStyle::Maximize: {
|
2019-07-23 22:18:36 +02:00
|
|
|
painter.setPen(color);
|
|
|
|
painter.drawRect(centerX - xD / 2, xD, xD - 1, xD - 1);
|
|
|
|
break;
|
|
|
|
}
|
2019-11-02 12:36:42 +01:00
|
|
|
case TitleBarButtonStyle::Unmaximize: {
|
2019-07-23 22:18:36 +02:00
|
|
|
int xD2 = xD * 1 / 5;
|
|
|
|
int xD3 = xD * 4 / 5;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
painter.drawRect(centerX - xD / 2 + xD2, xD, xD3, xD3);
|
|
|
|
painter.fillRect(centerX - xD / 2, xD + xD2, xD3, xD3,
|
|
|
|
this->theme->window.background);
|
|
|
|
painter.drawRect(centerX - xD / 2, xD + xD2, xD3, xD3);
|
|
|
|
break;
|
|
|
|
}
|
2019-11-02 12:36:42 +01:00
|
|
|
case TitleBarButtonStyle::Close: {
|
2019-07-23 22:18:36 +02:00
|
|
|
QRect rect(centerX - xD / 2, xD, xD - 1, xD - 1);
|
|
|
|
painter.setPen(QPen(color, 1));
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
painter.drawLine(rect.topLeft(), rect.bottomRight());
|
|
|
|
painter.drawLine(rect.topRight(), rect.bottomLeft());
|
|
|
|
break;
|
|
|
|
}
|
2019-11-02 12:36:42 +01:00
|
|
|
case TitleBarButtonStyle::User: {
|
2019-07-23 22:18:36 +02:00
|
|
|
color = "#999";
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
painter.setRenderHint(QPainter::Antialiasing);
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
auto a = xD / 3;
|
|
|
|
QPainterPath path;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
painter.save();
|
|
|
|
painter.translate(3, 3);
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
path.arcMoveTo(a, 4 * a, 6 * a, 6 * a, 0);
|
|
|
|
path.arcTo(a, 4 * a, 6 * a, 6 * a, 0, 180);
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
painter.fillPath(path, color);
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
painter.setBrush(background);
|
|
|
|
painter.drawEllipse(2 * a, 1 * a, 4 * a, 4 * a);
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
painter.setBrush(color);
|
|
|
|
painter.drawEllipse(2.5 * a, 1.5 * a, 3 * a + 1, 3 * a);
|
|
|
|
painter.restore();
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
break;
|
|
|
|
}
|
2019-11-02 12:36:42 +01:00
|
|
|
case TitleBarButtonStyle::Settings: {
|
2019-07-23 22:18:36 +02:00
|
|
|
color = "#999";
|
|
|
|
painter.setRenderHint(QPainter::Antialiasing);
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
painter.save();
|
|
|
|
painter.translate(3, 3);
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
auto a = xD / 3;
|
|
|
|
QPainterPath path;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
path.arcMoveTo(a, a, 6 * a, 6 * a, 0 - (360 / 32.0));
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
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));
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
painter.strokePath(path, color);
|
|
|
|
painter.fillPath(path, color);
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
painter.setBrush(background);
|
|
|
|
painter.drawEllipse(3 * a, 3 * a, 2 * a, 2 * a);
|
|
|
|
painter.restore();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:;
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
Button::paintEvent(event);
|
|
|
|
// this->fancyPaint(painter);
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-10-07 15:46:08 +02:00
|
|
|
} // namespace chatterino
|