-
Notifications
You must be signed in to change notification settings - Fork 0
/
tmsscene.cpp
45 lines (40 loc) · 1.06 KB
/
tmsscene.cpp
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
38
39
40
41
42
43
44
#include "tmsscene.h"
#include <QDebug>
#include <QGraphicsSceneWheelEvent>
#include <QKeyEvent>
#include <QGraphicsItem>
#include <QGraphicsView>
TMSScene::TMSScene(QObject *parent)
: QGraphicsScene(parent)
{}
void TMSScene::wheelEvent(QGraphicsSceneWheelEvent *event)
{
QList<QGraphicsView*> views = this->views();
if(event->delta() > 0){ // Scroll up
if(controlPressed)
{
views[0]->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
views[0]->scale(scaleFactor, scaleFactor);
event->accept();
}
}
else // Scroll down
{
if(controlPressed)
{
views[0]->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
views[0]->scale(1/scaleFactor, 1/scaleFactor);
event->accept();
}
}
}
void TMSScene::keyPressEvent(QKeyEvent *event)
{
if(event->key() == Qt::Key_Control)
controlPressed = true;
}
void TMSScene::keyReleaseEvent(QKeyEvent *event)
{
if(event->key() == Qt::Key_Control)
controlPressed = false;
}