Skip to content

Commit

Permalink
+ fix issue with cursor on viewer widget, prepare code for improved e…
Browse files Browse the repository at this point in the history
…vent handling
  • Loading branch information
wwmayer committed Mar 27, 2016
1 parent d43443a commit fa77887
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 19 deletions.
61 changes: 45 additions & 16 deletions src/Gui/Quarter/QuarterWidget.cpp
Expand Up @@ -754,27 +754,56 @@ void QuarterWidget::paintEvent(QPaintEvent* event)
}

bool QuarterWidget::viewportEvent(QEvent* event)
{
if( event->type() == QEvent::Paint || event->type() == QEvent::Resize) {
{
//TODO: After 0.16 is out activate the code below.
#if 1
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) {
return false;
}

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) {
return false;
}
return QGraphicsView::viewportEvent(event);
}

//if we return false the events get processed normally, this means they get passed to the quarter
//event filters for processing in the scene graph. If we return true event processing stops here.
return false;

#else
// If no item is selected still let the graphics scene handle it but
// additionally handle it by this viewer. This is e.g. needed when
// resizing a widget item because the cursor may already be outside
// this widget.
if (event->type() == QEvent::Wheel ||
event->type() == QEvent::MouseButtonDblClick ||
event->type() == QEvent::MouseButtonPress) {
QMouseEvent* mouse = static_cast<QMouseEvent*>(event);
QGraphicsItem *item = itemAt(mouse->pos());
if (!item) {
QGraphicsView::viewportEvent(event);
return false;
}
}
else if (event->type() == QEvent::MouseMove ||
event->type() == QEvent::MouseButtonRelease) {
QMouseEvent* mouse = static_cast<QMouseEvent*>(event);
QGraphicsScene* glScene = this->scene();
if (!(glScene && glScene->mouseGrabberItem())) {
QGraphicsView::viewportEvent(event);
return false;
}
}
return QGraphicsView::viewportEvent(event);
#endif
}

/*!
Expand Down
13 changes: 10 additions & 3 deletions src/Gui/View3DInventorViewer.cpp
Expand Up @@ -2530,10 +2530,17 @@ void View3DInventorViewer::setCursorRepresentation(int modearg)
// won't be changed as long as the user doesn't leave and enter
// the canvas. To fix this we explicitly set Qt::WA_UnderMouse
// if the mouse is inside the canvas.
QWidget* w = this->getGLWidget();
QWidget* glWindow = this->getGLWidget();

if (w && w->rect().contains(QCursor::pos()))
w->setAttribute(Qt::WA_UnderMouse);
// When a widget is added to the QGraphicsScene and the user
// hovered over it the 'WA_SetCursor' attribute is set to the
// GL widget but never reset and thus would cause that the
// cursor on this widget won't be set.
if (glWindow)
glWindow->setAttribute(Qt::WA_SetCursor, false);

if (glWindow && glWindow->rect().contains(QCursor::pos()))
glWindow->setAttribute(Qt::WA_UnderMouse);

switch (modearg) {
case NavigationStyle::IDLE:
Expand Down
15 changes: 15 additions & 0 deletions src/Mod/Sandbox/Gui/GLGraphicsView.cpp
Expand Up @@ -111,6 +111,21 @@ void GraphicsView::resizeEvent(QResizeEvent *event)
QGraphicsView::resizeEvent(event);
}


//QDialog *dialog = new QDialog(0, Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint);

////dialog->setWindowOpacity(0.8);
//dialog->setWindowTitle(tr("Titel"));
//dialog->setLayout(new QVBoxLayout);
//dialog->layout()->addWidget(new QLabel(tr("Use mouse wheel to zoom model, and click and drag to rotate model")));
//dialog->layout()->addWidget(new QLabel(tr("Move the sun around to change the light position")));
//dialog->layout()->addWidget(new QSpinBox);

//QGraphicsScene* scene = _viewer->scene();
//QGraphicsProxyWidget* g1 = scene->addWidget(dialog);
//g1->setWindowFlags(Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint);


// ----------------------------------------------------------------------------

class SceneEventFilter::Private
Expand Down

0 comments on commit fa77887

Please sign in to comment.