ImageHolder.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * 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 Figure {
  11. NoFigure,
  12. RectFigure,
  13. PolyFigure
  14. };
  15. struct BoundingBox {
  16. QRect rect;
  17. int label_ID_;
  18. };
  19. struct Polygon {
  20. QPolygon poly;
  21. int label_ID_;
  22. };
  23. struct HoveredPoint {
  24. Figure figure;
  25. int figureID;
  26. int pointID;
  27. };
  28. enum ZoomDirection {
  29. NoZoom,
  30. ZoomIn,
  31. ZoomOut
  32. };
  33. class QListWidgetItem;
  34. class QPixmap;
  35. class ImageHolder : public QLabel
  36. {
  37. Q_OBJECT
  38. protected:
  39. void keyPressEvent(QKeyEvent *anEvent);
  40. void mouseMoveEvent(QMouseEvent *anEvent);
  41. void mousePressEvent(QMouseEvent *anEvent);
  42. void mouseReleaseEvent(QMouseEvent *anEvent);
  43. void paintEvent (QPaintEvent *anEvent);
  44. void triggerBoundBox(
  45. const QPoint &aNewPos,
  46. const QPoint &anOldPos,
  47. QRect *aNewBox
  48. );
  49. void triggerPolygon(
  50. const QPoint &aPoint,
  51. QPolygon *aNewPoly
  52. );
  53. void drawBoundingBoxes(
  54. QPainter *aPainter,
  55. QPen *aPen
  56. );
  57. void drawPolygons(
  58. QPainter *aPainter,
  59. QPen *aPen
  60. );
  61. void checkForPoints(QPoint *aPos);
  62. public:
  63. enum Tool {
  64. NoTool,
  65. BoundingBoxTool,
  66. PolygonTool,
  67. TaggingTool
  68. };
  69. enum State {
  70. StandBy,
  71. NewSelection
  72. };
  73. ImageHolder(QWidget *aParent = 0);
  74. virtual ~ImageHolder();
  75. void setTool(Tool aTool);
  76. void setBoundingBoxList(QList< BoundingBox * > *aBBoxList);
  77. void setPolygonList(QList< Polygon * > *aPolyList);
  78. void setLabelColorList(QList< uint > *aLabelColorList);
  79. void setMainLabelNum(int *aNum);
  80. void setImage(QPixmap *anImage);
  81. void scaleImage(ZoomDirection aDirection, double scaleFactor);
  82. int focusedSelection();
  83. Figure focusedSelectionType();
  84. State state();
  85. Tool tool();
  86. public slots:
  87. void clearAll();
  88. void clearLast();
  89. void confirmSelection();
  90. void focusOnArea(QListWidgetItem *anItem);
  91. void clearFocusOnArea();
  92. void clearEdition();
  93. void undo();
  94. void redo();
  95. signals:
  96. void selectionStarted();
  97. void imageScaled();
  98. void areaEdited();
  99. private:
  100. bool repaint_needed_;
  101. QList< BoundingBox * > *list_bounding_box_;
  102. QList< Polygon * > *list_polygon_;
  103. QList< uint > *list_label_color_;
  104. QList< QPoint > list_poly_history_;
  105. QPixmap *image_;
  106. int *main_label_;
  107. BoundingBox bounding_box_;
  108. Polygon polygon_;
  109. int keyboard_modifier_;
  110. HoveredPoint hovered_point_;
  111. QPoint prev_cursor_pos_;
  112. Tool tool_;
  113. State state_;
  114. int focused_selection_;
  115. Figure focused_selection_type_;
  116. double scale_;
  117. int point_radius_;
  118. };
  119. #endif /* IMAGEHOLDER_H_ */
  120. /*
  121. *
  122. */