QElectroTech  0.70
independenttextitem.cpp
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 #include "independenttextitem.h"
19 #include "qet.h"
20 #include "diagram.h"
21 #include "diagramcommands.h"
22 #include "qetapp.h"
23 
24 #include <QDomElement>
25 #include <QSettings>
26 
32  DiagramTextItem(nullptr)
33 {
35  QSettings settings;
36  setRotation(settings.value("diagrameditor/independent_text_rotation", 0).toInt());
37 }
38 
45  DiagramTextItem(text, nullptr)
46 {}
47 
50 }
51 
58 void IndependentTextItem::fromXml(const QDomElement &e) {
59  setPos(e.attribute("x").toDouble(), e.attribute("y").toDouble());
60  setHtml(e.attribute("text"));
61  setRotation(e.attribute("rotation").toDouble());
62  if (e.hasAttribute("font"))
63  {
64  QFont font;
65  font.fromString(e.attribute("font"));
66  setFont(font);
67  }
68 }
69 
74 QDomElement IndependentTextItem::toXml(QDomDocument &document) const
75 {
76  QDomElement result = document.createElement("input");
77  result.setAttribute("x", QString("%1").arg(pos().x()));
78  result.setAttribute("y", QString("%1").arg(pos().y()));
79  result.setAttribute("text", toHtml());
80  result.setAttribute("rotation", QString::number(QET::correctAngle(rotation())));
81  result.setAttribute("font", font().toString());
82 
83  return(result);
84 }
85 
86 void IndependentTextItem::focusOutEvent(QFocusEvent *event)
87 {
89  if (diagram() && (m_previous_html_text != this->toHtml())) {
90  diagram()->undoStack().push(new ChangeDiagramTextCommand(this, m_previous_html_text, this->toHtml()));
91  }
92 }
void setHtml(const QString &text)
QDomElement toXml(QDomDocument &) const override
QString m_previous_html_text
qreal correctAngle(const qreal &)
Definition: qet.cpp:505
static QFont indiTextsItemFont(qreal=-1.0)
QETApp::indiTextsItemFont The default font to use for independent text item.
Definition: qetapp.cpp:1007
void fromXml(const QDomElement &) override
void focusOutEvent(QFocusEvent *event) override
void focusOutEvent(QFocusEvent *) override
DiagramTextItem::focusOutEvent.
void setFont(const QFont &font)
QUndoStack & undoStack()
Definition: diagram.h:337
~IndependentTextItem() override
Destructeur.
Diagram * diagram() const
DiagramTextItem::diagram.