mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-24 03:10:52 +01:00
Amelioration du rendu lors des deplacements d'elements, mais sans les bugs du commit 37 ; correction d'un bug : les conducteurs ne se mettaient pas bien a jour lors de la rotation d'un element
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@38 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -228,7 +228,6 @@ void Borne::mousePressEvent(QGraphicsSceneMouseEvent *e) {
|
||||
s -> poseConducteur(true);
|
||||
setCursor(Qt::CrossCursor);
|
||||
}
|
||||
//QGraphicsItem::mouseReleaseEvent(e);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -123,6 +123,10 @@ bool Element::setOrientation(Borne::Orientation o) {
|
||||
// rotation en consequence et rafraichissement de l'element graphique
|
||||
rotate(90.0 * (o - ori));
|
||||
ori = o;
|
||||
update();
|
||||
foreach(QGraphicsItem *qgi, children()) {
|
||||
if (Borne *p = qgraphicsitem_cast<Borne *>(qgi)) p -> updateConducteur();
|
||||
}
|
||||
return(true);
|
||||
}
|
||||
|
||||
@@ -215,7 +219,6 @@ void Element::setPos(qreal x, qreal y) {
|
||||
Gere les mouvements de souris lies a l'element, notamment
|
||||
*/
|
||||
void Element::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
||||
/*&& (flags() & ItemIsMovable)*/ // on le sait qu'il est movable
|
||||
if (e -> buttons() & Qt::LeftButton) {
|
||||
QPointF oldPos = pos();
|
||||
setPos(mapToParent(e -> pos()) - matrix().map(e -> buttonDownPos(Qt::LeftButton)));
|
||||
@@ -232,7 +235,7 @@ void Element::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
||||
// Deplace tous les elements selectionnes
|
||||
foreach (QGraphicsItem *item, selectedItems) {
|
||||
if (!item -> parentItem() || !item -> parentItem() -> isSelected())
|
||||
if (item != this) item -> setPos(item -> pos() + diff);
|
||||
if (item != this && qgraphicsitem_cast<Element *>(item)) item -> setPos(item -> pos() + diff);
|
||||
}
|
||||
} else e -> ignore();
|
||||
}
|
||||
|
||||
52
schema.cpp
52
schema.cpp
@@ -18,7 +18,6 @@ Schema::Schema(QObject *parent) : QGraphicsScene(parent) {
|
||||
poseur_de_conducteur -> setPen(t);
|
||||
poseur_de_conducteur -> setLine(QLineF(QPointF(0.0, 0.0), QPointF(0.0, 0.0)));
|
||||
doit_dessiner_grille = true;
|
||||
translation = QPoint(0, 0);
|
||||
connect(this, SIGNAL(changed(const QList<QRectF> &)), this, SLOT(slot_checkSelectionChange()));
|
||||
}
|
||||
|
||||
@@ -333,54 +332,3 @@ void Schema::slot_checkSelectionChange() {
|
||||
if (cache_selecteditems != selecteditems) emit(selectionChanged());
|
||||
cache_selecteditems = selecteditems;
|
||||
}
|
||||
|
||||
/**
|
||||
Gere les mouvements de souris sur le schema et, ipso facto, les
|
||||
deplacements d'elements. Cette fonction veille a ne deplacer que les
|
||||
elements (les conducteurs sont remis a jour par les bornes des elements)
|
||||
et tient compte de la grille.
|
||||
@param mouseEvent Un QGraphicsSceneMouseEvent decrivant l'evenement
|
||||
"mouvement de souris"
|
||||
*/
|
||||
void Schema::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent) {
|
||||
if (mouseEvent -> buttons() & Qt::LeftButton) {
|
||||
translation += (mouseEvent -> scenePos() - mouseEvent -> lastScenePos()).toPoint();
|
||||
|
||||
bool doit_translater = false;
|
||||
int coeffx = 0, coeffy = 0;
|
||||
|
||||
if (translation.x() >= GRILLE_X) {
|
||||
doit_translater = true;
|
||||
coeffx = translation.x() / GRILLE_X;
|
||||
translation.setX(translation.x() % GRILLE_X);
|
||||
} else if (translation.x() <= -GRILLE_X) {
|
||||
doit_translater = true;
|
||||
coeffx = translation.x() / GRILLE_X;
|
||||
translation.setX(translation.x() % GRILLE_X);
|
||||
}
|
||||
|
||||
if (translation.y() >= GRILLE_Y) {
|
||||
doit_translater = true;
|
||||
coeffy = translation.y() / GRILLE_Y;
|
||||
translation.setY(translation.y() % GRILLE_Y);
|
||||
} else if (translation.y() <= -GRILLE_Y) {
|
||||
doit_translater = true;
|
||||
coeffy = translation.y() / GRILLE_Y;
|
||||
translation.setY(translation.y() % GRILLE_Y);
|
||||
}
|
||||
|
||||
if (doit_translater) {
|
||||
// parcourt la listes des QGraphicsItem
|
||||
foreach (QGraphicsItem *qgi, selectedItems()) {
|
||||
// translate uniquement les elements (pas les conducteurs)
|
||||
if (Element *e = qgraphicsitem_cast<Element *>(qgi))
|
||||
e -> setPos(e -> pos() + QPointF(GRILLE_X * coeffx, GRILLE_Y * coeffy));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Schema::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent) {
|
||||
translation = QPoint(0, 0);
|
||||
QGraphicsScene::mouseReleaseEvent(mouseEvent);
|
||||
}
|
||||
|
||||
6
schema.h
6
schema.h
@@ -33,14 +33,10 @@
|
||||
QString folio; // vraiment necessaire ce truc ?
|
||||
QString nom_fichier; // meme remarque
|
||||
|
||||
protected:
|
||||
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *);
|
||||
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
|
||||
private:
|
||||
QGraphicsLineItem *poseur_de_conducteur;
|
||||
bool doit_dessiner_grille;
|
||||
Element *elementFromXml(QDomElement &e, QHash<int, Borne *> &);
|
||||
QPoint translation;
|
||||
Element *elementFromXml(QDomElement &, QHash<int, Borne *> &);
|
||||
|
||||
private slots:
|
||||
void slot_checkSelectionChange();
|
||||
|
||||
Reference in New Issue
Block a user