+ improve GraphicsScene class

This commit is contained in:
wmayer 2016-03-27 16:22:30 +02:00
parent 7993938ab6
commit d43443a832
2 changed files with 31 additions and 3 deletions

View File

@ -80,6 +80,29 @@ GraphicsView::~GraphicsView()
{
}
bool GraphicsView::viewportEvent(QEvent* event)
{
if (event->type() == QEvent::Paint || event->type() == QEvent::Resize) {
return QGraphicsView::viewportEvent(event);
}
else if (event->type() == QEvent::MouseMove ||
event->type() == QEvent::Wheel ||
event->type() == QEvent::MouseButtonDblClick ||
event->type() == QEvent::MouseButtonRelease ||
event->type() == QEvent::MouseButtonPress) {
QMouseEvent* mouse = static_cast<QMouseEvent*>(event);
QGraphicsItem *item = itemAt(mouse->pos());
if (!item) {
QGraphicsView::viewportEvent(event);
return false;
}
return QGraphicsView::viewportEvent(event);
}
return QGraphicsView::viewportEvent(event);
}
void GraphicsView::resizeEvent(QResizeEvent *event)
{
if (scene())
@ -350,7 +373,7 @@ GraphicsScene::GraphicsScene()
soeventmanager->setNavigationState(SoEventManager::MIXED_NAVIGATION);
eventfilter = new SceneEventFilter(this);
this->installEventFilter(eventfilter);
//this->installEventFilter(eventfilter);
connect(this, SIGNAL(sceneRectChanged(const QRectF&)),
this, SLOT(onSceneRectChanged(const QRectF&)));
@ -381,8 +404,11 @@ GraphicsScene::getEventFilter(void) const
bool
GraphicsScene::processSoEvent(const SoEvent * event)
{
return event && soeventmanager &&
soeventmanager->processEvent(event);
if (event) {
return soeventmanager && soeventmanager->processEvent(event);
}
return false;
}
void
@ -741,6 +767,7 @@ void GraphicsScene::wheelEvent(QGraphicsSceneWheelEvent *event)
GraphicsView3D::GraphicsView3D(Gui::Document* doc, QWidget* parent)
: Gui::MDIView(doc, parent), m_scene(new GraphicsScene()), m_view(new GraphicsView)
{
m_view->installEventFilter(m_scene->getEventFilter());
QGLFormat f;
f.setSampleBuffers(true);
f.setSamples(8);

View File

@ -137,6 +137,7 @@ public:
protected:
void resizeEvent(QResizeEvent *event);
bool viewportEvent(QEvent* event);
};
class /*GuiExport*/ GraphicsView3D : public Gui::MDIView