2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2009-04-03 19:30:25 +00:00
|
|
|
Copyright 2006-2009 Xavier Guerrin
|
2007-12-01 10:47:15 +00:00
|
|
|
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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2007-02-24 00:26:04 +00:00
|
|
|
#include "elementtextitem.h"
|
2007-09-25 23:24:36 +00:00
|
|
|
#include "diagram.h"
|
2007-09-26 22:57:53 +00:00
|
|
|
#include "diagramcommands.h"
|
2007-02-24 00:26:04 +00:00
|
|
|
|
2007-04-09 02:56:47 +00:00
|
|
|
/**
|
|
|
|
Constructeur
|
|
|
|
@param parent Le QGraphicsItem parent du champ de texte
|
|
|
|
@param scene La scene a laquelle appartient le champ de texte
|
|
|
|
*/
|
2007-09-26 22:57:53 +00:00
|
|
|
ElementTextItem::ElementTextItem(QGraphicsItem *parent, QGraphicsScene *scene) :
|
|
|
|
DiagramTextItem(parent, scene),
|
|
|
|
follow_parent_rotations(false)
|
|
|
|
{
|
2007-10-27 13:18:17 +00:00
|
|
|
setFlags(QGraphicsItem::ItemIsSelectable);
|
|
|
|
setTextInteractionFlags(Qt::TextEditorInteraction);
|
2007-02-24 00:26:04 +00:00
|
|
|
}
|
|
|
|
|
2007-04-09 02:56:47 +00:00
|
|
|
/**
|
|
|
|
Constructeur
|
|
|
|
@param parent Le QGraphicsItem parent du champ de texte
|
|
|
|
@param scene La scene a laquelle appartient le champ de texte
|
|
|
|
@param text Le texte affiche par le champ de texte
|
|
|
|
*/
|
2007-09-26 22:57:53 +00:00
|
|
|
ElementTextItem::ElementTextItem(const QString &text, QGraphicsItem *parent, QGraphicsScene *scene) :
|
|
|
|
DiagramTextItem(text, parent, scene),
|
|
|
|
follow_parent_rotations(false)
|
|
|
|
{
|
2007-10-27 13:18:17 +00:00
|
|
|
setFlags(QGraphicsItem::ItemIsSelectable);
|
|
|
|
setTextInteractionFlags(Qt::TextEditorInteraction);
|
2007-02-24 00:26:04 +00:00
|
|
|
}
|
|
|
|
|
2007-09-26 22:57:53 +00:00
|
|
|
/// Destructeur
|
2007-04-12 03:13:13 +00:00
|
|
|
ElementTextItem::~ElementTextItem() {
|
|
|
|
}
|
|
|
|
|
2007-04-09 02:56:47 +00:00
|
|
|
/**
|
|
|
|
Modifie la position du champ de texte
|
|
|
|
@param pos La nouvelle position du champ de texte
|
|
|
|
*/
|
2007-02-24 00:26:04 +00:00
|
|
|
void ElementTextItem::setPos(const QPointF &pos) {
|
|
|
|
QPointF actual_pos = pos;
|
|
|
|
actual_pos -= QPointF(0.0, boundingRect().height() / 2.0);
|
2007-09-26 22:57:53 +00:00
|
|
|
DiagramTextItem::setPos(actual_pos);
|
2007-02-24 00:26:04 +00:00
|
|
|
}
|
|
|
|
|
2007-04-09 02:56:47 +00:00
|
|
|
/**
|
|
|
|
Modifie la position du champ de texte
|
|
|
|
@param x La nouvelle abscisse du champ de texte
|
|
|
|
@param y La nouvelle ordonnee du champ de texte
|
|
|
|
*/
|
2007-02-24 00:26:04 +00:00
|
|
|
void ElementTextItem::setPos(qreal x, qreal y) {
|
|
|
|
setPos(QPointF(x, y));
|
|
|
|
}
|
|
|
|
|
2007-04-09 02:56:47 +00:00
|
|
|
/**
|
|
|
|
@return La position (bidouillee) du champ de texte
|
|
|
|
*/
|
2007-02-24 00:26:04 +00:00
|
|
|
QPointF ElementTextItem::pos() const {
|
2007-09-26 22:57:53 +00:00
|
|
|
QPointF actual_pos = DiagramTextItem::pos();
|
2007-02-24 00:26:04 +00:00
|
|
|
actual_pos += QPointF(0.0, boundingRect().height() / 2.0);
|
|
|
|
return(actual_pos);
|
|
|
|
}
|
2007-02-24 19:56:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Permet de lire le texte a mettre dans le champ a partir d'un element XML.
|
|
|
|
Cette methode se base sur la position du champ pour assigner ou non la
|
|
|
|
valeur a ce champ.
|
|
|
|
@param e L'element XML representant le champ de texte
|
|
|
|
*/
|
2007-04-12 03:13:13 +00:00
|
|
|
void ElementTextItem::fromXml(const QDomElement &e) {
|
2007-02-24 19:56:29 +00:00
|
|
|
QPointF _pos = pos();
|
2009-09-12 10:17:44 +00:00
|
|
|
if (qFuzzyCompare(qreal(e.attribute("x").toDouble()), _pos.x()) && qFuzzyCompare(qreal(e.attribute("y").toDouble()), _pos.y())) {
|
2007-02-24 19:56:29 +00:00
|
|
|
setPlainText(e.attribute("text"));
|
2007-09-26 22:57:53 +00:00
|
|
|
previous_text = e.attribute("text");
|
2007-02-24 19:56:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@param document Le document XML a utiliser
|
|
|
|
@return L'element XML representant ce champ de texte
|
|
|
|
*/
|
2007-04-12 03:13:13 +00:00
|
|
|
QDomElement ElementTextItem::toXml(QDomDocument &document) const {
|
2007-02-24 19:56:29 +00:00
|
|
|
QDomElement result = document.createElement("input");
|
2008-08-23 19:27:14 +00:00
|
|
|
result.setAttribute("x", QString("%1").arg(originalPos().x()));
|
|
|
|
result.setAttribute("y", QString("%1").arg(originalPos().y()));
|
2007-02-24 19:56:29 +00:00
|
|
|
result.setAttribute("text", toPlainText());
|
|
|
|
return(result);
|
|
|
|
}
|
2008-01-11 20:01:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
@param p Position originale / de reference pour ce champ
|
|
|
|
Cette position est utilisee lors de l'export en XML
|
|
|
|
*/
|
|
|
|
void ElementTextItem::setOriginalPos(const QPointF &p) {
|
|
|
|
original_position = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@return la position originale / de reference pour ce champ
|
|
|
|
*/
|
|
|
|
QPointF ElementTextItem::originalPos() const {
|
|
|
|
return(original_position);
|
|
|
|
}
|