CTextItem.h 1010 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #ifndef CTEXTITEM_H
  2. #define CTEXTITEM_H
  3. #include <QGraphicsTextItem>
  4. class CTextItem : public QGraphicsTextItem
  5. {
  6. Q_OBJECT
  7. public:
  8. explicit CTextItem(QGraphicsItem *parent = nullptr);
  9. explicit CTextItem(const QString &text = QString(), QGraphicsItem *parent = nullptr);
  10. virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
  11. void keyPressEvent(QKeyEvent *event) override;
  12. void beginEditing();
  13. void endEditing();
  14. bool isEditing() const;
  15. bool allowEdit() const;
  16. void setAllowEdit(bool a);
  17. static QSizeF textSize(const QString t, qreal width = -1);
  18. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
  19. public slots:
  20. void slotTextChanged();
  21. void slotTextChange(int from, int charsRemoved, int charsAdded);
  22. signals:
  23. void sigWillBeginEditing();
  24. void sigTextChanged();
  25. private:
  26. bool m_allowEdit = true;
  27. bool m_textChanged = false;
  28. };
  29. #endif // CTEXTITEM_H