sizehandle.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #ifndef SIZEHANDLE
  2. #define SIZEHANDLE
  3. #include <QGraphicsRectItem>
  4. #include <QList>
  5. QT_BEGIN_NAMESPACE
  6. class QFocusEvent;
  7. class QGraphicsItem;
  8. class QGraphicsScene;
  9. class QGraphicsSceneMouseEvent;
  10. QT_END_NAMESPACE
  11. enum { SELECTION_HANDLE_SIZE = 6, SELECTION_MARGIN = 10 };
  12. enum SelectionHandleState { SelectionHandleOff, SelectionHandleInactive, SelectionHandleActive };
  13. class SizeHandleRect :public QGraphicsRectItem
  14. {
  15. public:
  16. enum Direction { LeftTop , Top, RightTop, Right, RightBottom, Bottom, LeftBottom, Left , Center, None};
  17. SizeHandleRect(QGraphicsItem* parent , Direction d, QGraphicsItem *resizable);
  18. Direction dir() const { return m_dir; }
  19. void updateCursor();
  20. void setState(SelectionHandleState st);
  21. bool hitTest( const QPointF & point );
  22. void move(qreal x, qreal y );
  23. protected:
  24. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
  25. private:
  26. const Direction m_dir;
  27. QPoint m_startPos;
  28. QPoint m_curPos;
  29. QSize m_startSize;
  30. QSize m_curSize;
  31. QGraphicsItem *m_resizable;
  32. SelectionHandleState m_state;
  33. };
  34. #endif // SIZEHANDLE