ImageHolder.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*!
  2. * \file ImageHolder.h
  3. *
  4. * Created on: Oct 5, 2011
  5. * Author: Gapchich Vladislav
  6. */
  7. #ifndef __IMAGEHOLDER_H__
  8. #define __IMAGEHOLDER_H__
  9. #include <QLabel>
  10. //! enum indicating the figure of selection
  11. enum Figure {
  12. NoFigure,
  13. RectFigure,
  14. PolyFigure
  15. };
  16. //! structure containing rectangle and it's label ID
  17. struct BoundingBox {
  18. QRect rect;
  19. int label_ID_;
  20. };
  21. //! structure containing list of the polygon points and it's label ID
  22. struct Polygon {
  23. QPolygon poly;
  24. int label_ID_;
  25. };
  26. //! structure indicates hovered point and the object which belongs to this hovered point
  27. struct HoveredPoint {
  28. Figure figure; /*!< figure of the object which belongs to the hovered point */
  29. int figureID; /*!< ID of the object in list_bounding_box_ or list_polygon_ depend on figure */
  30. int pointID; /*!< number of the point in an object(rect or poly) */
  31. };
  32. //! enum indicating the direction of zooming
  33. enum ZoomDirection {
  34. NoZoom,
  35. ZoomIn,
  36. ZoomOut
  37. };
  38. class QListWidgetItem;
  39. class QPixmap;
  40. //! \brief Widget containing loaded image.
  41. //! It makes drawing rectangles and polygons on the image possible.
  42. /* \see paintEvent(QPaintEvent *)
  43. * \see ImageLabeler
  44. */
  45. class ImageHolder : public QLabel
  46. {
  47. Q_OBJECT
  48. protected:
  49. void keyPressEvent(QKeyEvent *anEvent);
  50. void mouseMoveEvent(QMouseEvent *anEvent);
  51. void mousePressEvent(QMouseEvent *anEvent);
  52. void mouseReleaseEvent(QMouseEvent *anEvent);
  53. void paintEvent (QPaintEvent *anEvent);
  54. void triggerBoundBox(
  55. const QPoint &aNewPos,
  56. const QPoint &anOldPos,
  57. QRect *aNewBox
  58. );
  59. void triggerPolygon(
  60. const QPoint &aPoint,
  61. QPolygon *aNewPoly
  62. );
  63. void drawBoundingBoxes(
  64. QPainter *aPainter,
  65. QPen *aPen
  66. );
  67. void drawPolygons(
  68. QPainter *aPainter,
  69. QPen *aPen
  70. );
  71. void checkForPoints(QPoint *aPos);
  72. public:
  73. enum Tool {
  74. NoTool,
  75. BoundingBoxTool,
  76. PolygonTool
  77. };
  78. enum State {
  79. StandBy,
  80. NewSelection
  81. };
  82. ImageHolder(QWidget *aParent = 0);
  83. virtual ~ImageHolder();
  84. void setTool(Tool aTool);
  85. void setBoundingBoxList(QList< BoundingBox * > *aBBoxList);
  86. void setPolygonList(QList< Polygon * > *aPolyList);
  87. void setLabelColorList(QList< uint > *aLabelColorList);
  88. void setMainLabelNum(int *aNum);
  89. void setImage(QPixmap *anImage);
  90. void scaleImage(ZoomDirection aDirection, double scaleFactor);
  91. int focusedSelection();
  92. Figure focusedSelectionType();
  93. State state();
  94. Tool tool();
  95. public slots:
  96. void clearAll();
  97. void clearLast();
  98. void confirmSelection();
  99. void focusOnArea(QListWidgetItem *anItem);
  100. void clearFocusOnArea();
  101. void clearHoveredPoint();
  102. void undo();
  103. void redo();
  104. signals:
  105. void selectionStarted();
  106. void areaEdited();
  107. private:
  108. //! flag for the internal use
  109. bool repaint_needed_;
  110. //! \brief pointer to the list of ImageLabeler
  111. //! \see ImageLabeler::list_bounding_box_
  112. QList< BoundingBox * > *list_bounding_box_;
  113. //! \brief pointer to the list of ImageLabeler
  114. //! \see ImageLabeler::list_polygon_
  115. QList< Polygon * > *list_polygon_;
  116. //! \brief pointer to the list of ImageLabeler
  117. //! \see ImageLabeler::list_label_color_
  118. QList< uint > *list_label_color_;
  119. //! \brief list of points for the undo\redo methods
  120. //! \see undo()
  121. //! \see redo()
  122. QList< QPoint > list_poly_history_;
  123. //! \brief pointer to the object of ImageLabeler
  124. //! \see ImageLabeler::image_
  125. QPixmap *image_;
  126. //! \brief pointer to the variable of ImageLabeler
  127. //! \see ImageLabeler::main_label_
  128. int *main_label_;
  129. //! \brief a structure that keeps not confirmed rectangle selection
  130. //! \see paintEvent(QPaintEvent *)
  131. //! \see ImageLabeler::confirmSelection()
  132. BoundingBox bounding_box_;
  133. //! \brief a structure that keeps not confirmed polygon selection
  134. //! \see paintEvent(QPaintEvent *)
  135. //! \see ImageLabeler::confirmSelection()
  136. Polygon polygon_;
  137. //! keeps current keyboard modifier(like ctrl, shift, alt etc)
  138. int keyboard_modifier_;
  139. //! \brief keeps an information about current hovered point
  140. //! \see checkForPoints(QPoint *aPos)
  141. HoveredPoint hovered_point_;
  142. //! \brief keeps the position of a mouse when it was clicked
  143. QPoint prev_cursor_pos_;
  144. //! enum indicating tool user applying currently
  145. Tool tool_;
  146. //! enum indicating the current state of image_holder_
  147. State state_;
  148. //! indicates which selection(selected area) is focused at the moment
  149. int focused_selection_;
  150. //! indicates the type of currently selected figure
  151. Figure focused_selection_type_;
  152. //! \brief indicates current scale
  153. //! \see scaleImage(ZoomDirection aDirection,double scaleFactor)
  154. double scale_;
  155. //! \brief declares the radius of the selecltable point
  156. //! \see drawBoundingBoxes(QPainter *aPainter,QPen *aPen)
  157. //! \see drawPolygons(QPainter *aPainter,QPen *aPen)
  158. int point_radius_;
  159. };
  160. #endif /* IMAGEHOLDER_H_ */
  161. /*
  162. *
  163. */