GraphicsRectItem.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #pragma once
  2. #include "preheader.h"
  3. #include "GraphicsItem.h"
  4. class GraphicsRectItem : public GraphicsItem
  5. {
  6. public:
  7. GraphicsRectItem(const QRect & rect ,QGraphicsItem * parent);
  8. QRectF boundingRect() const;
  9. QPainterPath shape() const;
  10. void resetShape()
  11. {
  12. m_rect.setLeft(0);
  13. m_rect.setTop(0);
  14. m_rect.setWidth(abs(m_width));
  15. m_rect.setHeight(abs(m_height));
  16. updateGeometry();
  17. }
  18. void setBorderColor(QColor color)
  19. {
  20. m_color =color;
  21. }
  22. void setIsSquare()
  23. {
  24. m_isSquare =true;
  25. }
  26. virtual void resizeTo(SizeHandleRect::Direction dir, const QPointF & point );
  27. virtual QRectF rect() const {
  28. return
  29. QRectF( QPointF(m_rect.left(),m_rect.top()),
  30. QPointF(m_rect.right(), m_rect.bottom())) ;}
  31. protected:
  32. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
  33. protected:
  34. qreal m_width;
  35. qreal m_height;
  36. bool m_isSquare; //是否为正方形
  37. QColor m_color;
  38. };