mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-19 06:20:53 +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);
|
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
|
// dessin du conducteur
|
||||||
qp -> drawPath(path());
|
qp -> drawPath(path());
|
||||||
if (properties_.type == ConductorProperties::Single) {
|
if (properties_.type == ConductorProperties::Single) {
|
||||||
|
|||||||
@@ -46,7 +46,8 @@
|
|||||||
CustomElement::CustomElement(const ElementsLocation &location, QGraphicsItem *qgi, Diagram *s, int *state) :
|
CustomElement::CustomElement(const ElementsLocation &location, QGraphicsItem *qgi, Diagram *s, int *state) :
|
||||||
FixedElement(qgi, s),
|
FixedElement(qgi, s),
|
||||||
elmt_state(-1),
|
elmt_state(-1),
|
||||||
location_(location)
|
location_(location),
|
||||||
|
forbid_antialiasing(false)
|
||||||
{
|
{
|
||||||
// recupere la definition de l'element
|
// recupere la definition de l'element
|
||||||
ElementsCollectionItem *element_item = QETApp::collectionItem(location);
|
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)
|
// initialisation du QPainter (pour dessiner l'element)
|
||||||
QPainter qp;
|
QPainter qp;
|
||||||
qp.begin(&drawing);
|
qp.begin(&drawing);
|
||||||
QPen t;
|
|
||||||
t.setColor(Qt::black);
|
QPainter low_zoom_qp;
|
||||||
t.setWidthF(1.0);
|
low_zoom_qp.begin(&low_zoom_drawing);
|
||||||
t.setJoinStyle(Qt::BevelJoin);
|
QPen tmp;
|
||||||
qp.setPen(t);
|
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
|
// extrait les noms de la definition XML
|
||||||
names.fromXml(xml_def_elmt);
|
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()) {
|
for (QDomNode n = node.firstChild() ; !n.isNull() ; n = n.nextSibling()) {
|
||||||
QDomElement qde = n.toElement();
|
QDomElement qde = n.toElement();
|
||||||
if (qde.isNull()) continue;
|
if (qde.isNull()) continue;
|
||||||
if (parseElement(qde, qp)) ++ parsed_elements_count;
|
if (parseElement(qde, qp)) {
|
||||||
else {
|
++ 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;
|
if (state) *state = 7;
|
||||||
return(false);
|
return(false);
|
||||||
}
|
}
|
||||||
@@ -180,6 +190,7 @@ bool CustomElement::buildFromXml(const QDomElement &xml_def_elmt, int *state) {
|
|||||||
|
|
||||||
// fin du dessin
|
// fin du dessin
|
||||||
qp.end();
|
qp.end();
|
||||||
|
low_zoom_qp.end();
|
||||||
|
|
||||||
// il doit y avoir au moins un element charge
|
// il doit y avoir au moins un element charge
|
||||||
if (!parsed_elements_count) {
|
if (!parsed_elements_count) {
|
||||||
@@ -226,9 +237,13 @@ int CustomElement::terminalsCount() const {
|
|||||||
@param qp Le QPainter a utiliser pour dessiner l'element
|
@param qp Le QPainter a utiliser pour dessiner l'element
|
||||||
@param options Les options graphiques
|
@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);
|
drawing.play(qp);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Analyse et prend en compte un element XML decrivant une partie du dessin
|
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);
|
t.setJoinStyle(Qt::MiterJoin);
|
||||||
qp.setPen(t);
|
qp.setPen(t);
|
||||||
|
|
||||||
//qp.drawLine(QLineF(x1, y1, x2, y2));
|
|
||||||
QLineF line(x1, y1, x2, y2);
|
QLineF line(x1, y1, x2, y2);
|
||||||
QPointF point1(line.p1());
|
QPointF point1(line.p1());
|
||||||
QPointF point2(line.p2());
|
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
|
@param aa Booleen a true pour activer l'antialiasing, a false pour le desactiver
|
||||||
*/
|
*/
|
||||||
void CustomElement::setQPainterAntiAliasing(QPainter &qp, bool aa) {
|
void CustomElement::setQPainterAntiAliasing(QPainter &qp, bool aa) {
|
||||||
|
if (forbid_antialiasing) aa = false;
|
||||||
qp.setRenderHint(QPainter::Antialiasing, aa);
|
qp.setRenderHint(QPainter::Antialiasing, aa);
|
||||||
qp.setRenderHint(QPainter::TextAntialiasing, aa);
|
qp.setRenderHint(QPainter::TextAntialiasing, aa);
|
||||||
qp.setRenderHint(QPainter::SmoothPixmapTransform, aa);
|
qp.setRenderHint(QPainter::SmoothPixmapTransform, aa);
|
||||||
|
|||||||
@@ -48,8 +48,10 @@ class CustomElement : public FixedElement {
|
|||||||
NamesList names;
|
NamesList names;
|
||||||
ElementsLocation location_;
|
ElementsLocation location_;
|
||||||
QPicture drawing;
|
QPicture drawing;
|
||||||
|
QPicture low_zoom_drawing;
|
||||||
QList<Terminal *> list_terminals;
|
QList<Terminal *> list_terminals;
|
||||||
QList<ElementTextItem *> list_texts_;
|
QList<ElementTextItem *> list_texts_;
|
||||||
|
bool forbid_antialiasing;
|
||||||
|
|
||||||
// methodes
|
// methodes
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -896,6 +896,7 @@ QETProject *Diagram::project() const {
|
|||||||
void Diagram::setProject(QETProject *project) {
|
void Diagram::setProject(QETProject *project) {
|
||||||
project_ = project;
|
project_ = project;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@return true si le schema est en lecture seule
|
@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);
|
setInternalConnections(true);
|
||||||
|
|
||||||
// on peut desormais confectionner le rendu de l'element
|
// on peut desormais confectionner le rendu de l'element
|
||||||
generateDrawing();
|
generateDrawings();
|
||||||
|
|
||||||
// position, selection et orientation
|
// position, selection et orientation
|
||||||
setPos(e.attribute("x").toDouble(), e.attribute("y").toDouble());
|
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.
|
representant grosso modo l'espace que devait prendre l'element initial.
|
||||||
En son centre est dessine un point d'interrogation. Une petite croix indique
|
En son centre est dessine un point d'interrogation. Une petite croix indique
|
||||||
le point de saisie de l'element.
|
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;
|
QPainter qp;
|
||||||
qp.begin(&drawing);
|
qp.begin(&drawing);
|
||||||
|
|
||||||
// style de dessin
|
|
||||||
QPen t;
|
|
||||||
t.setColor(Qt::black);
|
|
||||||
t.setWidthF(1.0);
|
|
||||||
t.setJoinStyle(Qt::BevelJoin);
|
|
||||||
qp.setPen(t);
|
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
|
// une petite croix indique le point de saisie de l'element
|
||||||
qp.drawLine(QLineF(-1.0, 0.0, 1.0, 0.0));
|
painter -> drawLine(QLineF(-1.0, 0.0, 1.0, 0.0));
|
||||||
qp.drawLine(QLineF(0.0, -1.0, 0.0, 1.0));
|
painter -> drawLine(QLineF(0.0, -1.0, 0.0, 1.0));
|
||||||
|
|
||||||
// rectangle avec un point d'interrogation au centre
|
// rectangle avec un point d'interrogation au centre
|
||||||
QRectF drawn_rect = boundingRect().adjusted(4.0, 4.0, -4.0, -4.0);
|
QRectF drawn_rect = boundingRect().adjusted(4.0, 4.0, -4.0, -4.0);
|
||||||
qp.drawRect(drawn_rect);
|
painter -> drawRect(drawn_rect);
|
||||||
qp.drawText(drawn_rect, Qt::AlignHCenter | Qt::AlignVCenter, "?");
|
painter -> drawText(drawn_rect, Qt::AlignHCenter | Qt::AlignVCenter, "?");
|
||||||
|
|
||||||
qp.end();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ class GhostElement : public CustomElement {
|
|||||||
protected:
|
protected:
|
||||||
QRectF minimalBoundingRect() const;
|
QRectF minimalBoundingRect() const;
|
||||||
bool terminalsFromXml(QDomElement &, QHash<int, Terminal *> &);
|
bool terminalsFromXml(QDomElement &, QHash<int, Terminal *> &);
|
||||||
void generateDrawing();
|
void generateDrawings();
|
||||||
|
void generateDrawing(QPainter *);
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -182,6 +182,9 @@ void Terminal::removeConductor(Conductor *f) {
|
|||||||
@param widget Le widget sur lequel on dessine
|
@param widget Le widget sur lequel on dessine
|
||||||
*/
|
*/
|
||||||
void Terminal::paint(QPainter *p, const QStyleOptionGraphicsItem *options, QWidget *widget) {
|
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();
|
p -> save();
|
||||||
|
|
||||||
#ifdef Q_WS_X11
|
#ifdef Q_WS_X11
|
||||||
@@ -219,6 +222,10 @@ void Terminal::paint(QPainter *p, const QStyleOptionGraphicsItem *options, QWidg
|
|||||||
QPen t;
|
QPen t;
|
||||||
t.setWidthF(1.0);
|
t.setWidthF(1.0);
|
||||||
|
|
||||||
|
if (options && options -> levelOfDetail < 1.0) {
|
||||||
|
t.setCosmetic(true);
|
||||||
|
}
|
||||||
|
|
||||||
// dessin de la borne en rouge
|
// dessin de la borne en rouge
|
||||||
t.setColor(Qt::red);
|
t.setColor(Qt::red);
|
||||||
p -> setPen(t);
|
p -> setPen(t);
|
||||||
|
|||||||
Reference in New Issue
Block a user