From a1b0c2ff32315aa09ad9b58d9716e878abe7ae4e Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 19 Aug 2018 18:14:06 +0200 Subject: [PATCH] Gui: Better visualization of the Active Object --- src/Gui/ActiveObjectList.cpp | 7 +++-- src/Gui/ActiveObjectList.h | 54 +++++++++++++++++------------------- src/Gui/Tree.cpp | 50 +++++++++++++++++++++++++-------- src/Gui/Tree.h | 13 +++++---- 4 files changed, 76 insertions(+), 48 deletions(-) diff --git a/src/Gui/ActiveObjectList.cpp b/src/Gui/ActiveObjectList.cpp index 9bfcf05228..2469570b4e 100644 --- a/src/Gui/ActiveObjectList.cpp +++ b/src/Gui/ActiveObjectList.cpp @@ -41,10 +41,13 @@ using namespace Gui; void Gui::ActiveObjectList::setObject(App::DocumentObject* obj, const char* name, const Gui::HighlightMode& mode) { if (hasObject(name)){ - Gui::Application::Instance->activeDocument()->signalHighlightObject(*dynamic_cast(Gui::Application::Instance->activeDocument()->getViewProvider(getObject(name))), mode, false); + App::DocumentObject* act = getObject(name); + Gui::Document* doc = Application::Instance->getDocument(act->getDocument()); + doc->signalHighlightObject(*dynamic_cast(doc->getViewProvider(act)), mode, false); } if (obj){ - Gui::Application::Instance->activeDocument()->signalHighlightObject(*dynamic_cast(Gui::Application::Instance->activeDocument()->getViewProvider(obj)), mode, true); + Gui::Document* doc = Application::Instance->getDocument(obj->getDocument()); + doc->signalHighlightObject(*dynamic_cast(doc->getViewProvider(obj)), mode, true); _ObjectMap[name] = obj; } else { if (hasObject(name)) diff --git a/src/Gui/ActiveObjectList.h b/src/Gui/ActiveObjectList.h index 6948e4419c..fd0f5d4915 100644 --- a/src/Gui/ActiveObjectList.h +++ b/src/Gui/ActiveObjectList.h @@ -29,42 +29,38 @@ #include #include "Tree.h" namespace App { - class DocumentObject; + class DocumentObject; } namespace Gui { - class Document; - class ViewProviderDocumentObject; - - /** List of active or special objects - * This class holds a list of objects with a special name. - * Its mainly used to points to something like the active Body or Part in a edit session. - * The class is used the viewer (editor) of a document. - * @see Gui::MDIViewer - * @author Jürgen Riegel - */ - class GuiExport ActiveObjectList - { - - public: - template - inline _T getObject(const char* name) const - { - std::map::const_iterator pos = _ObjectMap.find(name); - return pos == _ObjectMap.end() ? 0 : dynamic_cast<_T>(pos->second); - } - void setObject(App::DocumentObject*, const char*, const Gui::HighlightMode& m = Gui::LightBlue); - bool hasObject(const char*)const; - void objectDeleted(const ViewProviderDocumentObject& viewProviderIn); - protected: - std::map _ObjectMap; - - - }; + class Document; + class ViewProviderDocumentObject; + /** List of active or special objects + * This class holds a list of objects with a special name. + * Its mainly used to points to something like the active Body or Part in a edit session. + * The class is used the viewer (editor) of a document. + * @see Gui::MDIViewer + * @author Jürgen Riegel + */ + class GuiExport ActiveObjectList + { + public: + template + inline _T getObject(const char* name) const + { + std::map::const_iterator pos = _ObjectMap.find(name); + return pos == _ObjectMap.end() ? 0 : dynamic_cast<_T>(pos->second); + } + void setObject(App::DocumentObject*, const char*, const Gui::HighlightMode& m = Gui::UserDefined); + bool hasObject(const char*)const; + void objectDeleted(const ViewProviderDocumentObject& viewProviderIn); + protected: + std::map _ObjectMap; + }; } //namespace Gui diff --git a/src/Gui/Tree.cpp b/src/Gui/Tree.cpp index b0eab0bb19..36e2967dcf 100644 --- a/src/Gui/Tree.cpp +++ b/src/Gui/Tree.cpp @@ -1271,26 +1271,54 @@ void DocumentItem::slotHighlightObject (const Gui::ViewProviderDocumentObject& o { FOREACH_ITEM(item,obj) QFont f = item->font(0); - switch (high) { - case Gui::Bold: f.setBold(set); break; - case Gui::Italic: f.setItalic(set); break; - case Gui::Underlined: f.setUnderline(set); break; - case Gui::Overlined: f.setOverline(set); break; - case Gui::Blue: + auto highlight = [&item, &set](const QColor& col){ if (set) - item->setBackgroundColor(0,QColor(200,200,255)); + item->setBackgroundColor(0, col); else item->setData(0, Qt::BackgroundColorRole,QVariant()); + }; + + switch (high) { + case Gui::Bold: + f.setBold(set); + break; + case Gui::Italic: + f.setItalic(set); + break; + case Gui::Underlined: + f.setUnderline(set); + break; + case Gui::Overlined: + f.setOverline(set); + break; + case Gui::Blue: + highlight(QColor(200,200,255)); break; case Gui::LightBlue: + highlight(QColor(230,230,255)); + break; + case Gui::UserDefined: + { + QColor color(230,230,255); if (set) { ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/TreeView"); + bool italic = hGrp->GetBool("TreeActiveItalic",false); + bool underlined = hGrp->GetBool("TreeActiveUnderlined",false); + bool overlined = hGrp->GetBool("TreeActiveOverlined",false); + f.setItalic(italic); + f.setUnderline(underlined); + f.setOverline(overlined); + unsigned long col = hGrp->GetUnsigned("TreeActiveColor",3873898495); - item->setBackgroundColor(0,QColor((col >> 24) & 0xff,(col >> 16) & 0xff,(col >> 8) & 0xff)); + color = QColor((col >> 24) & 0xff,(col >> 16) & 0xff,(col >> 8) & 0xff); } - else - item->setData(0, Qt::BackgroundColorRole,QVariant()); - break; + else { + f.setItalic(false); + f.setUnderline(false); + f.setOverline(false); + } + highlight(color); + } break; default: break; } diff --git a/src/Gui/Tree.h b/src/Gui/Tree.h index 913fa49ddb..c970f07977 100644 --- a/src/Gui/Tree.h +++ b/src/Gui/Tree.h @@ -42,12 +42,13 @@ typedef std::shared_ptr DocumentObjectItemsPtr; class DocumentItem; /// highlight modes for the tree items -enum HighlightMode { Underlined, - Italic , - Overlined , - Bold , - Blue , - LightBlue +enum HighlightMode { Underlined, + Italic, + Overlined, + Bold, + Blue, + LightBlue, + UserDefined }; /// highlight modes for the tree items