Correction d'un bug dans la modification des conducteurs apres un deplacement d'elements

Implementation partielle de l'alignement des conducteurs sur la grille. Lors de la modification manuelle des conducteurs, les segments se fixent sur la grille. L'ancien comportement peut etre obtenu en maintenant la touche Shift enfoncee.
Optimisation des fonctions "Selectionner tout" et "Deselectionner tout"
Remplacement des #define par des attributs static const


git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@168 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
xavierqet 2007-10-10 22:35:32 +00:00
parent 08b01bccb0
commit b91b418c95
12 changed files with 63 additions and 42 deletions

View File

@ -499,7 +499,7 @@ void Conductor::mousePressEvent(QGraphicsSceneMouseEvent *e) {
// clic gauche // clic gauche
if (e -> buttons() & Qt::LeftButton) { if (e -> buttons() & Qt::LeftButton) {
// recupere les coordonnees du clic // recupere les coordonnees du clic
press_point = mapFromScene(e -> pos()); press_point = e -> pos();
/* /*
parcourt les segments pour determiner si le clic a eu lieu parcourt les segments pour determiner si le clic a eu lieu
@ -541,6 +541,11 @@ void Conductor::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
qreal mouse_x = e -> pos().x(); qreal mouse_x = e -> pos().x();
qreal mouse_y = e -> pos().y(); qreal mouse_y = e -> pos().y();
bool snap_conductors_to_grid = e -> modifiers() ^ Qt::ShiftModifier;
if (snap_conductors_to_grid) {
mouse_x = qRound(mouse_x / (Diagram::xGrid * 1.0)) * Diagram::xGrid;
mouse_y = qRound(mouse_y / (Diagram::yGrid * 1.0)) * Diagram::yGrid;
}
if (moving_point) { if (moving_point) {
// la modification par points revient bientot // la modification par points revient bientot
/* /*

View File

@ -6,6 +6,10 @@
#include "exportdialog.h" #include "exportdialog.h"
#include "diagramcommands.h" #include "diagramcommands.h"
const int Diagram::xGrid = 10;
const int Diagram::yGrid = 10;
const qreal Diagram::margin = 5.0;
/** /**
Constructeur Constructeur
@param parent Le QObject parent du schema @param parent Le QObject parent du schema
@ -58,18 +62,18 @@ void Diagram::drawBackground(QPainter *p, const QRectF &r) {
qreal limite_y = r.y() + r.height(); qreal limite_y = r.y() + r.height();
int g_x = (int)ceil(r.x()); int g_x = (int)ceil(r.x());
while (g_x % GRILLE_X) ++ g_x; while (g_x % xGrid) ++ g_x;
int g_y = (int)ceil(r.y()); int g_y = (int)ceil(r.y());
while (g_y % GRILLE_Y) ++ g_y; while (g_y % yGrid) ++ g_y;
for (int gx = g_x ; gx < limite_x ; gx += GRILLE_X) { for (int gx = g_x ; gx < limite_x ; gx += xGrid) {
for (int gy = g_y ; gy < limite_y ; gy += GRILLE_Y) { for (int gy = g_y ; gy < limite_y ; gy += yGrid) {
p -> drawPoint(gx, gy); p -> drawPoint(gx, gy);
} }
} }
} }
if (use_border) border_and_inset.draw(p, MARGIN, MARGIN); if (use_border) border_and_inset.draw(p, margin, margin);
p -> restore(); p -> restore();
} }
@ -80,10 +84,10 @@ void Diagram::drawBackground(QPainter *p, const QRectF &r) {
void Diagram::keyPressEvent(QKeyEvent *e) { void Diagram::keyPressEvent(QKeyEvent *e) {
QPointF movement; QPointF movement;
switch(e -> key()) { switch(e -> key()) {
case Qt::Key_Left: movement = QPointF(-GRILLE_X, 0.0); break; case Qt::Key_Left: movement = QPointF(-xGrid, 0.0); break;
case Qt::Key_Right: movement = QPointF(+GRILLE_X, 0.0); break; case Qt::Key_Right: movement = QPointF(+xGrid, 0.0); break;
case Qt::Key_Up: movement = QPointF(0.0, -GRILLE_Y); break; case Qt::Key_Up: movement = QPointF(0.0, -yGrid); break;
case Qt::Key_Down: movement = QPointF(0.0, +GRILLE_Y); break; case Qt::Key_Down: movement = QPointF(0.0, +yGrid); break;
} }
if (!movement.isNull()) { if (!movement.isNull()) {
QSet<Element *> moved_elements = elementsToMove(); QSet<Element *> moved_elements = elementsToMove();
@ -136,15 +140,15 @@ bool Diagram::toPaintDevice(QPaintDevice &pix, int width, int height, Qt::Aspect
QRectF source_area; QRectF source_area;
if (!use_border) { if (!use_border) {
source_area = itemsBoundingRect(); source_area = itemsBoundingRect();
source_area.translate(-MARGIN, -MARGIN); source_area.translate(-margin, -margin);
source_area.setWidth (source_area.width () + 2.0 * MARGIN); source_area.setWidth (source_area.width () + 2.0 * margin);
source_area.setHeight(source_area.height() + 2.0 * MARGIN); source_area.setHeight(source_area.height() + 2.0 * margin);
} else { } else {
source_area = QRectF( source_area = QRectF(
0.0, 0.0,
0.0, 0.0,
border_and_inset.borderWidth () + 2.0 * MARGIN, border_and_inset.borderWidth () + 2.0 * margin,
border_and_inset.borderHeight() + 2.0 * MARGIN border_and_inset.borderHeight() + 2.0 * margin
); );
} }
@ -190,8 +194,8 @@ QSize Diagram::imageSize() const {
image_height = border_and_inset.borderHeight(); image_height = border_and_inset.borderHeight();
} }
image_width += 2.0 * MARGIN; image_width += 2.0 * margin;
image_height += 2.0 * MARGIN; image_height += 2.0 * margin;
// renvoie la taille de la zone source // renvoie la taille de la zone source
return(QSizeF(image_width, image_height).toSize()); return(QSizeF(image_width, image_height).toSize());
@ -448,8 +452,8 @@ void Diagram::slot_checkSelectionEmptinessChange() {
QRectF Diagram::border() const { QRectF Diagram::border() const {
return( return(
QRectF( QRectF(
MARGIN, margin,
MARGIN, margin,
border_and_inset.borderWidth(), border_and_inset.borderWidth(),
border_and_inset.borderHeight() border_and_inset.borderHeight()
) )

View File

@ -1,8 +1,5 @@
#ifndef SCHEMA_H #ifndef SCHEMA_H
#define SCHEMA_H #define SCHEMA_H
#define GRILLE_X 10
#define GRILLE_Y 10
#define MARGIN 5.0
#include <QtGui> #include <QtGui>
#include <QtXml> #include <QtXml>
#include "qetdiagrameditor.h" #include "qetdiagrameditor.h"
@ -32,6 +29,12 @@ class Diagram : public QGraphicsScene {
enum BorderOptions { EmptyBorder, Inset, Columns }; enum BorderOptions { EmptyBorder, Inset, Columns };
BorderInset border_and_inset; BorderInset border_and_inset;
QPointF current_movement; QPointF current_movement;
/// taille de la grille en abscisse
static const int xGrid;
/// taille de la grille en ordonnee
static const int yGrid;
/// marge autour du schema
static const qreal margin;
private: private:
QGraphicsLineItem *conductor_setter; QGraphicsLineItem *conductor_setter;

View File

@ -47,7 +47,9 @@ DiagramView::~DiagramView() {
*/ */
void DiagramView::selectAll() { void DiagramView::selectAll() {
if (scene -> items().isEmpty()) return; if (scene -> items().isEmpty()) return;
foreach (QGraphicsItem *item, scene -> items()) item -> setSelected(true); QPainterPath path;
path.addRect(scene -> itemsBoundingRect());
scene -> setSelectionArea(path);
} }
/** /**
@ -55,7 +57,7 @@ void DiagramView::selectAll() {
*/ */
void DiagramView::selectNothing() { void DiagramView::selectNothing() {
if (scene -> items().isEmpty()) return; if (scene -> items().isEmpty()) return;
foreach (QGraphicsItem *item, scene -> items()) item -> setSelected(false); scene -> clearSelection();
} }
/** /**
@ -595,7 +597,7 @@ void DiagramView::adjustSceneRect() {
QRectF elements_bounding_rect = scene -> itemsBoundingRect(); QRectF elements_bounding_rect = scene -> itemsBoundingRect();
// rectangle contenant le cadre = colonnes + cartouche // rectangle contenant le cadre = colonnes + cartouche
QRectF border_bounding_rect = scene -> border().adjusted(-MARGIN, -MARGIN, MARGIN, MARGIN); QRectF border_bounding_rect = scene -> border().adjusted(-Diagram::margin, -Diagram::margin, Diagram::margin, Diagram::margin);
// ajuste la sceneRect // ajuste la sceneRect
QRectF new_scene_rect = elements_bounding_rect.united(border_bounding_rect); QRectF new_scene_rect = elements_bounding_rect.united(border_bounding_rect);

View File

@ -11,8 +11,9 @@
#include "partarc.h" #include "partarc.h"
#include "hotspoteditor.h" #include "hotspoteditor.h"
#include "editorcommands.h" #include "editorcommands.h"
#define GRILLE_X 10
#define GRILLE_Y 10 const int ElementScene::xGrid = 10;
const int ElementScene::yGrid = 10;
ElementScene::ElementScene(QETElementEditor *editor, QObject *parent) : ElementScene::ElementScene(QETElementEditor *editor, QObject *parent) :
QGraphicsScene(parent), QGraphicsScene(parent),
@ -248,12 +249,12 @@ void ElementScene::drawBackground(QPainter *p, const QRectF &r) {
qreal limite_y = r.y() + r.height(); qreal limite_y = r.y() + r.height();
int g_x = (int)ceil(r.x()); int g_x = (int)ceil(r.x());
while (g_x % GRILLE_X) ++ g_x; while (g_x % xGrid) ++ g_x;
int g_y = (int)ceil(r.y()); int g_y = (int)ceil(r.y());
while (g_y % GRILLE_Y) ++ g_y; while (g_y % yGrid) ++ g_y;
for (int gx = g_x ; gx < limite_x ; gx += GRILLE_X) { for (int gx = g_x ; gx < limite_x ; gx += xGrid) {
for (int gy = g_y ; gy < limite_y ; gy += GRILLE_Y) { for (int gy = g_y ; gy < limite_y ; gy += yGrid) {
p -> drawPoint(gx, gy); p -> drawPoint(gx, gy);
} }
} }

View File

@ -26,6 +26,10 @@ class ElementScene : public QGraphicsScene {
ElementScene(const ElementScene &); ElementScene(const ElementScene &);
// attributs // attributs
public:
static const int xGrid;
static const int yGrid;
private: private:
/// longueur de l'element en dizaines de pixels /// longueur de l'element en dizaines de pixels
uint _width; uint _width;

View File

@ -1,5 +1,5 @@
#ifndef PART_TEXT #ifndef PART_TEXT_H
#define PART_TEXT #define PART_TEXT_H
#include <QtGui> #include <QtGui>
#include "customelementpart.h" #include "customelementpart.h"
class TextEditor; class TextEditor;

View File

@ -1,5 +1,5 @@
#ifndef PART_TEXTFIELD #ifndef PART_TEXTFIELD_H
#define PART_TEXTFIELD #define PART_TEXTFIELD_H
#include <QtGui> #include <QtGui>
#include "customelementpart.h" #include "customelementpart.h"
class TextFieldEditor; class TextFieldEditor;

View File

@ -206,9 +206,9 @@ void Element::setPos(const QPointF &p) {
// pas la peine de positionner sur la grille si l'element n'est pas sur un Diagram // pas la peine de positionner sur la grille si l'element n'est pas sur un Diagram
if (scene()) { if (scene()) {
// arrondit l'abscisse a 10 px pres // arrondit l'abscisse a 10 px pres
int p_x = qRound(p.x() / 10.0) * 10; int p_x = qRound(p.x() / (Diagram::xGrid * 1.0)) * Diagram::xGrid;
// arrondit l'ordonnee a 10 px pres // arrondit l'ordonnee a 10 px pres
int p_y = qRound(p.y() / 10.0) * 10; int p_y = qRound(p.y() / (Diagram::yGrid * 1.0)) * Diagram::yGrid;
QGraphicsItem::setPos(p_x, p_y); QGraphicsItem::setPos(p_x, p_y);
} else QGraphicsItem::setPos(p); } else QGraphicsItem::setPos(p);
} }

View File

@ -33,7 +33,7 @@ HotspotEditor::HotspotEditor(QWidget *parent) :
diagram_view = new QGraphicsView(diagram_scene); diagram_view = new QGraphicsView(diagram_scene);
diagram_view -> setMaximumSize( diagram_view -> setMaximumSize(
static_cast<int>((5 * diagram_scene -> border_and_inset.columnsWidth()) + (3 * MARGIN)), static_cast<int>((5 * diagram_scene -> border_and_inset.columnsWidth()) + (3 * Diagram::margin)),
300 300
); );
diagram_view -> setTransformationAnchor(QGraphicsView::AnchorUnderMouse); diagram_view -> setTransformationAnchor(QGraphicsView::AnchorUnderMouse);

View File

@ -8,6 +8,7 @@ QColor Terminal::couleur_neutre = QColor(Qt::blue);
QColor Terminal::couleur_autorise = QColor(Qt::darkGreen); QColor Terminal::couleur_autorise = QColor(Qt::darkGreen);
QColor Terminal::couleur_prudence = QColor("#ff8000"); QColor Terminal::couleur_prudence = QColor("#ff8000");
QColor Terminal::couleur_interdit = QColor(Qt::red); QColor Terminal::couleur_interdit = QColor(Qt::red);
const qreal Terminal::terminalSize = 4.0;
/** /**
Fonction privee pour initialiser la borne. Fonction privee pour initialiser la borne.
@ -25,11 +26,11 @@ void Terminal::initialise(QPointF pf, QET::Orientation o) {
// calcul de la position du point d'amarrage a l'element // calcul de la position du point d'amarrage a l'element
amarrage_elmt = amarrage_conductor; amarrage_elmt = amarrage_conductor;
switch(sens) { switch(sens) {
case QET::North: amarrage_elmt += QPointF(0, TAILLE_BORNE); break; case QET::North: amarrage_elmt += QPointF(0, Terminal::terminalSize); break;
case QET::East : amarrage_elmt += QPointF(-TAILLE_BORNE, 0); break; case QET::East : amarrage_elmt += QPointF(-Terminal::terminalSize, 0); break;
case QET::West : amarrage_elmt += QPointF(TAILLE_BORNE, 0); break; case QET::West : amarrage_elmt += QPointF(Terminal::terminalSize, 0); break;
case QET::South: case QET::South:
default : amarrage_elmt += QPointF(0, -TAILLE_BORNE); default : amarrage_elmt += QPointF(0, -Terminal::terminalSize);
} }
// par defaut : pas de conducteur // par defaut : pas de conducteur

View File

@ -61,6 +61,7 @@ class Terminal : public QGraphicsItem {
// attributs // attributs
public: public:
enum { Type = UserType + 1002 }; enum { Type = UserType + 1002 };
static const qreal terminalSize;
// differentes couleurs statiques utilisables pour l'effet "hover" // differentes couleurs statiques utilisables pour l'effet "hover"
static QColor couleur_neutre; static QColor couleur_neutre;