widgets/colorbutton.cpp

changeset 346
3e3784c4cd3e
parent 345
81cd5dee6d77
child 347
5c655cc006de
equal deleted inserted replaced
345:81cd5dee6d77 346:3e3784c4cd3e
1 #include <QColorDialog> 1 #include <QColorDialog>
2 #include <QStyleFactory>
3 #include <QHBoxLayout> 2 #include <QHBoxLayout>
4 #include "widgets/colorbutton.h" 3 #include "widgets/colorbutton.h"
5 4
6 ColorButton::ColorButton(const QColor& color, QWidget* parent) : 5 ColorButton::ColorButton(const QColor& color, QWidget* parent) :
7 ColorButton{parent} 6 ColorButton{parent}
26 this->setColor(color); 25 this->setColor(color);
27 } 26 }
28 }); 27 });
29 connect(this->lineEdit, &QLineEdit::textChanged, [&]{ 28 connect(this->lineEdit, &QLineEdit::textChanged, [&]{
30 const QColor color = this->color(); 29 const QColor color = this->color();
31 QPalette palette{color};
32 const qreal lightness = color.lightnessF(); 30 const qreal lightness = color.lightnessF();
33 const QColor foreground = lightness < 0.4 ? Qt::white : Qt::black; 31 const QColor foreground = lightness < 0.4 ? Qt::white : Qt::black;
34 const auto style = QStyleFactory::create("Fusion"); 32 this->setStyleSheet(
35 this->setStyle(style); 33 QStringLiteral("QLineEdit{background-color: %1; color: %2;}")
36 this->setStyleSheet(QStringLiteral( 34 .arg(color.name())
37 "*{background-color: %1; color: %2;}" 35 .arg(foreground.name()));
38 ).arg(color.name()).arg(foreground.name()));
39 Q_EMIT this->colorChanged(this->color()); 36 Q_EMIT this->colorChanged(this->color());
40 }); 37 });
41 this->setColor(Qt::black); 38 this->setColor(Qt::black);
42 } 39 }
43 40

mercurial