diff --git a/elementperso.cpp b/elementperso.cpp index ac14436e0..8bacedec3 100644 --- a/elementperso.cpp +++ b/elementperso.cpp @@ -145,6 +145,7 @@ void ElementPerso::paint(QPainter *qp, const QStyleOptionGraphicsItem *) { bool ElementPerso::parseElement(QDomElement &e, QPainter &qp, Schema *s) { if (e.tagName() == "borne") return(parseBorne(e, s)); else if (e.tagName() == "ligne") return(parseLigne(e, qp)); + else if (e.tagName() == "ellipse") return(parseEllipse(e, qp)); else if (e.tagName() == "cercle") return(parseCercle(e, qp)); else if (e.tagName() == "polygone") return(parsePolygone(e, qp)); else return(true); // on n'est pas chiant, on ignore l'element inconnu @@ -157,14 +158,8 @@ bool ElementPerso::parseLigne(QDomElement &e, QPainter &qp) { 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.save(); - if (e.attribute("style") == "dashed") { - QPen t = qp.pen(); - t.setStyle(Qt::DashLine); - qp.setPen(t); - } + setPainterStyle(e, qp); qp.drawLine(QLineF(x1, y1, x2, y2)); qp.restore(); return(true); @@ -176,9 +171,24 @@ bool ElementPerso::parseCercle(QDomElement &e, QPainter &qp) { 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.save(); + setPainterStyle(e, qp); qp.drawEllipse(QRectF(cercle_x, cercle_y, cercle_r, cercle_r)); + qp.restore(); + return(true); +} + +bool ElementPerso::parseEllipse(QDomElement &e, QPainter &qp) { + // verifie la presence des attributs obligatoires + double ellipse_x, ellipse_y, ellipse_l, ellipse_h; + if (!attributeIsAReal(e, QString("x"), &ellipse_x)) return(false); + if (!attributeIsAReal(e, QString("y"), &ellipse_y)) return(false); + if (!attributeIsAReal(e, QString("largeur"), &ellipse_l)) return(false); + if (!attributeIsAReal(e, QString("hauteur"), &ellipse_h)) return(false); + qp.save(); + setPainterStyle(e, qp); + qp.drawEllipse(QRectF(ellipse_x, ellipse_y, ellipse_l, ellipse_h)); + qp.restore(); return(true); } @@ -196,8 +206,10 @@ bool ElementPerso::parsePolygone(QDomElement &e, QPainter &qp) { e.attribute(QString("y%1").arg(j)).toDouble() ); } - setQPainterAntiAliasing(&qp, e.attribute("antialias") == "true"); + qp.save(); + setPainterStyle(e, qp); qp.drawPolygon(points, i-1); + qp.restore(); return(true); } @@ -218,10 +230,10 @@ bool ElementPerso::parseBorne(QDomElement &e, Schema *s) { return(true); } -void ElementPerso::setQPainterAntiAliasing(QPainter *qp, bool aa) { - qp -> setRenderHint(QPainter::Antialiasing, aa); - qp -> setRenderHint(QPainter::TextAntialiasing, aa); - qp -> setRenderHint(QPainter::SmoothPixmapTransform, aa); +void ElementPerso::setQPainterAntiAliasing(QPainter &qp, bool aa) { + qp.setRenderHint(QPainter::Antialiasing, aa); + qp.setRenderHint(QPainter::TextAntialiasing, aa); + qp.setRenderHint(QPainter::SmoothPixmapTransform, aa); } bool ElementPerso::attributeIsAnInteger(QDomElement &e, QString nom_attribut, int *entier) { @@ -272,3 +284,77 @@ bool ElementPerso::validOrientationAttribute(QDomElement &e) { ori = ori_d; return(true); } + +/** + Applique les parametres de style definis dans l'attribut "style" de + l'element XML e au QPainter qp + Les styles possibles sont : + - line-style : style du trait + - dashed : trait en pointilles + - normal : trait plein [par defaut] + - line-weight : epaiseur du trait + - thin : trait fin + - normal : trait d'epaisseur 1 [par defaut] + - filling : remplissage de la forme + - white : remplissage blanc + - black : remplissage noir + - none : pas de remplissage [par defaut] + Les autres valeurs ne sont pas prises en compte. + @param e L'element XML a parser + @param qp Le QPainter a modifier en fonction des styles +*/ +void ElementPerso::setPainterStyle(QDomElement &e, QPainter &qp) { + // recupere le QPen et la QBrush du QPainter + QPen pen = qp.pen(); + QBrush brush = qp.brush(); + + // attributs par defaut + pen.setJoinStyle(Qt::MiterJoin); + pen.setCapStyle(Qt::SquareCap); + pen.setColor(Qt::black); + pen.setStyle(Qt::SolidLine); + pen.setWidthF(1.0); + brush.setStyle(Qt::NoBrush); + + // recupere la liste des couples style / valeur + QStringList styles = e.attribute("style").split(";", QString::SkipEmptyParts); + + // agit sur le QPen et la QBrush en fonction des valeurs rencontrees + QRegExp rx("^\\s*([a-z-]+)\\s*:\\s*([a-z-]+)\\s*$"); + foreach (QString style, styles) { + if (rx.exactMatch(style)) { + QString style_name = rx.cap(1); + QString style_value = rx.cap(2); + if (style_name == "line-style") { + if (style_value == "dashed") pen.setStyle(Qt::DashLine); + else if (style_value == "normal") pen.setStyle(Qt::SolidLine); + } else if (style_name == "line-weight") { + if (style_value == "thin") pen.setWidth(0); + else if (style_value == "normal") pen.setWidthF(1.0); + } else if (style_name == "filling") { + if (style_value == "white") { + brush.setStyle(Qt::SolidPattern); + brush.setColor(Qt::white); + } else if (style_value == "black") { + brush.setStyle(Qt::SolidPattern); + brush.setColor(Qt::black); + } else if (style_value == "none") { + brush.setStyle(Qt::NoBrush); + } + } + } + } + /*line-style:dashed; + if (e.attribute("style") == "dashed") { + + pen.setStyle(Qt::DashLine); + + }*/ + + // affectation du QPen et de la QBrush modifies au QPainter + qp.setPen(pen); + qp.setBrush(brush); + + // mise en place (ou non) de l'antialiasing + setQPainterAntiAliasing(qp, e.attribute("antialias") == "true"); +} diff --git a/elementperso.h b/elementperso.h index 240bec908..4e2fea502 100644 --- a/elementperso.h +++ b/elementperso.h @@ -20,13 +20,15 @@ QPicture dessin; bool parseElement(QDomElement &, QPainter &, Schema *); bool parseLigne(QDomElement &, QPainter &); + bool parseEllipse(QDomElement &, QPainter &); bool parseCercle(QDomElement &, QPainter &); bool parsePolygone(QDomElement &, QPainter &); bool parseBorne(QDomElement &, Schema *); - void setQPainterAntiAliasing(QPainter *, bool); + void setQPainterAntiAliasing(QPainter &, bool); bool attributeIsAnInteger(QDomElement &, QString, int * = NULL); bool attributeIsAReal(QDomElement &, QString, double * = NULL); bool validOrientationAttribute(QDomElement &); + void setPainterStyle(QDomElement &, QPainter &); int nb_bornes; }; #endif diff --git a/elements/bobine.elmt b/elements/bobine.elmt index a1c21e766..d5c337641 100644 --- a/elements/bobine.elmt +++ b/elements/bobine.elmt @@ -6,13 +6,13 @@ - - - - + + + + - - + + diff --git a/elements/contacts/bp.elmt b/elements/contacts/bp.elmt index 742fdfde2..37e0abab7 100644 --- a/elements/contacts/bp.elmt +++ b/elements/contacts/bp.elmt @@ -6,14 +6,14 @@ - - - + + + - - - - + + + + diff --git a/elements/contacts/bp_nf.elmt b/elements/contacts/bp_nf.elmt index b68109a4f..3e4d37371 100644 --- a/elements/contacts/bp_nf.elmt +++ b/elements/contacts/bp_nf.elmt @@ -6,15 +6,15 @@ - - - - + + + + - - - - + + + + diff --git a/elements/contacts/capteur.elmt b/elements/contacts/capteur.elmt index ab5263c7e..e11edffc3 100644 --- a/elements/contacts/capteur.elmt +++ b/elements/contacts/capteur.elmt @@ -6,12 +6,12 @@ - - - + + + - - + + diff --git a/elements/contacts/capteur_nf.elmt b/elements/contacts/capteur_nf.elmt index a272f4159..a8bf79ae8 100644 --- a/elements/contacts/capteur_nf.elmt +++ b/elements/contacts/capteur_nf.elmt @@ -6,13 +6,13 @@ - - - - + + + + - - + + diff --git a/elements/contacts/contact.elmt b/elements/contacts/contact.elmt index 148aa0624..ddae42aa8 100644 --- a/elements/contacts/contact.elmt +++ b/elements/contacts/contact.elmt @@ -6,9 +6,9 @@ - - - + + + diff --git a/elements/contacts/contact_nf.elmt b/elements/contacts/contact_nf.elmt index 03139ba83..287a0358b 100644 --- a/elements/contacts/contact_nf.elmt +++ b/elements/contacts/contact_nf.elmt @@ -6,10 +6,10 @@ - - - - + + + + diff --git a/elements/contacts/disjoncteur.elmt b/elements/contacts/disjoncteur.elmt index 48aa26b0f..71409557e 100644 --- a/elements/contacts/disjoncteur.elmt +++ b/elements/contacts/disjoncteur.elmt @@ -6,12 +6,12 @@ - - - + + + - - + + diff --git a/elements/contacts/disjoncteur_sectionneur.elmt b/elements/contacts/disjoncteur_sectionneur.elmt index b30b90d73..bab5d199e 100644 --- a/elements/contacts/disjoncteur_sectionneur.elmt +++ b/elements/contacts/disjoncteur_sectionneur.elmt @@ -6,14 +6,14 @@ - - - + + + - - + + - + diff --git a/elements/contacts/sectionneur.elmt b/elements/contacts/sectionneur.elmt index 6c8182518..ba7c1d47c 100644 --- a/elements/contacts/sectionneur.elmt +++ b/elements/contacts/sectionneur.elmt @@ -6,11 +6,11 @@ - - - + + + - + diff --git a/elements/del.elmt b/elements/del.elmt index 4a6d43ab0..1935b03f0 100644 --- a/elements/del.elmt +++ b/elements/del.elmt @@ -6,12 +6,12 @@ - - - + + + - - + + diff --git a/elements/entree.elmt b/elements/entree.elmt index 60e0c9d50..f02e8d333 100644 --- a/elements/entree.elmt +++ b/elements/entree.elmt @@ -5,8 +5,8 @@ Input - - + + diff --git a/elements/moteurs/mcc.elmt b/elements/moteurs/mcc.elmt index d1a347c87..083deceb0 100644 --- a/elements/moteurs/mcc.elmt +++ b/elements/moteurs/mcc.elmt @@ -6,24 +6,24 @@ - + - - - + + + - + - - - + + + - + - - - - + + + + diff --git a/elements/moteurs/moteur_alt3.elmt b/elements/moteurs/moteur_alt3.elmt index c85c64cec..3fa15aa71 100644 --- a/elements/moteurs/moteur_alt3.elmt +++ b/elements/moteurs/moteur_alt3.elmt @@ -5,20 +5,20 @@ Three-phase induction motor - + - - + + - + - - + + - - - - + + + + diff --git a/elements/moteurs/moteur_alt6.elmt b/elements/moteurs/moteur_alt6.elmt index f19c37dbf..d5739f4ad 100644 --- a/elements/moteurs/moteur_alt6.elmt +++ b/elements/moteurs/moteur_alt6.elmt @@ -5,28 +5,28 @@ Three-phase induction motor (not coupled) - + - - + + - + - - + + - - + + - + - - + + - - - - + + + + diff --git a/elements/semi_conducteurs/diode.elmt b/elements/semi_conducteurs/diode.elmt index 973dfbfbf..59da5ddc6 100644 --- a/elements/semi_conducteurs/diode.elmt +++ b/elements/semi_conducteurs/diode.elmt @@ -6,9 +6,9 @@ - - - + + + diff --git a/elements/semi_conducteurs/thyristor.elmt b/elements/semi_conducteurs/thyristor.elmt index f168a1f43..ae3ec4a15 100644 --- a/elements/semi_conducteurs/thyristor.elmt +++ b/elements/semi_conducteurs/thyristor.elmt @@ -6,12 +6,12 @@ - - - + + + - - + + diff --git a/elements/semi_conducteurs/zener.elmt b/elements/semi_conducteurs/zener.elmt index 855077cbb..f8a0fc0bb 100644 --- a/elements/semi_conducteurs/zener.elmt +++ b/elements/semi_conducteurs/zener.elmt @@ -6,12 +6,12 @@ - - - + + + - - + + diff --git a/elements/terre.elmt b/elements/terre.elmt index 19f8e9d33..90a39b7d6 100644 --- a/elements/terre.elmt +++ b/elements/terre.elmt @@ -6,10 +6,10 @@ - - - - + + + + diff --git a/elements/transformateurs/transfo_mono.elmt b/elements/transformateurs/transfo_mono.elmt index fd0dc8def..2d15b6559 100644 --- a/elements/transformateurs/transfo_mono.elmt +++ b/elements/transformateurs/transfo_mono.elmt @@ -6,20 +6,20 @@ - - + + - - + + - - + + - - + + - - + + diff --git a/elements/transformateurs/transfo_tri.elmt b/elements/transformateurs/transfo_tri.elmt index f02ac808a..11efcee6e 100644 --- a/elements/transformateurs/transfo_tri.elmt +++ b/elements/transformateurs/transfo_tri.elmt @@ -6,24 +6,24 @@ - - + + - - + + - + - - + + - - + + - + - - + +