Ground-Truthing GUI  1.0
imagegraphicsscene.h
1 
24 #ifndef DRAWRECTANGLE
25 #define DRAWRECTANGLE
26 
27 #include <QGraphicsScene>
28 #include <QPoint>
29 #include <QMouseEvent>
30 #include <QDebug>
31 #include <QGraphicsSceneMouseEvent>
32 #include <QPainter>
33 #include <QPixmap>
34 #include <QGraphicsRectItem>
35 #include <QPointF>
36 #include <QGraphicsView>
37 #include <QCursor>
38 
39 #include "filewriter.h"
40 #include "createfileabstraction.h"
41 #include "rectangledraw.h"
42 #include "rectanglewindow.h"
43 #include "removeconfirmationwindow.h"
44 #include "filereader.h"
45 #include "removeconfirmationwindow.h"
46 
47 class ImageGraphicsScene:public QGraphicsScene
48 {
49  Q_OBJECT
50 
51 private:
52 
53  // The pixmap of the image the user wants to work with
54  QPixmap *pixmap;
55 
56  // The pixmap representing the mouse cursor when the erase button is activated
57  QPixmap *erase_pixmap;
58 
59  // The pixmap representing the mouse when the modify button is activated
60  QPixmap *modify_pixmap;
61 
62  // The size of the application scene
63  QRectF sceneRectangle;
64 
65  // The rectangles which are going to be drawn by the user
66  RectangleDraw *rect;
67 
68  // The rectangle ID
69  int id;
70 
71  // Corner top-left point
72  QPointF origPoint;
73  QList<RectangleDraw*> list;
74 
75  // User's click on a rectangle in order to open the dialog window
76  QPointF UserPoint;
77 
78  // The object which is going to write all the rectangles information
79  // in the text file
80  FileWriter *filewriter;
81 
82  // The text file associated to the image
83  CreateFileAbstraction *createfileabstraction;
84 
85  // Check the state of the mouse's left button
86  bool mouseLeftPressed;
87 
88  // Window corresponding to the rectangle
89  RectangleWindow* window;
90 
91  // DrawButton state
92  bool drawButton;
93 
94  // EraseButton state
95  bool eraseButton;
96 
97  // Check if the user has double-clicked on the rectangle
98  bool doubleClick;
99 
100  // DragButton state
101  bool dragButton;
102 
103  // State of the modify button
104  bool modifyButton;
105 
106  // Check if one of the rectangles is selected
107  bool isSelected;
108 
109  // Check of the mouse is on one of the rectangle's corners
110  bool isOnCorner;
111 
112  // Check if the mouse is pressed on one of the corners
113  bool isOnTopLeftCornerPressed;
114  bool isOnTopRightCornerPressed;
115  bool isOnBottomLeftCornerPressed;
116  bool isOnBottomRightCornerPressed;
117 
118  // The rectangle modification can take place
119  bool startModifying;
120 
121  // Te rectangle which is going to be modified by the user
122  RectangleDraw* rectModified;
123 
124  // The view containing the scene
125  QGraphicsView *view;
126 
127  // The erase cursor
128  QCursor *erase_cursor;
129 
130  // The modify cursor
131  QCursor *modify_cursor;
132 
133  // The confirmation window when the user wants to remove a rectangle
134  RemoveConfirmationWindow *remove;
135 
136 public:
137 
144  ImageGraphicsScene(QGraphicsView *view_1,QPixmap *pixmap_1,QRectF sceneRectangle_1,CreateFileAbstraction *cfa_1):
145  sceneRectangle(sceneRectangle_1),pixmap(pixmap_1),mouseLeftPressed(false),
146  createfileabstraction(cfa_1),rect(NULL),id(0),UserPoint(0,0),window(NULL),drawButton(false),eraseButton(false),
147  dragButton(false),doubleClick(true),view(view_1),modifyButton(false),isSelected(false),
148  rectModified(NULL),isOnCorner(false),isOnTopLeftCornerPressed(false),isOnTopRightCornerPressed(false),
149  isOnBottomLeftCornerPressed(false),isOnBottomRightCornerPressed(false),startModifying(false),remove(NULL)
150  {
151  // Create the file writer
152  filewriter=new FileWriter(createfileabstraction);
153 
154  // Create the file readr
155  //filereader=new FileReader(createfileabstraction);
156 
157  // The size of the GraphicsScene must be equal to the image size
158  this->setSceneRect(sceneRectangle);
159 
160  // Display the image
161  this->addPixmap(*pixmap);
162 
163  // Erase pixmap
164  erase_pixmap=new QPixmap("../Icons/cursor_erase.png");
165 
166  // Modidy pixmap
167  modify_pixmap=new QPixmap("../Icons/pencil.png");
168 
169  // Instatiate the mouse cursor
170  erase_cursor=new QCursor(*erase_pixmap);
171 
172  // Modify cursor
173  modify_cursor=new QCursor(*modify_pixmap);
174  }
175 
179 
185  virtual bool Iscontaining(RectangleDraw *rectangle,QPointF point)const;
186 
190  virtual void setDrawButton(bool value);
191 
195  virtual bool getDrawButton()const;
196 
200  virtual void setEraseButton(bool value);
201 
205  virtual bool getEraseButton()const;
206 
209  virtual void setDoubleClick(bool value);
210 
213  virtual bool getDoubleClick()const;
214 
218  virtual void setDragButton(bool value);
219 
223  virtual bool getDragButton()const;
224 
228  virtual QCursor* getEraseCursor()const;
229 
233  virtual QCursor* getModifyCursor()const;
234 
238  virtual QList<RectangleDraw*> getList()const;
239 
243  virtual void setList(QList<RectangleDraw*> list_1);
244 
248  virtual void setId(int id);
249 
253  virtual FileWriter* getFileWriter()const;
254 
258  virtual void setFileWriter(FileWriter *filewriter_1);
259 
264  virtual int checkMouseMove(QPointF point);
265 
270  virtual int checkMousePress(QPointF point);
271 
274  virtual void setIsSelected(bool state);
275 
279  virtual bool checkModify()const;
280 
283  virtual void setModify(bool state);
284 
289 
293  virtual void setCreateFileAbstraction(CreateFileAbstraction *createfileabstraction_1);
294 
295 protected:
296 
300  void mousePressEvent(QGraphicsSceneMouseEvent *event);
301 
305  void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
306 
310  void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
311 
315  void mouseDoubleClickEvent(QGraphicsSceneMouseEvent * event);
316 
317 signals:
318 
322  void changeCursor(bool value);
323 };
324 
325 #endif // DRAWRECTANGLE
326 
virtual void setDoubleClick(bool value)
Deprecated. Will be removed in a future release.
Definition: imagegraphicsscene.cpp:449
virtual void setId(int id)
Sets the rectangle ID.
Definition: imagegraphicsscene.cpp:501
virtual QList< RectangleDraw * > getList() const
Returns a list of all the rectangles in the scene.
Definition: imagegraphicsscene.cpp:481
virtual void setModify(bool state)
Deprecated. Will be remove in a future release.
Definition: imagegraphicsscene.cpp:469
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
Deprecated. Will be removed in a future release.
Definition: imagegraphicsscene.cpp:118
virtual void setEraseButton(bool value)
Sets the state of the erase icon.
Definition: imagegraphicsscene.cpp:436
virtual QCursor * getModifyCursor() const
Returns the shape of the Modify cursor.
Definition: imagegraphicsscene.cpp:477
virtual void setList(QList< RectangleDraw * > list_1)
Sets the list of the rectangles drawn in th scene.
Definition: imagegraphicsscene.cpp:497
virtual bool Iscontaining(RectangleDraw *rectangle, QPointF point) const
Checks if the user is pressing on one rectangle.
Definition: imagegraphicsscene.cpp:415
The window asking for the user confirmation when he wants to delete a rectangle.
Definition: removeconfirmationwindow.h:36
Creates a text file related to an image.
Definition: createfileabstraction.h:34
virtual FileWriter * getFileWriter() const
Returns the FileWriter object.
Definition: imagegraphicsscene.cpp:485
void mousePressEvent(QGraphicsSceneMouseEvent *event)
Detects when the user presses one button of the mouse.
Definition: imagegraphicsscene.cpp:3
virtual void setCreateFileAbstraction(CreateFileAbstraction *createfileabstraction_1)
Sets the text file associated to the image.
Definition: imagegraphicsscene.cpp:505
virtual bool getDoubleClick() const
Deprecated method. Will be removed in the future release.
Definition: imagegraphicsscene.cpp:453
virtual bool checkModify() const
Checks if we are in the "Modify" mode or not.
Definition: imagegraphicsscene.cpp:465
virtual QCursor * getEraseCursor() const
Returns the shape of the erase cursor.
Definition: imagegraphicsscene.cpp:473
virtual void setFileWriter(FileWriter *filewriter_1)
Sets the FielWriter object.
Definition: imagegraphicsscene.cpp:509
ImageGraphicsScene(QGraphicsView *view_1, QPixmap *pixmap_1, QRectF sceneRectangle_1, CreateFileAbstraction *cfa_1)
The constructor of the ImageGraphicsScene class.
Definition: imagegraphicsscene.h:144
virtual void setDrawButton(bool value)
Sets the state of the draw icon.
Definition: imagegraphicsscene.cpp:431
void changeCursor(bool value)
Deprecated signal. Will be deleted in a future release.
virtual CreateFileAbstraction * getCreateFileAbstraction() const
Returns the text file.
Definition: imagegraphicsscene.cpp:493
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
Detects when the user releases one button of the mouse.
Definition: imagegraphicsscene.cpp:388
Displays the rectangles and work on the image.
Definition: imagegraphicsscene.h:47
Write in a text file.
Definition: filewriter.h:28
The annotation window.
Definition: rectanglewindow.h:42
Describes a rectangle drawn by the user.
Definition: rectangledraw.h:34
virtual bool getDrawButton() const
Returns the state of the draw icon.
Definition: imagegraphicsscene.cpp:441
void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
Detects when the user moves his mouse all around the scene.
Definition: imagegraphicsscene.cpp:146
virtual bool getDragButton() const
Returns the state of the drag icon.
Definition: imagegraphicsscene.cpp:461
virtual void setDragButton(bool value)
Sets the state of the drag icon.
Definition: imagegraphicsscene.cpp:457
virtual int checkMousePress(QPointF point)
Checks if the mouse is pressing one of the rectangle corners when we are in the "Modify" mode...
Definition: imagegraphicsscene.cpp:319
virtual void setIsSelected(bool state)
Deprecated. Will be removed in a future release.
Definition: imagegraphicsscene.cpp:489
virtual bool getEraseButton() const
Returns the state of the erase icon.
Definition: imagegraphicsscene.cpp:445
virtual int checkMouseMove(QPointF point)
Checks if the mouse is around one of the rectangle corners when we are in the "Modify" mode...
Definition: imagegraphicsscene.cpp:251
virtual ~ImageGraphicsScene()
Class destructor.
Definition: imagegraphicsscene.h:178