CRectItem.cpp 822 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include "CRectItem.h"
  2. #include <QDebug>
  3. CRectItem::CRectItem(QGraphicsItem *parent) : CRectItem(QRectF(), parent) { }
  4. CRectItem::CRectItem(const QRectF &rect, QGraphicsItem *parent) : CPathItem(parent), m_rect(rect)
  5. {
  6. updatePath();
  7. }
  8. QRectF CRectItem::rect() const
  9. {
  10. return m_rect;
  11. }
  12. void CRectItem::setRect(const QRectF &rect)
  13. {
  14. m_rect = rect;
  15. updatePath();
  16. }
  17. int CRectItem::cornerRadius() const
  18. {
  19. return m_cornerRadius;
  20. }
  21. void CRectItem::setCornerRadius(qreal radius)
  22. {
  23. m_cornerRadius = radius;
  24. updatePath();
  25. }
  26. void CRectItem::updatePath()
  27. {
  28. QPainterPath path;
  29. path.addRoundedRect(m_rect, m_cornerRadius, m_cornerRadius);
  30. setPath(path);
  31. }
  32. void CRectItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
  33. {
  34. qDebug() << __FUNCTION__ << __LINE__ << event << endl;
  35. }