diff --git a/sources/conductor.cpp b/sources/conductor.cpp index 733f983a0..cd1ac5d3d 100644 --- a/sources/conductor.cpp +++ b/sources/conductor.cpp @@ -461,6 +461,13 @@ void Conductor::paint(QPainter *qp, const QStyleOptionGraphicsItem *options, QWi qp -> setPen(tmp); } + // utilisation d'un trait "cosmetique" en-dessous d'un certain zoom + if (options && options -> levelOfDetail < 1.0) { + QPen tmp = qp -> pen(); + tmp.setCosmetic(true); + qp -> setPen(tmp); + } + // dessin du conducteur qp -> drawPath(path()); if (properties_.type == ConductorProperties::Single) { diff --git a/sources/customelement.cpp b/sources/customelement.cpp index ef9f6de88..ed518fcc4 100644 --- a/sources/customelement.cpp +++ b/sources/customelement.cpp @@ -46,7 +46,8 @@ CustomElement::CustomElement(const ElementsLocation &location, QGraphicsItem *qgi, Diagram *s, int *state) : FixedElement(qgi, s), elmt_state(-1), - location_(location) + location_(location), + forbid_antialiasing(false) { // recupere la definition de l'element ElementsCollectionItem *element_item = QETApp::collectionItem(location); @@ -148,11 +149,13 @@ bool CustomElement::buildFromXml(const QDomElement &xml_def_elmt, int *state) { // initialisation du QPainter (pour dessiner l'element) QPainter qp; qp.begin(&drawing); - QPen t; - t.setColor(Qt::black); - t.setWidthF(1.0); - t.setJoinStyle(Qt::BevelJoin); - qp.setPen(t); + + QPainter low_zoom_qp; + low_zoom_qp.begin(&low_zoom_drawing); + QPen tmp; + tmp.setWidthF(1.0); // ligne vaudou pour prise en compte du setCosmetic - ne pas enlever + tmp.setCosmetic(true); + low_zoom_qp.setPen(tmp); // extrait les noms de la definition XML names.fromXml(xml_def_elmt); @@ -169,8 +172,15 @@ bool CustomElement::buildFromXml(const QDomElement &xml_def_elmt, int *state) { for (QDomNode n = node.firstChild() ; !n.isNull() ; n = n.nextSibling()) { QDomElement qde = n.toElement(); if (qde.isNull()) continue; - if (parseElement(qde, qp)) ++ parsed_elements_count; - else { + if (parseElement(qde, qp)) { + ++ parsed_elements_count; + QString current_tag = qde.tagName(); + if (current_tag != "terminal" && current_tag != "input") { + forbid_antialiasing = true; + parseElement(qde, low_zoom_qp); + forbid_antialiasing = false; + } + } else { if (state) *state = 7; return(false); } @@ -180,6 +190,7 @@ bool CustomElement::buildFromXml(const QDomElement &xml_def_elmt, int *state) { // fin du dessin qp.end(); + low_zoom_qp.end(); // il doit y avoir au moins un element charge if (!parsed_elements_count) { @@ -226,8 +237,12 @@ int CustomElement::terminalsCount() const { @param qp Le QPainter a utiliser pour dessiner l'element @param options Les options graphiques */ -void CustomElement::paint(QPainter *qp, const QStyleOptionGraphicsItem *) { - drawing.play(qp); +void CustomElement::paint(QPainter *qp, const QStyleOptionGraphicsItem *options) { + if (options && options -> levelOfDetail < 1.0) { + low_zoom_drawing.play(qp); + } else { + drawing.play(qp); + } } /** @@ -287,7 +302,6 @@ bool CustomElement::parseLine(QDomElement &e, QPainter &qp) { t.setJoinStyle(Qt::MiterJoin); qp.setPen(t); - //qp.drawLine(QLineF(x1, y1, x2, y2)); QLineF line(x1, y1, x2, y2); QPointF point1(line.p1()); QPointF point2(line.p2()); @@ -604,6 +618,7 @@ Terminal *CustomElement::parseTerminal(QDomElement &e) { @param aa Booleen a true pour activer l'antialiasing, a false pour le desactiver */ void CustomElement::setQPainterAntiAliasing(QPainter &qp, bool aa) { + if (forbid_antialiasing) aa = false; qp.setRenderHint(QPainter::Antialiasing, aa); qp.setRenderHint(QPainter::TextAntialiasing, aa); qp.setRenderHint(QPainter::SmoothPixmapTransform, aa); diff --git a/sources/customelement.h b/sources/customelement.h index 7629a79e4..02d17cf04 100644 --- a/sources/customelement.h +++ b/sources/customelement.h @@ -48,8 +48,10 @@ class CustomElement : public FixedElement { NamesList names; ElementsLocation location_; QPicture drawing; + QPicture low_zoom_drawing; QList list_terminals; QList list_texts_; + bool forbid_antialiasing; // methodes public: diff --git a/sources/diagram.cpp b/sources/diagram.cpp index 4fa9a8ec2..eed01da41 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -896,6 +896,7 @@ QETProject *Diagram::project() const { void Diagram::setProject(QETProject *project) { project_ = project; } + /** @return true si le schema est en lecture seule */ diff --git a/sources/ghostelement.cpp b/sources/ghostelement.cpp index 7432e5857..b8aa75b73 100644 --- a/sources/ghostelement.cpp +++ b/sources/ghostelement.cpp @@ -59,7 +59,7 @@ bool GhostElement::fromXml(QDomElement &e, QHash &table_id_adr) setInternalConnections(true); // on peut desormais confectionner le rendu de l'element - generateDrawing(); + generateDrawings(); // position, selection et orientation setPos(e.attribute("x").toDouble(), e.attribute("y").toDouble()); @@ -125,30 +125,44 @@ bool GhostElement::terminalsFromXml(QDomElement &e, QHash &tabl } /** - Genere le rendu de l'element fantome : il s'agit d'un rectangle + Genere les rendus de l'element fantome : il s'agit d'un rectangle representant grosso modo l'espace que devait prendre l'element initial. En son centre est dessine un point d'interrogation. Une petite croix indique le point de saisie de l'element. */ -void GhostElement::generateDrawing() { +void GhostElement::generateDrawings() { + // style de dessin + QPen t(QBrush(Qt::black), 1.0); + + // rendu normal QPainter qp; qp.begin(&drawing); - - // style de dessin - QPen t; - t.setColor(Qt::black); - t.setWidthF(1.0); - t.setJoinStyle(Qt::BevelJoin); qp.setPen(t); + qp.setRenderHint(QPainter::Antialiasing, false); + generateDrawing(&qp); + qp.end(); + // rendu low_zoom + QPainter low_zoom_qp; + low_zoom_qp.begin(&low_zoom_drawing); + t.setCosmetic(true); + low_zoom_qp.setRenderHint(QPainter::Antialiasing, false); + low_zoom_qp.setPen(t); + generateDrawing(&low_zoom_qp); + low_zoom_qp.end(); +} + +/** + Genere un rendu de l'element fantome + @see generateDrawings +*/ +void GhostElement::generateDrawing(QPainter *painter) { // une petite croix indique le point de saisie de l'element - qp.drawLine(QLineF(-1.0, 0.0, 1.0, 0.0)); - qp.drawLine(QLineF(0.0, -1.0, 0.0, 1.0)); + painter -> drawLine(QLineF(-1.0, 0.0, 1.0, 0.0)); + painter -> drawLine(QLineF(0.0, -1.0, 0.0, 1.0)); // rectangle avec un point d'interrogation au centre QRectF drawn_rect = boundingRect().adjusted(4.0, 4.0, -4.0, -4.0); - qp.drawRect(drawn_rect); - qp.drawText(drawn_rect, Qt::AlignHCenter | Qt::AlignVCenter, "?"); - - qp.end(); + painter -> drawRect(drawn_rect); + painter -> drawText(drawn_rect, Qt::AlignHCenter | Qt::AlignVCenter, "?"); } diff --git a/sources/ghostelement.h b/sources/ghostelement.h index e1dcf7d07..854bb9315 100644 --- a/sources/ghostelement.h +++ b/sources/ghostelement.h @@ -49,6 +49,7 @@ class GhostElement : public CustomElement { protected: QRectF minimalBoundingRect() const; bool terminalsFromXml(QDomElement &, QHash &); - void generateDrawing(); + void generateDrawings(); + void generateDrawing(QPainter *); }; #endif diff --git a/sources/terminal.cpp b/sources/terminal.cpp index e7a3ed27e..568480249 100644 --- a/sources/terminal.cpp +++ b/sources/terminal.cpp @@ -182,6 +182,9 @@ void Terminal::removeConductor(Conductor *f) { @param widget Le widget sur lequel on dessine */ void Terminal::paint(QPainter *p, const QStyleOptionGraphicsItem *options, QWidget *widget) { + // en dessous d'un certain zoom, les bornes ne sont plus dessinees + if (options && options -> levelOfDetail < 0.5) return; + p -> save(); #ifdef Q_WS_X11 @@ -219,6 +222,10 @@ void Terminal::paint(QPainter *p, const QStyleOptionGraphicsItem *options, QWidg QPen t; t.setWidthF(1.0); + if (options && options -> levelOfDetail < 1.0) { + t.setCosmetic(true); + } + // dessin de la borne en rouge t.setColor(Qt::red); p -> setPen(t);