Skip to content

Commit

Permalink
Gui: Extend ViewProvider to enable merging of overlays on icon
Browse files Browse the repository at this point in the history
  • Loading branch information
abdullahtahiriyo authored and wwmayer committed Jun 22, 2019
1 parent e632e9f commit b0fdf13
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 14 deletions.
48 changes: 34 additions & 14 deletions src/Gui/ViewProvider.cpp
Expand Up @@ -132,18 +132,18 @@ void ViewProvider::finishEditing()

bool ViewProvider::setEdit(int ModNum)
{
Q_UNUSED(ModNum);
Q_UNUSED(ModNum);
return true;
}

void ViewProvider::unsetEdit(int ModNum)
{
Q_UNUSED(ModNum);
Q_UNUSED(ModNum);
}

void ViewProvider::setEditViewer(View3DInventorViewer*, int ModNum)
{
Q_UNUSED(ModNum);
Q_UNUSED(ModNum);
}

void ViewProvider::unsetEditViewer(View3DInventorViewer*)
Expand All @@ -162,7 +162,7 @@ void ViewProvider::setUpdatesEnabled (bool enable)

void highlight(const HighlightMode& high)
{
Q_UNUSED(high);
Q_UNUSED(high);
}

void ViewProvider::eventCallback(void * ud, SoEventCallback * node)
Expand Down Expand Up @@ -266,7 +266,12 @@ void ViewProvider::update(const App::Property* prop)

QIcon ViewProvider::getIcon(void) const
{
return Gui::BitmapFactory().pixmap(sPixmap);
return mergeOverlayIcons (Gui::BitmapFactory().pixmap(sPixmap));
}

QIcon ViewProvider::mergeOverlayIcons (const QIcon & orig) const
{
return orig;
}

void ViewProvider::setTransformation(const Base::Matrix4D &rcMatrix)
Expand Down Expand Up @@ -495,6 +500,21 @@ void addNodes(Graph& graph, std::map<SoNode*, Vertex>& vertexNodeMap, SoNode* no
}
}

QIcon ViewProvider::mergePixmap (const QIcon &base, const QPixmap &px, Gui::BitmapFactoryInst::Position position) const
{
QIcon overlayedIcon;

int w = QApplication::style()->pixelMetric(QStyle::PM_ListViewIconSize);

overlayedIcon.addPixmap(Gui::BitmapFactory().merge(base.pixmap(w, w, QIcon::Normal, QIcon::Off),
px,position), QIcon::Normal, QIcon::Off);

overlayedIcon.addPixmap(Gui::BitmapFactory().merge(base.pixmap(w, w, QIcon::Normal, QIcon::On ),
px,position), QIcon::Normal, QIcon::Off);

return overlayedIcon;
}

bool ViewProvider::checkRecursion(SoNode* node)
{
if (node->getTypeId().isDerivedFrom(SoGroup::getClassTypeId())) {
Expand Down Expand Up @@ -531,8 +551,8 @@ SoPickedPoint* ViewProvider::getPointOnRay(const SbVec2s& pos, const View3DInven
SoTransform* trans = new SoTransform;
trans->setMatrix(gm.getMatrix());
trans->ref();
// build a temporary scenegraph only keeping this viewproviders nodes and the accumulated

// build a temporary scenegraph only keeping this viewproviders nodes and the accumulated
// transformation
SoSeparator* root = new SoSeparator;
root->ref();
Expand All @@ -556,27 +576,27 @@ SoPickedPoint* ViewProvider::getPointOnRay(const SbVec3f& pos,const SbVec3f& dir
{
// Note: There seems to be a bug with setRay() which causes SoRayPickAction
// to fail to get intersections between the ray and a line

//first get the path to this node and calculate the current setTransformation
SoSearchAction sa;
sa.setNode(pcRoot);
sa.setSearchingAll(true);
sa.apply(viewer->getSoRenderManager()->getSceneGraph());
SoGetMatrixAction gm(viewer->getSoRenderManager()->getViewportRegion());
gm.apply(sa.getPath());
// build a temporary scenegraph only keeping this viewproviders nodes and the accumulated

// build a temporary scenegraph only keeping this viewproviders nodes and the accumulated
// transformation
SoTransform* trans = new SoTransform;
trans->ref();
trans->setMatrix(gm.getMatrix());

SoSeparator* root = new SoSeparator;
root->ref();
root->addChild(viewer->getSoRenderManager()->getCamera());
root->addChild(trans);
root->addChild(pcRoot);

//get the picked point
SoRayPickAction rp(viewer->getSoRenderManager()->getViewportRegion());
rp.setRay(pos,dir);
Expand Down Expand Up @@ -783,7 +803,7 @@ std::vector< App::DocumentObject* > ViewProvider::claimChildren(void) const
for (Gui::ViewProviderExtension* ext : vector) {
std::vector< App::DocumentObject* > nvec = ext->extensionClaimChildren();
if (!nvec.empty())
vec.insert(std::end(vec), std::begin(nvec), std::end(nvec));
vec.insert(std::end(vec), std::begin(nvec), std::end(nvec));
}
return vec;
}
Expand All @@ -795,7 +815,7 @@ std::vector< App::DocumentObject* > ViewProvider::claimChildren3D(void) const
for (Gui::ViewProviderExtension* ext : vector) {
std::vector< App::DocumentObject* > nvec = ext->extensionClaimChildren3D();
if (!nvec.empty())
vec.insert(std::end(vec), std::begin(nvec), std::end(nvec));
vec.insert(std::end(vec), std::begin(nvec), std::end(nvec));
}
return vec;
}
14 changes: 14 additions & 0 deletions src/Gui/ViewProvider.h
Expand Up @@ -32,6 +32,7 @@
#include <boost/signals2.hpp>

#include <App/TransactionalObject.h>
#include <Gui/BitmapFactory.h>
#include <Base/Vector3D.h>

class SbVec2s;
Expand Down Expand Up @@ -159,6 +160,7 @@ class GuiExport ViewProvider : public App::TransactionalObject
//@{
/// deliver the icon shown in the tree view
virtual QIcon getIcon(void) const;

/** deliver the children belonging to this object
* this method is used to deliver the objects to
* the tree framework which should be grouped under its
Expand Down Expand Up @@ -361,6 +363,18 @@ class GuiExport ViewProvider : public App::TransactionalObject
/// Reimplemented from subclass
void onChanged(const App::Property* prop);


/** @name Methods used by the Tree
* If you want to take control over the
* viewprovider specific overlay icons, such as status, you
* can reimplement this method.
*/
virtual QIcon mergeOverlayIcons (const QIcon & orig) const;

/// Helper method to merge a pixmap into one corner of a QIcon
QIcon mergePixmap (const QIcon &base, const QPixmap &px, Gui::BitmapFactoryInst::Position position) const;


protected:
/// The root Separator of the ViewProvider
SoSeparator *pcRoot;
Expand Down

0 comments on commit b0fdf13

Please sign in to comment.