-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshapeobjecteditor.cpp
More file actions
175 lines (137 loc) · 4.33 KB
/
shapeobjecteditor.cpp
File metadata and controls
175 lines (137 loc) · 4.33 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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include "shapeobjecteditor.h"
#include "ui_shapeobjecteditor.h"
ShapeObjectEditor::ShapeObjectEditor(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::ShapeObjectEditor){
ui->setupUi(this);
setMouseTracking(true);
setFixedSize(1000,500);
setWindowTitle("Малювалка");
QActionGroup *alignGroup = new QActionGroup(this);
alignGroup->addAction(ui->line);
alignGroup->addAction(ui->dot);
alignGroup->addAction(ui->ellipse);
alignGroup->addAction(ui->rectangle);
alignGroup->addAction(ui->lineCirlcle);
alignGroup->addAction(ui->cube);
}
ShapeObjectEditor* ShapeObjectEditor::p_instance=nullptr;
ShapeObjectEditor::~ShapeObjectEditor(){
deleting();
delete ui;
p_instance = nullptr;
}
ShapeObjectEditor *ShapeObjectEditor::getInstance(QWidget *parent){
if(!p_instance){
p_instance = new ShapeObjectEditor(nullptr);
}
return p_instance;
}
void ShapeObjectEditor::cubeSizeGetter(int cubeLength,int cubeCoef){
this->cubeLength = cubeLength;
this->cubeCoef = cubeCoef;
}
void ShapeObjectEditor::mouseMoveEvent(QMouseEvent *event){
if (event->buttons() & Qt::LeftButton && isDraw){
movePoint = event->pos();
update();
}
}
void ShapeObjectEditor::mousePressEvent(QMouseEvent *event){
movePoint = pressPoint;
if (event->button() == Qt::LeftButton){
isDraw = true;
isRel = false;
pressPoint = event->pos();
update();
}
}
void ShapeObjectEditor::mouseReleaseEvent(QMouseEvent *event){
isRel = true;
isDraw = false;
isDebug = true;
update();
}
void ShapeObjectEditor::paintEvent(QPaintEvent *event){
QPainter *painterForWidget = new QPainter{this};
if(isDebug && isDraw){
movePoint = pressPoint;
isDebug = false;
}
if(isShapeChecked){
drawing(painterForWidget);
}
if(ui->line->isChecked()){
ui->statusbar->showMessage("Обрана лінія");
if(isDraw){
shapeArray[counter] = new Line;
isShapeChecked=true;
}
}else if(ui->ellipse->isChecked()){
ui->statusbar->showMessage("Обран еліпс");
if(isDraw){
shapeArray[counter] = new Ellipse;
isShapeChecked=true;
}
}else if(ui->rectangle->isChecked()){
ui->statusbar->showMessage("Обран прямокутник");
if(isDraw){
shapeArray[counter] = new Rect;
isShapeChecked=true;
}
}else if(ui->dot->isChecked()){
ui->statusbar->showMessage("Обрана точка");
if(isDraw){
shapeArray[counter] = new Dot;
isShapeChecked=true;
}
}else if(ui->lineCirlcle->isChecked()){
ui->statusbar->showMessage("Обрана ліня з точками");
if(isDraw){
shapeArray[counter] = new Lineellipse;
isShapeChecked=true;
}
}else if(ui->cube->isChecked()){
ui->statusbar->showMessage("Обран куб");
if(isDraw){
shapeArray[counter] = new Cube(cubeLength,cubeCoef);
isShapeChecked=true;
}
}
if(isRel && isShapeChecked){
emit sendShapeTable(shapeArray[counter]->nameOfClass(),pressPoint,movePoint);
}
if(isRel && counter<arraySize && isShapeChecked){
counter++;
}
if(isDraw && isShapeChecked && counter<arraySize){
shapeArray[counter]->setCord(pressPoint,movePoint);
shapeArray[counter]->showShape(*painterForWidget,isDraw);
}
isRel=false;
delete painterForWidget;
update();
}
void ShapeObjectEditor::drawing(QPainter *painter){
for(int row = 0;row < counter;row++){
if(shapeArray[row]){
shapeArray[row]->showShape(*painter,false);
}
}
}
void ShapeObjectEditor::deleting(){
for(int row = 0;row < arraySize;row++){
if(shapeArray[row]){
delete shapeArray[row];
}
}
}
void ShapeObjectEditor::on_actionopenTab_triggered(){
emit widgetOpenResize();
}
void ShapeObjectEditor::on_openTableCoord_triggered(){
emit widgetOpenTablet();
}
void ShapeObjectEditor::closeEvent(QCloseEvent *event){
emit widgetClose();
}