-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #212 from kevinzg/add-drag-zoom-gui
Add drag and zoom to gui
- Loading branch information
Showing
5 changed files
with
57 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include "CustomGraphicsView.h" | ||
|
||
CustomGraphicsView::CustomGraphicsView(QWidget* parent) : | ||
QGraphicsView(parent) {} | ||
|
||
CustomGraphicsView::CustomGraphicsView (QGraphicsScene* scene, QWidget* parent) : | ||
QGraphicsView(scene, parent) {} | ||
|
||
void CustomGraphicsView::wheelEvent(QWheelEvent* event) | ||
{ | ||
static const double zoomInFactor = 1.5; | ||
static const double zoomOutFactor = 1.0 / zoomInFactor; | ||
|
||
if(event->modifiers() & Qt::ControlModifier) | ||
{ | ||
QGraphicsView::wheelEvent(event); | ||
} | ||
else | ||
{ | ||
if(event->delta() > 0) | ||
{ | ||
scale(zoomInFactor, zoomInFactor); | ||
} | ||
else | ||
{ | ||
scale(zoomOutFactor, zoomOutFactor); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef CUSTOMGRAPHICSVIEW_H | ||
#define CUSTOMGRAPHICSVIEW_H | ||
|
||
#include <QGraphicsView> | ||
#include <QWheelEvent> | ||
|
||
class CustomGraphicsView : public QGraphicsView | ||
{ | ||
public: | ||
CustomGraphicsView(QWidget* parent = 0); | ||
CustomGraphicsView(QGraphicsScene* scene, QWidget* parent = 0); | ||
|
||
protected: | ||
virtual void wheelEvent(QWheelEvent* event); | ||
}; | ||
|
||
#endif // CUSTOMGRAPHICSVIEW_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters