Gui: Better visualization of the Active Object

This commit is contained in:
wmayer
2018-08-19 18:14:06 +02:00
parent 55fb508346
commit a1b0c2ff32
4 changed files with 76 additions and 48 deletions

View File

@@ -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::ViewProviderDocumentObject*>(Gui::Application::Instance->activeDocument()->getViewProvider(getObject<App::DocumentObject*>(name))), mode, false);
App::DocumentObject* act = getObject<App::DocumentObject*>(name);
Gui::Document* doc = Application::Instance->getDocument(act->getDocument());
doc->signalHighlightObject(*dynamic_cast<Gui::ViewProviderDocumentObject*>(doc->getViewProvider(act)), mode, false);
}
if (obj){
Gui::Application::Instance->activeDocument()->signalHighlightObject(*dynamic_cast<Gui::ViewProviderDocumentObject*>(Gui::Application::Instance->activeDocument()->getViewProvider(obj)), mode, true);
Gui::Document* doc = Application::Instance->getDocument(obj->getDocument());
doc->signalHighlightObject(*dynamic_cast<Gui::ViewProviderDocumentObject*>(doc->getViewProvider(obj)), mode, true);
_ObjectMap[name] = obj;
} else {
if (hasObject(name))

View File

@@ -29,42 +29,38 @@
#include <map>
#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<typename _T>
inline _T getObject(const char* name) const
{
std::map<std::string, App::DocumentObject*>::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<std::string, App::DocumentObject*> _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<typename _T>
inline _T getObject(const char* name) const
{
std::map<std::string, App::DocumentObject*>::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<std::string, App::DocumentObject*> _ObjectMap;
};
} //namespace Gui

View File

@@ -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;
}

View File

@@ -42,12 +42,13 @@ typedef std::shared_ptr<DocumentObjectItems> 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