QElectroTech  0.8-dev
parttext.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 PART_TEXT_H
19 #define PART_TEXT_H
20 #include <QtWidgets>
21 #include "customelementpart.h"
22 #include "qetapp.h"
23 
24 class TextEditor;
30 class PartText : public QGraphicsTextItem, public CustomElementPart {
31  Q_OBJECT
32  Q_PROPERTY(qreal real_size READ realSize WRITE setRealSize)
33  Q_PROPERTY(QColor color READ defaultTextColor WRITE setDefaultTextColor NOTIFY colorChanged)
34  Q_PROPERTY(QString text READ toPlainText WRITE setPlainText NOTIFY plainTextChanged)
35  Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
36 
37  signals:
38  void fontChanged(const QFont &font);
39  void colorChanged(const QColor &color);
40  void plainTextChanged(const QString &text);
41 
42  // constructors, destructor
43  public:
44  PartText(QETElementEditor *, QGraphicsItem * = nullptr);
45  ~PartText() override;
46 
47  private:
48  PartText(const PartText &);
49 
50  // methods
51  public:
52  enum { Type = UserType + 1107 };
58  int type() const override { return Type; }
59  QString name() const override { return(QObject::tr("texte", "element part name")); }
60  QString xmlName() const override { return(QString("text")); }
61  void fromXml(const QDomElement &) override;
62  const QDomElement toXml(QDomDocument &) const override;
63  void setRotation(qreal angle) {(QGraphicsObject::setRotation(QET::correctAngle(angle)));}
64  bool isUseless() const override;
65  QRectF sceneGeometricRect() const override;
66  void startUserTransformation(const QRectF &) override;
67  void handleUserTransformation(const QRectF &, const QRectF &) override;
68 
69  void setProperty(const char *name, const QVariant &value) override {QGraphicsTextItem::setProperty(name, value);}
70  QVariant property(const char *name) const override {return QGraphicsTextItem::property(name);}
71 
72  qreal realSize() const {return real_font_size_;}
73  void setRealSize(qreal rs) {real_font_size_ = rs;}
74  void setDefaultTextColor(const QColor &color);
75  void setPlainText(const QString &text);
76  void setFont(const QFont &font);
77 
78  public slots:
79  void adjustItemPosition(int = 0);
80  void setEditable(bool);
81  void startEdition();
82  void endEdition();
83 
84  protected:
85  void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
86  void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
87  void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
88  void focusInEvent(QFocusEvent *) override;
89  void focusOutEvent(QFocusEvent *) override;
90  void keyPressEvent(QKeyEvent *) override;
91  void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *) override;
92  QVariant itemChange(GraphicsItemChange, const QVariant &) override;
93  QRectF boundingRect() const override;
94 
95  private:
96  QPointF margin() const;
97  QString previous_text;
99  QPointF saved_point_;
101  QGraphicsItem *decorator_;
102  QPointF m_origine_pos;
103 };
104 #endif
PartText::setRotation
void setRotation(qreal angle)
Definition: parttext.h:63
PartText::realSize
qreal realSize() const
Definition: parttext.h:72
ElementPrimitiveDecorator
Definition: elementprimitivedecorator.h:41
PartText::~PartText
~PartText() override
Destructeur.
Definition: parttext.cpp:61
PartText::mouseDoubleClickEvent
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *) override
Definition: parttext.cpp:170
PartText::Type
@ Type
Definition: parttext.h:52
PartText::real_size
qreal real_size
Definition: parttext.h:32
TextEditor
Definition: texteditor.h:32
texteditor.h
PartText::text
QString text
Definition: parttext.h:34
PartText::boundingRect
QRectF boundingRect() const override
Definition: parttext.cpp:194
elementprimitivedecorator.h
PartText::fontChanged
void fontChanged(const QFont &font)
PartText::saved_font_size_
qreal saved_font_size_
Definition: parttext.h:100
PartText::startEdition
void startEdition()
Definition: parttext.cpp:330
PartText::setProperty
void setProperty(const char *name, const QVariant &value) override
Definition: parttext.h:69
PartText::setRealSize
void setRealSize(qreal rs)
Definition: parttext.h:73
CustomElementPart::undoStack
virtual QUndoStack & undoStack() const
Definition: customelementpart.cpp:42
PartText::keyPressEvent
void keyPressEvent(QKeyEvent *) override
PartText::keyPressEvent Used to handle the escape key when the event is delivered to the field,...
Definition: parttext.cpp:157
qetapp.h
PartText::mouseMoveEvent
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
Definition: parttext.cpp:264
PartText::real_font_size_
qreal real_font_size_
Definition: parttext.h:98
PartText::property
QVariant property(const char *name) const override
Definition: parttext.h:70
CustomElementPart::updateCurrentPartEditor
virtual void updateCurrentPartEditor() const
Definition: customelementpart.cpp:30
PartText::mousePressEvent
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
Definition: parttext.cpp:274
PartText::setEditable
void setEditable(bool)
Definition: parttext.cpp:315
QET::correctAngle
qreal correctAngle(const qreal &)
Definition: qet.cpp:545
PartText::setPlainText
void setPlainText(const QString &text)
Definition: parttext.cpp:250
PartText::endEdition
void endEdition()
Definition: parttext.cpp:339
PartText::setFont
void setFont(const QFont &font)
Definition: parttext.cpp:257
elementscene.h
PartText::setDefaultTextColor
void setDefaultTextColor(const QColor &color)
Definition: parttext.cpp:243
parttext.h
qpropertyundocommand.h
PartText::m_origine_pos
QPointF m_origine_pos
Definition: parttext.h:102
PartText::adjustItemPosition
void adjustItemPosition(int=0)
Definition: parttext.cpp:302
PartText::font
QFont font
Definition: parttext.h:35
PartText::itemChange
QVariant itemChange(GraphicsItemChange, const QVariant &) override
Definition: parttext.cpp:182
PartText::decorator_
QGraphicsItem * decorator_
Definition: parttext.h:101
PartText::PartText
PartText(QETElementEditor *, QGraphicsItem *=nullptr)
Definition: parttext.cpp:30
PartText::isUseless
bool isUseless() const override
Definition: parttext.cpp:205
PartText::name
QString name() const override
Definition: parttext.h:59
PartText::focusOutEvent
void focusOutEvent(QFocusEvent *) override
PartText::focusOutEvent.
Definition: parttext.cpp:145
PartText::fromXml
void fromXml(const QDomElement &) override
Definition: parttext.cpp:68
PartText::margin
QPointF margin() const
Definition: parttext.cpp:114
PartText::handleUserTransformation
void handleUserTransformation(const QRectF &, const QRectF &) override
Definition: parttext.cpp:232
PartText::focusInEvent
void focusInEvent(QFocusEvent *) override
PartText::focusInEvent.
Definition: parttext.cpp:134
PartText::type
int type() const override
Definition: parttext.h:58
PartText::color
QColor color
Definition: parttext.h:33
PartText::xmlName
QString xmlName() const override
Definition: parttext.h:60
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
CustomElementPart::mapPoints
QList< QPointF > mapPoints(const QRectF &, const QRectF &, const QList< QPointF > &)
Definition: customelementpart.cpp:69
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
PartText::colorChanged
void colorChanged(const QColor &color)
PartText::plainTextChanged
void plainTextChanged(const QString &text)
PartText
Definition: parttext.h:30
QPropertyUndoCommand
The QPropertyUndoCommand class This undo command manage QProperty of a QObject. This undo command can...
Definition: qpropertyundocommand.h:34
PartText::toXml
const QDomElement toXml(QDomDocument &) const override
Definition: parttext.cpp:98
PartText::saved_point_
QPointF saved_point_
Definition: parttext.h:99
PartText::sceneGeometricRect
QRectF sceneGeometricRect() const override
Definition: parttext.cpp:215
PartText::PartText
PartText(const PartText &)
QET::Icons::tr
QIcon tr
Definition: qeticons.cpp:206
customelementpart.h
PartText::startUserTransformation
void startUserTransformation(const QRectF &) override
Definition: parttext.cpp:223
PartText::previous_text
QString previous_text
Definition: parttext.h:97
QETElementEditor
Definition: qetelementeditor.h:33
PartText::mouseReleaseEvent
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
Definition: parttext.cpp:281