Commit a6dd87c0 authored by Christian Ehrlicher's avatar Christian Ehrlicher
Browse files

Make sure the text has not the same color like the background color

svn path=/trunk/KDE/kdegames/ksudoku/; revision=742727
parent 608811c6
...@@ -139,12 +139,16 @@ QSize GameVariantDelegate::sizeHint(const QStyleOptionViewItem& option, const QM ...@@ -139,12 +139,16 @@ QSize GameVariantDelegate::sizeHint(const QStyleOptionViewItem& option, const QM
void GameVariantDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { void GameVariantDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
// show background // show background
QColor bkgColor;
if (option.state & QStyle::State_Selected) { if (option.state & QStyle::State_Selected) {
painter->fillRect(option.rect, option.palette.color(QPalette::Highlight)); bkgColor = option.palette.color(QPalette::Highlight);
painter->fillRect(option.rect, bkgColor);
} else if(index.row() % 2) { } else if(index.row() % 2) {
painter->fillRect(option.rect, option.palette.color(QPalette::AlternateBase)); bkgColor = option.palette.color(QPalette::AlternateBase);
painter->fillRect(option.rect, bkgColor);
} else { } else {
painter->fillRect(option.rect, option.palette.color(QPalette::Base)); bkgColor = option.palette.color(QPalette::Base);
painter->fillRect(option.rect, bkgColor);
} }
QRect contentRect = option.rect.adjusted(m_leftMargin, m_separatorPixels, -m_rightMargin, -m_separatorPixels); QRect contentRect = option.rect.adjusted(m_leftMargin, m_separatorPixels, -m_rightMargin, -m_separatorPixels);
...@@ -167,6 +171,16 @@ void GameVariantDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o ...@@ -167,6 +171,16 @@ void GameVariantDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o
titleFont.setPointSize(titleFont.pointSize() + 2); titleFont.setPointSize(titleFont.pointSize() + 2);
titleFont.setWeight(QFont::Bold); titleFont.setWeight(QFont::Bold);
QPen previousPen(painter->pen());
// TODO: don't we have a function for 'color1 similar color2'
if(previousPen.color() == bkgColor) {
QPen p(previousPen);
int color = bkgColor.rgb();
color = ~color | 0xff000000;
p.setColor(color);
painter->setPen(p);
}
QFont previousFont(painter->font()); QFont previousFont(painter->font());
painter->setFont(titleFont); painter->setFont(titleFont);
QString titleStr = painter->fontMetrics().elidedText(title(index), Qt::ElideRight, contentRect.width()); QString titleStr = painter->fontMetrics().elidedText(title(index), Qt::ElideRight, contentRect.width());
...@@ -177,6 +191,8 @@ void GameVariantDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o ...@@ -177,6 +191,8 @@ void GameVariantDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o
// Show Description // Show Description
QString descrStr = painter->fontMetrics().elidedText(description(index), Qt::ElideRight, contentRect.width()); QString descrStr = painter->fontMetrics().elidedText(description(index), Qt::ElideRight, contentRect.width());
painter->drawText(contentRect, descrStr); painter->drawText(contentRect, descrStr);
painter->setPen(previousPen);
} }
QString GameVariantDelegate::title(const QModelIndex& index) const { QString GameVariantDelegate::title(const QModelIndex& index) const {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment