Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- Zoom In/Out with MouseWheel.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@23438 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Nov 18, 2014
1 parent 7c1c4f2 commit d123e4f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
41 changes: 37 additions & 4 deletions OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -1026,17 +1026,23 @@ void GraphicsView::resetZoom()
//! @see zoomOut()
void GraphicsView::zoomIn()
{
scale(1.12, 1.12);
setIsCustomScale(true);
// zoom in limitation max: 1000%
if (matrix().m11() < 34 && matrix().m22() > -34) {
scale(1.12, 1.12);
setIsCustomScale(true);
}
}

//! Decreases zoom factor by 12%.
//! @see resetZoom()
//! @see zoomIn()
void GraphicsView::zoomOut()
{
scale(1/1.12, 1/1.12);
setIsCustomScale(true);
// zoom out limitation min: 10%
if (matrix().m11() > 0.2 && matrix().m22() < -0.2) {
scale(1/1.12, 1/1.12);
setIsCustomScale(true);
}
}

//! Selects all objects and connectors.
Expand Down Expand Up @@ -1606,6 +1612,33 @@ void GraphicsView::resizeEvent(QResizeEvent *event)
QGraphicsView::resizeEvent(event);
}

/*!
Reimplementation of QGraphicsView::wheelEvent.
*/
void GraphicsView::wheelEvent(QWheelEvent *event)
{
int numDegrees = event->delta() / 8;
bool controlModifier = event->modifiers().testFlag(Qt::ControlModifier);
bool shiftModifier = event->modifiers().testFlag(Qt::ShiftModifier);
// If Ctrl key is pressed and user has scrolled vertically then Zoom In/Out based on the scroll distance.
if (event->orientation() == Qt::Vertical && controlModifier) {
if (event->delta() > 0) {
zoomIn();
} else {
zoomOut();
}
} else if ((event->orientation() == Qt::Horizontal) || (event->orientation() == Qt::Vertical && shiftModifier)) {
// If Shift key is pressed and user has scrolled vertically then scroll the horizontal scrollbars.
// If user has scrolled horizontally then scroll the horizontal scrollbars.
horizontalScrollBar()->setValue(horizontalScrollBar()->value() - numDegrees);
} else if (event->orientation() == Qt::Vertical) {
// If user has scrolled vertically then scroll the vertical scrollbars.
verticalScrollBar()->setValue(verticalScrollBar()->value() - numDegrees);
} else {
QGraphicsView::wheelEvent(event);
}
}

WelcomePageWidget::WelcomePageWidget(MainWindow *parent)
: QWidget(parent)
{
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.h
Expand Up @@ -239,6 +239,7 @@ public slots:
virtual void keyReleaseEvent(QKeyEvent *event);
virtual void contextMenuEvent(QContextMenuEvent *event);
virtual void resizeEvent(QResizeEvent *event);
virtual void wheelEvent(QWheelEvent *event);
};

class WelcomePageWidget : public QWidget
Expand Down

0 comments on commit d123e4f

Please sign in to comment.