Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions libpgmodeler_ui/src/modelwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -441,7 +442,7 @@ bool ModelWidget::eventFilter(QObject *object, QEvent *event)
QGraphicsSceneMouseEvent *m_event = dynamic_cast<QGraphicsSceneMouseEvent *>(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);
Expand Down Expand Up @@ -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);
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions libpgmodeler_ui/src/modelwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down