mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-19 14:50:53 +01:00
Possibilite d'ajouter des champs de texte editables aux elements
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@66 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
#include "customelement.h"
|
#include "customelement.h"
|
||||||
|
#include "elementtextitem.h"
|
||||||
|
#include "diagram.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Constructeur de la classe ElementPerso. Permet d'instancier un element
|
Constructeur de la classe ElementPerso. Permet d'instancier un element
|
||||||
@@ -150,7 +152,6 @@ CustomElement::CustomElement(QString &nom_fichier, QGraphicsItem *qgi, Diagram *
|
|||||||
// fermeture du fichier
|
// fermeture du fichier
|
||||||
fichier.close();
|
fichier.close();
|
||||||
|
|
||||||
//(new QGraphicsTextItem("plop", this, scene())) -> setTextInteractionFlags(Qt::TextEditorInteraction);
|
|
||||||
if (etat != NULL) *etat = 0;
|
if (etat != NULL) *etat = 0;
|
||||||
elmt_etat = 0;
|
elmt_etat = 0;
|
||||||
}
|
}
|
||||||
@@ -192,6 +193,7 @@ bool CustomElement::parseElement(QDomElement &e, QPainter &qp, Diagram *s) {
|
|||||||
else if (e.tagName() == "arc") return(parseArc(e, qp));
|
else if (e.tagName() == "arc") return(parseArc(e, qp));
|
||||||
else if (e.tagName() == "polygon") return(parsePolygon(e, qp));
|
else if (e.tagName() == "polygon") return(parsePolygon(e, qp));
|
||||||
else if (e.tagName() == "text") return(parseText(e, qp));
|
else if (e.tagName() == "text") return(parseText(e, qp));
|
||||||
|
else if (e.tagName() == "input") return(parseInput(e, s));
|
||||||
else return(true); // on n'est pas chiant, on ignore l'element inconnu
|
else return(true); // on n'est pas chiant, on ignore l'element inconnu
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -365,6 +367,34 @@ bool CustomElement::parseText(QDomElement &e, QPainter &qp) {
|
|||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Analyse un element XML suppose representer un champ de texte editable par
|
||||||
|
l'utilisateur. Si l'analyse reussit, le champ est ajoute au dessin.
|
||||||
|
Le texte est defini par :
|
||||||
|
- une position
|
||||||
|
- une chaine de caractères facultative utilisee comme valeur par defaut
|
||||||
|
- une taille
|
||||||
|
- le fait de subir les rotations de l'element ou non
|
||||||
|
@param e L'element XML a analyser
|
||||||
|
@param s Le schema sur lequel l'element perso sera affiche
|
||||||
|
@return true si l'analyse reussit, false sinon
|
||||||
|
*/
|
||||||
|
bool CustomElement::parseInput(QDomElement &e, Diagram *s) {
|
||||||
|
qreal pos_x, pos_y;
|
||||||
|
int size;
|
||||||
|
if (
|
||||||
|
!attributeIsAReal(e, "x", &pos_x) ||\
|
||||||
|
!attributeIsAReal(e, "y", &pos_y) ||\
|
||||||
|
!attributeIsAnInteger(e, "size", &size)
|
||||||
|
) return(false);
|
||||||
|
|
||||||
|
ElementTextItem *eti = new ElementTextItem(e.attribute("text"), this, s);
|
||||||
|
eti -> setFont(QFont("Sans Serif", size));
|
||||||
|
eti -> setPos(pos_x, pos_y);
|
||||||
|
if (e.attribute("rotate") == "true") eti -> setFollowParentRotations(true);
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Analyse un element XML suppose representer une borne. Si l'analyse
|
Analyse un element XML suppose representer une borne. Si l'analyse
|
||||||
reussit, la borne est ajoutee a l'element.
|
reussit, la borne est ajoutee a l'element.
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
bool parseArc(QDomElement &, QPainter &);
|
bool parseArc(QDomElement &, QPainter &);
|
||||||
bool parsePolygon(QDomElement &, QPainter &);
|
bool parsePolygon(QDomElement &, QPainter &);
|
||||||
bool parseText(QDomElement &, QPainter &);
|
bool parseText(QDomElement &, QPainter &);
|
||||||
|
bool parseInput(QDomElement &, Diagram *);
|
||||||
bool parseTerminal(QDomElement &, Diagram *);
|
bool parseTerminal(QDomElement &, Diagram *);
|
||||||
void setQPainterAntiAliasing(QPainter &, bool);
|
void setQPainterAntiAliasing(QPainter &, bool);
|
||||||
bool attributeIsAnInteger(QDomElement &, QString, int * = NULL);
|
bool attributeIsAnInteger(QDomElement &, QString, int * = NULL);
|
||||||
|
|||||||
16
element.cpp
16
element.cpp
@@ -1,5 +1,6 @@
|
|||||||
#include "element.h"
|
#include "element.h"
|
||||||
#include "diagram.h"
|
#include "diagram.h"
|
||||||
|
#include "elementtextitem.h"
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
|
|
||||||
/*** Methodes publiques ***/
|
/*** Methodes publiques ***/
|
||||||
@@ -122,11 +123,24 @@ bool Element::setOrientation(Terminal::Orientation o) {
|
|||||||
if (!acceptOrientation(o)) return(false);
|
if (!acceptOrientation(o)) return(false);
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
// rotation en consequence et rafraichissement de l'element graphique
|
// rotation en consequence et rafraichissement de l'element graphique
|
||||||
rotate(90.0 * (o - ori));
|
qreal rotation_value = 90.0 * (o - ori);
|
||||||
|
rotate(rotation_value);
|
||||||
ori = o;
|
ori = o;
|
||||||
update();
|
update();
|
||||||
foreach(QGraphicsItem *qgi, children()) {
|
foreach(QGraphicsItem *qgi, children()) {
|
||||||
if (Terminal *p = qgraphicsitem_cast<Terminal *>(qgi)) p -> updateConducer();
|
if (Terminal *p = qgraphicsitem_cast<Terminal *>(qgi)) p -> updateConducer();
|
||||||
|
else if (ElementTextItem *eti = qgraphicsitem_cast<ElementTextItem *>(qgi)) {
|
||||||
|
// applique une rotation contraire si besoin
|
||||||
|
if (!eti -> followParentRotations()) {
|
||||||
|
QMatrix new_matrix = eti -> matrix();
|
||||||
|
qreal dx = eti -> boundingRect().width() / 2.0;
|
||||||
|
qreal dy = eti -> boundingRect().height() / 2.0;
|
||||||
|
new_matrix.translate(dx, dy);
|
||||||
|
new_matrix.rotate(-rotation_value);
|
||||||
|
new_matrix.translate(-dx, -dy);
|
||||||
|
eti -> setMatrix(new_matrix);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|||||||
27
elementtextitem.cpp
Normal file
27
elementtextitem.cpp
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#include "elementtextitem.h"
|
||||||
|
|
||||||
|
ElementTextItem::ElementTextItem(QGraphicsItem *parent, QGraphicsScene *scene) : QGraphicsTextItem(parent, scene) {
|
||||||
|
follow_parent_rotations = false;
|
||||||
|
setTextInteractionFlags(Qt::TextEditorInteraction);
|
||||||
|
}
|
||||||
|
|
||||||
|
ElementTextItem::ElementTextItem(const QString &text, QGraphicsItem *parent, QGraphicsScene *scene) : QGraphicsTextItem(text, parent, scene) {
|
||||||
|
follow_parent_rotations = false;
|
||||||
|
setTextInteractionFlags(Qt::TextEditorInteraction);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ElementTextItem::setPos(const QPointF &pos) {
|
||||||
|
QPointF actual_pos = pos;
|
||||||
|
actual_pos -= QPointF(0.0, boundingRect().height() / 2.0);
|
||||||
|
QGraphicsItem::setPos(actual_pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ElementTextItem::setPos(qreal x, qreal y) {
|
||||||
|
setPos(QPointF(x, y));
|
||||||
|
}
|
||||||
|
|
||||||
|
QPointF ElementTextItem::pos() const {
|
||||||
|
QPointF actual_pos = pos();
|
||||||
|
actual_pos += QPointF(0.0, boundingRect().height() / 2.0);
|
||||||
|
return(actual_pos);
|
||||||
|
}
|
||||||
24
elementtextitem.h
Normal file
24
elementtextitem.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#ifndef ELEMENT_TEXT_ITEM_H
|
||||||
|
#define ELEMENT_TEXT_ITEM_H
|
||||||
|
#include <QGraphicsTextItem>
|
||||||
|
class ElementTextItem : public QGraphicsTextItem {
|
||||||
|
// constructeurs
|
||||||
|
public:
|
||||||
|
ElementTextItem(QGraphicsItem * = 0, QGraphicsScene * = 0);
|
||||||
|
ElementTextItem(const QString &, QGraphicsItem * = 0, QGraphicsScene * = 0);
|
||||||
|
|
||||||
|
// attributs
|
||||||
|
private:
|
||||||
|
bool follow_parent_rotations;
|
||||||
|
|
||||||
|
// methodes
|
||||||
|
public:
|
||||||
|
enum { Type = UserType + 1003 };
|
||||||
|
virtual int type() const { return Type; }
|
||||||
|
inline bool followParentRotations() const { return(follow_parent_rotations); }
|
||||||
|
inline void setFollowParentRotations(bool frp) { follow_parent_rotations = frp; }
|
||||||
|
void setPos(const QPointF &);
|
||||||
|
void setPos(qreal, qreal);
|
||||||
|
QPointF pos() const;
|
||||||
|
};
|
||||||
|
#endif
|
||||||
@@ -20,7 +20,8 @@ HEADERS += aboutqet.h \
|
|||||||
fixedelement.h \
|
fixedelement.h \
|
||||||
qetapp.h \
|
qetapp.h \
|
||||||
terminal.h \
|
terminal.h \
|
||||||
conducersegment.h
|
conducersegment.h \
|
||||||
|
elementtextitem.h
|
||||||
SOURCES += aboutqet.cpp \
|
SOURCES += aboutqet.cpp \
|
||||||
borderinset.cpp \
|
borderinset.cpp \
|
||||||
conducer.cpp \
|
conducer.cpp \
|
||||||
@@ -34,7 +35,8 @@ SOURCES += aboutqet.cpp \
|
|||||||
main.cpp \
|
main.cpp \
|
||||||
qetapp.cpp \
|
qetapp.cpp \
|
||||||
terminal.cpp \
|
terminal.cpp \
|
||||||
conducersegment.cpp
|
conducersegment.cpp \
|
||||||
|
elementtextitem.cpp
|
||||||
RESOURCES += qelectrotech.qrc
|
RESOURCES += qelectrotech.qrc
|
||||||
TRANSLATIONS += lang/qet_en.ts lang/qt_fr.ts
|
TRANSLATIONS += lang/qet_en.ts lang/qt_fr.ts
|
||||||
QT += xml
|
QT += xml
|
||||||
|
|||||||
Reference in New Issue
Block a user