QElectroTech  0.8-dev
diagramtextitem.h
Go to the documentation of this file.
1 /*
2  Copyright 2006-2020 The QElectroTech Team
3  This file is part of QElectroTech.
4 
5  QElectroTech is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 2 of the License, or
8  (at your option) any later version.
9 
10  QElectroTech is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef DIAGRAM_TEXT_ITEM_H
19 #define DIAGRAM_TEXT_ITEM_H
20 
21 #include <QGraphicsTextItem>
22 #include <QFont>
23 
24 class Diagram;
25 class QDomElement;
26 class QDomDocument;
27 
33 class DiagramTextItem : public QGraphicsTextItem
34 {
35  Q_OBJECT
36 
37  Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
38  Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
39  Q_PROPERTY(QString plainText READ toPlainText WRITE setPlainText)
40  Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
41 
42 
43  signals:
44  void colorChanged(QColor color);
45  void alignmentChanged(Qt::Alignment alignment);
46  void textEdited(const QString &old_str, const QString &new_str);
47  void fontChanged(QFont font);
48 
49  public:
50  DiagramTextItem(QGraphicsItem * = nullptr);
51  DiagramTextItem(const QString &, QGraphicsItem * = nullptr);
52 
53  private:
54  void build();
55 
56  public:
57  enum { Type = UserType + 1004 };
58  int type() const override { return Type; }
59 
60  Diagram *diagram() const;
61  virtual void fromXml(const QDomElement &) = 0;
62  virtual QDomElement toXml(QDomDocument &) const;
63  void edit();
64 
65  QPointF mapMovementToScene (const QPointF &) const;
66  QPointF mapMovementFromScene (const QPointF &) const;
67  QPointF mapMovementToParent (const QPointF &) const;
68  QPointF mapMovementFromParent (const QPointF &) const;
69 
70  void setFont(const QFont &font);
71 
72  void setColor(const QColor& color);
73  QColor color() const;
74 
75  void setNoEditable(bool e = true) {m_no_editable = e;}
76 
77  void setAlignment(const Qt::Alignment &alignment);
78  Qt::Alignment alignment() const;
79  bool m_block_alignment = false;
80 
81  QRectF frameRect() const;
82 
83  void setHtml(const QString &text);
84  void setPlainText(const QString &text);
85  bool isHtml() const;
86 
87  protected:
88  void paint(QPainter *,
89  const QStyleOptionGraphicsItem *,
90  QWidget *) override;
91  void focusInEvent(QFocusEvent *) override;
92  void focusOutEvent(QFocusEvent *) override;
93 
94  void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event) override;
95  void mousePressEvent (QGraphicsSceneMouseEvent *event) override;
96  void mouseMoveEvent (QGraphicsSceneMouseEvent *event) override;
97  void mouseReleaseEvent (QGraphicsSceneMouseEvent *event) override;
98 
99  void hoverEnterEvent(QGraphicsSceneHoverEvent *) override;
100  void hoverLeaveEvent(QGraphicsSceneHoverEvent *) override;
101  void hoverMoveEvent(QGraphicsSceneHoverEvent *) override;
102 
103  virtual void applyRotation(const qreal &);
104  void prepareAlignment();
105  void finishAlignment();
106 
107 
108  protected:
109  bool
110  m_mouse_hover = false,
111  m_first_move = true,
113  m_is_html = false;
114 
115  QString
118 
120 
121  private:
123  Qt::Alignment m_alignment = (Qt::AlignTop | Qt::AlignLeft);
124 };
125 #endif
ElementsMover::beginMovement
int beginMovement(Diagram *, QGraphicsItem *=nullptr)
ElementsMover::beginMovement Start a new movement.
Definition: elementsmover.cpp:65
DiagramTextItem::fromXml
virtual void fromXml(const QDomElement &)=0
DiagramTextItem::hoverLeaveEvent
void hoverLeaveEvent(QGraphicsSceneHoverEvent *) override
Definition: diagramtextitem.cpp:486
DiagramTextItem::m_is_html
bool m_is_html
Definition: diagramtextitem.h:113
DiagramTextItem::Type
@ Type
Definition: diagramtextitem.h:57
qdesigner_internal::RichTextEditorDialog
Definition: richtexteditor_p.h:71
DiagramTextItem::m_alignment
Qt::Alignment m_alignment
Definition: diagramtextitem.h:123
DiagramTextItem::mousePressEvent
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
DiagramTextItem::mousePressEvent.
Definition: diagramtextitem.cpp:319
diagramcommands.h
DiagramTextItem::type
int type() const override
Definition: diagramtextitem.h:58
DiagramTextItem::build
void build()
DiagramTextItem::build Build this item with default value.
Definition: diagramtextitem.cpp:47
DiagramTextItem::plainText
QString plainText
Definition: diagramtextitem.h:39
DiagramTextItem::focusInEvent
void focusInEvent(QFocusEvent *) override
DiagramTextItem::focusInEvent.
Definition: diagramtextitem.cpp:267
DiagramTextItem::m_mouse_hover
bool m_mouse_hover
Definition: diagramtextitem.h:110
DiagramTextItem::mouseMoveEvent
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
DiagramTextItem::mouseMoveEvent.
Definition: diagramtextitem.cpp:334
DiagramTextItem::diagram
Diagram * diagram() const
DiagramTextItem::diagram.
Definition: diagramtextitem.cpp:63
DiagramTextItem::m_mouse_to_origin_movement
QPointF m_mouse_to_origin_movement
Definition: diagramtextitem.h:119
DiagramTextItem::mapMovementToParent
QPointF mapMovementToParent(const QPointF &) const
Definition: diagramtextitem.cpp:121
DiagramTextItem::color
QColor color
Definition: diagramtextitem.h:37
richtexteditor_p.h
DiagramTextItem::setPlainText
void setPlainText(const QString &text)
Definition: diagramtextitem.cpp:218
DiagramTextItem::setHtml
void setHtml(const QString &text)
Definition: diagramtextitem.cpp:212
ElementsMover::endMovement
void endMovement()
ElementsMover::endMovement Ended the current movement by creating an undo added to the undostack of t...
Definition: elementsmover.cpp:150
DiagramTextItem::m_previous_text
QString m_previous_text
Definition: diagramtextitem.h:117
DiagramTextItem::applyRotation
virtual void applyRotation(const qreal &)
Definition: diagramtextitem.cpp:392
DiagramTextItem::colorChanged
void colorChanged(QColor color)
DiagramTextItem::alignment
Qt::Alignment alignment
Definition: diagramtextitem.h:38
DiagramTextItem::mapMovementFromScene
QPointF mapMovementFromScene(const QPointF &) const
Definition: diagramtextitem.cpp:102
qetapp.h
DiagramTextItem::m_block_alignment
bool m_block_alignment
Definition: diagramtextitem.h:79
ElementsMover::continueMovement
void continueMovement(const QPointF &)
ElementsMover::continueMovement Add a move to the current movement.
Definition: elementsmover.cpp:112
Diagram
The Diagram class This class represents an electric diagram. It manages its various child elements,...
Definition: diagram.h:56
DiagramTextItem::mapMovementToScene
QPointF mapMovementToScene(const QPointF &) const
Definition: diagramtextitem.cpp:83
DiagramTextItem::m_first_move
bool m_first_move
Definition: diagramtextitem.h:111
QET::correctAngle
qreal correctAngle(const qreal &)
Definition: qet.cpp:545
DiagramTextItem::mouseReleaseEvent
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
DiagramTextItem::mouseReleaseEvent.
Definition: diagramtextitem.cpp:365
DiagramTextItem::m_no_editable
bool m_no_editable
Definition: diagramtextitem.h:112
DiagramTextItem::setAlignment
void setAlignment(const Qt::Alignment &alignment)
Definition: diagramtextitem.cpp:177
DiagramTextItem::hoverMoveEvent
void hoverMoveEvent(QGraphicsSceneHoverEvent *) override
Definition: diagramtextitem.cpp:496
DiagramTextItem::fontChanged
void fontChanged(QFont font)
DiagramTextItem::toXml
virtual QDomElement toXml(QDomDocument &) const
DiagramTextItem::toXml This method do nothing and return an empty DomElement This is used to be inher...
Definition: diagramtextitem.cpp:73
DiagramTextItem::setColor
void setColor(const QColor &color)
Definition: diagramtextitem.cpp:167
qdesigner_internal::RichTextEditorDialog::applyEditText
void applyEditText(const QString &)
DiagramTextItem::finishAlignment
void finishAlignment()
DiagramTextItem::finishAlignment Call this function after changing the bouding rect of this text to s...
Definition: diagramtextitem.cpp:410
DiagramTextItem::paint
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override
DiagramTextItem::paint Draw this text field. This method draw the text by calling QGraphicsTextItem::...
Definition: diagramtextitem.cpp:236
DiagramTextItem
Definition: diagramtextitem.h:34
DiagramTextItem::m_previous_html_text
QString m_previous_html_text
Definition: diagramtextitem.h:116
DiagramTextItem::focusOutEvent
void focusOutEvent(QFocusEvent *) override
DiagramTextItem::focusOutEvent.
Definition: diagramtextitem.cpp:281
DiagramTextItem::mapMovementFromParent
QPointF mapMovementFromParent(const QPointF &) const
Definition: diagramtextitem.cpp:140
DiagramTextItem::isHtml
bool isHtml() const
Definition: diagramtextitem.cpp:224
QETApp::diagramTextsItemFont
static QFont diagramTextsItemFont(qreal=-1.0)
QETApp::diagramTextsItemFont the font for to use in independent text item.
Definition: qetapp.cpp:1137
DiagramTextItem::edit
void edit()
Edit the text with HtmlEditor.
Definition: diagramtextitem.cpp:453
DiagramTextItem::alignmentChanged
void alignmentChanged(Qt::Alignment alignment)
DiagramTextItem::mouseDoubleClickEvent
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override
Definition: diagramtextitem.cpp:303
Diagram::elementsMover
ElementsMover & elementsMover()
Diagram::elementsMover.
Definition: diagram.cpp:2057
DiagramTextItem::setNoEditable
void setNoEditable(bool e=true)
Definition: diagramtextitem.h:75
DiagramTextItem::setFont
void setFont(const QFont &font)
Definition: diagramtextitem.cpp:153
DiagramTextItem::prepareAlignment
void prepareAlignment()
DiagramTextItem::prepareAlignment Call this function before changing the bounding rect of this text.
Definition: diagramtextitem.cpp:400
diagramtextitem.h
Diagram::snapToGrid
static QPointF snapToGrid(const QPointF &p)
Diagram::snapToGrid Return a nearest snap point of p.
Definition: diagram.cpp:2240
DiagramTextItem::DiagramTextItem
DiagramTextItem(QGraphicsItem *=nullptr)
DiagramTextItem::DiagramTextItem.
Definition: diagramtextitem.cpp:28
DiagramTextItem::frameRect
QRectF frameRect() const
DiagramTextItem::frameRect.
Definition: diagramtextitem.cpp:192
DiagramTextItem::font
QFont font
Definition: diagramtextitem.h:40
DiagramTextItem::hoverEnterEvent
void hoverEnterEvent(QGraphicsSceneHoverEvent *) override
Definition: diagramtextitem.cpp:472
QET::Icons::tr
QIcon tr
Definition: qeticons.cpp:206
DiagramTextItem::m_alignment_rect
QRectF m_alignment_rect
Definition: diagramtextitem.h:122
diagram.h
DiagramTextItem::textEdited
void textEdited(const QString &old_str, const QString &new_str)
qdesigner_internal::RichTextEditorDialog::setText
void setText(const QString &text)
Definition: richtexteditor.cpp:875