Debugger: Fix theming issues in the QML Debugger Console

Use QPalette::HighlightedText for text on selected QML debugger console
items. Also, use QPalette::Highlight/Base for the background area. Both
changes make the console behave like a standard Qt itemview in that
regard, and therefore ensure a proper text contrast of selected items.

Fixes: QTCREATORBUG-25200
Change-Id: Ia292069c3b8d749166356496f16665345b57e3e0
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Alessandro Portale
2021-02-03 11:17:03 +01:00
parent dad2b3d84b
commit d2c4976bec
3 changed files with 12 additions and 18 deletions

View File

@@ -68,18 +68,13 @@ void ConsoleItemDelegate::emitSizeHintChanged(const QModelIndex &index)
QColor ConsoleItemDelegate::drawBackground(QPainter *painter, const QRect &rect,
const QModelIndex &index,
bool selected) const
const QStyleOptionViewItem &opt) const
{
const Utils::Theme *theme = Utils::creatorTheme();
painter->save();
QColor backgroundColor = theme->color(selected
? Utils::Theme::BackgroundColorSelected
: Utils::Theme::BackgroundColorNormal);
if (!(index.flags() & Qt::ItemIsEditable))
painter->setBrush(backgroundColor);
painter->setPen(Qt::NoPen);
painter->drawRect(rect);
painter->restore();
const bool selected = opt.state & QStyle::State_Selected;
const bool editing = index.flags() & Qt::ItemIsEditable;
const QPalette::ColorRole cr = (selected && !editing) ? QPalette::Highlight : QPalette::Base;
const QColor backgroundColor = opt.palette.color(cr);
painter->fillRect(rect, backgroundColor);
return backgroundColor;
}
@@ -119,8 +114,7 @@ void ConsoleItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &o
}
// Paint background
QColor backgroundColor = drawBackground(painter, opt.rect, index,
bool(opt.state & QStyle::State_Selected));
const QColor backgroundColor = drawBackground(painter, opt.rect, index, opt);
// Calculate positions
const auto view = qobject_cast<const QTreeView*>(opt.widget);
@@ -144,7 +138,8 @@ void ConsoleItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &o
positions.typeIconHeight()));
// Set Text Color
painter->setPen(textColor);
painter->setPen(opt.state & QStyle::State_Selected
? opt.palette.color(QPalette::HighlightedText) : textColor);
// Paint TextArea:
// Layout the description
QString str = index.data(Qt::DisplayRole).toString();

View File

@@ -43,7 +43,7 @@ public:
void emitSizeHintChanged(const QModelIndex &index);
QColor drawBackground(QPainter *painter, const QRect &rect, const QModelIndex &index,
bool selected) const;
const QStyleOptionViewItem &opt) const;
void currentChanged(const QModelIndex &current, const QModelIndex &previous);
protected:

View File

@@ -135,8 +135,7 @@ void ConsoleView::resizeEvent(QResizeEvent *e)
void ConsoleView::drawBranches(QPainter *painter, const QRect &rect,
const QModelIndex &index) const
{
static_cast<ConsoleItemDelegate *>(itemDelegate())->drawBackground(painter, rect, index,
false);
static_cast<ConsoleItemDelegate *>(itemDelegate())->drawBackground(painter, rect, index, {});
Utils::TreeView::drawBranches(painter, rect, index);
}