-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShapes.h
442 lines (406 loc) · 17.2 KB
/
Shapes.h
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
#ifndef SHAPES_H
#define SHAPES_H
/*! \file */
//general includes
#include <iostream>
#include <iomanip>
#include <string>
//for Shape class
#include <Qt>
#include <QPainter>
#include <QPaintDevice>
#include <QPen>
//for Text class
#include <QTextEdit>
#include <QString>
#include <QColor>
#include <QFont>
//for Polyline class
#include <QPoint>
class Shape
{
public:
enum ShapeType {LINE, POLYLINE, POLYGON, RECTANGLE, SQUARE, ELLIPSE, TEXT, CIRCLE, NONE};
//constructors
/*!*****************************************************************
* @brief Constructor Shape: Class Shape
*___________________________________________________________________
* Constructs a fully instantiated object of the shape class.
*___________________________________________________________________
* PRE-CONDITIONS
* int id - id of the shape
* ShapeType type - type of shape
*
* POST-CONDITIONS
* This function creates a Shape object of type NONE.
@param id id of the shape
@param type type of shape
*******************************************************************/
Shape(int id = -1, ShapeType type = NONE);
/*!*****************************************************************
* @brief Constructor Shape: Class Shape
*___________________________________________________________________
* Creates the default instance of the shape class.
*___________________________________________________________________
* PRE-CONDITIONS
* <none>
*
* POST-CONDITIONS
* This function creates a Shape object of type NONE.
*******************************************************************/
Shape();
//destructor
/*!*****************************************************************
* @brief Destructor ~Shape: Class Shape
*___________________________________________________________________
* Destructs the shape object.
*___________________________________________________________________
* PRE-CONDITIONS
* <none>
*
* POST-CONDITIONS
* This function destructs the outstanding pointers in Shape.
*******************************************************************/
virtual ~Shape() {}
//pure virtual functions
/*!*****************************************************************
* @brief Method draw: Class Shape
*___________________________________________________________________
* This method will draw a shape on the canvas. Returns nothing.
*___________________________________________________________________
* PRE-CONDITIONS
* <none>
*
* POST-CONDITIONS
* Returns nothing. Draws shape on canvas.
*******************************************************************/
virtual void draw(QPainter*) = 0;
/*!*****************************************************************
* @brief Method move: Class Shape
*___________________________________________________________________
* This method will move a shape on the canvas. Returns nothing.
*___________________________________________________________________
* PRE-CONDITIONS
* int[] - array of integers with new coordinates
*
* POST-CONDITIONS
* Returns nothing. Moves shape on canvas.
@param int[] array of integers with new coordinates
*******************************************************************/
virtual void move(int[]) = 0;
/*!*****************************************************************
* @brief Method perimeter: Class Shape
*___________________________________________________________________
* This virtual method will calculate the perimeter of a Shape,
* which adds up the length of each side.
*___________________________________________________________________
* PRE-CONDITIONS
* <none>
*
* POST-CONDITIONS
@return Returns integer perimeter for Shape
*******************************************************************/
virtual int perimeter() = 0;
/*!*****************************************************************
* @brief Method area: Class Shape
*___________________________________________________________________
* This virtual method will calculate the area of a Shape,
* which multiplies the width by the height.
*___________________________________________________________________
* PRE-CONDITIONS
* <none>
*
* POST-CONDITIONS
* Returns integer area for Shape
@return Returns integer area for Shape
*******************************************************************/
virtual int area() = 0;
//overloaded operators
/*!*****************************************************************
* Method operator == : Class Shape
*___________________________________________________________________
* This method is an overloaded version of the operator ==; the
* purpose of this method is to compare one shape to another to
* determine whether they share the same values.
*___________________________________________________________________
* PRE-CONDITIONS
* Two shapes
*
* POST-CONDITIONS
* bool is returned to represent shape similarity
@param rhs The other shape
@return bool is returned to represent shape similarity
*******************************************************************/
bool operator==(const Shape& rhs) const;
/*!*****************************************************************
* @brief Method operator < : Class Shape
*___________________________________________________________________
* This method is an overloaded version of the operator <; the
* purpose of this method is to compare if one shape's id is smaller
* than the id of the other.
*___________________________________________________________________
* PRE-CONDITIONS
* Two shapes
*
* POST-CONDITIONS
* bool is returned to represent shape similarity
@param rhs The other shape
@return bool is returned to represent shape similarity
*******************************************************************/
bool operator<(const Shape& rhs) const;
//accessors
/*!*****************************************************************
* @brief Method getPen: Class Shape
*___________________________________________________________________
* This method will return the QPen address of the calling shape.
*___________________________________________________________________
* PRE-CONDITIONS
* <none>
*
* POST-CONDITIONS
* Returns const QPen& pen.
@return Returns const QPen& pen.
*******************************************************************/
const QPen& getPen() const;
/*!*****************************************************************
* @brief Method getBrush: Class Shape
*___________________________________________________________________
* This method will return the QBrush address of the calling shape.
*___________________________________________________________________
* PRE-CONDITIONS
* <none>
*
* POST-CONDITIONS
* Returns const QBrush& brush.
@return Returns const QBrush& brush.
*******************************************************************/
const QBrush& getBrush() const;
/*!*****************************************************************
* @brief Method getShape: Class Shape
*___________________________________________________________________
* This method will return the ShapeType of the calling shape.
*___________________________________________________________________
* PRE-CONDITIONS
* <none>
*
* POST-CONDITIONS
* Returns ShapeType type.
@return Returns ShapeType type.
*******************************************************************/
ShapeType getShape() const;
/*!*****************************************************************
* @brief Method getDimensions: Class Shape
*___________________________________________________________________
* This method will return the vector of ints which stores the
* dimensions of the calling shape.
*___________________________________________________________________
* PRE-CONDITIONS
* <none>
*
* POST-CONDITIONS
* Returns vector<int>& vector.
@return Returns vector<int>& vector.
*******************************************************************/
std::vector<int>& getDimensions();
/*!*****************************************************************
* @brief Method getPainter: Class Shape
*___________________________________________________________________
* This method will return the QPainter& of the calling shape.
*___________________________________________________________________
* PRE-CONDITIONS
* <none>
*
* POST-CONDITIONS
* Returns QPainter& painter.
@return Returns QPainter& painter.
*******************************************************************/
QPainter& getPainter();
/*!*****************************************************************
* @brief Method getId: Class Shape
*___________________________________________________________________
* This method will return the int id of the calling shape.
*___________________________________________________________________
* PRE-CONDITIONS
* <none>
*
* POST-CONDITIONS
* Returns int id.
@return Returns int id.
*******************************************************************/
int getId();
//mutators
/*!*****************************************************************
* @brief Method setPen: Class Shape
*___________________________________________________________________
* This method will set the pen of the calling shape using parameter
* global color.
*___________________________________________________________________
* PRE-CONDITIONS
* Qt::GlobalColor - color of the pen
*
* POST-CONDITIONS
* <none>
@param QtGlobalColor color of the pen
*******************************************************************/
void setPen(Qt::GlobalColor);
/*!*****************************************************************
* @brief Method setBrush: Class Shape
*___________________________________________________________________
* This method will set the brush of the calling shape using parameter
* brush style and color.
*___________________________________________________________________
* PRE-CONDITIONS
* Qt::GlobalColor - color of the brush
* Qt::BrushStyle - style of the brush
*
* POST-CONDITIONS
* <none>
@param QtGlobalColor color of the brush
@param QtBrushStyle style of the brush
*******************************************************************/
void setBrush(Qt::GlobalColor, Qt::BrushStyle);
/*!*****************************************************************
* @brief Method setShape: Class Shape
*___________________________________________________________________
* This method will set the type of shape using the parameter ShapeType
*___________________________________________________________________
* PRE-CONDITIONS
* ShapeType shape - type of shape
*
* POST-CONDITIONS
* <none>
@param shape type of shape
*******************************************************************/
void setShape(ShapeType shape);
//shape properties mutators
/*!*****************************************************************
* @brief Method addDimension: Class Shape
*___________________________________________________________________
* This method will add another dimension to the dimensions vector.
* Returns nothing.
*___________________________________________________________________
* PRE-CONDITIONS
* int dim - new dimension to be added
*
* POST-CONDITIONS
* <none>
@param dim new dimension to be added
*******************************************************************/
void addDimension(int dim);
/*!*****************************************************************
* @brief Method setColor: Class Shape
*___________________________________________________________________
* This method will set the color of the shape.
* Returns nothing.
*___________________________________________________________________
* PRE-CONDITIONS
* QColor color - new color
*
* POST-CONDITIONS
* <none>
@param color new color
*******************************************************************/
void setColor(const QColor color);
/*!*****************************************************************
* @brief Method setWidth: Class Shape
*___________________________________________________________________
* This method will set the width of the shape.
* Returns nothing.
*___________________________________________________________________
* PRE-CONDITIONS
* int width - new width
*
* POST-CONDITIONS
* <none>
@param width new width
*******************************************************************/
void setWidth(int width);
/*!*****************************************************************
* @brief Method setStyle: Class Shape
*___________________________________________________________________
* This method will set the pen style of the shape.
* Returns nothing.
*___________________________________________________________________
* PRE-CONDITIONS
* Qt::PenStyle style - new pen style
*
* POST-CONDITIONS
* <none>
@param style new pen style
*******************************************************************/
void setStyle(Qt::PenStyle style);
/*!*****************************************************************
* @brief Method setCapStyle: Class Shape
*___________________________________________________________________
* This method will set the cap style of the pen.
* Returns nothing.
*___________________________________________________________________
* PRE-CONDITIONS
* Qt::PenCapStyle capStyle - new pen cap style
*
* POST-CONDITIONS
* <none>
@param capStyle new pen cap style
*******************************************************************/
void setCapStyle(Qt::PenCapStyle capStyle);
/*!*****************************************************************
* @brief Method setJoinStyle: Class Shape
*___________________________________________________________________
* This method will set the join style of the pen.
* Returns nothing.
*___________________________________________________________________
* PRE-CONDITIONS
* Qt::PenJoinStyle style - new pen join style
*
* POST-CONDITIONS
* <none>
@param style new pen join style
*******************************************************************/
void setJoinStyle(Qt::PenJoinStyle style);
/*!*****************************************************************
* @brief Method setBrushColor: Class Shape
*___________________________________________________________________
* This method will set the brush color.
* Returns nothing.
*___________________________________________________________________
* PRE-CONDITIONS
* QColor color - new color
*
* POST-CONDITIONS
* <none>
*******************************************************************/
void setBrushColor(QColor color);
/*!*****************************************************************
* @brief Method setBrushStyle: Class Shape
*___________________________________________________________________
* This method will set the brush style.
* Returns nothing.
*___________________________________________________________________
* PRE-CONDITIONS
* Qt::BrushStyle style - new style
*
* POST-CONDITIONS
* <none>
@param style - new style
*******************************************************************/
void setBrushStyle(Qt::BrushStyle style);
//disabling copy constructor and copy assignment operator
Shape(const Shape &s) = delete;
Shape& operator=(const Shape &s) = delete;
private:
/* The qpainter for the shape */
QPainter qpainter;
/* the shape id*/
int id;
/*the shape type*/
ShapeType shape;
/* the pen for the shape */
QPen pen;
/* the brush for the shape */
QBrush brush;
/* vector of ints for the dimensions */
std::vector<int> dimensions; //vector of ints
/* the index */
int index {0}; //defaults to 0
};
#endif // SHAPES_H