-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflvizgv.cpp
73 lines (62 loc) · 1.39 KB
/
flvizgv.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
69
70
71
72
73
#include "flvizgv.h"
#include <QFile>
#include <QWheelEvent>
#include <QMouseEvent>
#include <QGraphicsRectItem>
#include <QGraphicsSvgItem>
#include <QPaintEvent>
#include <qmath.h>
/*
* Constructor makes graphical objects in which we will put picture of the
* C graph. Now we make draw a chess-board.
*/
FLVizGv::FLVizGv(QWidget *parent)
: QGraphicsView(parent)
, m_svgItem(0)
{
setScene(new QGraphicsScene(this));
setTransformationAnchor(AnchorUnderMouse);
setDragMode(ScrollHandDrag);
// Tlo
QPixmap tilePixmap(64, 64);
tilePixmap.fill(Qt::white);
QPainter tilePainter(&tilePixmap);
QColor color(220, 220, 220);
tilePainter.fillRect(0, 0, 32, 32, color);
tilePainter.fillRect(32, 32, 32, 32, color);
tilePainter.end();
setBackgroundBrush(tilePixmap);
}
/*
* Open new file.
*/
void
FLVizGv::openFile(const QString &fname)
{
QGraphicsScene *s = scene();
s->clear();
resetTransform();
m_svgItem = new QGraphicsSvgItem(fname);
m_svgItem->setFlags(QGraphicsItem::ItemClipsToShape);
m_svgItem->setCacheMode(QGraphicsItem::NoCache);
m_svgItem->setZValue(0);
s->addItem(m_svgItem);
}
/*
* Request to draw new image.
*/
void
FLVizGv::paintEvent(QPaintEvent *event)
{
QGraphicsView::paintEvent(event);
}
/*
* Skaling of the image.
*/
void
FLVizGv::wheelEvent(QWheelEvent *event)
{
qreal factor = qPow(1.2, event->delta() / 240.0);
scale(factor, factor);
event->accept();
}