QElectroTech 0.100.0-dev
Loading...
Searching...
No Matches
parttext.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 PART_TEXT_H
19#define PART_TEXT_H
20#include "../../qetapp.h"
21#include "customelementpart.h"
22
23#include <QtWidgets>
24
25class TextEditor;
31class PartText : public QGraphicsTextItem, public CustomElementPart {
32 Q_OBJECT
33 Q_PROPERTY(qreal real_size READ realSize WRITE setRealSize)
34 Q_PROPERTY(QColor color READ defaultTextColor WRITE setDefaultTextColor NOTIFY colorChanged)
35 Q_PROPERTY(QString text READ toPlainText WRITE setPlainText NOTIFY plainTextChanged)
36 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
37
38 signals:
39 void fontChanged(const QFont &font);
40 void colorChanged(const QColor &color);
41 void plainTextChanged(const QString &text);
42
43 // constructors, destructor
44 public:
45 PartText(QETElementEditor *, QGraphicsItem * = nullptr);
46 ~PartText() override;
47
48 private:
50
51 // methods
52 public:
53 enum { Type = UserType + 1107 };
59 int type() const override { return Type; }
60 QString name() const override { return(QObject::tr("texte", "element part name")); }
61 QString xmlName() const override { return(QString("text")); }
62 void fromXml(const QDomElement &) override;
63 const QDomElement toXml(QDomDocument &) const override;
64 void setRotation(qreal angle) {(QGraphicsObject::setRotation(QET::correctAngle(angle)));}
65 bool isUseless() const override;
66 QRectF sceneGeometricRect() const override;
67 void startUserTransformation(const QRectF &) override;
68 void handleUserTransformation(const QRectF &, const QRectF &) override;
69
70 void setProperty(const char *name, const QVariant &value) override {QGraphicsTextItem::setProperty(name, value);}
71 QVariant property(const char *name) const override {return QGraphicsTextItem::property(name);}
72
73 qreal realSize() const {return real_font_size_;}
74 void setRealSize(qreal rs) {real_font_size_ = rs;}
75 void setDefaultTextColor(const QColor &color);
76 void setPlainText(const QString &text);
77 void setFont(const QFont &font);
78
79 public slots:
80 void adjustItemPosition(int = 0);
81 void setEditable(bool);
82 void startEdition();
83 void endEdition();
84
85 protected:
86 void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
87 void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
88 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
89 void focusInEvent(QFocusEvent *) override;
90 void focusOutEvent(QFocusEvent *) override;
91 void keyPressEvent(QKeyEvent *) override;
92 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *) override;
93 QVariant itemChange(GraphicsItemChange, const QVariant &) override;
94 QRectF boundingRect() const override;
95
96 private:
97 QPointF margin() const;
102 QGraphicsItem *decorator_;
104};
105#endif
The CustomElementPart class This abstract class represents a primitive of the visual representation o...
Definition customelementpart.h:40
Definition elementprimitivedecorator.h:42
Definition parttext.h:31
void startEdition()
Definition parttext.cpp:337
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
Definition parttext.cpp:281
QString xmlName() const override
Definition parttext.h:61
void keyPressEvent(QKeyEvent *) override
PartText::keyPressEvent Used to handle the escape key when the event is delivered to the field,...
Definition parttext.cpp:161
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
Definition parttext.cpp:271
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *) override
Definition parttext.cpp:174
void endEdition()
Definition parttext.cpp:347
void setProperty(const char *name, const QVariant &value) override
Definition parttext.h:70
@ Type
Definition parttext.h:53
void fontChanged(const QFont &font)
int type() const override
Definition parttext.h:59
void setRotation(qreal angle)
Definition parttext.h:64
bool isUseless() const override
Definition parttext.cpp:210
QPointF m_origine_pos
Definition parttext.h:103
void adjustItemPosition(int=0)
Definition parttext.cpp:309
QVariant property(const char *name) const override
Definition parttext.h:71
void handleUserTransformation(const QRectF &, const QRectF &) override
Definition parttext.cpp:239
void setRealSize(qreal rs)
Definition parttext.h:74
QVariant itemChange(GraphicsItemChange, const QVariant &) override
Definition parttext.cpp:186
void setPlainText(const QString &text)
Definition parttext.cpp:257
QString text
Definition parttext.h:35
QGraphicsItem * decorator_
Definition parttext.h:102
void plainTextChanged(const QString &text)
qreal real_font_size_
Definition parttext.h:99
void focusInEvent(QFocusEvent *) override
PartText::focusInEvent.
Definition parttext.cpp:138
QFont font
Definition parttext.h:36
QRectF boundingRect() const override
Definition parttext.cpp:198
void setEditable(bool)
Definition parttext.cpp:322
QString previous_text
Definition parttext.h:98
qreal realSize() const
Definition parttext.h:73
void startUserTransformation(const QRectF &) override
Definition parttext.cpp:230
void setDefaultTextColor(const QColor &color)
Definition parttext.cpp:250
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
Definition parttext.cpp:288
qreal saved_font_size_
Definition parttext.h:101
void setFont(const QFont &font)
Definition parttext.cpp:264
QColor color
Definition parttext.h:34
QPointF margin() const
Definition parttext.cpp:117
void focusOutEvent(QFocusEvent *) override
PartText::focusOutEvent.
Definition parttext.cpp:149
qreal real_size
Definition parttext.h:33
QPointF saved_point_
Definition parttext.h:100
const QDomElement toXml(QDomDocument &) const override
Definition parttext.cpp:100
void fromXml(const QDomElement &) override
Definition parttext.cpp:70
QRectF sceneGeometricRect() const override
Definition parttext.cpp:221
QString name() const override
Definition parttext.h:60
void colorChanged(const QColor &color)
Definition qetelementeditor.h:39
Definition texteditor.h:34
qreal correctAngle(const qreal &, const bool &positive=false)
Definition qet.cpp:582