QElectroTech 0.100.0-dev
Loading...
Searching...
No Matches
partdynamictextfield.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 PARTDYNAMICTEXTFIELD_H
19#define PARTDYNAMICTEXTFIELD_H
20
21#include "../../qetgraphicsitem/dynamicelementtextitem.h"
22#include "QGraphicsTextItem"
23#include "customelementpart.h"
24
33class PartDynamicTextField : public QGraphicsTextItem, public CustomElementPart
34{
35 Q_OBJECT
36
37 Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
38 Q_PROPERTY(DynamicElementTextItem::TextFrom textFrom READ textFrom WRITE setTextFrom NOTIFY textFromChanged)
39 Q_PROPERTY(QString infoName READ infoName WRITE setInfoName NOTIFY infoNameChanged)
41 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
42 Q_PROPERTY(bool frame READ frame WRITE setFrame NOTIFY frameChanged)
43 Q_PROPERTY(qreal textWidth READ textWidth WRITE setTextWidth NOTIFY textWidthChanged)
44 Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
45 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
47
48 public:
50 void setProperty(const char *name, const QVariant &value) override {QGraphicsTextItem::setProperty(name, value);}
51 QVariant property(const char *name) const override {return QGraphicsTextItem::property(name);}
52
53 signals:
54 void taggChanged(QString tagg);
55 void textChanged(QString text);
57 void infoNameChanged(QString info);
59 void colorChanged(QColor color);
60 void frameChanged(bool frame);
61 void textWidthChanged(qreal width);
62 void alignmentChanged(Qt::Alignment alignment);
63 void fontChanged(QFont font);
65
66 public:
67 PartDynamicTextField(QETElementEditor *editor, QGraphicsItem *parent = nullptr);
68
69 enum {Type = UserType + 1110};
70 int type() const override {return Type;}
71
72 QString name() const override;
73 QString xmlName() const override;
74 static QString xmlTaggName() {return QString("dynamic_text");}
75 bool isUseless() const override {return false;}
76 QRectF sceneGeometricRect() const override {return sceneBoundingRect();}
77 void startUserTransformation(const QRectF &initial_selection_rect) override;
78 void handleUserTransformation(const QRectF &initial_selection_rect, const QRectF &new_selection_rect) override;
79
80 const QDomElement toXml(QDomDocument &dom_doc) const override;
81 void fromXml(const QDomElement &dom_elmt) override;
82 void fromTextFieldXml(const QDomElement &dom_element);
83
86 QString text() const;
87 void setText(const QString &text);
88 void setInfoName(const QString &info_name);
89 QString infoName() const;
90 void setCompositeText(const QString &text);
91 QString compositeText() const;
92 void setColor(const QColor& color);
93 QColor color() const;
94 void setFrame(bool frame);
95 bool frame() const;
96 void setTextWidth(qreal width);
97 void setPlainText(const QString &text);
98 void setAlignment(Qt::Alignment alignment);
99 Qt::Alignment alignment() const;
100 void setFont(const QFont &font);
101 void setKeepVisualRotation(const bool &keep);
102 bool keepVisualRotation() const;
103
104 protected:
105 void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
106 void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
107 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
108 QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
109 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
110
111 private:
112 void elementInfoChanged();
113 void prepareAlignment();
114 void finishAlignment();
115
116 private:
119 QString m_text,
123 QUuid m_uuid;
124 bool m_frame = false,
128 qreal m_text_width = -1;
129 Qt::Alignment m_alignment = Qt::AlignTop|Qt::AlignLeft;
131};
132
133#endif // PARTDYNAMICTEXTFIELD_H
The CustomElementPart class This abstract class represents a primitive of the visual representation o...
Definition customelementpart.h:40
The DynamicElementTextItem class This class provide a simple text field of element who can be added o...
Definition dynamicelementtextitem.h:40
TextFrom
Definition dynamicelementtextitem.h:57
@ UserText
Definition dynamicelementtextitem.h:58
The PartDynamicTextField class This class represents an editable dynamic text field which may be used...
Definition partdynamictextfield.h:34
qreal textWidth
Definition partdynamictextfield.h:43
QString compositeText
Definition partdynamictextfield.h:40
void fromTextFieldXml(const QDomElement &dom_element)
PartDynamicTextField::fromTextFieldXml Setup this text from the xml definition of a text field (The x...
Definition partdynamictextfield.cpp:240
QString infoName
Definition partdynamictextfield.h:39
QVariant property(const char *name) const override
Definition partdynamictextfield.h:51
Qt::Alignment alignment
Definition partdynamictextfield.h:44
QFont font
Definition partdynamictextfield.h:45
void alignmentChanged(Qt::Alignment alignment)
static QString xmlTaggName()
Definition partdynamictextfield.h:74
void colorChanged(QColor color)
QPointF m_origine_pos
Definition partdynamictextfield.h:117
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
PartDynamicTextField::mouseMoveEvent.
Definition partdynamictextfield.cpp:459
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
Definition partdynamictextfield.cpp:521
void setCompositeText(const QString &text)
PartDynamicTextField::setCompositeText Set the composite text of this text item to text.
Definition partdynamictextfield.cpp:346
bool isUseless() const override
Definition partdynamictextfield.h:75
void infoNameChanged(QString info)
void elementInfoChanged()
PartDynamicTextField::elementInfoChanged Used to up to date this text field, when the element informa...
Definition partdynamictextfield.cpp:570
void handleUserTransformation(const QRectF &initial_selection_rect, const QRectF &new_selection_rect) override
PartDynamicTextField::handleUserTransformation.
Definition partdynamictextfield.cpp:82
QString name() const override
Definition partdynamictextfield.cpp:53
void setAlignment(Qt::Alignment alignment)
Definition partdynamictextfield.cpp:421
void setText(const QString &text)
PartDynamicTextField::setText Set the text of this text.
Definition partdynamictextfield.cpp:320
QUuid m_uuid
Definition partdynamictextfield.h:123
void prepareAlignment()
Definition partdynamictextfield.cpp:582
DynamicElementTextItem::TextFrom textFrom
Definition partdynamictextfield.h:38
DynamicElementTextItem::TextFrom m_text_from
Definition partdynamictextfield.h:122
bool keepVisualRotation
Definition partdynamictextfield.h:46
void setTextWidth(qreal width)
Definition partdynamictextfield.cpp:391
void keepVisualRotationChanged(bool keep)
int type() const override
Definition partdynamictextfield.h:70
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
PartDynamicTextField::mousePressEvent.
Definition partdynamictextfield.cpp:472
QString xmlName() const override
Definition partdynamictextfield.cpp:58
qreal m_text_width
Definition partdynamictextfield.h:128
void setFrame(bool frame)
Definition partdynamictextfield.cpp:380
bool m_keep_visual_rotation
Definition partdynamictextfield.h:127
void taggChanged(QString tagg)
void setFont(const QFont &font)
Definition partdynamictextfield.cpp:431
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
PartDynamicTextField::itemChange.
Definition partdynamictextfield.cpp:503
void startUserTransformation(const QRectF &initial_selection_rect) override
PartDynamicTextField::startUserTransformation.
Definition partdynamictextfield.cpp:70
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
PartDynamicTextField::mouseReleaseEvent.
Definition partdynamictextfield.cpp:483
QString m_text
Definition partdynamictextfield.h:119
void textWidthChanged(qreal width)
void setPlainText(const QString &text)
Definition partdynamictextfield.cpp:402
void setKeepVisualRotation(const bool &keep)
Definition partdynamictextfield.cpp:441
void textFromChanged(DynamicElementTextItem::TextFrom text_from)
bool m_first_add
Definition partdynamictextfield.h:125
const QDomElement toXml(QDomDocument &dom_doc) const override
PartDynamicTextField::toXml.
Definition partdynamictextfield.cpp:96
void compositeTextChanged(QString text)
QString m_info_name
Definition partdynamictextfield.h:120
void setTextFrom(DynamicElementTextItem::TextFrom text_from)
PartDynamicTextField::setTextFrom Set the final text is created from.
Definition partdynamictextfield.cpp:288
QRectF m_alignment_rect
Definition partdynamictextfield.h:130
void setProperty(const char *name, const QVariant &value) override
PROPERTY.
Definition partdynamictextfield.h:50
QRectF sceneGeometricRect() const override
Definition partdynamictextfield.h:76
bool m_block_alignment
Definition partdynamictextfield.h:126
void textChanged(QString text)
Qt::Alignment m_alignment
Definition partdynamictextfield.h:129
void finishAlignment()
Definition partdynamictextfield.cpp:587
void fontChanged(QFont font)
QString text
Definition partdynamictextfield.h:37
@ Type
Definition partdynamictextfield.h:69
void fromXml(const QDomElement &dom_elmt) override
PartDynamicTextField::fromXml.
Definition partdynamictextfield.cpp:160
QString m_composite_text
Definition partdynamictextfield.h:121
bool m_frame
Definition partdynamictextfield.h:124
bool frame
Definition partdynamictextfield.h:42
void setColor(const QColor &color)
PartDynamicTextField::setColor.
Definition partdynamictextfield.cpp:366
void frameChanged(bool frame)
QPointF m_saved_point
Definition partdynamictextfield.h:118
QColor color
Definition partdynamictextfield.h:41
void setInfoName(const QString &info_name)
Definition partdynamictextfield.cpp:326
Definition qetelementeditor.h:39