CRectItem.cpp 804 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. }
  16. int CRectItem::cornerRadius() const
  17. {
  18. return m_cornerRadius;
  19. }
  20. void CRectItem::setCornerRadius(qreal radius)
  21. {
  22. m_cornerRadius = radius;
  23. updatePath();
  24. }
  25. void CRectItem::updatePath()
  26. {
  27. QPainterPath path;
  28. path.addRoundedRect(m_rect, m_cornerRadius, m_cornerRadius);
  29. setPath(path);
  30. }
  31. void CRectItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
  32. {
  33. qDebug() << __FUNCTION__ << __LINE__ << event << endl;
  34. }