diff --git a/sources/editor/graphicspart/partdynamictextfield.cpp b/sources/editor/graphicspart/partdynamictextfield.cpp
index 224ba534a..70413f038 100644
--- a/sources/editor/graphicspart/partdynamictextfield.cpp
+++ b/sources/editor/graphicspart/partdynamictextfield.cpp
@@ -33,8 +33,8 @@ PartDynamicTextField::PartDynamicTextField(QETElementEditor *editor, QGraphicsIt
setDefaultTextColor(Qt::black);
setFont(QETApp::dynamicTextsItemFont());
QSettings settings;
- setRotation(settings.value("dynamic_rotation", 0).toInt());
- setTextWidth(settings.value("dynamic_with", -1).toInt());
+ setRotation(settings.value("diagrameditor/dynamic_text_rotation", 0).toInt());
+ setTextWidth(settings.value("diagrameditor/dynamic_text_width", -1).toInt());
setText("_");
setTextFrom(DynamicElementTextItem::UserText);
setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemSendsGeometryChanges | QGraphicsItem::ItemIsMovable);
@@ -94,8 +94,7 @@ const QDomElement PartDynamicTextField::toXml(QDomDocument &dom_doc) const
root_element.setAttribute("y", QString::number(pos().y()));
root_element.setAttribute("z", QString::number(zValue()));
root_element.setAttribute("rotation", QString::number(QET::correctAngle(rotation())));
- root_element.setAttribute("font_size", font().pointSize());
- root_element.setAttribute("font_family", (QETApp::dynamicTextsItemFont().family()));
+ root_element.setAttribute("font", font().toString());
root_element.setAttribute("uuid", m_uuid.toString());
root_element.setAttribute("frame", m_frame? "true" : "false");
root_element.setAttribute("text_width", QString::number(m_text_width));
@@ -165,7 +164,16 @@ void PartDynamicTextField::fromXml(const QDomElement &dom_elmt)
dom_elmt.attribute("y", QString::number(0)).toDouble());
setZValue(dom_elmt.attribute("z", QString::number(zValue())).toDouble());
QGraphicsTextItem::setRotation(dom_elmt.attribute("rotation", QString::number(0)).toDouble());
- setFont(QETApp::diagramTextsFont(dom_elmt.attribute("font_size", QString::number(9)).toInt()));
+
+ if (dom_elmt.hasAttribute("font"))
+ {
+ QFont font_;
+ font_.fromString(dom_elmt.attribute("font"));
+ setFont(font_);
+ } else { //Keep compatibility TODO remove in futur
+ setFont(QETApp::dynamicTextsItemFont(9));
+ }
+
m_uuid = QUuid(dom_elmt.attribute("uuid", QUuid::createUuid().toString()));
setFrame(dom_elmt.attribute("frame", "false") == "true"? true : false);
setTextWidth(dom_elmt.attribute("text_width", QString::number(-1)).toDouble());
@@ -352,22 +360,6 @@ QColor PartDynamicTextField::color() const {
return defaultTextColor();
}
-/**
- * @brief PartDynamicTextField::setFontSize
- * @param s
- */
-void PartDynamicTextField::setFontSize(int s)
-{
- prepareAlignment();
- setFont(QETApp::dynamicTextsItemFont(s));
- finishAlignment();
- emit fontSizeChanged(s);
-}
-
-int PartDynamicTextField::fontSize() const {
- return font().pointSize();
-}
-
void PartDynamicTextField::setFrame(bool frame)
{
m_frame = frame;
@@ -425,6 +417,17 @@ Qt::Alignment PartDynamicTextField::alignment() const {
return m_alignment;
}
+void PartDynamicTextField::setFont(const QFont &font)
+{
+ if (font == this->font()) {
+ return;
+ }
+ prepareAlignment();
+ QGraphicsTextItem::setFont(font);
+ finishAlignment();
+ emit fontChanged(font);
+}
+
/**
* @brief PartDynamicTextField::mouseMoveEvent
* @param event
@@ -501,13 +504,13 @@ void PartDynamicTextField::paint(QPainter *painter, const QStyleOptionGraphicsIt
if (m_frame)
{
painter->save();
- painter->setFont(QETApp::dynamicTextsItemFont(fontSize()));
+ painter->setFont(this->font());
//Adjust the thickness according to the font size,
qreal w=0.3;
- if(fontSize() >= 5)
+ if(this->font().pointSize() >= 5)
{
- w = (qreal)fontSize()*0.1;
+ w = this->font().pointSizeF()*0.1;
if(w > 2.5)
w = 2.5;
}
@@ -534,7 +537,7 @@ void PartDynamicTextField::paint(QPainter *painter, const QStyleOptionGraphicsIt
pos.ry() -= size.height()/2;
//Adjust the rounding of the rectangle according to the size of the font
- qreal ro = (qreal)fontSize()/3;
+ qreal ro = this->font().pointSizeF()/3;
painter->drawRoundedRect(QRectF(pos, size), ro, ro);
painter->restore();
diff --git a/sources/editor/graphicspart/partdynamictextfield.h b/sources/editor/graphicspart/partdynamictextfield.h
index fa095a7b8..118cc2fec 100644
--- a/sources/editor/graphicspart/partdynamictextfield.h
+++ b/sources/editor/graphicspart/partdynamictextfield.h
@@ -38,10 +38,10 @@ class PartDynamicTextField : public QGraphicsTextItem, public CustomElementPart
Q_PROPERTY(QString infoName READ infoName WRITE setInfoName NOTIFY infoNameChanged)
Q_PROPERTY(QString compositeText READ compositeText WRITE setCompositeText NOTIFY compositeTextChanged)
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
- Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged)
Q_PROPERTY(bool frame READ frame WRITE setFrame NOTIFY frameChanged)
Q_PROPERTY(qreal textWidth READ textWidth WRITE setTextWidth NOTIFY textWidthChanged)
Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
+ Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
public:
///PROPERTY
@@ -55,10 +55,10 @@ class PartDynamicTextField : public QGraphicsTextItem, public CustomElementPart
void infoNameChanged(QString info);
void compositeTextChanged(QString text);
void colorChanged(QColor color);
- void fontSizeChanged(int size);
void frameChanged(bool frame);
void textWidthChanged(qreal width);
void alignmentChanged(Qt::Alignment alignment);
+ void fontChanged(QFont font);
public:
PartDynamicTextField(QETElementEditor *editor, QGraphicsItem *parent = nullptr);
@@ -88,14 +88,13 @@ class PartDynamicTextField : public QGraphicsTextItem, public CustomElementPart
QString compositeText() const;
void setColor(const QColor& color);
QColor color() const;
- void setFontSize(int s);
- int fontSize()const;
void setFrame(bool frame);
bool frame() const;
void setTextWidth(qreal width);
void setPlainText(const QString &text);
void setAlignment(Qt::Alignment alignment);
Qt::Alignment alignment() const;
+ void setFont(const QFont &font);
protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
diff --git a/sources/editor/graphicspart/parttext.cpp b/sources/editor/graphicspart/parttext.cpp
index 1e05c5692..58ef30cc9 100644
--- a/sources/editor/graphicspart/parttext.cpp
+++ b/sources/editor/graphicspart/parttext.cpp
@@ -55,24 +55,32 @@ PartText::~PartText() {
Importe les proprietes d'un texte statique depuis un element XML
@param xml_element Element XML a lire
*/
-void PartText::fromXml(const QDomElement &xml_element) {
+void PartText::fromXml(const QDomElement &xml_element)
+{
bool ok;
- int font_size = xml_element.attribute("size").toInt(&ok);
- if (!ok || font_size < 1) font_size = 20;
-
- setBlack(xml_element.attribute("color") != "white");
- setProperty("size" , font_size);
- setPlainText(xml_element.attribute("text"));
-
- qreal default_rotation_angle = 0.0;
- if (QET::attributeIsAReal(xml_element, "rotation", &default_rotation_angle)) {
- setRotation(default_rotation_angle);
+
+ if (xml_element.hasAttribute("size"))
+ {
+ int font_size = xml_element.attribute("size").toInt(&ok);
+ if (!ok || font_size < 1) {
+ font_size = 20;
+ }
+ QFont font_ = this->font();
+ font_.setPointSize(font_size);
+ setFont(font_);
+ }
+ else if (xml_element.hasAttribute("font"))
+ {
+ QFont font_;
+ font_.fromString(xml_element.attribute("font"));
+ setFont(font_);
}
- setPos(
- xml_element.attribute("x").toDouble(),
- xml_element.attribute("y").toDouble()
- );
+ setDefaultTextColor(QColor(xml_element.attribute("color", "#000000")));
+ setPlainText(xml_element.attribute("text"));
+ setPos(xml_element.attribute("x").toDouble(),
+ xml_element.attribute("y").toDouble());
+ setRotation(xml_element.attribute("rotation", QString::number(0)).toDouble());
}
/**
@@ -80,19 +88,17 @@ void PartText::fromXml(const QDomElement &xml_element) {
@param xml_document Document XML a utiliser pour creer l'element XML
@return un element XML decrivant le texte statique
*/
-const QDomElement PartText::toXml(QDomDocument &xml_document) const {
- QDomElement xml_element = xml_document.createElement("text");
- xml_element.setAttribute("x", QString("%1").arg(pos().x()));
- xml_element.setAttribute("y", QString("%1").arg(pos().y()));
+const QDomElement PartText::toXml(QDomDocument &xml_document) const
+{
+ QDomElement xml_element = xml_document.createElement(xmlName());
+
+ xml_element.setAttribute("x", QString::number(pos().x()));
+ xml_element.setAttribute("y", QString::number(pos().y()));
xml_element.setAttribute("text", toPlainText());
- xml_element.setAttribute("size", font().pointSize());
- // angle de rotation du champ de texte
- if (rotation()) {
- xml_element.setAttribute("rotation", QString("%1").arg(rotation()));
- }
- if (!isBlack()) {
- xml_element.setAttribute("color", "white");
- }
+ xml_element.setAttribute("font", font().toString());
+ xml_element.setAttribute("rotation", QString::number(rotation()));
+ xml_element.setAttribute("color", defaultTextColor().name());
+
return(xml_element);
}
@@ -228,6 +234,33 @@ void PartText::handleUserTransformation(const QRectF &initial_selection_rect, co
setProperty("real_size", qMax(1, qRound(new_font_size)));
}
+void PartText::setDefaultTextColor(const QColor &color)
+{
+ if (color != this->defaultTextColor())
+ {
+ QGraphicsTextItem::setDefaultTextColor(color);
+ emit colorChanged(color);
+ }
+}
+
+void PartText::setPlainText(const QString &text)
+{
+ if (text != this->toPlainText())
+ {
+ QGraphicsTextItem::setPlainText(text);
+ emit plainTextChanged(text);
+ }
+}
+
+void PartText::setFont(const QFont &font)
+{
+ if (font != this->font())
+ {
+ QGraphicsTextItem::setFont(font);
+ emit fontChanged(font);
+ }
+}
+
void PartText::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
diff --git a/sources/editor/graphicspart/parttext.h b/sources/editor/graphicspart/parttext.h
index c76f0208d..6299bb6ca 100644
--- a/sources/editor/graphicspart/parttext.h
+++ b/sources/editor/graphicspart/parttext.h
@@ -26,53 +26,55 @@ class ElementPrimitiveDecorator;
This class represents an static text primitive which may be used to compose
the drawing of an electrical element within the element editor.
*/
-class PartText : public QGraphicsTextItem, public CustomElementPart {
+class PartText : public QGraphicsTextItem, public CustomElementPart
+{
Q_OBJECT
+
+ Q_PROPERTY(qreal real_size READ realSize WRITE setRealSize)
+ Q_PROPERTY(QColor color READ defaultTextColor WRITE setDefaultTextColor NOTIFY colorChanged)
+ Q_PROPERTY(QString text READ toPlainText WRITE setPlainText NOTIFY plainTextChanged)
+ Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
+
+ signals:
+ void fontChanged(const QFont &font);
+ void colorChanged(const QColor &color);
+ void plainTextChanged(const QString &text);
- // constructors, destructor
+ // constructors, destructor
public:
- PartText(QETElementEditor *, QGraphicsItem * = nullptr);
- ~PartText() override;
+ PartText(QETElementEditor *, QGraphicsItem * = nullptr);
+ ~PartText() override;
private:
- PartText(const PartText &);
+ PartText(const PartText &);
- // methods
+ // methods
public:
- enum { Type = UserType + 1107 };
- /**
- Enable the use of qgraphicsitem_cast to safely cast a QGraphicsItem into a
- PartText.
- @return the QGraphicsItem type
- */
- int type() const override { return Type; }
- QString name() const override { return(QObject::tr("texte", "element part name")); }
- QString xmlName() const override { return(QString("text")); }
- void fromXml(const QDomElement &) override;
- const QDomElement toXml(QDomDocument &) const override;
- void setRotation(qreal angle) {(QGraphicsObject::setRotation(QET::correctAngle(angle)));}
- bool isUseless() const override;
- QRectF sceneGeometricRect() const override;
- void startUserTransformation(const QRectF &) override;
- void handleUserTransformation(const QRectF &, const QRectF &) override;
+ enum { Type = UserType + 1107 };
+ /**
+ Enable the use of qgraphicsitem_cast to safely cast a QGraphicsItem into a
+ PartText.
+ @return the QGraphicsItem type
+ */
+ int type() const override { return Type; }
+ QString name() const override { return(QObject::tr("texte", "element part name")); }
+ QString xmlName() const override { return(QString("text")); }
+ void fromXml(const QDomElement &) override;
+ const QDomElement toXml(QDomDocument &) const override;
+ void setRotation(qreal angle) {(QGraphicsObject::setRotation(QET::correctAngle(angle)));}
+ bool isUseless() const override;
+ QRectF sceneGeometricRect() const override;
+ void startUserTransformation(const QRectF &) override;
+ void handleUserTransformation(const QRectF &, const QRectF &) override;
+
+ void setProperty(const char *name, const QVariant &value) override {QGraphicsTextItem::setProperty(name, value);}
+ QVariant property(const char *name) const override {return QGraphicsTextItem::property(name);}
- ///PROPERTY
- void setProperty(const char *name, const QVariant &value) override {QGraphicsTextItem::setProperty(name, value);}
- QVariant property(const char *name) const override {return QGraphicsTextItem::property(name);}
- // Size value
- Q_PROPERTY(qreal size READ size WRITE setSize)
- qreal size () const {return font().pointSize();}
- void setSize (qreal s) {setFont(QETApp::dynamicTextsItemFont(s));}
- // Real size value
- Q_PROPERTY(qreal real_size READ realSize WRITE setRealSize)
qreal realSize() const {return real_font_size_;}
void setRealSize(qreal rs) {real_font_size_ = rs;}
- // Color value (true = black , false = white)
- Q_PROPERTY(bool color READ isBlack WRITE setBlack)
- bool isBlack() const {return defaultTextColor() == Qt::black;}
- void setBlack(bool b) {setDefaultTextColor(b ? Qt::black : Qt::white);}
- // displayed string
- Q_PROPERTY(QString text READ toPlainText WRITE setPlainText)
+ void setDefaultTextColor(const QColor &color);
+ void setPlainText(const QString &text);
+ void setFont(const QFont &font);
public slots:
void adjustItemPosition(int = 0);
diff --git a/sources/editor/texteditor.cpp b/sources/editor/texteditor.cpp
deleted file mode 100644
index d6532d6db..000000000
--- a/sources/editor/texteditor.cpp
+++ /dev/null
@@ -1,241 +0,0 @@
-/*
- Copyright 2006-2019 The QElectroTech Team
- This file is part of QElectroTech.
-
- QElectroTech is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 2 of the License, or
- (at your option) any later version.
-
- QElectroTech is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with QElectroTech. If not, see .
-*/
-#include "texteditor.h"
-#include "parttext.h"
-#include "qetapp.h"
-#include "qtextorientationspinboxwidget.h"
-#include "QPropertyUndoCommand/qpropertyundocommand.h"
-
-/**
- Constructeur
- @param editor L'editeur d'element concerne
- @param text Champ de texte a editer
- @param parent QWidget parent de ce widget
-*/
-TextEditor::TextEditor(QETElementEditor *editor, PartText *text, QWidget *parent) :
- ElementItemEditor(editor, parent),
- part(text),
- m_locked(false)
-{
- qle_x = new QDoubleSpinBox();
- qle_y = new QDoubleSpinBox();
- qle_text = new QLineEdit();
- qle_text ->setClearButtonEnabled(true);
- font_size = new QSpinBox();
- font_size -> setRange(0, 144);
- black_color_ = new QRadioButton(tr("Noir", "element text part color"));
- white_color_ = new QRadioButton(tr("Blanc", "element text part color"));
- color_ = new QButtonGroup(this);
- color_ -> addButton(black_color_, true);
- color_ -> addButton(white_color_, false);
- connect(color_, SIGNAL(buttonClicked(int)), this, SLOT(updateTextC()));
- QLabel *rotation_angle_label = new QLabel(tr("Angle de rotation : "));
- rotation_angle_label -> setWordWrap(true);
- rotation_angle_ = QETApp::createTextOrientationSpinBoxWidget();
-
- qle_x -> setRange(-5000, 5000);
- qle_y -> setRange(-5000, 5000);
-
- QVBoxLayout *main_layout = new QVBoxLayout();
- main_layout -> addWidget(new QLabel(tr("Position : ")));
-
- QHBoxLayout *position = new QHBoxLayout();
- position -> addWidget(new QLabel(tr("x : ")));
- position -> addWidget(qle_x );
- position -> addWidget(new QLabel(tr("y : ")));
- position -> addWidget(qle_y );
- main_layout -> addLayout(position);
-
- QHBoxLayout *fs = new QHBoxLayout();
- fs -> addWidget(new QLabel(tr("Taille : ")));
- fs -> addWidget(font_size);
- main_layout -> addLayout(fs);
-
- QHBoxLayout *color_layout = new QHBoxLayout();
- color_layout -> addWidget(new QLabel(tr("Couleur : ")));
- color_layout -> addWidget(black_color_);
- color_layout -> addWidget(white_color_);
- color_layout -> addStretch();
- main_layout -> addLayout(color_layout);
-
- QHBoxLayout *t = new QHBoxLayout();
- t -> addWidget(new QLabel(tr("Texte : ")));
- t -> addWidget(qle_text);
-
- QHBoxLayout *rotation_angle_layout = new QHBoxLayout();
- rotation_angle_layout -> addWidget(rotation_angle_label);
- rotation_angle_layout -> addWidget(rotation_angle_);
-
- main_layout -> addLayout(t);
- main_layout -> addLayout(rotation_angle_layout);
- main_layout -> addStretch();
- setLayout(main_layout);
-
- updateForm();
-}
-
-/**
- Destructeur
-*/
-TextEditor::~TextEditor() {
-}
-
-/**
- Permet de specifier a cet editeur quelle primitive il doit editer. A noter
- qu'un editeur peut accepter ou refuser d'editer une primitive.
- L'editeur de texte statique acceptera d'editer la primitive new_part s'il
- s'agit d'un objet de la classe PartText.
- @param new_part Nouvelle primitive a editer
- @return true si l'editeur a accepter d'editer la primitive, false sinon
-*/
-bool TextEditor::setPart(CustomElementPart *new_part)
-{
- if (!new_part)
- {
- part = nullptr;
- return(true);
- }
- if (PartText *part_text = dynamic_cast(new_part))
- {
- if (part == part_text) return true;
- part = part_text;
- updateForm();
- return(true);
- }
- return(false);
-}
-
-/**
- @return la primitive actuellement editee, ou 0 si ce widget n'en edite pas
-*/
-CustomElementPart *TextEditor::currentPart() const {
- return(part);
-}
-
-/// Met a jour le texte et cree un objet d'annulation
-void TextEditor::updateTextT()
-{
- if(m_locked) return;
- m_locked = true;
- QString text = qle_text->text();
- if (text != part->property("text"))
- {
- QPropertyUndoCommand *undo = new QPropertyUndoCommand(part, "text", part->property("text"), text);
- undo->setText(tr("Modifier le contenu d'un champ texte"));
- undoStack().push(undo);
- }
- m_locked= false;
-}
-
-/// Met a jour la taille du texte et cree un objet d'annulation
-void TextEditor::updateTextS()
-{
- if(m_locked) return;
- m_locked = true;
- int size = font_size->value();
- if (size != part->property("size"))
- {
- QPropertyUndoCommand *undo = new QPropertyUndoCommand(part, "size", part->property("size"), size);
- undo->setText(tr("Modifier la taille d'un champ texte"));
- undo->enableAnimation();
- undoStack().push(undo);
- }
- m_locked= false;
-}
-
-/// Update the text color and create an undo object
-void TextEditor::updateTextC()
-{
- if(m_locked) return;
- m_locked = true;
- int color = color_->checkedId();
- if (color != part->property("color"))
- {
- QPropertyUndoCommand *undo = new QPropertyUndoCommand(part, "color", part->property("color"), color);
- undo->setText(tr("Modifier la couleur d'un champ texte"));
- undoStack().push(undo);
- }
- m_locked= false;
-}
-/// Met a jour l'angle de rotation du champ de texte et cree un objet d'annulation
-void TextEditor::updateTextRotationAngle()
-{
- if(m_locked) return;
- m_locked = true;
- double rot = rotation_angle_->value();
- if (rot != part->property("rotation"))
- {
- QPropertyUndoCommand *undo = new QPropertyUndoCommand(part, "rotation", part->property("rotation"), rot);
- undo->setText(tr("Modifier l'angle d'un champ texte"));
- undo->enableAnimation();
- undoStack().push(undo);
- }
- m_locked= false;
-}
-
-void TextEditor::updatePos()
-{
- if(m_locked) return;
- m_locked = true;
- QPointF pos(qle_x->value(), qle_y->value());
- if (pos != part->pos())
- {
- QPropertyUndoCommand *undo = new QPropertyUndoCommand(part, "pos", part->pos(), pos);
- undo->setText(tr("Déplacer un champ texte"));
- undo->enableAnimation();
- undoStack().push(undo);
- }
- m_locked= false;
-}
-
-/**
- Met a jour le formulaire a partir du champ de texte
-*/
-void TextEditor::updateForm() {
- if (!part) return;
- activeConnections(false);
- qle_x -> setValue(part->property("x").toReal());
- qle_y -> setValue(part->property("y").toReal());
- qle_text -> setText(part -> property("text").toString());
- font_size -> setValue(part -> property("size").toInt());
- if (QAbstractButton *button = color_ -> button(part -> property("color").toBool())) {
- button -> setChecked(true);
- }
- rotation_angle_ -> setValue(part -> property("rotation").toReal());
- activeConnections(true);
-}
-
-void TextEditor::activeConnections(bool active)
-{
- if (active)
- {
- connect(qle_x, SIGNAL(editingFinished()), this, SLOT(updatePos()));
- connect(qle_y, SIGNAL(editingFinished()), this, SLOT(updatePos()));
- connect(qle_text, SIGNAL(editingFinished()), this, SLOT(updateTextT()));
- connect(font_size, SIGNAL(editingFinished()), this, SLOT(updateTextS()));
- connect(rotation_angle_, SIGNAL(editingFinished()), this, SLOT(updateTextRotationAngle()));
- }
- else
- {
- disconnect(qle_x, SIGNAL(editingFinished()), this, SLOT(updatePos()));
- disconnect(qle_y, SIGNAL(editingFinished()), this, SLOT(updatePos()));
- disconnect(qle_text, SIGNAL(editingFinished()), this, SLOT(updateTextT()));
- disconnect(font_size, SIGNAL(editingFinished()), this, SLOT(updateTextS()));
- disconnect(rotation_angle_, SIGNAL(editingFinished()), this, SLOT(updateTextRotationAngle()));
- }
-}
diff --git a/sources/editor/ui/dynamictextfieldeditor.cpp b/sources/editor/ui/dynamictextfieldeditor.cpp
index 8da2e83ce..d8cbafbd8 100644
--- a/sources/editor/ui/dynamictextfieldeditor.cpp
+++ b/sources/editor/ui/dynamictextfieldeditor.cpp
@@ -73,7 +73,7 @@ bool DynamicTextFieldEditor::setPart(CustomElementPart *part)
//Setup the connection
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::colorChanged, [this](){this->updateForm();});
- m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::fontSizeChanged, [this](){this->updateForm();});
+ m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::fontChanged, [this](){this->updateForm();});
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::taggChanged, [this](){this->updateForm();});
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::textFromChanged, [this](){this->updateForm();});
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::textChanged, [this](){this->updateForm();});
@@ -104,9 +104,10 @@ void DynamicTextFieldEditor::updateForm()
ui->m_rotation_sb->setValue(QET::correctAngle(m_text_field.data()->rotation()));
ui->m_frame_cb->setChecked(m_text_field.data()->frame());
ui->m_user_text_le->setText(m_text_field.data()->text());
- ui->m_size_sb->setValue(m_text_field.data()->fontSize());
+ ui->m_size_sb->setValue(m_text_field.data()->font().pointSize());
setColorPushButton(m_text_field.data()->color());
ui->m_width_sb->setValue(m_text_field.data()->textWidth());
+ ui->m_font_pb->setText(m_text_field->font().family());
switch (m_text_field.data()->textFrom())
{
@@ -117,12 +118,10 @@ void DynamicTextFieldEditor::updateForm()
{
ui->m_text_from_cb->setCurrentIndex(1);
ui->m_elmt_info_cb->setCurrentIndex(ui->m_elmt_info_cb->findData(m_text_field.data()->infoName()));
- }
break;
+ }
case DynamicElementTextItem::CompositeText:
ui->m_text_from_cb->setCurrentIndex(2);
- default:
- break;
}
on_m_text_from_cb_activated(ui->m_text_from_cb->currentIndex()); //For enable the good widget
@@ -195,9 +194,10 @@ void DynamicTextFieldEditor::on_m_user_text_le_editingFinished()
void DynamicTextFieldEditor::on_m_size_sb_editingFinished()
{
- QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "fontSize", m_text_field.data()->fontSize(), ui->m_size_sb->value());
- undo->setText(tr("Modifier la taille d'un champ texte"));
- undo->enableAnimation(true);
+ QFont font_ = m_text_field->font();
+ font_.setPointSize(ui->m_size_sb->value());
+ QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "font", m_text_field.data()->font(), font_);
+ undo->setText(tr("Modifier la police d'un champ texte"));
undoStack().push(undo);
}
@@ -306,3 +306,18 @@ void DynamicTextFieldEditor::on_m_alignment_pb_clicked()
undoStack().push(undo);
}
}
+
+void DynamicTextFieldEditor::on_m_font_pb_clicked()
+{
+ bool ok;
+ QFont font_ = QFontDialog::getFont(&ok, m_text_field->font(), this);
+ if (ok && font_ != this->font())
+ {
+ ui->m_font_pb->setText(font_.family());
+ ui->m_size_sb->setValue(font_.pointSize());
+
+ QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field.data(), "font", m_text_field->font(), font_);
+ undo->setText(tr("Modifier la police d'un champ texte"));
+ undoStack().push(undo);
+ }
+}
diff --git a/sources/editor/ui/dynamictextfieldeditor.h b/sources/editor/ui/dynamictextfieldeditor.h
index b5c0671e0..ad7b730bd 100644
--- a/sources/editor/ui/dynamictextfieldeditor.h
+++ b/sources/editor/ui/dynamictextfieldeditor.h
@@ -58,8 +58,9 @@ class DynamicTextFieldEditor : public ElementItemEditor
void on_m_text_from_cb_activated(int index);
void on_m_composite_text_pb_clicked();
void on_m_alignment_pb_clicked();
-
- private:
+ void on_m_font_pb_clicked();
+
+ private:
Ui::DynamicTextFieldEditor *ui;
QPointer m_text_field;
QList m_connection_list;
diff --git a/sources/editor/ui/dynamictextfieldeditor.ui b/sources/editor/ui/dynamictextfieldeditor.ui
index f352935fc..c62fb586b 100644
--- a/sources/editor/ui/dynamictextfieldeditor.ui
+++ b/sources/editor/ui/dynamictextfieldeditor.ui
@@ -6,8 +6,8 @@
0
0
- 299
- 332
+ 344
+ 285
@@ -76,13 +76,10 @@
-
- Taille
+ Police
- -
-
-
-
@@ -206,6 +203,16 @@
+ -
+
+
+ -
+
+
+
+
+
+
diff --git a/sources/editor/ui/texteditor.cpp b/sources/editor/ui/texteditor.cpp
new file mode 100644
index 000000000..05b9f074e
--- /dev/null
+++ b/sources/editor/ui/texteditor.cpp
@@ -0,0 +1,224 @@
+/*
+ Copyright 2006-2019 The QElectroTech Team
+ This file is part of QElectroTech.
+
+ QElectroTech is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ QElectroTech is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with QElectroTech. If not, see .
+*/
+#include "texteditor.h"
+#include "ui_texteditor.h"
+#include "parttext.h"
+#include "QPropertyUndoCommand/qpropertyundocommand.h"
+
+/**
+ * @brief TextEditor::TextEditor
+ * Default constructor
+ * @param editor : the element editor who use this editor
+ * @param text : the text to edit
+ * @param parent : the parent widget
+ */
+TextEditor::TextEditor(QETElementEditor *editor, PartText *text, QWidget *parent) :
+ ElementItemEditor(editor, parent),
+ ui(new Ui::TextEditor)
+{
+ ui->setupUi(this);
+ setUpEditConnection();
+ if (text)
+ {
+ setPart(text);
+ updateForm();
+ }
+}
+
+/**
+ * @brief TextEditor::~TextEditor
+ */
+TextEditor::~TextEditor() {
+ delete ui;
+}
+
+/**
+ * @brief TextEditor::updateForm
+ * Update the gui
+ */
+void TextEditor::updateForm()
+{
+ if (m_text.isNull()) {
+ return;
+ }
+
+ for (QMetaObject::Connection c : m_edit_connection) {
+ disconnect(c);
+ }
+ m_edit_connection.clear();
+
+ ui->m_line_edit->setText(m_text->toPlainText());
+ ui->m_x_sb->setValue(m_text->pos().x());
+ ui->m_y_sb->setValue(m_text->pos().y());
+ ui->m_rotation_sb->setValue(m_text->rotation());
+ ui->m_size_sb->setValue(m_text->font().pointSize());
+ ui->m_font_pb->setText(m_text->font().family());
+ ui->m_color_pb->setColor(m_text->defaultTextColor());
+
+ setUpEditConnection();
+}
+
+/**
+ * @brief TextEditor::setPart
+ * Set the current text to edit.
+ * Set @part to nullptr to clear the current text.
+ * @param part : part to edit
+ * @return : return if @part is a partext or nullptr, else return false
+ */
+bool TextEditor::setPart(CustomElementPart *part)
+{
+ if (!part)
+ {
+ m_text = nullptr;
+ for (QMetaObject::Connection c : m_change_connection) {
+ disconnect(c);
+ }
+ m_change_connection.clear();
+ return true;
+ }
+
+ if (PartText *part_text = dynamic_cast(part))
+ {
+ if (part_text == m_text) {
+ return true;
+ }
+ m_text = part_text;
+
+ m_change_connection.clear();
+ m_change_connection << connect(part_text, &PartText::plainTextChanged, this, &TextEditor::updateForm);
+ m_change_connection << connect(part_text, &PartText::xChanged, this, &TextEditor::updateForm);
+ m_change_connection << connect(part_text, &PartText::yChanged, this, &TextEditor::updateForm);
+ m_change_connection << connect(part_text, &PartText::rotationChanged, this, &TextEditor::updateForm);
+ m_change_connection << connect(part_text, &PartText::fontChanged, this, &TextEditor::updateForm);
+ m_change_connection << connect(part_text, &PartText::colorChanged, this, &TextEditor::updateForm);
+
+ updateForm();
+ return true;
+ }
+ return false;
+}
+
+/**
+ * @brief TextEditor::currentPart
+ * @return The current part
+ */
+CustomElementPart *TextEditor::currentPart() const {
+ return m_text;
+}
+
+/**
+ * @brief TextEditor::setUpEditConnection
+ * Setup the connection between the widgets of this editor and the undo command
+ * use to apply the change to the edited text.
+ */
+void TextEditor::setUpEditConnection()
+{
+ for (QMetaObject::Connection c : m_edit_connection) {
+ disconnect(c);
+ }
+ m_edit_connection.clear();
+
+ m_edit_connection << connect(ui->m_line_edit, &QLineEdit::textEdited, [this]()
+ {
+ QString text_ = ui->m_line_edit->text();
+ if (text_ != m_text->toPlainText())
+ {
+ QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text, "text", m_text->toPlainText(), text_);
+ undo->setText(tr("Modifier le contenu d'un champ texte"));
+ undoStack().push(undo);
+ }
+ });
+ m_edit_connection << connect(ui->m_x_sb, QOverload::of(&QSpinBox::valueChanged), [this]()
+ {
+ QPointF pos(ui->m_x_sb->value(), ui->m_y_sb->value());
+ if (pos != m_text->pos())
+ {
+ QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text, "pos", m_text->pos(), pos);
+ undo->setText(tr("Déplacer un champ texte"));
+ undo->setAnimated(true, false);
+ undoStack().push(undo);
+ }
+ });
+ m_edit_connection << connect(ui->m_y_sb, QOverload::of(&QSpinBox::valueChanged), [this]()
+ {
+ QPointF pos(ui->m_x_sb->value(), ui->m_y_sb->value());
+ if (pos != m_text->pos())
+ {
+ QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text, "pos", m_text->pos(), pos);
+ undo->setText(tr("Déplacer un champ texte"));
+ undo->setAnimated(true, false);
+ undoStack().push(undo);
+ }
+ });
+ m_edit_connection << connect(ui->m_rotation_sb, QOverload::of(&QSpinBox::valueChanged), [this]()
+ {
+ if (ui->m_rotation_sb->value() != m_text->rotation())
+ {
+ QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text, "rotation", m_text->rotation(), ui->m_rotation_sb->value());
+ undo->setText(tr("Pivoter un champ texte"));
+ undo->setAnimated(true, false);
+ undoStack().push(undo);
+ }
+ });
+ m_edit_connection << connect(ui->m_size_sb, QOverload::of(&QSpinBox::valueChanged), [this]()
+ {
+ if (m_text->font().pointSize() != ui->m_size_sb->value())
+ {
+ QFont font_ = m_text->font();
+ font_.setPointSize(ui->m_size_sb->value());
+ QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text, "font", m_text->font(), font_);
+ undo->setText(tr("Modifier la police d'un texte"));
+ undoStack().push(undo);
+ }
+ });
+}
+
+/**
+ * @brief TextEditor::on_m_font_pb_clicked
+ */
+void TextEditor::on_m_font_pb_clicked()
+{
+ bool ok;
+ QFont font_ = QFontDialog::getFont(&ok, m_text->font(), this);
+
+ if (ok && font_ != m_text->font())
+ {
+ ui->m_size_sb->blockSignals(true);
+ ui->m_size_sb->setValue(font_.pointSize());
+ ui->m_size_sb->blockSignals(false);
+
+ ui->m_font_pb->setText(font_.family());
+ QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text, "font", m_text->font(), font_);
+ undo->setText(tr("Modifier la police d'un texte"));
+ undoStack().push(undo);
+ }
+}
+
+/**
+ * @brief TextEditor::on_m_color_pb_changed
+ * @param newColor
+ */
+void TextEditor::on_m_color_pb_changed(const QColor &newColor)
+{
+ if (newColor != m_text->defaultTextColor())
+ {
+ QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text, "color", m_text->defaultTextColor(), newColor);
+ undo->setText(tr("Modifier la couleur d'un texte"));
+ undoStack().push(undo);
+ }
+}
diff --git a/sources/editor/texteditor.h b/sources/editor/ui/texteditor.h
similarity index 50%
rename from sources/editor/texteditor.h
rename to sources/editor/ui/texteditor.h
index 864a23584..bff7cff1a 100644
--- a/sources/editor/texteditor.h
+++ b/sources/editor/ui/texteditor.h
@@ -1,73 +1,58 @@
-/*
+/*
Copyright 2006-2019 The QElectroTech Team
This file is part of QElectroTech.
-
+
QElectroTech is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
-
+
QElectroTech is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-
+
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see .
*/
-#ifndef TEXT_EDITOR_H
-#define TEXT_EDITOR_H
+#ifndef TEXTEDITOR_H
+#define TEXTEDITOR_H
#include "elementitemeditor.h"
-class PartText;
-class QTextOrientationSpinBoxWidget;
-class QLineEdit;
-class QDoubleSpinBox;
-class QSpinBox;
-class QButtonGroup;
-class QRadioButton;
+#include
+#include
+
+class PartText;
+
+namespace Ui {
+class TextEditor;
+}
-/**
- This class provides a widget to edit static texts within the element
- editor.
-*/
class TextEditor : public ElementItemEditor
{
- Q_OBJECT
+ Q_OBJECT
- // Constructors, destructor
public:
- TextEditor(QETElementEditor *, PartText * = nullptr, QWidget * = nullptr);
+ explicit TextEditor(QETElementEditor *editor, PartText *text = nullptr, QWidget *parent = nullptr);
~TextEditor() override;
- private:
- TextEditor(const TextEditor &);
-
- // attributes
- private:
- PartText *part;
- QLineEdit *qle_text;
- QDoubleSpinBox *qle_x, *qle_y;
- QSpinBox *font_size;
- QButtonGroup *color_;
- QRadioButton *black_color_, *white_color_;
- QTextOrientationSpinBoxWidget *rotation_angle_;
- bool m_locked;
-
- // methods
- public:
- bool setPart(CustomElementPart *) override;
- CustomElementPart *currentPart() const override;
-
- public slots:
- void updateTextT();
- void updateTextS();
- void updateTextC();
- void updateTextRotationAngle();
- void updatePos();
+
void updateForm() override;
-
+ bool setPart(CustomElementPart *part) override;
+ CustomElementPart *currentPart() const override;
+
+ private slots:
+ void on_m_font_pb_clicked();
+ void on_m_color_pb_changed(const QColor &newColor);
private:
- void activeConnections(bool);
+ void setUpEditConnection();
+
+ private:
+ Ui::TextEditor *ui;
+
+ QPointer m_text;
+ QList m_edit_connection;
+ QList m_change_connection;
};
-#endif
+
+#endif // TEXTEDITOR_H
diff --git a/sources/editor/ui/texteditor.ui b/sources/editor/ui/texteditor.ui
new file mode 100644
index 000000000..1fcd957bf
--- /dev/null
+++ b/sources/editor/ui/texteditor.ui
@@ -0,0 +1,132 @@
+
+
+ TextEditor
+
+
+
+ 0
+ 0
+ 378
+ 133
+
+
+
+ Form
+
+
+ -
+
+
+ -10000
+
+
+ 10000
+
+
+
+ -
+
+
+ Y :
+
+
+
+ -
+
+
+ Police :
+
+
+
+ -
+
+
+ true
+
+
+ °
+
+
+ 360
+
+
+
+ -
+
+
+ Rotation :
+
+
+
+ -
+
+
+ -10000
+
+
+ 10000
+
+
+
+ -
+
+
+ X :
+
+
+
+ -
+
+
+ -
+
+
+ Entrer votre texte ici
+
+
+ true
+
+
+
+ -
+
+
+ -
+
+
+ Couleur :
+
+
+
+ -
+
+
+
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 40
+
+
+
+
+
+
+
+
+ KColorButton
+ QPushButton
+
+
+
+
+
+
diff --git a/sources/factory/elementpicturefactory.cpp b/sources/factory/elementpicturefactory.cpp
index 5121fb659..0520113df 100644
--- a/sources/factory/elementpicturefactory.cpp
+++ b/sources/factory/elementpicturefactory.cpp
@@ -470,13 +470,8 @@ void ElementPictureFactory::parsePolygon(const QDomElement &dom, QPainter &paint
void ElementPictureFactory::parseText(const QDomElement &dom, QPainter &painter, ElementPictureFactory::primitives &prim) const
{
Q_UNUSED(prim);
-
- qreal pos_x, pos_y;
- int size;
- if (!QET::attributeIsAReal(dom, "x", &pos_x) ||\
- !QET::attributeIsAReal(dom, "y", &pos_y) ||\
- !QET::attributeIsAnInteger(dom, "size", &size) ||\
- !dom.hasAttribute("text")) {
+
+ if (dom.tagName() != "text") {
return;
}
@@ -484,23 +479,25 @@ void ElementPictureFactory::parseText(const QDomElement &dom, QPainter &painter,
setPainterStyle(dom, painter);
//Get the font and metric
- QFont used_font = QETApp::diagramTextsFont(size);
- QFontMetrics qfm(used_font);
- QColor text_color = (dom.attribute("color") != "white"? Qt::black : Qt::white);
+ QFont font_;
+ if (dom.hasAttribute("size")) {
+ font_ = QETApp::diagramTextsFont(dom.attribute("size").toDouble());
+ }
+ else if (dom.hasAttribute("font")) {
+ font_.fromString(dom.attribute("font"));
+ }
+
+ QColor text_color(dom.attribute("color", "#000000"));
//Instanciate a QTextDocument (like the QGraphicsTextItem class)
//for generate the graphics rendering of the text
QTextDocument text_document;
- text_document.setDefaultFont(used_font);
+ text_document.setDefaultFont(font_);
text_document.setPlainText(dom.attribute("text"));
painter.setTransform(QTransform(), false);
- painter.translate(pos_x, pos_y);
-
- qreal default_rotation_angle = 0.0;
- if (QET::attributeIsAReal(dom, "rotation", &default_rotation_angle)) {
- painter.rotate(default_rotation_angle);
- }
+ painter.translate(dom.attribute("x").toDouble(), dom.attribute("y").toDouble());
+ painter.rotate(dom.attribute("rotation", "0").toDouble());
/*
Deplace le systeme de coordonnees du QPainter pour effectuer le rendu au
@@ -508,6 +505,7 @@ void ElementPictureFactory::parseText(const QDomElement &dom, QPainter &painter,
determiner le coin superieur gauche du texte alors que la position
indiquee correspond a la baseline.
*/
+ QFontMetrics qfm(font_);
QPointF qpainter_offset(0.0, -qfm.ascent());
//adjusts the offset by the margin of the text document