-
Notifications
You must be signed in to change notification settings - Fork 0
/
Point.cpp
84 lines (76 loc) · 2.64 KB
/
Point.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
/*
@mainpage HW3
@author Tim Maytom
@date 10/24/2014
@section DESCRIPTION
In this assignment I draw a Particle Board which is a horizontal axis.
I allow the user to use mouse inputs to interactive with the Board, and place
particles. Each particle can store a string of 10 chars. The user can switch
between the particle input and output state by clicking on an empty particle or
the label of a populated particle. They can also delete a particle by pressing the
'X' in the output state of the label.
*/
#include "Point.h"
#include <QString>
#include <QPointF>
//Include my constant variables
using namespace CONSTANTS;
/*
Default Constructor for the Point class.
@detail This constructor just sets the data pointers to NULL.
*/
Point::Point()
{
data = NULL;
center = NULL;
}
/*
Constructor for the Point class.
@detail This is the constructor that I use to populate the std::vector<Points*>
in the GraphicsScene object. It accepts the coordinates of the location where
the Point is being drawn and initializes the QString as "".
@param int x is the x coordinate of the Point on the GraphicsScene
@param int y is the y coordinate of the Point on the GraphicsScene
*/
Point::Point(int x, int y)
{
data = new QString("");
center = new QPointF(x,y);
}
/*
Function to check if the Point's data is empty.
@detail I have set up the program so that a data value of "" is understood
to be 'empty'.
@return bool to indicate if the Point's data is empty
*/
bool Point::isEmpty()
{
if(data->compare(QString("")) == 0){ return true; }
return false;
}
/*
Function to check if the event position is within the Point's bounds.
@detail The Point calculates its bounds by using its position as a central
point within a rectangle defined by the constants DETECTION_WIDTH and
DETECTION_HEIGHT.
@param QPointF position the inputted event position
@return bool to indicate if the event position was within the Point's bounds
*/
bool Point::inRegion(QPointF position)
{
if( (position.rx() >= center->rx()-DETECTION_WIDTH/2 && position.rx() <= center->rx()+DETECTION_WIDTH/2) &&
(position.ry() >= center->ry()-DETECTION_HEIGHT/2 && position.ry() <= center->ry()+DETECTION_HEIGHT/2))
return true;
return false;
}
/*
Function to change the Point's data
@detail This fuction deletes the data that the current variable is pointing to
and then generates a new QString object on the heap base off the given QString.
@param QString s is the desired data value
*/
void Point::updateData(QString s)
{
delete data;
data = new QString(s);
}