mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 13:30:34 +01:00
Element editor : When open a .elmt file in the element editor, the texts field are converted to dynamic text field, except for text field with tagg : label, function and tension/protocol.
In other words every text without tagg are converted. git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5050 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -23,12 +23,26 @@
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QFont>
|
||||
#include <QColor>
|
||||
#include <QMatrix>
|
||||
|
||||
/**
|
||||
* @brief PartDynamicTextField::PartDynamicTextField
|
||||
* Return if a dynamic text field can import information from the xml definition of a text field
|
||||
* @param editor
|
||||
* @param parent
|
||||
*/
|
||||
bool PartDynamicTextField::canImportFromTextField(const QDomElement &dom_element)
|
||||
{
|
||||
if(dom_element.tagName() != "input")
|
||||
return false;
|
||||
|
||||
QString tagg = dom_element.attribute("tagg", "none");
|
||||
if(tagg == "none")
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
PartDynamicTextField::PartDynamicTextField(QETElementEditor *editor, QGraphicsItem *parent) :
|
||||
QGraphicsTextItem(parent),
|
||||
CustomElementPart(editor),
|
||||
@@ -184,6 +198,35 @@ void PartDynamicTextField::fromXml(const QDomElement &dom_elmt)
|
||||
setColor(QColor(dom_color.text()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief PartDynamicTextField::fromTextFieldXml
|
||||
* Setup this text from the xml definition of a text field (The xml tagg of a text field is "input");
|
||||
* @param dom_element
|
||||
*/
|
||||
void PartDynamicTextField::fromTextFieldXml(const QDomElement &dom_element)
|
||||
{
|
||||
if(canImportFromTextField(dom_element))
|
||||
{
|
||||
setFont(QETApp::diagramTextsFont(dom_element.attribute("size", QString::number(9)).toInt()));
|
||||
setTextFrom(DynamicElementTextItem::UserText);
|
||||
setText(dom_element.attribute("text", "_"));
|
||||
QGraphicsTextItem::setRotation(dom_element.attribute("rotation", "0").toDouble());
|
||||
|
||||
//the origin transformation point of PartDynamicTextField is the top left corner, no matter the font size
|
||||
//The origin transformation point of PartTextField is the middle of left edge, and so by definition, change with the size of the font
|
||||
//We need to use a QMatrix to find the pos of this text from the saved pos of text item
|
||||
QMatrix matrix;
|
||||
//First make the rotation
|
||||
matrix.rotate(dom_element.attribute("rotation", "0").toDouble());
|
||||
QPointF pos = matrix.map(QPointF(0, -boundingRect().height()/2));
|
||||
matrix.reset();
|
||||
//Second translate to the pos
|
||||
matrix.translate(dom_element.attribute("x", QString::number(0)).toDouble(),
|
||||
dom_element.attribute("y", QString::number(0)).toDouble());
|
||||
QGraphicsTextItem::setPos(matrix.map(pos));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief PartDynamicTextField::textFrom
|
||||
* @return what the final text is created from.
|
||||
@@ -358,12 +401,10 @@ void PartDynamicTextField::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
*/
|
||||
QVariant PartDynamicTextField::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
|
||||
{
|
||||
if (change == QGraphicsItem::ItemPositionHasChanged || change == QGraphicsItem::ItemSceneHasChanged) {
|
||||
if (change == QGraphicsItem::ItemPositionHasChanged || change == QGraphicsItem::ItemSceneHasChanged)
|
||||
updateCurrentPartEditor();
|
||||
} else if (change == QGraphicsItem::ItemSelectedHasChanged) {
|
||||
if (value.toBool() == true) {
|
||||
else if ((change == QGraphicsItem::ItemSelectedHasChanged) && (value.toBool() == true))
|
||||
updateCurrentPartEditor();
|
||||
}
|
||||
}
|
||||
|
||||
return(QGraphicsTextItem::itemChange(change, value));
|
||||
}
|
||||
|
||||
@@ -41,6 +41,9 @@ class PartDynamicTextField : public QGraphicsTextItem, public CustomElementPart
|
||||
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
|
||||
Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged)
|
||||
|
||||
public:
|
||||
static bool canImportFromTextField(const QDomElement &dom_element);
|
||||
|
||||
public:
|
||||
///PROPERTY
|
||||
void setProperty(const char *name, const QVariant &value) override {QGraphicsTextItem::setProperty(name, value);}
|
||||
@@ -70,6 +73,7 @@ class PartDynamicTextField : public QGraphicsTextItem, public CustomElementPart
|
||||
|
||||
const QDomElement toXml(QDomDocument &dom_doc) const override;
|
||||
void fromXml(const QDomElement &dom_elmt) override;
|
||||
void fromTextFieldXml(const QDomElement &dom_element);
|
||||
|
||||
DynamicElementTextItem::TextFrom textFrom() const;
|
||||
void setTextFrom (DynamicElementTextItem::TextFrom text_from);
|
||||
|
||||
@@ -102,14 +102,6 @@ const QDomElement PartTextField::toXml(QDomDocument &xml_document) const {
|
||||
return(xml_element);
|
||||
}
|
||||
|
||||
/**
|
||||
@return le decalage entre l'origine du QGraphicsItem et l'origine du champ de
|
||||
texte.
|
||||
*/
|
||||
QPointF PartTextField::margin() const {
|
||||
return(QPointF(0.0, boundingRect().bottom() / 2.0));
|
||||
}
|
||||
|
||||
void PartTextField::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if((event->buttons() & Qt::LeftButton) && (flags() & QGraphicsItem::ItemIsMovable))
|
||||
|
||||
@@ -108,7 +108,6 @@ class PartTextField : public QGraphicsTextItem, public CustomElementPart
|
||||
QRectF boundingRect() const override;
|
||||
|
||||
private:
|
||||
QPointF margin() const;
|
||||
QString previous_text;
|
||||
qreal real_font_size_;
|
||||
QPointF saved_point_;
|
||||
|
||||
Reference in New Issue
Block a user