-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevicegraphicwidget.cpp
53 lines (41 loc) · 1.5 KB
/
devicegraphicwidget.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
#include "devicegraphicwidget.h"
DeviceGraphicWidget::DeviceGraphicWidget()
{
QGraphicsScene *scene = new QGraphicsScene(this);
scene->setItemIndexMethod(QGraphicsScene::NoIndex);
scene->setSceneRect(-200, -200, 400, 400);
setScene(scene);
//setViewportUpdateMode(BoundingRectViewportUpdate);
QPixmap m_tile = QPixmap(100, 100);
m_tile.fill(Qt::white);
QPainter pt(&m_tile);
QColor color(220, 220, 220);
pt.fillRect(0, 0, 50, 50, color);
pt.fillRect(50, 50, 50, 50, color);
pt.end();
scene->setBackgroundBrush(m_tile);
setCacheMode(CacheBackground);
setRenderHint(QPainter::Antialiasing);
setTransformationAnchor(AnchorUnderMouse);
setResizeAnchor(AnchorViewCenter);
setMinimumSize(480, 480);
renderer = new QSvgRenderer( QString("./deviceElements.svg"), scene );
//Node* node = new Node(renderer);
SubDevice *subdevice1 = new SubDevice(renderer);
subdevice1->setPos(-150.0, -10.0);
scene->addItem(subdevice1);
SubDevice *subdevice2 = new SubDevice(renderer);
subdevice2->setPos(50.0, 50.0);
scene->addItem(subdevice2);
conn = new Connector(subdevice1, subdevice2, scene);
//pen.setWidth(16);
//conn1->setPen(pen);
conn->setZValue(1);
scene->addItem(conn);
//qDebug("render");
}
void DeviceGraphicWidget::mouseReleaseEvent ( QMouseEvent * e ) //itemChange(GraphicsItemChange change, const QVariant &value)
{
//if (change == QGraphicsItem::ItemPositionChange)
conn->updatePosition();
}