| 26 |
27 |
| 27 void ColorButton::setColor(const QColor& color) |
28 void ColorButton::setColor(const QColor& color) |
| 28 { |
29 { |
| 29 if (this->storedSelectedColor != color) { |
30 if (this->storedSelectedColor != color) { |
| 30 this->storedSelectedColor = color; |
31 this->storedSelectedColor = color; |
| 31 this->setStyleSheet(QString{"background-color: %1"}.arg(color.name())); |
|
| 32 this->setText(color.name()); |
32 this->setText(color.name()); |
| |
33 QPalette palette{color}; |
| |
34 const qreal lightness = color.lightnessF(); |
| |
35 const QColor foreground = lightness < 0.4 ? Qt::white : Qt::black; |
| |
36 palette.setColor(QPalette::ButtonText, foreground); |
| |
37 this->setPalette(palette); |
| |
38 this->setStyle(QStyleFactory::create("Fusion")); |
| 33 Q_EMIT this->colorChanged(this->storedSelectedColor); |
39 Q_EMIT this->colorChanged(this->storedSelectedColor); |
| 34 } |
40 } |
| 35 } |
41 } |
| 36 |
|