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,
|
QColor ConsoleItemDelegate::drawBackground(QPainter *painter, const QRect &rect,
|
||||||
const QModelIndex &index,
|
const QModelIndex &index,
|
||||||
bool selected) const
|
const QStyleOptionViewItem &opt) const
|
||||||
{
|
{
|
||||||
const Utils::Theme *theme = Utils::creatorTheme();
|
const bool selected = opt.state & QStyle::State_Selected;
|
||||||
painter->save();
|
const bool editing = index.flags() & Qt::ItemIsEditable;
|
||||||
QColor backgroundColor = theme->color(selected
|
const QPalette::ColorRole cr = (selected && !editing) ? QPalette::Highlight : QPalette::Base;
|
||||||
? Utils::Theme::BackgroundColorSelected
|
const QColor backgroundColor = opt.palette.color(cr);
|
||||||
: Utils::Theme::BackgroundColorNormal);
|
painter->fillRect(rect, backgroundColor);
|
||||||
if (!(index.flags() & Qt::ItemIsEditable))
|
|
||||||
painter->setBrush(backgroundColor);
|
|
||||||
painter->setPen(Qt::NoPen);
|
|
||||||
painter->drawRect(rect);
|
|
||||||
painter->restore();
|
|
||||||
return backgroundColor;
|
return backgroundColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,8 +114,7 @@ void ConsoleItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &o
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Paint background
|
// Paint background
|
||||||
QColor backgroundColor = drawBackground(painter, opt.rect, index,
|
const QColor backgroundColor = drawBackground(painter, opt.rect, index, opt);
|
||||||
bool(opt.state & QStyle::State_Selected));
|
|
||||||
|
|
||||||
// Calculate positions
|
// Calculate positions
|
||||||
const auto view = qobject_cast<const QTreeView*>(opt.widget);
|
const auto view = qobject_cast<const QTreeView*>(opt.widget);
|
||||||
@@ -144,7 +138,8 @@ void ConsoleItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &o
|
|||||||
positions.typeIconHeight()));
|
positions.typeIconHeight()));
|
||||||
|
|
||||||
// Set Text Color
|
// Set Text Color
|
||||||
painter->setPen(textColor);
|
painter->setPen(opt.state & QStyle::State_Selected
|
||||||
|
? opt.palette.color(QPalette::HighlightedText) : textColor);
|
||||||
// Paint TextArea:
|
// Paint TextArea:
|
||||||
// Layout the description
|
// Layout the description
|
||||||
QString str = index.data(Qt::DisplayRole).toString();
|
QString str = index.data(Qt::DisplayRole).toString();
|
||||||
|
@@ -43,7 +43,7 @@ public:
|
|||||||
|
|
||||||
void emitSizeHintChanged(const QModelIndex &index);
|
void emitSizeHintChanged(const QModelIndex &index);
|
||||||
QColor drawBackground(QPainter *painter, const QRect &rect, 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);
|
void currentChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@@ -135,8 +135,7 @@ void ConsoleView::resizeEvent(QResizeEvent *e)
|
|||||||
void ConsoleView::drawBranches(QPainter *painter, const QRect &rect,
|
void ConsoleView::drawBranches(QPainter *painter, const QRect &rect,
|
||||||
const QModelIndex &index) const
|
const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
static_cast<ConsoleItemDelegate *>(itemDelegate())->drawBackground(painter, rect, index,
|
static_cast<ConsoleItemDelegate *>(itemDelegate())->drawBackground(painter, rect, index, {});
|
||||||
false);
|
|
||||||
Utils::TreeView::drawBranches(painter, rect, index);
|
Utils::TreeView::drawBranches(painter, rect, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user