Gestion du dessin des elements persos avec des coordonnees reelles

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
xavierqet
2006-10-28 13:17:50 +00:00
parent 0de5b7ebfd
commit 186e9751d5
3 changed files with 29 additions and 19 deletions

View File

@@ -118,33 +118,33 @@ bool ElementPerso::parseElement(QDomElement &e, QPainter &qp, Schema *s) {
bool ElementPerso::parseLigne(QDomElement &e, QPainter &qp) {
// verifie la presence et la validite des attributs obligatoires
int x1, y1, x2, y2;
if (!attributeIsAnInteger(e, QString("x1"), &x1)) return(false);
if (!attributeIsAnInteger(e, QString("y1"), &y1)) return(false);
if (!attributeIsAnInteger(e, QString("x2"), &x2)) return(false);
if (!attributeIsAnInteger(e, QString("y2"), &y2)) return(false);
double x1, y1, x2, y2;
if (!attributeIsAReal(e, QString("x1"), &x1)) return(false);
if (!attributeIsAReal(e, QString("y1"), &y1)) return(false);
if (!attributeIsAReal(e, QString("x2"), &x2)) return(false);
if (!attributeIsAReal(e, QString("y2"), &y2)) return(false);
/// @todo : gerer l'antialiasing (mieux que ca !) et le type de trait
setQPainterAntiAliasing(&qp, e.attribute("antialias") == "true");
qp.drawLine(x1, y1, x2, y2);
qp.drawLine(QLineF(x1, y1, x2, y2));
return(true);
}
bool ElementPerso::parseCercle(QDomElement &e, QPainter &qp) {
// verifie la presence des attributs obligatoires
int cercle_x, cercle_y, cercle_r;
if (!attributeIsAnInteger(e, QString("x"), &cercle_x)) return(false);
if (!attributeIsAnInteger(e, QString("y"), &cercle_y)) return(false);
if (!attributeIsAnInteger(e, QString("rayon"), &cercle_r)) return(false);
double cercle_x, cercle_y, cercle_r;
if (!attributeIsAReal(e, QString("x"), &cercle_x)) return(false);
if (!attributeIsAReal(e, QString("y"), &cercle_y)) return(false);
if (!attributeIsAReal(e, QString("rayon"), &cercle_r)) return(false);
/// @todo : gerer l'antialiasing (mieux que ca !) et le type de trait
setQPainterAntiAliasing(&qp, e.attribute("antialias") == "true");
qp.drawEllipse(cercle_x, cercle_y, cercle_r, cercle_r);
qp.drawEllipse(QRectF(cercle_x, cercle_y, cercle_r, cercle_r));
return(true);
}
bool ElementPerso::parsePolygone(QDomElement &e, QPainter &qp) {
int i = 1;
while(true) {
if (attributeIsAnInteger(e, QString("x%1").arg(i)) && attributeIsAnInteger(e, QString("y%1").arg(i))) ++ i;
if (attributeIsAReal(e, QString("x%1").arg(i)) && attributeIsAReal(e, QString("y%1").arg(i))) ++ i;
else break;
}
if (i < 3) return(false);
@@ -162,10 +162,10 @@ bool ElementPerso::parsePolygone(QDomElement &e, QPainter &qp) {
bool ElementPerso::parseBorne(QDomElement &e, Schema *s) {
// verifie la presence et la validite des attributs obligatoires
int bornex, borney;
double bornex, borney;
Borne::Orientation borneo;
if (!attributeIsAnInteger(e, QString("x"), &bornex)) return(false);
if (!attributeIsAnInteger(e, QString("y"), &borney)) return(false);
if (!attributeIsAReal(e, QString("x"), &bornex)) return(false);
if (!attributeIsAReal(e, QString("y"), &borney)) return(false);
if (!e.hasAttribute("orientation")) return(false);
if (e.attribute("orientation") == "n") borneo = Borne::Nord;
else if (e.attribute("orientation") == "s") borneo = Borne::Sud;
@@ -183,7 +183,7 @@ void ElementPerso::setQPainterAntiAliasing(QPainter *qp, bool aa) {
qp -> setRenderHint(QPainter::SmoothPixmapTransform, aa);
}
int ElementPerso::attributeIsAnInteger(QDomElement &e, QString nom_attribut, int *entier) {
bool ElementPerso::attributeIsAnInteger(QDomElement &e, QString nom_attribut, int *entier) {
// verifie la presence de l'attribut
if (!e.hasAttribute(nom_attribut)) return(false);
// verifie la validite de l'attribut
@@ -194,3 +194,13 @@ int ElementPerso::attributeIsAnInteger(QDomElement &e, QString nom_attribut, int
return(true);
}
bool ElementPerso::attributeIsAReal(QDomElement &e, QString nom_attribut, double *reel) {
// verifie la presence de l'attribut
if (!e.hasAttribute(nom_attribut)) return(false);
// verifie la validite de l'attribut
bool ok;
qreal tmp = e.attribute(nom_attribut).toDouble(&ok);
if (!ok) return(false);
if (reel != NULL) *reel = tmp;
return(true);
}

View File

@@ -24,7 +24,8 @@
bool parsePolygone(QDomElement &, QPainter &);
bool parseBorne(QDomElement &, Schema *);
void setQPainterAntiAliasing(QPainter *, bool);
int attributeIsAnInteger(QDomElement &, QString, int * = NULL);
bool attributeIsAnInteger(QDomElement &, QString, int * = NULL);
bool attributeIsAReal(QDomElement &, QString, double * = NULL);
int nb_bornes;
};
#endif

View File

@@ -1,6 +1,5 @@
<definition type="element" nom="entree" width="20" height="40" hotspot_x="10" hotspot_y="15" orientation="dnny">
<!-- note : 7.5 a la place de 8 -->
<polygone x1="-8" y1="-13" x2="8" y2="-13" x3="0" y3="0" antialias="true" style="normal" />
<polygone x1="-7.5" y1="-13" x2="7.5" y2="-13" x3="0" y3="0" antialias="true" style="normal" />
<ligne x1="0" y1="0" x2="0" y2="13" antialias="false" style="normal" />
<borne orientation="s" x="0" y="15" />
</definition>