selectwidget.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #ifndef SELECTWIDGET_H
  2. #define SELECTWIDGET_H
  3. /**
  4. * 描点跟随窗体控件,并且增加了VisionPlus相关的业务逻辑
  5. * 1:可设置是否绘制描点
  6. * 2:可设置边距
  7. * 3:可设置描点颜色
  8. * 4:可设置描点尺寸
  9. * 5:可设置描点样式 正方形+圆形
  10. * 6:可设置选中边框宽度
  11. * 7:支持上下左右按键移动窗体
  12. * 8:支持delete键删除窗体
  13. * 9:支持八个描点改变窗体大小尺寸
  14. * 10:支持拖动窗体
  15. */
  16. #include "Common.h"
  17. #ifdef quc
  18. #if (QT_VERSION < QT_VERSION_CHECK(5,7,0))
  19. #include <QtDesigner/QDesignerExportWidget>
  20. #else
  21. #include <QtUiPlugin/QDesignerExportWidget>
  22. #endif
  23. class QDESIGNER_WIDGET_EXPORT SelectWidget : public QWidget
  24. #else
  25. class SelectWidget : public QWidget
  26. #endif
  27. {
  28. Q_OBJECT
  29. Q_ENUMS(PointStyle)
  30. Q_PROPERTY(bool drawPoint READ getDrawPoint WRITE setDrawPoint)
  31. Q_PROPERTY(int padding READ getPadding WRITE setPadding)
  32. Q_PROPERTY(int borderWidth READ getBorderWidth WRITE setBorderWidth)
  33. Q_PROPERTY(int pointSize READ getPointSize WRITE setPointSize)
  34. Q_PROPERTY(QColor pointColor READ getPointColor WRITE setPointColor)
  35. Q_PROPERTY(PointStyle pointStyle READ getPointStyle WRITE setPointStyle)
  36. public:
  37. enum class PointStyle {
  38. PointStyle_Rect = 0, //正方形
  39. PointStyle_Circle = 1 //圆形
  40. };
  41. explicit SelectWidget(QWidget *parent = 0);
  42. QWidget* widget; // 跟随的窗体
  43. VALUE_TYPE m_Type; // 增加:控件的类型
  44. CONTROL_PROPERTY* m_pProperty; // 增加:控件的属性
  45. CONTROL_PROPERTY_EX* m_pPropertyEx; // 2021-12-11 增加:控件的扩展属性(仅复杂控件才有)
  46. protected:
  47. bool eventFilter(QObject *watched, QEvent *event);
  48. void resizeEvent(QResizeEvent *);
  49. void mouseMoveEvent(QMouseEvent *);
  50. void paintEvent(QPaintEvent *);
  51. void drawRect(QPainter *painter);
  52. void drawCircle(QPainter *painter);
  53. void drawBorder(QPainter *painter);
  54. private:
  55. bool drawPoint; //绘制描点
  56. int padding; //窗体的边距
  57. int borderWidth; //边框宽度
  58. int pointSize; //描点的尺寸
  59. QColor pointColor; //描点的颜色
  60. PointStyle pointStyle; //描点的形状
  61. bool pressed; //鼠标按下
  62. bool pressedLeft; //鼠标按下左侧
  63. bool pressedRight; //鼠标按下右侧
  64. bool pressedTop; //鼠标按下上侧
  65. bool pressedBottom; //鼠标按下下侧
  66. bool pressedLeftTop; //鼠标按下左上侧
  67. bool pressedRightTop; //鼠标按下右上侧
  68. bool pressedLeftBottom; //鼠标按下左下侧
  69. bool pressedRightBottom; //鼠标按下右下侧
  70. int rectX, rectY, rectW, rectH; //窗体坐标+宽高
  71. QPoint lastPos; //鼠标按下处坐标
  72. // 2022-3-20 ,保存上一次的矩形区域位置,防止无效的矩形区域位置变动通知,提高效率
  73. QRectF oldGeometry;
  74. QRectF rectLeft; //左侧区域
  75. QRectF rectRight; //右侧区域
  76. QRectF rectTop; //上侧区域
  77. QRectF rectBottom; //下侧区域
  78. QRectF rectLeftTop; //左上侧区域
  79. QRectF rectRightTop; //右上侧区域
  80. QRectF rectLeftBottom; //左下侧区域
  81. QRectF rectRightBottom; //右下侧区域
  82. public:
  83. bool getDrawPoint() const;
  84. int getPadding() const;
  85. int getBorderWidth() const;
  86. int getPointSize() const;
  87. QColor getPointColor() const;
  88. PointStyle getPointStyle() const;
  89. QWidget *getWidget() const;
  90. QSize sizeHint() const;
  91. QSize minimumSizeHint() const;
  92. public Q_SLOTS:
  93. //设置是否绘制描点
  94. void setDrawPoint(bool drawPoint);
  95. //设置跟随窗体的边距
  96. void setPadding(int padding);
  97. //设置线条宽度
  98. void setBorderWidth(int borderWidth);
  99. //设置描点的尺寸
  100. void setPointSize(int pointSize);
  101. //设置描点的颜色
  102. void setPointColor(const QColor &pointColor);
  103. //设置描点的样式
  104. void setPointStyle(const PointStyle &pointStyle);
  105. // 设置绑定窗体以及本窗体的数据类型
  106. void setWidget(QWidget *widget);
  107. Q_SIGNALS:
  108. void widgetPressed(QWidget *widget);
  109. void widgetRelease(QWidget *widget);
  110. void widgetDelete(QWidget *widget);
  111. //// 2022-2-13 增加控件移动消息用于向属性表同步数值
  112. //void widgetMove(QWidget* widget);
  113. };
  114. #endif // SELECTWIDGET_H