ProjectTree: Do not use disabled state for disabled nodes

Rendering disabled nodes using the disabled state in the painter
breaks themes as it introduces a discrepancy between the actual
state of the node and its graphical representation.

IIRC this was introduced since there was no easy way to find what
color was supposed to be used for disabled items. That is no longer
the case, so let's clean this up.

Change-Id: Ic5653cd970e07eb680cb1d28d1feefd70aded540
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Tobias Hunger
2018-03-22 10:13:19 +01:00
parent e760cbdd52
commit f7a0a3cd26
4 changed files with 11 additions and 9 deletions

View File

@@ -88,7 +88,6 @@ public:
enum ModelRoles { enum ModelRoles {
// Absolute file path // Absolute file path
FilePathRole = QFileSystemModel::FilePathRole, FilePathRole = QFileSystemModel::FilePathRole,
EnabledRole,
isParsingRole isParsingRole
}; };

View File

@@ -89,6 +89,9 @@ FlatModel::FlatModel(QObject *parent)
for (Project *project : SessionManager::projects()) for (Project *project : SessionManager::projects())
handleProjectAdded(project); handleProjectAdded(project);
m_disabledTextColor = Utils::creatorTheme()->color(Utils::Theme::TextColorDisabled);
m_enabledTextColor = Utils::creatorTheme()->color(Utils::Theme::TextColorNormal);
} }
QVariant FlatModel::data(const QModelIndex &index, int role) const QVariant FlatModel::data(const QModelIndex &index, int role) const
@@ -137,12 +140,12 @@ QVariant FlatModel::data(const QModelIndex &index, int role) const
result = font; result = font;
break; break;
} }
case Project::FilePathRole: { case Qt::TextColorRole: {
result = node->filePath().toString(); result = node->isEnabled() ? m_enabledTextColor : m_disabledTextColor;
break; break;
} }
case Project::EnabledRole: { case Project::FilePathRole: {
result = node->isEnabled(); result = node->filePath().toString();
break; break;
} }
case Project::isParsingRole: { case Project::isParsingRole: {

View File

@@ -109,6 +109,8 @@ private:
QTimer m_timer; QTimer m_timer;
QSet<ExpandData> m_toExpand; QSet<ExpandData> m_toExpand;
QColor m_enabledTextColor;
QColor m_disabledTextColor;
}; };
} // namespace Internal } // namespace Internal

View File

@@ -93,12 +93,10 @@ public:
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
{ {
QStyleOptionViewItem opt = option; QStyledItemDelegate::paint(painter, option, index);
if (!index.data(Project::EnabledRole).toBool())
opt.state &= ~QStyle::State_Enabled;
QStyledItemDelegate::paint(painter, opt, index);
if (index.data(Project::isParsingRole).toBool()) { if (index.data(Project::isParsingRole).toBool()) {
QStyleOptionViewItem opt = option;
initStyleOption(&opt, index); initStyleOption(&opt, index);
ProgressIndicatorPainter *indicator = findOrCreateIndicatorPainter(index); ProgressIndicatorPainter *indicator = findOrCreateIndicatorPainter(index);