QElectroTech 0.100.0-dev
Loading...
Searching...
No Matches
diagramtextitem.h
Go to the documentation of this file.
1/*
2 Copyright 2006-2024 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
24class Diagram;
25class QDomElement;
26class QDomDocument;
27
33class 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
113 m_is_html = false;
114
115 QString
118
120
121 private:
123 Qt::Alignment m_alignment = (Qt::AlignTop | Qt::AlignLeft);
124};
125#endif
The Diagram class This class represents an electric diagram. It manages its various child elements,...
Definition diagram.h:56
Definition diagramtextitem.h:34
void fontChanged(QFont font)
QString m_previous_html_text
Definition diagramtextitem.h:116
QPointF mapMovementFromParent(const QPointF &) const
Definition diagramtextitem.cpp:146
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
DiagramTextItem::mouseReleaseEvent.
Definition diagramtextitem.cpp:374
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:75
void hoverLeaveEvent(QGraphicsSceneHoverEvent *) override
Definition diagramtextitem.cpp:495
bool isHtml() const
Definition diagramtextitem.cpp:232
bool m_first_move
Definition diagramtextitem.h:111
virtual void fromXml(const QDomElement &)=0
QPointF mapMovementToScene(const QPointF &) const
Definition diagramtextitem.cpp:86
void build()
DiagramTextItem::build Build this item with default value.
Definition diagramtextitem.cpp:48
QPointF m_mouse_to_origin_movement
Definition diagramtextitem.h:119
void colorChanged(QColor color)
int type() const override
Definition diagramtextitem.h:58
QColor color
Definition diagramtextitem.h:37
void focusInEvent(QFocusEvent *) override
DiagramTextItem::focusInEvent.
Definition diagramtextitem.cpp:276
void setColor(const QColor &color)
Definition diagramtextitem.cpp:174
void edit()
Edit the text with HtmlEditor.
Definition diagramtextitem.cpp:462
void finishAlignment()
DiagramTextItem::finishAlignment Call this function after changing the bounding rect of this text to ...
Definition diagramtextitem.cpp:419
void prepareAlignment()
DiagramTextItem::prepareAlignment Call this function before changing the bounding rect of this text.
Definition diagramtextitem.cpp:409
QPointF mapMovementFromScene(const QPointF &) const
Definition diagramtextitem.cpp:106
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override
Definition diagramtextitem.cpp:312
void setHtml(const QString &text)
Definition diagramtextitem.cpp:220
virtual void applyRotation(const qreal &)
Definition diagramtextitem.cpp:401
bool m_no_editable
Definition diagramtextitem.h:112
bool m_mouse_hover
Definition diagramtextitem.h:110
@ Type
Definition diagramtextitem.h:57
QRectF frameRect() const
DiagramTextItem::frameRect.
Definition diagramtextitem.cpp:200
QFont font
Definition diagramtextitem.h:40
void hoverEnterEvent(QGraphicsSceneHoverEvent *) override
Definition diagramtextitem.cpp:481
QRectF m_alignment_rect
Definition diagramtextitem.h:122
QString plainText
Definition diagramtextitem.h:39
QString m_previous_text
Definition diagramtextitem.h:117
void setFont(const QFont &font)
Definition diagramtextitem.cpp:160
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
DiagramTextItem::mousePressEvent.
Definition diagramtextitem.cpp:328
void textEdited(const QString &old_str, const QString &new_str)
void focusOutEvent(QFocusEvent *) override
DiagramTextItem::focusOutEvent.
Definition diagramtextitem.cpp:290
void setAlignment(const Qt::Alignment &alignment)
Definition diagramtextitem.cpp:185
void alignmentChanged(Qt::Alignment alignment)
Qt::Alignment alignment
Definition diagramtextitem.h:38
bool m_block_alignment
Definition diagramtextitem.h:79
QPointF mapMovementToParent(const QPointF &) const
Definition diagramtextitem.cpp:126
void setPlainText(const QString &text)
Definition diagramtextitem.cpp:226
void hoverMoveEvent(QGraphicsSceneHoverEvent *) override
Definition diagramtextitem.cpp:505
Qt::Alignment m_alignment
Definition diagramtextitem.h:123
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override
DiagramTextItem::paint Draw this text field. This method draws the text by calling QGraphicsTextItem:...
Definition diagramtextitem.cpp:245
Diagram * diagram() const
DiagramTextItem::diagram.
Definition diagramtextitem.cpp:64
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
DiagramTextItem::mouseMoveEvent.
Definition diagramtextitem.cpp:343
void setNoEditable(bool e=true)
Definition diagramtextitem.h:75
bool m_is_html
Definition diagramtextitem.h:113