+ fix issue with cursor on viewer widget, prepare code for improved event handling

This commit is contained in:
wmayer 2016-03-28 00:55:37 +02:00
parent d43443a832
commit fa77887d09
3 changed files with 70 additions and 19 deletions

View File

@ -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
}
/*!

View File

@ -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:

View File

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