1 #include "TitlebarButton.hpp"
2 
3 #include "BaseTheme.hpp"
4 
5 #include <QPainterPath>
6 
7 namespace chatterino {
8 
TitleBarButton()9 TitleBarButton::TitleBarButton()
10     : Button(nullptr)
11 {
12 }
13 
getButtonStyle() const14 TitleBarButtonStyle TitleBarButton::getButtonStyle() const
15 {
16     return this->style_;
17 }
18 
setButtonStyle(TitleBarButtonStyle _style)19 void TitleBarButton::setButtonStyle(TitleBarButtonStyle _style)
20 {
21     this->style_ = _style;
22     this->update();
23 }
24 
paintEvent(QPaintEvent * event)25 void TitleBarButton::paintEvent(QPaintEvent *event)
26 {
27     QPainter painter(this);
28 
29     painter.setOpacity(this->getCurrentDimAmount());
30 
31     QColor color = this->theme->window.text;
32     QColor background = this->theme->window.background;
33 
34     int xD = this->height() / 3;
35     int centerX = this->width() / 2;
36 
37     painter.setRenderHint(QPainter::Antialiasing, false);
38 
39     switch (this->style_)
40     {
41         case TitleBarButtonStyle::Minimize: {
42             painter.fillRect(centerX - xD / 2, xD * 3 / 2, xD, 1, color);
43             break;
44         }
45         case TitleBarButtonStyle::Maximize: {
46             painter.setPen(color);
47             painter.drawRect(centerX - xD / 2, xD, xD - 1, xD - 1);
48             break;
49         }
50         case TitleBarButtonStyle::Unmaximize: {
51             int xD2 = xD * 1 / 5;
52             int xD3 = xD * 4 / 5;
53 
54             painter.drawRect(centerX - xD / 2 + xD2, xD, xD3, xD3);
55             painter.fillRect(centerX - xD / 2, xD + xD2, xD3, xD3,
56                              this->theme->window.background);
57             painter.drawRect(centerX - xD / 2, xD + xD2, xD3, xD3);
58             break;
59         }
60         case TitleBarButtonStyle::Close: {
61             QRect rect(centerX - xD / 2, xD, xD - 1, xD - 1);
62             painter.setPen(QPen(color, 1));
63 
64             painter.drawLine(rect.topLeft(), rect.bottomRight());
65             painter.drawLine(rect.topRight(), rect.bottomLeft());
66             break;
67         }
68         case TitleBarButtonStyle::User: {
69             color = "#999";
70 
71             painter.setRenderHint(QPainter::Antialiasing);
72 
73             auto a = xD / 3;
74             QPainterPath path;
75 
76             painter.save();
77             painter.translate(3, 3);
78 
79             path.arcMoveTo(a, 4 * a, 6 * a, 6 * a, 0);
80             path.arcTo(a, 4 * a, 6 * a, 6 * a, 0, 180);
81 
82             painter.fillPath(path, color);
83 
84             painter.setBrush(background);
85             painter.drawEllipse(2 * a, 1 * a, 4 * a, 4 * a);
86 
87             painter.setBrush(color);
88             painter.drawEllipse(2.5 * a, 1.5 * a, 3 * a + 1, 3 * a);
89             painter.restore();
90 
91             break;
92         }
93         case TitleBarButtonStyle::Settings: {
94             color = "#999";
95             painter.setRenderHint(QPainter::Antialiasing);
96 
97             painter.save();
98             painter.translate(3, 3);
99 
100             auto a = xD / 3;
101             QPainterPath path;
102 
103             path.arcMoveTo(a, a, 6 * a, 6 * a, 0 - (360 / 32.0));
104 
105             for (int i = 0; i < 8; i++)
106             {
107                 path.arcTo(a, a, 6 * a, 6 * a, i * (360 / 8.0) - (360 / 32.0),
108                            (360 / 32.0));
109                 path.arcTo(2 * a, 2 * a, 4 * a, 4 * a,
110                            i * (360 / 8.0) + (360 / 32.0), (360 / 32.0));
111             }
112 
113             painter.strokePath(path, color);
114             painter.fillPath(path, color);
115 
116             painter.setBrush(background);
117             painter.drawEllipse(3 * a, 3 * a, 2 * a, 2 * a);
118             painter.restore();
119             break;
120         }
121         default:;
122     }
123 
124     Button::paintEvent(event);
125     //    this->fancyPaint(painter);
126 }
127 
128 }  // namespace chatterino
129