/
cubo.cpp
147 lines (124 loc) · 2.85 KB
/
cubo.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include "cubo.h"
#include "ui_cubo.h"
#include <QMessageBox>
#include <math.h>
void drawCubo(QPainter & painter);
cubo::cubo(QWidget *parent) :
QDialog(parent),
ui(new Ui::cubo)
{
ui->setupUi(this);
centerX = width()/2;
centerY = height()/2;
QTransform center;
center.translate(centerX,centerY);
transforms.push_back(center);
}
cubo::~cubo()
{
delete ui;
}
void cubo::paintEvent(QPaintEvent *e)
{
QPainter painter(this);
QPen pointPen(Qt::black);
pointPen.setWidth(2);
painter.setPen(pointPen);
if (dibuja)
{
for(int i=0; i<transforms.size(); ++i)
{
painter.setTransform(transforms[i],true);
drawCubo(painter);
}
}
}
void drawCubo(QPainter &painter){
int x1 = -25;
int y1 = 25;
int x2 = 25;
int y2 = 25;
int x3 = -25;
int y3 = -25;
int x4 = 25;
int y4 = -25;
int distProp = (x2-x1)/2;
int _x1 = x1+distProp;
int _y1 = y1-distProp;
int _x2 = x2+distProp;
int _y2 = y2-distProp;
int _x3 = x3+distProp;
int _y3 = y3-distProp;
int _x4 = x4+distProp;
int _y4 = y4-distProp;
painter.drawLine(x1, y1, x2, y2);
painter.drawLine(x1, y1, x3, y3);
painter.drawLine(x2, y2, x4, y4);
painter.drawLine(x3, y3, x4, y4);
painter.drawLine(_x1, _y1, _x2, _y2);
painter.drawLine(_x1, _y1, _x3, _y3);
painter.drawLine(_x2, _y2, _x4, _y4);
painter.drawLine(_x3, _y3, _x4, _y4);
painter.drawLine(x1, y1, _x1, _y1);
painter.drawLine(x2, y2, _x2, _y2);
painter.drawLine(x3, y3, _x3, _y3);
painter.drawLine(x4, y4, _x4, _y4);
}
void cubo::on_pushButton_clicked()
{
dibuja=!dibuja;
transforms.clear();
QTransform center;
center.translate(centerX,centerY);
transforms.push_back(center);
update();
}
void cubo::on_pushButton_2_clicked()
{
QString xStr = ui->transX->toPlainText();
QString yStr = ui->transY->toPlainText();
if(!xStr.isEmpty() && !yStr.isEmpty())
{
int _xStr = xStr.toInt();
int _yStr = yStr.toInt();
QTransform translate;
translate.translate(_xStr, _yStr);
transforms.push_back(translate);
}
update();
}
void cubo::on_pushButton_3_clicked()
{
QTransform zoomOut;
zoomOut.scale(0.5,0.5);
transforms.push_back(zoomOut);
update();
}
void cubo::on_pushButton_4_clicked()
{
QTransform zoomIn;
zoomIn.scale(2,2);
transforms.push_back(zoomIn);
update();
}
void cubo::on_pushButton_5_clicked()
{
QTransform rotate;
rotate.rotate(30);
transforms.push_back(rotate);
update();
}
void cubo::on_pushButton_6_clicked()
{
QTransform zoomIn;
zoomIn.scale(-1,1);
transforms.push_back(zoomIn);
update();
}
void cubo::on_pushButton_7_clicked()
{
QTransform zoomIn;
zoomIn.scale(1,-1);
transforms.push_back(zoomIn);
update();
}