-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustomgraphicsview.cpp
More file actions
37 lines (30 loc) · 1.22 KB
/
customgraphicsview.cpp
File metadata and controls
37 lines (30 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "customgraphicsview.h"
#include "ui_mainwindow.h"
#include <QtWidgets>
CustomGraphicsView::CustomGraphicsView(QWidget *parent) : QGraphicsView(parent)
{
}
/********************************************************************************/
/* Method - CustomGraphicsView::wheelEvent(QWheelEvent *zoomEvent) */
/* */
/* Description - Intercepts mouse wheel events in QGraphicsView and scales */
/* image accordingly. */
/********************************************************************************/
void CustomGraphicsView::wheelEvent(QWheelEvent *zoomEvent)
{
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
static const double scaleFactor = 1.15;
// Stores the current scale value.
static double currentScale = 1.0;
// Defines the minimum scale limit.
static const double scaleMin = 1.0;
if(zoomEvent->delta() > 0)
{
scale(scaleFactor, scaleFactor);
currentScale *= scaleFactor;
}
else if (currentScale > scaleMin) {
scale(1/scaleFactor, 1/scaleFactor);
currentScale /= scaleFactor;
}
}