22#include "KPropertyUtils_p.h"
28#include <KColorCollection>
34 if (!color.isValid()) {
35 return locale.language() == QLocale::C ? QString::fromLatin1(
"#invalid")
36 : QObject::tr(
"#invalid",
"Invalid color");
47 explicit ColorCodePainter(
const QFont &font)
50 m_font.setFamily(QLatin1String(
"courier"));
52 void paint(QPainter *painter,
const QRect &rect,
const QColor &color) {
53 painter->
setPen(KPropertyUtilsPrivate::contrastColor(color));
69 QWidget *colorCodeOverlay;
70 QScopedPointer<ColorCodePainter> colorCodePainter;
73KPropertyColorComboEditor::KPropertyColorComboEditor(
QWidget *parent)
77 installEventFilter(
this);
78 d->colorCodePainter.reset(
new ColorCodePainter(font()));
81 d->combo->installEventFilter(
this);
83 d->colorCodeOverlay->raise();
84 d->colorCodeOverlay->installEventFilter(
this);
86 const int oxygenColorsCount = g_oxygenColors->
count();
87 for (
int i = 0; i < oxygenColorsCount; i++) {
88 colors += g_oxygenColors->color(i);
90 d->combo->setColors(colors);
91 setFocusProxy(d->combo);
94 if (!KPropertyUtilsPrivate::gridLineColor(
this).
isValid()) {
95 d->combo->setFrame(
false);
100 padding-top: %2px; padding-left: 1px; }")
101 .
arg(KPropertyComboBoxEditor::borderSheet(
this))
103 setStyleSheet(styleSheet);
106KPropertyColorComboEditor::~KPropertyColorComboEditor()
111QVariant KPropertyColorComboEditor::value()
const
113 return d->combo->color();
116void KPropertyColorComboEditor::setValue(
const QVariant &value)
118 d->combo->setColor(value.value<QColor>());
121void KPropertyColorComboEditor::slotValueChanged(
const QColor&)
123 emit commitData(
this);
126bool KPropertyColorComboEditor::eventFilter(
QObject *o,
QEvent *e)
129 if (o == d->colorCodeOverlay) {
131 QPainter painter(d->colorCodeOverlay);
132 d->colorCodePainter->paint(&painter, d->colorCodeOverlay->rect(), d->combo->color());
134 }
else if (o == d->combo) {
136 d->colorCodeOverlay->setGeometry(0, 0, d->combo->width(), d->combo->height());
138 }
else if (o ==
this) {
148class Q_DECL_HIDDEN KPropertyColorComboDelegate::Private
152 QScopedPointer<ColorCodePainter> colorCodePainter;
155KPropertyColorComboDelegate::KPropertyColorComboDelegate()
160KPropertyColorComboDelegate::~KPropertyColorComboDelegate()
165QWidget * KPropertyColorComboDelegate::createEditor(
int type,
QWidget *parent,
171 return new KPropertyColorComboEditor(parent);
174void KPropertyColorComboDelegate::paint(
QPainter * painter,
177 const KPropertyUtilsPrivate::PainterSaver saver(painter);
182 if (!d->colorCodePainter) {
183 d->colorCodePainter.reset(
new ColorCodePainter(option.font));
185 d->colorCodePainter->paint(painter, option.rect, b.color());
190 return colorToName(value.
value<QColor>(), locale);
Class for handling color collections ("palettes").
bool isValid(QStringView ifopt)
qsizetype count() const const
QVariant data(int role) const const
virtual bool eventFilter(QObject *watched, QEvent *event)
void drawRect(const QRect &rectangle)
void drawText(const QPoint &position, const QString &text)
void setBrush(Qt::BrushStyle style)
void setFont(const QFont &font)
void setPen(Qt::PenStyle style)
QString arg(Args &&... args) const const
QString fromLatin1(QByteArrayView str)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)