-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGraphicsScene.cpp
More file actions
67 lines (52 loc) · 1.88 KB
/
GraphicsScene.cpp
File metadata and controls
67 lines (52 loc) · 1.88 KB
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
#include "GraphicsScene.h"
#include <QPainter>
#include <QBrush>
#include <QColor>
#include <QtDebug>
#include <cmath>
#include "NodeScene.h"
GraphicsScene::GraphicsScene(QObject *parent) : QGraphicsScene(parent)
{
// Setup the background colors here
backgroundColor = QColor("#393939");
setBackgroundBrush(backgroundColor);
primaryGridPen = QPen("#2F2F2F");
primaryGridPen.setWidth(1);
secondaryGridPen = QPen("#292929");
secondaryGridPen.setWidth(2);
sceneWidth = 8000;
sceneHeight = 4000;
gridSpacing = 20, tileSize = 100;
setSceneRect(-sceneWidth / 2, -sceneHeight / 2, sceneWidth, sceneHeight);
int canvasLeft = sceneRect().left();
int canvasRight = sceneRect().right();
int canvasTop = sceneRect().top();
int canvasBottom = sceneRect().bottom();
// Generate horizontal lines
for (int x = canvasLeft; x < canvasRight; x += gridSpacing) {
if (x % tileSize != 0) gridLinesPrimary.append(QLine(x, canvasTop, x, canvasBottom));
else gridLinesSecondary.append(QLine(x, canvasTop, x, canvasBottom));
}
// Generate vertical lines
for (int y = canvasTop; y < canvasBottom; y += gridSpacing) {
if (y % tileSize != 0) gridLinesPrimary.append(QLine(canvasLeft, y, canvasRight, y));
else gridLinesSecondary.append(QLine(canvasLeft, y, canvasRight, y));
}
}
void GraphicsScene::setScene(NodeScene *scene)
{
this->activeScene = scene;
}
void GraphicsScene::drawBackground(QPainter *painter, const QRectF &rect)
{
QGraphicsScene::drawBackground(painter, rect);
// Draw the node canvas background
painter->setPen(primaryGridPen);
painter->drawLines(gridLinesPrimary);
painter->setPen(secondaryGridPen);
painter->drawLines(gridLinesSecondary);
}
//void GraphicsScene::drawForeground(QPainter *painter, const QRectF &rect)
//{
// QGraphicsScene::drawForeground(painter, rect);
//}