Skip to content

Commit

Permalink
Fix problems with selected/hide state for 2,3 column
Browse files Browse the repository at this point in the history
  • Loading branch information
KuzemkoA committed May 15, 2024
1 parent 344015f commit f2c2e84
Showing 1 changed file with 31 additions and 16 deletions.
47 changes: 31 additions & 16 deletions src/Gui/Tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@


#include "PreCompiled.h"
#include "qdebug.h"

#ifndef _PreComp_
# include <QAction>
Expand Down Expand Up @@ -464,7 +463,16 @@ void TreeWidgetItemDelegate::paint(QPainter *painter,
{
auto item = static_cast<DocumentObjectItem*>(ti);
App::DocumentObject* obj = item->object()->getObject();
painter->drawText(rect, Qt::AlignLeft | Qt::AlignVCenter, QString::fromUtf8(obj->getNameInDocument()));
QString text = QString::fromUtf8(obj->getNameInDocument());

if (opt.state & QStyle::State_Selected) {
painter->fillRect(rect, opt.palette.highlight());
painter->setPen(opt.palette.highlightedText().color());
} else {
painter->setPen(opt.palette.text().color());
}
painter->drawText(rect, Qt::AlignLeft | Qt::AlignVCenter, text);
return;
}
}

Expand Down Expand Up @@ -669,7 +677,7 @@ TreeWidget::TreeWidget(const char* name, QWidget* parent)
}
setColumnHidden(1, TreeParams::getHideColumn());
setColumnHidden(2, !TreeParams::getShowInternalNames());
header()->setVisible((!TreeParams::getHideColumn() || TreeParams::getShowInternalNames()));
header()->setVisible(!(TreeParams::getHideColumn() || !TreeParams::getShowInternalNames()));
}

TreeWidget::~TreeWidget()
Expand Down Expand Up @@ -2722,20 +2730,27 @@ void TreeWidget::sortDroppedObjects(TargetItemInfo& targetInfo, std::vector<App:

void TreeWidget::drawRow(QPainter* painter, const QStyleOptionViewItem& options, const QModelIndex& index) const
{
QTreeWidget::drawRow(painter, options, index);
// QTreeWidget::drawRow(painter, options, index);
// Set the text and highlighted text color of a hidden object to a dark
//QTreeWidgetItem * item = itemFromIndex(index);
//if (item->type() == ObjectType && !(static_cast<DocumentObjectItem*>(item)->previousStatus & 1)) {
// QStyleOptionViewItem opt(options);
// opt.state ^= QStyle::State_Enabled;
// QColor c = opt.palette.color(QPalette::Inactive, QPalette::Dark);
// opt.palette.setColor(QPalette::Inactive, QPalette::Text, c);
// opt.palette.setColor(QPalette::Inactive, QPalette::HighlightedText, c);
// QTreeWidget::drawRow(painter, opt, index);
//}
//else {
// QTreeWidget::drawRow(painter, options, index);
//}
QTreeWidgetItem * item = itemFromIndex(index);
if (!isVisibilityIconEnabled() && item->type() == ObjectType && !(static_cast<DocumentObjectItem*>(item)->previousStatus & 1)) {
QStyleOptionViewItem opt(options);
opt.state ^= QStyle::State_Enabled;
// Set color for all states, not just Inactive
QColor c = opt.palette.color(QPalette::Disabled, QPalette::Dark);
opt.palette.setColor(QPalette::Disabled, QPalette::Text, c);
opt.palette.setColor(QPalette::Disabled, QPalette::HighlightedText, c);

// Optionally, set colors for Active and Inactive states
opt.palette.setColor(QPalette::Inactive, QPalette::Text, c);
opt.palette.setColor(QPalette::Inactive, QPalette::HighlightedText, c);
opt.palette.setColor(QPalette::Active, QPalette::Text, c);
opt.palette.setColor(QPalette::Active, QPalette::HighlightedText, c);
QTreeWidget::drawRow(painter, opt, index);
}
else {
QTreeWidget::drawRow(painter, options, index);
}
}

void TreeWidget::slotNewDocument(const Gui::Document& Doc, bool isMainDoc)
Expand Down

0 comments on commit f2c2e84

Please sign in to comment.