mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 13:30:34 +01:00
Amelioration du rendu graphique lorsque le zoom est inferieur a 1.0.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@566 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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,9 +237,13 @@ 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 *) {
|
||||
void CustomElement::paint(QPainter *qp, const QStyleOptionGraphicsItem *options) {
|
||||
if (options && options -> levelOfDetail < 1.0) {
|
||||
low_zoom_drawing.play(qp);
|
||||
} else {
|
||||
drawing.play(qp);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Analyse et prend en compte un element XML decrivant une partie du dessin
|
||||
@@ -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);
|
||||
|
||||
@@ -48,8 +48,10 @@ class CustomElement : public FixedElement {
|
||||
NamesList names;
|
||||
ElementsLocation location_;
|
||||
QPicture drawing;
|
||||
QPicture low_zoom_drawing;
|
||||
QList<Terminal *> list_terminals;
|
||||
QList<ElementTextItem *> list_texts_;
|
||||
bool forbid_antialiasing;
|
||||
|
||||
// methodes
|
||||
public:
|
||||
|
||||
@@ -896,6 +896,7 @@ QETProject *Diagram::project() const {
|
||||
void Diagram::setProject(QETProject *project) {
|
||||
project_ = project;
|
||||
}
|
||||
|
||||
/**
|
||||
@return true si le schema est en lecture seule
|
||||
*/
|
||||
|
||||
@@ -59,7 +59,7 @@ bool GhostElement::fromXml(QDomElement &e, QHash<int, Terminal *> &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<int, Terminal *> &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, "?");
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ class GhostElement : public CustomElement {
|
||||
protected:
|
||||
QRectF minimalBoundingRect() const;
|
||||
bool terminalsFromXml(QDomElement &, QHash<int, Terminal *> &);
|
||||
void generateDrawing();
|
||||
void generateDrawings();
|
||||
void generateDrawing(QPainter *);
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user