hivemind 1.0.0
Loading...
Searching...
No Matches
color_box.cpp
Go to the documentation of this file.
1#include "gui/color_box.h"
2
3#include <QPainter>
4#include <QPainterPath>
5
6namespace Gui
7{
8
9 ColorBox::ColorBox(QWidget* parent)
10 : QPushButton(parent), m_Color{ Qt::gray },
11 m_ColorDialog{ new QColorDialog(this) }
12 {
13 setObjectName("ColorBox");
14 setFixedSize(50, 50);
15 setCursor(Qt::PointingHandCursor);
16
17 m_ColorDialog->setModal(true);
18 }
19
20 void
21 ColorBox::paintEvent(QPaintEvent* event)
22 {
23 if (m_Color.isValid()) {
24 QPainter painter(this);
25 painter.setRenderHint(QPainter::Antialiasing);
26
27 int radius = qRound(width() * 0.2); // Adjust the factor as needed
28
29 QPainterPath path;
30 path.addRoundedRect(rect(), radius, radius);
31 painter.fillPath(path, m_Color);
32
33 painter.setPen({ Qt::black, 2 });
34 painter.drawPath(path);
35 }
36 }
37
38 void
39 ColorBox::mousePressEvent(QMouseEvent* event)
40 {
42 }
43
44 void
46 {
47 m_Color = color;
48 m_ColorDialog->setCurrentColor(color);
49 }
50
51 void
53 {
54 m_ColorDialog->open();
55 m_ColorDialog->raise();
56 m_ColorDialog->exec();
57
58 QColor color = m_ColorDialog->selectedColor();
59 if (color.isValid()) {
60 m_Color = color;
61 update();
63 }
64 }
65
66} // namespace Gui
void paintEvent(QPaintEvent *event) override
Definition: color_box.cpp:21
void ColorUpdated(QColor color)
QColorDialog * m_ColorDialog
Definition: color_box.h:30
QColor m_Color
Definition: color_box.h:29
void UpdateColor(QColor color)
Definition: color_box.cpp:45
ColorBox(QWidget *parent=nullptr)
Definition: color_box.cpp:9
void SelectColor()
Definition: color_box.cpp:52
void mousePressEvent(QMouseEvent *event) override
Definition: color_box.cpp:39
Definition: action.h:6