forked from CCOMJHC/camp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscaledview.cpp
69 lines (55 loc) · 1.29 KB
/
scaledview.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "scaledview.h"
ScaledView::ScaledView():m_scale(1.0),m_zoomFactor(0.8)
{
}
void ScaledView::setScale(double scale)
{
m_scale = scale;
}
double ScaledView::scale() const
{
return m_scale;
}
void ScaledView::setOffset(const QPointF &offset)
{
m_offset = offset;
}
QPointF const &ScaledView::offset() const
{
return m_offset;
}
void ScaledView::setSizeInPixels(const QSize &psize)
{
m_sizeInPixels = psize;
}
QSize const &ScaledView::sizeInPixels() const
{
return m_sizeInPixels;
}
void ScaledView::zoomIn(const QPoint &mousePosition)
{
zoom(mousePosition,1.0/m_zoomFactor);
}
void ScaledView::zoomOut(const QPoint &mousePosition)
{
zoom(mousePosition,m_zoomFactor);
}
void ScaledView::zoom(const QPoint &mousePosition, double factor)
{
QPointF offCenter = mousePosition-QPointF(m_sizeInPixels.width(),m_sizeInPixels.height())/2.0;
m_offset += offCenter/m_scale;
m_scale *= factor;
m_offset -= offCenter/m_scale;
}
void ScaledView::pan(const QPointF &deltaMouse)
{
m_offset -= deltaMouse/m_scale;
}
QPointF ScaledView::scaledOffset() const
{
return (QPointF(m_sizeInPixels.width(),m_sizeInPixels.height())/2.0) - m_offset*m_scale;
}
QPointF ScaledView::transform(const QPointF &screenPoint) const
{
return (screenPoint-scaledOffset())/m_scale;
}