diff --git a/libpgmodeler_ui/src/modelwidget.cpp b/libpgmodeler_ui/src/modelwidget.cpp index b6b23b5faf..b488602446 100644 --- a/libpgmodeler_ui/src/modelwidget.cpp +++ b/libpgmodeler_ui/src/modelwidget.cpp @@ -91,6 +91,7 @@ ModelWidget::ModelWidget(QWidget *parent) : QWidget(parent) BaseRelationship::RELATIONSHIP_GEN }; current_zoom=1; + zoom_on_scroll=1; // @etosan: temporary, I have no clue how to connect this to GUI modified=panning_mode=false; new_obj_type=BASE_OBJECT; @@ -441,7 +442,7 @@ bool ModelWidget::eventFilter(QObject *object, QEvent *event) QGraphicsSceneMouseEvent *m_event = dynamic_cast(event); //Filters the Wheel event if it is raised by the viewport scrollbars - if(event->type() == QEvent::Wheel && w_event->modifiers()==Qt::ControlModifier) + if(event->type() == QEvent::Wheel && (zoom_on_scroll || w_event->modifiers()==Qt::ControlModifier) ) { //Redirects the event to the wheelEvent() method of the model widget this->wheelEvent(w_event); @@ -535,12 +536,19 @@ void ModelWidget::mousePressEvent(QMouseEvent *event) void ModelWidget::wheelEvent(QWheelEvent * event) { - if(event->modifiers()==Qt::ControlModifier) - { + if(zoom_on_scroll || event->modifiers()==Qt::ControlModifier) { + int numDegrees = abs(event->delta()/8); + int numSteps = numDegrees/15; + double newZoom = ZOOM_INCREMENT * numSteps; + if(event->delta() < 0) - this->applyZoom(this->current_zoom - ZOOM_INCREMENT); - else - this->applyZoom(this->current_zoom + ZOOM_INCREMENT); + { + this->applyZoom(this->current_zoom - newZoom); + } + else if(event->delta() > 0) + { + this->applyZoom(this->current_zoom + newZoom); + } } } diff --git a/libpgmodeler_ui/src/modelwidget.h b/libpgmodeler_ui/src/modelwidget.h index 3f3fde2873..57312c5c8b 100644 --- a/libpgmodeler_ui/src/modelwidget.h +++ b/libpgmodeler_ui/src/modelwidget.h @@ -47,6 +47,9 @@ class ModelWidget: public QWidget { //! \brief Indicates if the model was modified by some operation bool modified, + zoom_on_scroll, + //! \brief Indicates whether we want to zoom by default when user rolls the mousewheel + //! brief Indicates if the panning mode was activated via event filter (see eventFilter()) panning_mode;