QHalconWindow.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #ifndef QHALCONWINDOW_H
  2. #define QHALCONWINDOW_H
  3. #include "showunit_global.h"
  4. #include <QtWidgets/qwidget.h>
  5. #include <qwidget.h>
  6. #include "HalconCpp.h"
  7. #include "HObjectEntry.h"
  8. #include "GraphicsContext.h"
  9. #include "ROIController.h"
  10. #include "ROI.h"
  11. #include "HWndMessage.h"
  12. #include <QtWidgets/QLabel>
  13. #include "ROI.h"
  14. #include "ROICircle.h"
  15. #include "ROIRect1.h"
  16. #include "ROICircularArc.h"
  17. #include "ROIRect2.h"
  18. #include "ROILine.h"
  19. #include "ROIPoint.h"
  20. #include<QAction>
  21. #include<QMenu>
  22. #include <QMutex>
  23. enum class ShowMode
  24. {
  25. IncludeROI = 1,
  26. ExcludeROI
  27. };
  28. enum class ResultShow
  29. {
  30. Image,
  31. AllObject
  32. };
  33. using namespace HalconCpp;
  34. class ROIController;
  35. class HWndMessage;
  36. class SHOWUNITSHARED_EXPORT QHalconWindow:public QWidget
  37. {
  38. Q_OBJECT
  39. public:
  40. QHalconWindow(QWidget *parent = 0);
  41. virtual ~QHalconWindow(void);
  42. HTuple getWindowID(void) { return winID; }
  43. void refresh();
  44. void addIconicVar(HImage img);
  45. void addIconicVar(HObject obj);
  46. void addMessage(HWndMessage message);
  47. void useROIController(ROIController *rC);
  48. void resetWindow();
  49. void clearWindow();
  50. void changeGraphicSettings(const QString &mode, const HTuple &val);
  51. void setResultShow(const ResultShow &resultShow);
  52. void setShowMode(const ShowMode &showMode);
  53. GraphicsContext mGC;
  54. void setBackgroundColor(QString color);
  55. signals:
  56. void mouseMoveStatus(const QString &message);
  57. public slots:
  58. void on_actDispImageOnly();
  59. void on_actDispFit();
  60. void on_actSaveImage();
  61. void on_actDumpWindow();
  62. void on_actShowCross();
  63. void on_actDelActiveRoi();
  64. void on_actDelAllRoi();
  65. void on_actSetRoiAdd();
  66. void on_actSetRoiSub();
  67. void on_actGetDistance();
  68. void on_actShowImageOnly();
  69. void on_actCreateCircle();
  70. void on_actCreateCircleArc();
  71. void on_actCreateLine();
  72. void on_actCreateRect1();
  73. void on_actCreateRect2();
  74. protected:
  75. void resizeEvent(QResizeEvent*);
  76. //鼠标操作
  77. void mousePressEvent(QMouseEvent *)override;
  78. void wheelEvent(QWheelEvent *) override;
  79. void mouseReleaseEvent(QMouseEvent *)override;
  80. void mouseMoveEvent(QMouseEvent *)override;
  81. void contextMenuEvent(QContextMenuEvent *) override;
  82. void enterEvent(QEvent *) override;
  83. void showEvent(QShowEvent* )override;
  84. private:
  85. HTuple winID;
  86. //HTuple bufferID;
  87. const int MAX_NUM_OBJ_LIST = 50;
  88. bool mousePressed = false;
  89. double startX, startY;
  90. QString backguoundColor;
  91. QMenu *popMenu;
  92. QAction *actDispImageOnly;
  93. QAction *actDispFit;
  94. QAction *actShowCross;
  95. QAction *actSaveImage;
  96. QAction *actDumpWindow;
  97. ShowMode showMode;
  98. int windowWidth;
  99. int windowHeight;
  100. int imageWidth;
  101. int imageHeight;
  102. double ImgRow1, ImgCol1, ImgRow2, ImgCol2;
  103. double zoomWndFactor;
  104. bool showCross = false;
  105. QList<HObjectEntry> HObjList;
  106. HImage originalImage;
  107. HObject showImage;
  108. ROIController * roiManager=NULL;
  109. ResultShow resultShow;
  110. QMutex m_Mutex;
  111. bool firstEnter;
  112. // 设定图像的窗口显示部分
  113. int zoom_beginRow, zoom_beginCol, zoom_endRow, zoom_endCol;
  114. // 获取图像的当前显示部分
  115. HTuple current_beginRow, current_beginCol, current_endRow, current_endCol;
  116. void OpenWindow(void);
  117. void DispImageZoom(HTuple mode, HTuple Mouse_row, HTuple Mouse_col);
  118. void InitUserUI();
  119. void moveImage(double motionX, double motionY);
  120. };
  121. #endif // QHALCONWINDOW_H