QElectroTech  0.8-dev
partdynamictextfield.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 PARTDYNAMICTEXTFIELD_H
19 #define PARTDYNAMICTEXTFIELD_H
20 
21 #include "customelementpart.h"
22 #include "QGraphicsTextItem"
23 #include "dynamicelementtextitem.h"
24 
33 class PartDynamicTextField : public QGraphicsTextItem, public CustomElementPart
34 {
35  Q_OBJECT
36 
37  Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
39  Q_PROPERTY(QString infoName READ infoName WRITE setInfoName NOTIFY infoNameChanged)
40  Q_PROPERTY(QString compositeText READ compositeText WRITE setCompositeText NOTIFY compositeTextChanged)
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)
46 
47  public:
49  void setProperty(const char *name, const QVariant &value) override {QGraphicsTextItem::setProperty(name, value);}
50  QVariant property(const char *name) const override {return QGraphicsTextItem::property(name);}
51 
52  signals:
53  void taggChanged(QString tagg);
54  void textChanged(QString text);
56  void infoNameChanged(QString info);
57  void compositeTextChanged(QString text);
58  void colorChanged(QColor color);
59  void frameChanged(bool frame);
60  void textWidthChanged(qreal width);
61  void alignmentChanged(Qt::Alignment alignment);
62  void fontChanged(QFont font);
63 
64  public:
65  PartDynamicTextField(QETElementEditor *editor, QGraphicsItem *parent = nullptr);
66 
67  enum {Type = UserType + 1110};
68  int type() const override {return Type;}
69 
70  QString name() const override;
71  QString xmlName() const override;
72  static QString xmlTaggName() {return QString("dynamic_text");}
73  bool isUseless() const override {return false;}
74  QRectF sceneGeometricRect() const override {return sceneBoundingRect();}
75  void startUserTransformation(const QRectF &initial_selection_rect) override;
76  void handleUserTransformation(const QRectF &initial_selection_rect, const QRectF &new_selection_rect) override;
77 
78  const QDomElement toXml(QDomDocument &dom_doc) const override;
79  void fromXml(const QDomElement &dom_elmt) override;
80  void fromTextFieldXml(const QDomElement &dom_element);
81 
84  QString text() const;
85  void setText(const QString &text);
86  void setInfoName(const QString &info_name);
87  QString infoName() const;
88  void setCompositeText(const QString &text);
89  QString compositeText() const;
90  void setColor(const QColor& color);
91  QColor color() const;
92  void setFrame(bool frame);
93  bool frame() const;
94  void setTextWidth(qreal width);
95  void setPlainText(const QString &text);
96  void setAlignment(Qt::Alignment alignment);
97  Qt::Alignment alignment() const;
98  void setFont(const QFont &font);
99 
100  protected:
101  void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
102  void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
103  void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
104  QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
105  void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
106 
107  private:
108  void elementInfoChanged();
109  void prepareAlignment();
110  void finishAlignment();
111 
112  private:
113  QPointF m_origine_pos,
115  QString m_text,
119  QUuid m_uuid;
120  bool m_frame = false,
121  m_first_add = true,
123  qreal m_text_width = -1;
124  Qt::Alignment m_alignment = Qt::AlignTop|Qt::AlignLeft;
126 };
127 
128 #endif // PARTDYNAMICTEXTFIELD_H
QETApp::dynamicTextsItemFont
static QFont dynamicTextsItemFont(qreal=-1.0)
QETApp::dynamicTextsFont the default font of dynamic element text item.
Definition: qetapp.cpp:1169
PartDynamicTextField::m_block_alignment
bool m_block_alignment
Definition: partdynamictextfield.h:122
PartDynamicTextField::compositeTextChanged
void compositeTextChanged(QString text)
PartDynamicTextField::fromXml
void fromXml(const QDomElement &dom_elmt) override
PartDynamicTextField::fromXml.
Definition: partdynamictextfield.cpp:155
PartDynamicTextField::m_alignment_rect
QRectF m_alignment_rect
Definition: partdynamictextfield.h:125
PartDynamicTextField::m_info_name
QString m_info_name
Definition: partdynamictextfield.h:116
PartDynamicTextField::color
QColor color
Definition: partdynamictextfield.h:41
PartDynamicTextField::sceneGeometricRect
QRectF sceneGeometricRect() const override
Definition: partdynamictextfield.h:74
PartDynamicTextField::paint
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
Definition: partdynamictextfield.cpp:486
PartDynamicTextField::itemChange
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
PartDynamicTextField::itemChange.
Definition: partdynamictextfield.cpp:468
PartDynamicTextField::text
QString text
Definition: partdynamictextfield.h:37
PartDynamicTextField::m_composite_text
QString m_composite_text
Definition: partdynamictextfield.h:117
PartDynamicTextField::xmlTaggName
static QString xmlTaggName()
Definition: partdynamictextfield.h:72
PartDynamicTextField::name
QString name() const override
Definition: partdynamictextfield.cpp:52
PartDynamicTextField::setFrame
void setFrame(bool frame)
Definition: partdynamictextfield.cpp:361
PartDynamicTextField::elementInfoChanged
void elementInfoChanged()
PartDynamicTextField::elementInfoChanged Used to up to date this text field, when the element informa...
Definition: partdynamictextfield.cpp:535
PartDynamicTextField::m_text_width
qreal m_text_width
Definition: partdynamictextfield.h:123
PartDynamicTextField::textFrom
DynamicElementTextItem::TextFrom textFrom
Definition: partdynamictextfield.h:38
CustomElementPart::undoStack
virtual QUndoStack & undoStack() const
Definition: customelementpart.cpp:42
PartDynamicTextField::setTextWidth
void setTextWidth(qreal width)
Definition: partdynamictextfield.cpp:371
PartDynamicTextField::startUserTransformation
void startUserTransformation(const QRectF &initial_selection_rect) override
PartDynamicTextField::startUserTransformation.
Definition: partdynamictextfield.cpp:67
PartDynamicTextField::mousePressEvent
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
PartDynamicTextField::mousePressEvent.
Definition: partdynamictextfield.cpp:437
PartDynamicTextField::frameChanged
void frameChanged(bool frame)
PartDynamicTextField::compositeText
QString compositeText
Definition: partdynamictextfield.h:40
qetapp.h
PartDynamicTextField::infoName
QString infoName
Definition: partdynamictextfield.h:39
PartDynamicTextField::m_origine_pos
QPointF m_origine_pos
Definition: partdynamictextfield.h:113
autonum::AssignVariables::replaceVariable
static QString replaceVariable(const QString &formula, const DiagramContext &dc)
AssignVariables::replaceVariable Replace the variables in formula in form %{my-var} to the correspond...
Definition: assignvariables.cpp:208
PartDynamicTextField::fromTextFieldXml
void fromTextFieldXml(const QDomElement &dom_element)
PartDynamicTextField::fromTextFieldXml Setup this text from the xml definition of a text field (The x...
Definition: partdynamictextfield.cpp:225
PartDynamicTextField::finishAlignment
void finishAlignment()
Definition: partdynamictextfield.cpp:550
PartDynamicTextField::m_alignment
Qt::Alignment m_alignment
Definition: partdynamictextfield.h:124
PartDynamicTextField::setAlignment
void setAlignment(Qt::Alignment alignment)
Definition: partdynamictextfield.cpp:401
CustomElementPart::updateCurrentPartEditor
virtual void updateCurrentPartEditor() const
Definition: customelementpart.cpp:30
QET::correctAngle
qreal correctAngle(const qreal &)
Definition: qet.cpp:545
PartDynamicTextField::setPlainText
void setPlainText(const QString &text)
Definition: partdynamictextfield.cpp:382
PartDynamicTextField::textWidthChanged
void textWidthChanged(qreal width)
PartDynamicTextField
The PartDynamicTextField class This class represents an editable dynamic text field which may be used...
Definition: partdynamictextfield.h:34
PartDynamicTextField::alignmentChanged
void alignmentChanged(Qt::Alignment alignment)
PartDynamicTextField::setTextFrom
void setTextFrom(DynamicElementTextItem::TextFrom text_from)
PartDynamicTextField::setTextFrom Set the final text is created from.
Definition: partdynamictextfield.cpp:272
elementscene.h
PartDynamicTextField::property
QVariant property(const char *name) const override
Definition: partdynamictextfield.h:50
PartDynamicTextField::type
int type() const override
Definition: partdynamictextfield.h:68
DynamicElementTextItem::CompositeText
@ CompositeText
Definition: dynamicelementtextitem.h:58
qpropertyundocommand.h
PartDynamicTextField::isUseless
bool isUseless() const override
Definition: partdynamictextfield.h:73
PartDynamicTextField::xmlName
QString xmlName() const override
Definition: partdynamictextfield.cpp:56
DynamicElementTextItem::TextFrom
TextFrom
Definition: dynamicelementtextitem.h:55
DynamicElementTextItem::UserText
@ UserText
Definition: dynamicelementtextitem.h:56
ElementScene::elementInfoChanged
void elementInfoChanged()
PartDynamicTextField::mouseMoveEvent
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
PartDynamicTextField::mouseMoveEvent.
Definition: partdynamictextfield.cpp:424
PartDynamicTextField::m_uuid
QUuid m_uuid
Definition: partdynamictextfield.h:119
PartDynamicTextField::m_frame
bool m_frame
Definition: partdynamictextfield.h:120
PartDynamicTextField::setFont
void setFont(const QFont &font)
Definition: partdynamictextfield.cpp:410
PartDynamicTextField::m_saved_point
QPointF m_saved_point
Definition: partdynamictextfield.h:114
DynamicElementTextItem::textFromMetaEnum
static QMetaEnum textFromMetaEnum()
DynamicElementTextItem::textFromMetaEnum.
Definition: dynamicelementtextitem.cpp:72
QET::Icons::ro
QIcon ro
Definition: qeticons.cpp:200
PartDynamicTextField::fontChanged
void fontChanged(QFont font)
CustomElementPart
The CustomElementPart class This abstract class represents a primitive of the visual representation o...
Definition: customelementpart.h:40
CustomElementPart::elementScene
virtual ElementScene * elementScene() const
Definition: customelementpart.cpp:37
PartDynamicTextField::m_text_from
DynamicElementTextItem::TextFrom m_text_from
Definition: partdynamictextfield.h:118
CustomElementPart::mapPoints
QList< QPointF > mapPoints(const QRectF &, const QRectF &, const QList< QPointF > &)
Definition: customelementpart.cpp:69
PartDynamicTextField::textWidth
qreal textWidth
Definition: partdynamictextfield.h:43
QETApp::diagramTextsFont
static QFont diagramTextsFont(qreal=-1.0)
QETApp::diagramTextsFont The font to use By default the font is "sans Serif" and size 9.
Definition: qetapp.cpp:1111
PartDynamicTextField::font
QFont font
Definition: partdynamictextfield.h:45
PartDynamicTextField::m_first_add
bool m_first_add
Definition: partdynamictextfield.h:121
PartDynamicTextField::setText
void setText(const QString &text)
PartDynamicTextField::setText Set the text of this text.
Definition: partdynamictextfield.cpp:303
PartDynamicTextField::taggChanged
void taggChanged(QString tagg)
PartDynamicTextField::setInfoName
void setInfoName(const QString &info_name)
Definition: partdynamictextfield.cpp:309
PartDynamicTextField::m_text
QString m_text
Definition: partdynamictextfield.h:115
PartDynamicTextField::alignment
Qt::Alignment alignment
Definition: partdynamictextfield.h:44
PartDynamicTextField::PartDynamicTextField
PartDynamicTextField(QETElementEditor *editor, QGraphicsItem *parent=nullptr)
Definition: partdynamictextfield.cpp:27
PartDynamicTextField::prepareAlignment
void prepareAlignment()
Definition: partdynamictextfield.cpp:546
dynamicelementtextitem.h
PartDynamicTextField::colorChanged
void colorChanged(QColor color)
PartDynamicTextField::textFromChanged
void textFromChanged(DynamicElementTextItem::TextFrom text_from)
PartDynamicTextField::setCompositeText
void setCompositeText(const QString &text)
PartDynamicTextField::setCompositeText Set the composite text of this text item to text.
Definition: partdynamictextfield.cpp:329
PartDynamicTextField::setProperty
void setProperty(const char *name, const QVariant &value) override
PROPERTY.
Definition: partdynamictextfield.h:49
PartDynamicTextField::Type
@ Type
Definition: partdynamictextfield.h:67
QPropertyUndoCommand
The QPropertyUndoCommand class This undo command manage QProperty of a QObject. This undo command can...
Definition: qpropertyundocommand.h:34
PartDynamicTextField::frame
bool frame
Definition: partdynamictextfield.h:42
PartDynamicTextField::textChanged
void textChanged(QString text)
QET::Icons::tr
QIcon tr
Definition: qeticons.cpp:206
customelementpart.h
DynamicElementTextItem::ElementInfo
@ ElementInfo
Definition: dynamicelementtextitem.h:57
partdynamictextfield.h
PartDynamicTextField::handleUserTransformation
void handleUserTransformation(const QRectF &initial_selection_rect, const QRectF &new_selection_rect) override
PartDynamicTextField::handleUserTransformation.
Definition: partdynamictextfield.cpp:79
QETElementEditor
Definition: qetelementeditor.h:33
PartDynamicTextField::toXml
const QDomElement toXml(QDomDocument &dom_doc) const override
PartDynamicTextField::toXml.
Definition: partdynamictextfield.cpp:93
PartDynamicTextField::mouseReleaseEvent
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
PartDynamicTextField::mouseReleaseEvent.
Definition: partdynamictextfield.cpp:448
PartDynamicTextField::setColor
void setColor(const QColor &color)
PartDynamicTextField::setColor.
Definition: partdynamictextfield.cpp:348
PartDynamicTextField::infoNameChanged
void infoNameChanged(QString info)