forked from qt-creator/qt-creator
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:
@@ -67,19 +67,14 @@ void ConsoleItemDelegate::emitSizeHintChanged(const QModelIndex &index)
|
||||
}
|
||||
|
||||
QColor ConsoleItemDelegate::drawBackground(QPainter *painter, const QRect &rect,
|
||||
const QModelIndex &index,
|
||||
bool selected) const
|
||||
const QModelIndex &index,
|
||||
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();
|
||||
|
@@ -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 ¤t, const QModelIndex &previous);
|
||||
|
||||
protected:
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user