ImageHolder.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 undo();
  93. void redo();
  94. signals:
  95. void selectionStarted();
  96. void imageScaled();
  97. void areaEdited();
  98. private:
  99. bool repaint_needed_;
  100. QList< BoundingBox * > *list_bounding_box_;
  101. QList< Polygon * > *list_polygon_;
  102. QList< uint > *list_label_color_;
  103. QList< QPoint > list_poly_history_;
  104. QPixmap *image_;
  105. int *main_label_;
  106. BoundingBox bounding_box_;
  107. Polygon polygon_;
  108. int keyboard_modifier_;
  109. HoveredPoint hovered_point_;
  110. QPoint prev_cursor_pos_;
  111. Tool tool_;
  112. State state_;
  113. int focused_selection_;
  114. Figure focused_selection_type_;
  115. double scale_;
  116. int point_radius_;
  117. };
  118. #endif /* IMAGEHOLDER_H_ */
  119. /*
  120. *
  121. */