-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchipview.cpp
51 lines (44 loc) · 1021 Bytes
/
chipview.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
45
46
47
48
49
50
51
#include "chipview.h"
#include <QWheelEvent>
#include <QDebug>
#include <cmath>
ChipView::ChipView(QWidget *parent) :
QGraphicsView(parent)
{
}
void ChipView::wheelEvent ( QWheelEvent * event )
{
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
int delta = event->delta();
qDebug() << delta;
qreal zoom = 1.15;
if(delta < 0)
zoom = 1./zoom;
scale(zoom,zoom);
event->accept();
}
void ChipView::zoomIn(int speed)
{
qreal zoom=pow(1.15,speed);
scale(zoom,zoom);
}
void ChipView::zoomOut(int speed)
{
qreal zoom=pow(0.9,speed);
scale(zoom,zoom);
}
void ChipView::mousePressEvent(QMouseEvent *event)
{
if(event->button()==Qt::RightButton)
_moveStartPos=event->posF();
}
void ChipView::mouseMoveEvent(QMouseEvent *event)
{
if(event->buttons() & Qt::RightButton)
{
qreal dx = event->x()-_moveStartPos.x();
qreal dy = event->y()-_moveStartPos.y();
translate(dx,dy);
_moveStartPos = event->pos();
}
}