QElectroTech  0.70
partdynamictextfield.h
Go to the documentation of this file.
1 /*
2  Copyright 2006-2019 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 
32 class PartDynamicTextField : public QGraphicsTextItem, public CustomElementPart
33 {
34  Q_OBJECT
35 
36  Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
37  Q_PROPERTY(DynamicElementTextItem::TextFrom textFrom READ textFrom WRITE setTextFrom NOTIFY textFromChanged)
38  Q_PROPERTY(QString infoName READ infoName WRITE setInfoName NOTIFY infoNameChanged)
39  Q_PROPERTY(QString compositeText READ compositeText WRITE setCompositeText NOTIFY compositeTextChanged)
40  Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
41  Q_PROPERTY(bool frame READ frame WRITE setFrame NOTIFY frameChanged)
42  Q_PROPERTY(qreal textWidth READ textWidth WRITE setTextWidth NOTIFY textWidthChanged)
43  Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
44  Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
45 
46  public:
48  void setProperty(const char *name, const QVariant &value) override {QGraphicsTextItem::setProperty(name, value);}
49  QVariant property(const char *name) const override {return QGraphicsTextItem::property(name);}
50 
51  signals:
52  void taggChanged(QString tagg);
53  void textChanged(QString text);
55  void infoNameChanged(QString info);
56  void compositeTextChanged(QString text);
57  void colorChanged(QColor color);
58  void frameChanged(bool frame);
59  void textWidthChanged(qreal width);
60  void alignmentChanged(Qt::Alignment alignment);
61  void fontChanged(QFont font);
62 
63  public:
64  PartDynamicTextField(QETElementEditor *editor, QGraphicsItem *parent = nullptr);
65 
66  enum {Type = UserType + 1110};
67  int type() const override {return Type;}
68 
69  QString name() const override;
70  QString xmlName() const override;
71  static QString xmlTaggName() {return QString("dynamic_text");}
72  bool isUseless() const override {return false;}
73  QRectF sceneGeometricRect() const override {return sceneBoundingRect();}
74  void startUserTransformation(const QRectF &initial_selection_rect) override;
75  void handleUserTransformation(const QRectF &initial_selection_rect, const QRectF &new_selection_rect) override;
76 
77  const QDomElement toXml(QDomDocument &dom_doc) const override;
78  void fromXml(const QDomElement &dom_elmt) override;
79  void fromTextFieldXml(const QDomElement &dom_element);
80 
83  QString text() const;
84  void setText(const QString &text);
85  void setInfoName(const QString &info_name);
86  QString infoName() const;
87  void setCompositeText(const QString &text);
88  QString compositeText() const;
89  void setColor(const QColor& color);
90  QColor color() const;
91  void setFrame(bool frame);
92  bool frame() const;
93  void setTextWidth(qreal width);
94  void setPlainText(const QString &text);
95  void setAlignment(Qt::Alignment alignment);
96  Qt::Alignment alignment() const;
97  void setFont(const QFont &font);
98 
99  protected:
100  void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
101  void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
102  void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
103  QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
104  void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
105 
106  private:
107  void elementInfoChanged();
108 
109  void prepareAlignment();
110  void finishAlignment();
111 
112  private:
113  QPointF m_origine_pos,
115  QString m_text,
116  m_info_name,
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
void setInfoName(const QString &info_name)
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
PartDynamicTextField::itemChange.
The DynamicElementTextItem class This class provide a simple text field of element who can be added o...
void setFont(const QFont &font)
DynamicElementTextItem::TextFrom textFrom() const
void setTextWidth(qreal width)
void handleUserTransformation(const QRectF &initial_selection_rect, const QRectF &new_selection_rect) override
PartDynamicTextField::handleUserTransformation.
void compositeTextChanged(QString text)
void colorChanged(QColor color)
void setColor(const QColor &color)
PartDynamicTextField::setColor.
static QString xmlTaggName()
Qt::Alignment alignment() const
QString xmlName() const override
The PartDynamicTextField class This class represents an editable dynamic text field which may be used...
void textChanged(QString text)
void fromTextFieldXml(const QDomElement &dom_element)
PartDynamicTextField::fromTextFieldXml Setup this text from the xml definition of a text field (The x...
void setAlignment(Qt::Alignment alignment)
void setTextFrom(DynamicElementTextItem::TextFrom text_from)
PartDynamicTextField::setTextFrom Set the final text is created from.
QRectF sceneGeometricRect() const override
void setText(const QString &text)
PartDynamicTextField::setText Set the text of this text.
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
PartDynamicTextField::mousePressEvent.
bool frame() const
void fontChanged(QFont font)
void fromXml(const QDomElement &dom_elmt) override
PartDynamicTextField::fromXml.
void setCompositeText(const QString &text)
PartDynamicTextField::setCompositeText Set the composite text of this text item to ...
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
void alignmentChanged(Qt::Alignment alignment)
void textWidthChanged(qreal width)
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
PartDynamicTextField::mouseMoveEvent.
DynamicElementTextItem::TextFrom m_text_from
void taggChanged(QString tagg)
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
PartDynamicTextField::mouseReleaseEvent.
void textFromChanged(DynamicElementTextItem::TextFrom text_from)
void setPlainText(const QString &text)
int type() const override
void infoNameChanged(QString info)
void elementInfoChanged()
PartDynamicTextField::elementInfoChanged Used to up to date this text field, when the element informa...
PartDynamicTextField(QETElementEditor *editor, QGraphicsItem *parent=nullptr)
void setProperty(const char *name, const QVariant &value) override
PROPERTY.
QString infoName() const
QColor color() const
QString text() const
QString compositeText() const
bool isUseless() const override
QVariant property(const char *name) const override
void frameChanged(bool frame)
void startUserTransformation(const QRectF &initial_selection_rect) override
PartDynamicTextField::startUserTransformation.
QString name() const override
const QDomElement toXml(QDomDocument &dom_doc) const override
PartDynamicTextField::toXml.