Make it possible to use the Tag System in dark themes

The color used on the bright theme was cyan, and it's too bright when the
font is also white.

This patch uses the HSL information of the color to determine if the text
color is light or dark, and adjusting the background color for that.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2013-12-19 17:16:57 -02:00 committed by Dirk Hohndel
parent 9e57dd4826
commit bdd1b3b546
2 changed files with 27 additions and 3 deletions

View file

@ -207,7 +207,12 @@ void GroupedLineEdit::paintEvent(QPaintEvent *e)
i.toFront(); i.toFront();
path.addRoundedRect(rectangle, 5.0, 5.0); path.addRoundedRect(rectangle, 5.0, 5.0);
painter.setPen(i.peekNext()); painter.setPen(i.peekNext());
painter.setBrush(i.next().lighter(180)); if (palette().color(QPalette::Text).lightnessF() <= 0.3 )
painter.setBrush(i.next().lighter());
else if (palette().color(QPalette::Text).lightnessF() <= 0.6 )
painter.setBrush(i.next());
else
painter.setBrush(i.next().darker());
painter.drawPath(path); painter.drawPath(path);
} }
#endif #endif

View file

@ -2,14 +2,33 @@
#include <QPair> #include <QPair>
#include <QDebug> #include <QDebug>
#include <QAbstractItemView> #include <QAbstractItemView>
#include <QSettings>
#include <QFont>
TagWidget::TagWidget(QWidget *parent) : GroupedLineEdit(parent), m_completer(NULL) TagWidget::TagWidget(QWidget *parent) : GroupedLineEdit(parent), m_completer(NULL)
{ {
connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(reparse())); connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(reparse()));
connect(this, SIGNAL(textChanged()), this, SLOT(reparse())); connect(this, SIGNAL(textChanged()), this, SLOT(reparse()));
addColor(QColor(0x00, 0xAE, 0xFF)); QColor textColor = palette().color(QPalette::Text);
addColor(QColor(0x00, 0x78, 0xB0)); qreal h, s, l, a;
textColor.getHslF(&h, &s, &l, &a);
// I use dark themes
if (l <= 0.3 ){ // very dark text. get a brigth background
addColor( QColor(Qt::red).lighter(120) );
addColor( QColor(Qt::green).lighter(120) );
addColor( QColor(Qt::blue).lighter(120) );
}
else if ( l <= 0.6 ){ // moderated dark text. get a somewhat brigth background
addColor( QColor(Qt::red).lighter(60) );
addColor( QColor(Qt::green).lighter(60) );
addColor( QColor(Qt::blue).lighter(60) );
}
else{
addColor( QColor(Qt::red).darker(120) );
addColor( QColor(Qt::green).darker(120) );
addColor( QColor(Qt::blue).darker(120) );
} // light text. get a dark background.
} }
void TagWidget::setCompleter(QCompleter *completer) void TagWidget::setCompleter(QCompleter *completer)