-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcube.cpp
More file actions
50 lines (44 loc) · 1.5 KB
/
Copy pathcube.cpp
File metadata and controls
50 lines (44 loc) · 1.5 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
#include "cube.h"
#include "scene3d.h"
#include "line.h"
#include <QPainter>
#include <cmath>
Cube::Cube(int x, int y, int z, int width, int height, int length, Scene3D *scene, QGraphicsItem *parent)
:QGraphicsItem(parent), x(x), y(y), z(z), width(width), height(height), length(length), scene(scene)
{
// drawCube();
}
QPainterPath Cube::shape() const
{
return path;
}
QRectF Cube::boundingRect() const
{
const int thickness = this->scene->getThickness();
QPoint botLeft = scene->toScenePos(scene->to2D(x, y, z));
botLeft.setX(botLeft.x() - width * thickness - thickness * 2);
botLeft.setY(botLeft.y() - height * thickness - thickness * 2);
return QRectF(botLeft, QSize((length + width) * thickness + thickness * 4, (height + width) * thickness + thickness * 4));
}
void Cube::drawPixel(const QPoint &point)
{
const QPoint scenePos = scene->toScenePos(point);
const int thickness = this->scene->getThickness();
if (scenePos.x() < 0 || scenePos.x() > this->scene->width() ||
scenePos.y() < 0 || scenePos.y() > this->scene->height()) return;
path.addRect(QRect(scenePos, QSize(thickness, thickness)));
}
void Cube::drawCube()
{
for(const auto &point : Drawer::drawCube(x, y, z, width, height, length, scene->to2D)){
drawPixel(point);
}
}
void Cube::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
path = QPainterPath();
drawCube();
painter->fillPath(path, brush);
}