1 #include <QColorDialog> |
1 #include <QColorDialog> |
2 #include <QHBoxLayout> |
2 #include <QHBoxLayout> |
3 #include "widgets/colorbutton.h" |
3 #include "widgets/colorbutton.h" |
4 |
4 |
5 ColorButton::ColorButton(const QColor& color, QWidget* parent) : |
5 ColorEdit::ColorEdit(const QColor& color, QWidget* parent) : |
6 ColorButton{parent} |
6 ColorEdit{parent} |
7 { |
7 { |
8 this->setColor(color); |
8 this->setColor(color); |
9 } |
9 } |
10 |
10 |
11 ColorButton::ColorButton(QWidget* parent) : |
11 ColorEdit::ColorEdit(QWidget* parent) : |
12 QWidget{parent}, |
12 QWidget{parent}, |
13 lineEdit{new QLineEdit{this}}, |
13 lineEdit{new QLineEdit{this}}, |
14 button{new QPushButton{"…", this}} |
14 button{new QPushButton{"…", this}} |
15 { |
15 { |
16 auto*const layout = new QHBoxLayout{}; |
16 auto*const layout = new QHBoxLayout{}; |
36 Q_EMIT this->colorChanged(this->color()); |
36 Q_EMIT this->colorChanged(this->color()); |
37 }); |
37 }); |
38 this->setColor(Qt::black); |
38 this->setColor(Qt::black); |
39 } |
39 } |
40 |
40 |
41 QColor ColorButton::color() const |
41 QColor ColorEdit::color() const |
42 { |
42 { |
43 return QColor{this->lineEdit->text()}; |
43 return QColor{this->lineEdit->text()}; |
44 } |
44 } |
45 |
45 |
46 void ColorButton::setColor(const QColor& color) |
46 void ColorEdit::setColor(const QColor& color) |
47 { |
47 { |
48 if (color.isValid() and this->color() != color) { |
48 if (color.isValid() and this->color() != color) { |
49 this->lineEdit->setText(color.name()); |
49 this->lineEdit->setText(color.name()); |
50 } |
50 } |
51 } |
51 } |