Gui: Extend ViewProvider to enable merging of overlays on icon

This commit is contained in:
Abdullah Tahiri
2019-06-16 12:10:46 +02:00
committed by wmayer
parent e632e9feb8
commit b0fdf138b8
2 changed files with 48 additions and 14 deletions

View File

@@ -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*)
@@ -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)
@@ -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)
@@ -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())) {
@@ -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();
@@ -556,7 +576,7 @@ 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);
@@ -564,19 +584,19 @@ SoPickedPoint* ViewProvider::getPointOnRay(const SbVec3f& pos,const SbVec3f& dir
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);
@@ -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;
}
@@ -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;
}

View File

@@ -32,6 +32,7 @@
#include <boost/signals2.hpp>
#include <App/TransactionalObject.h>
#include <Gui/BitmapFactory.h>
#include <Base/Vector3D.h>
class SbVec2s;
@@ -159,6 +160,7 @@ public:
//@{
/// 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
@@ -361,6 +363,18 @@ protected:
/// 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;