From f84385979494d7875c5f377c50a21b538959bd2e Mon Sep 17 00:00:00 2001 From: vsv Date: Thu, 15 May 2014 18:48:25 +0400 Subject: [PATCH] Issue #23: Indicating of active document by color --- src/XGUI/XGUI_DataTreeModel.h | 8 +++++++- src/XGUI/XGUI_DocumentDataModel.cpp | 29 ++++++++++++++++++++++++----- src/XGUI/XGUI_ObjectsBrowser.cpp | 2 -- src/XGUI/XGUI_PartDataModel.cpp | 7 +++++++ 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/XGUI/XGUI_DataTreeModel.h b/src/XGUI/XGUI_DataTreeModel.h index b7313a922..be7111292 100644 --- a/src/XGUI/XGUI_DataTreeModel.h +++ b/src/XGUI/XGUI_DataTreeModel.h @@ -7,6 +7,7 @@ #include #include +#include /**\class XGUI_FeaturesModel * \ingroup GUI @@ -16,7 +17,7 @@ class XGUI_EXPORT XGUI_FeaturesModel : public QAbstractItemModel { public: XGUI_FeaturesModel(const boost::shared_ptr& theDocument, QObject* theParent): - QAbstractItemModel(theParent), myDocument(theDocument) {} + QAbstractItemModel(theParent), myDocument(theDocument), myItemsColor(Qt::black) {} //! Returns Feature object by the given Model index. //! Returns 0 if the given index is not index of a feature @@ -28,8 +29,13 @@ public: //! Returns index corresponded to the group virtual QModelIndex findGroup(const std::string& theGroup) const = 0; + void setItemsColor(const QColor& theColor) { myItemsColor = theColor; } + + QColor itemsColor() const { return myItemsColor; } + protected: boost::shared_ptr myDocument; + QColor myItemsColor; }; diff --git a/src/XGUI/XGUI_DocumentDataModel.cpp b/src/XGUI/XGUI_DocumentDataModel.cpp index b5cc13697..7962105ca 100644 --- a/src/XGUI/XGUI_DocumentDataModel.cpp +++ b/src/XGUI/XGUI_DocumentDataModel.cpp @@ -14,8 +14,12 @@ #include #include +#include +#define ACTIVE_COLOR QColor(0,72,140) +#define PASSIVE_COLOR Qt::black + XGUI_DocumentDataModel::XGUI_DocumentDataModel(QObject* theParent) : QAbstractItemModel(theParent), myActivePart(0) { @@ -30,6 +34,7 @@ XGUI_DocumentDataModel::XGUI_DocumentDataModel(QObject* theParent) // Create a top part of data tree model myModel = new XGUI_TopDataModel(myDocument, this); + myModel->setItemsColor(ACTIVE_COLOR); } @@ -154,6 +159,11 @@ QVariant XGUI_DocumentDataModel::data(const QModelIndex& theIndex, int theRole) return QIcon(":pictures/constr_folder.png"); case Qt::ToolTipRole: return tr("Parts folder"); + case Qt::ForegroundRole: + if (myActivePart) + return QBrush(PASSIVE_COLOR); + else + return QBrush(ACTIVE_COLOR); default: return QVariant(); } @@ -174,6 +184,11 @@ QVariant XGUI_DocumentDataModel::data(const QModelIndex& theIndex, int theRole) return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind())); case Qt::ToolTipRole: return tr("Feature object"); + case Qt::ForegroundRole: + if (myActivePart) + return QBrush(PASSIVE_COLOR); + else + return QBrush(ACTIVE_COLOR); default: return QVariant(); } @@ -213,10 +228,10 @@ int XGUI_DocumentDataModel::rowCount(const QModelIndex& theParent) const if (!isSubModel(aModel)) return 0; - if (isPartSubModel(aModel)) { + /*if (isPartSubModel(aModel)) { if (aModel != myActivePart) return 0; - } + }*/ return aModel->rowCount(*aParent); } @@ -415,10 +430,14 @@ bool XGUI_DocumentDataModel::activatedIndex(const QModelIndex& theIndex) if (isPartSubModel(aModel)) { // if this is root node (Part item index) if (!aIndex->parent().isValid()) { - beginResetModel(); + if (myActivePart) myActivePart->setItemsColor(PASSIVE_COLOR); myActivePart = (myActivePart == aModel)? 0 : (XGUI_PartModel*)aModel; - endResetModel(); - return true; + if (myActivePart) { + myActivePart->setItemsColor(ACTIVE_COLOR); + myModel->setItemsColor(PASSIVE_COLOR); + } else + myModel->setItemsColor(ACTIVE_COLOR); + return true; } } return false; diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp index 15539c3e6..21530908e 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.cpp +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -39,8 +39,6 @@ void XGUI_ObjectsBrowser::mouseDoubleClickEvent(QMouseEvent* theEvent) bool isChanged = myDocModel->activatedIndex(aIndex); QTreeView::mouseDoubleClickEvent(theEvent); if (isChanged) { - setExpanded(aIndex.parent(), true); - setExpanded(aIndex, myDocModel->hasChildren(aIndex)); emit activePartChanged(myDocModel->activePart()); } } diff --git a/src/XGUI/XGUI_PartDataModel.cpp b/src/XGUI/XGUI_PartDataModel.cpp index 44b74b320..fc5549846 100644 --- a/src/XGUI/XGUI_PartDataModel.cpp +++ b/src/XGUI/XGUI_PartDataModel.cpp @@ -8,6 +8,7 @@ #include #include +#include XGUI_TopDataModel::XGUI_TopDataModel(const boost::shared_ptr& theDocument, QObject* theParent) : XGUI_FeaturesModel(theDocument, theParent) @@ -63,6 +64,9 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const case Qt::ToolTipRole: // return Tooltip break; + case Qt::ForegroundRole: + return QBrush(myItemsColor); + break; } return QVariant(); } @@ -248,6 +252,9 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons case Qt::ToolTipRole: // return Tooltip break; + case Qt::ForegroundRole: + return QBrush(myItemsColor); + break; } return QVariant(); } -- 2.39.2