Make the debugger console theme aware

Use the generic output panes colors rather than hand rolled ones. Also,
remove the prompt icon and use the "next" icon instead, and remove the
borders between console items.

Change-Id: I219badbfbbde3aa01d7937ff505205cb9d725a43
Task-number: QTCREATORBUG-17532
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Ulf Hermann
2017-03-16 14:25:25 +01:00
parent 4f4b02a36c
commit cd31fd1a60
4 changed files with 16 additions and 64 deletions

View File

@@ -29,6 +29,7 @@
#include <coreplugin/coreconstants.h> #include <coreplugin/coreconstants.h>
#include <utils/utilsicons.h> #include <utils/utilsicons.h>
#include <utils/theme/theme.h>
#include <QPainter> #include <QPainter>
#include <QTreeView> #include <QTreeView>
@@ -36,23 +37,6 @@
#include <QTextLayout> #include <QTextLayout>
#include <QUrl> #include <QUrl>
const char CONSOLE_LOG_BACKGROUND_COLOR[] = "#E8EEF2";
const char CONSOLE_WARNING_BACKGROUND_COLOR[] = "#F6F4EB";
const char CONSOLE_ERROR_BACKGROUND_COLOR[] = "#F6EBE7";
const char CONSOLE_EDITOR_BACKGROUND_COLOR[] = "#F7F7F7";
const char CONSOLE_LOG_BACKGROUND_SELECTED_COLOR[] = "#CDDEEA";
const char CONSOLE_WARNING_BACKGROUND_SELECTED_COLOR[] = "#F3EED1";
const char CONSOLE_ERROR_BACKGROUND_SELECTED_COLOR[] = "#F5D4CB";
const char CONSOLE_EDITOR_BACKGROUND_SELECTED_COLOR[] = "#DEDEDE";
const char CONSOLE_LOG_TEXT_COLOR[] = "#333333";
const char CONSOLE_WARNING_TEXT_COLOR[] = "#666666";
const char CONSOLE_ERROR_TEXT_COLOR[] = "#1D5B93";
const char CONSOLE_EDITOR_TEXT_COLOR[] = "#000000";
const char CONSOLE_BORDER_COLOR[] = "#C9C9C9";
const int ELLIPSIS_GRADIENT_WIDTH = 16; const int ELLIPSIS_GRADIENT_WIDTH = 16;
namespace Debugger { namespace Debugger {
@@ -72,7 +56,8 @@ ConsoleItemDelegate::ConsoleItemDelegate(ConsoleItemModel *model, QObject *paren
m_errorIcon(Utils::Icons::CRITICAL.icon()), m_errorIcon(Utils::Icons::CRITICAL.icon()),
m_expandIcon(Utils::Icons::EXPAND.icon()), m_expandIcon(Utils::Icons::EXPAND.icon()),
m_collapseIcon(Utils::Icons::COLLAPSE.icon()), m_collapseIcon(Utils::Icons::COLLAPSE.icon()),
m_prompt(QLatin1String(":/qmljstools/images/prompt.png")), m_prompt(Utils::Icon({{QLatin1String(":/utils/images/next.png"),
Utils::Theme::TextColorNormal}}, Utils::Icon::Tint).icon()),
m_cachedHeight(0) m_cachedHeight(0)
{ {
} }
@@ -86,39 +71,15 @@ QColor ConsoleItemDelegate::drawBackground(QPainter *painter, const QRect &rect,
const QModelIndex &index, const QModelIndex &index,
bool selected) const bool selected) const
{ {
const Utils::Theme *theme = Utils::creatorTheme();
painter->save(); painter->save();
ConsoleItem::ItemType itemType = (ConsoleItem::ItemType)index.data( QColor backgroundColor = theme->color(selected
ConsoleItem::TypeRole).toInt(); ? Utils::Theme::BackgroundColorSelected
QColor backgroundColor; : Utils::Theme::BackgroundColorNormal);
switch (itemType) {
case ConsoleItem::DebugType:
backgroundColor = selected ? QColor(CONSOLE_LOG_BACKGROUND_SELECTED_COLOR) :
QColor(CONSOLE_LOG_BACKGROUND_COLOR);
break;
case ConsoleItem::WarningType:
backgroundColor = selected ? QColor(CONSOLE_WARNING_BACKGROUND_SELECTED_COLOR) :
QColor(CONSOLE_WARNING_BACKGROUND_COLOR);
break;
case ConsoleItem::ErrorType:
backgroundColor = selected ? QColor(CONSOLE_ERROR_BACKGROUND_SELECTED_COLOR) :
QColor(CONSOLE_ERROR_BACKGROUND_COLOR);
break;
case ConsoleItem::InputType:
default:
backgroundColor = selected ? QColor(CONSOLE_EDITOR_BACKGROUND_SELECTED_COLOR) :
QColor(CONSOLE_EDITOR_BACKGROUND_COLOR);
break;
}
if (!(index.flags() & Qt::ItemIsEditable)) if (!(index.flags() & Qt::ItemIsEditable))
painter->setBrush(backgroundColor); painter->setBrush(backgroundColor);
painter->setPen(Qt::NoPen); painter->setPen(Qt::NoPen);
painter->drawRect(rect); painter->drawRect(rect);
// Separator lines
painter->setPen(QColor(CONSOLE_BORDER_COLOR));
if (!(index.flags() & Qt::ItemIsEditable))
painter->drawLine(0, rect.bottom(), rect.right(),
rect.bottom());
painter->restore(); painter->restore();
return backgroundColor; return backgroundColor;
} }
@@ -126,6 +87,7 @@ QColor ConsoleItemDelegate::drawBackground(QPainter *painter, const QRect &rect,
void ConsoleItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, void ConsoleItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const const QModelIndex &index) const
{ {
const Utils::Theme *theme = Utils::creatorTheme();
QStyleOptionViewItem opt = option; QStyleOptionViewItem opt = option;
initStyleOption(&opt, index); initStyleOption(&opt, index);
painter->save(); painter->save();
@@ -137,23 +99,23 @@ void ConsoleItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &o
ConsoleItem::TypeRole).toInt(); ConsoleItem::TypeRole).toInt();
switch (type) { switch (type) {
case ConsoleItem::DebugType: case ConsoleItem::DebugType:
textColor = QColor(CONSOLE_LOG_TEXT_COLOR); textColor = theme->color(Utils::Theme::OutputPanes_NormalMessageTextColor);
taskIcon = m_logIcon; taskIcon = m_logIcon;
break; break;
case ConsoleItem::WarningType: case ConsoleItem::WarningType:
textColor = QColor(CONSOLE_WARNING_TEXT_COLOR); textColor = theme->color(Utils::Theme::OutputPanes_WarningMessageTextColor);
taskIcon = m_warningIcon; taskIcon = m_warningIcon;
break; break;
case ConsoleItem::ErrorType: case ConsoleItem::ErrorType:
textColor = QColor(CONSOLE_ERROR_TEXT_COLOR); textColor = theme->color(Utils::Theme::OutputPanes_ErrorMessageTextColor);
taskIcon = m_errorIcon; taskIcon = m_errorIcon;
break; break;
case ConsoleItem::InputType: case ConsoleItem::InputType:
textColor = QColor(CONSOLE_EDITOR_TEXT_COLOR); textColor = theme->color(Utils::Theme::TextColorNormal);
taskIcon = m_prompt; taskIcon = m_prompt;
break; break;
default: default:
textColor = QColor(CONSOLE_EDITOR_TEXT_COLOR); textColor = theme->color(Utils::Theme::TextColorNormal);
break; break;
} }
@@ -307,18 +269,11 @@ QWidget *ConsoleItemDelegate::createEditor(QWidget *parent,
{ {
ConsoleEdit *editor = new ConsoleEdit(index, parent); ConsoleEdit *editor = new ConsoleEdit(index, parent);
// Fiddle the prompt into the margin so that we don't have to put it into the text. // Make the background transparent so that the prompt shines through
// Apparently you can have both background-image and background-color, which conveniently
// prevents the painted text from shining through.
editor->setStyleSheet(QLatin1String("QTextEdit {" editor->setStyleSheet(QLatin1String("QTextEdit {"
"margin-left: 24px;" "margin-left: 24px;"
"margin-top: 4px;" "margin-top: 4px;"
"color: black;" "background-color: transparent;"
"background-color: white;"
"background-image: url(:/qmljstools/images/prompt.png);"
"background-position: baseline left;"
"background-origin: margin;"
"background-repeat: none;"
"}")); "}"));
connect(editor, &ConsoleEdit::editingFinished, this, [this, editor] { connect(editor, &ConsoleEdit::editingFinished, this, [this, editor] {
auto delegate = const_cast<ConsoleItemDelegate*>(this); auto delegate = const_cast<ConsoleItemDelegate*>(this);

View File

@@ -97,9 +97,7 @@ ConsoleView::ConsoleView(ConsoleItemModel *model, QWidget *parent) :
"QTreeView::branch:open:has-children:!has-siblings," "QTreeView::branch:open:has-children:!has-siblings,"
"QTreeView::branch:open:has-children:has-siblings {" "QTreeView::branch:open:has-children:has-siblings {"
"border-image: none;" "border-image: none;"
"image: none; }" "image: none; }"));
"QTreeView {"
"background-color: white; }"));
QString baseName = QApplication::style()->objectName(); QString baseName = QApplication::style()->objectName();
if (Utils::HostOsInfo::isAnyUnixHost() && !Utils::HostOsInfo::isMacHost() if (Utils::HostOsInfo::isAnyUnixHost() && !Utils::HostOsInfo::isMacHost()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

View File

@@ -1,6 +1,5 @@
<RCC> <RCC>
<qresource prefix="/qmljstools"> <qresource prefix="/qmljstools">
<file>images/category_qml.png</file> <file>images/category_qml.png</file>
<file>images/prompt.png</file>
</qresource> </qresource>
</RCC> </RCC>