mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
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:
parent
08b01bccb0
commit
b91b418c95
@ -499,7 +499,7 @@ void Conductor::mousePressEvent(QGraphicsSceneMouseEvent *e) {
|
||||
// clic gauche
|
||||
if (e -> buttons() & Qt::LeftButton) {
|
||||
// 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
|
||||
@ -541,6 +541,11 @@ void Conductor::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
||||
qreal mouse_x = e -> pos().x();
|
||||
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) {
|
||||
// la modification par points revient bientot
|
||||
/*
|
||||
|
40
diagram.cpp
40
diagram.cpp
@ -6,6 +6,10 @@
|
||||
#include "exportdialog.h"
|
||||
#include "diagramcommands.h"
|
||||
|
||||
const int Diagram::xGrid = 10;
|
||||
const int Diagram::yGrid = 10;
|
||||
const qreal Diagram::margin = 5.0;
|
||||
|
||||
/**
|
||||
Constructeur
|
||||
@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();
|
||||
|
||||
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());
|
||||
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 gy = g_y ; gy < limite_y ; gy += GRILLE_Y) {
|
||||
for (int gx = g_x ; gx < limite_x ; gx += xGrid) {
|
||||
for (int gy = g_y ; gy < limite_y ; gy += yGrid) {
|
||||
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();
|
||||
}
|
||||
|
||||
@ -80,10 +84,10 @@ void Diagram::drawBackground(QPainter *p, const QRectF &r) {
|
||||
void Diagram::keyPressEvent(QKeyEvent *e) {
|
||||
QPointF movement;
|
||||
switch(e -> key()) {
|
||||
case Qt::Key_Left: movement = QPointF(-GRILLE_X, 0.0); break;
|
||||
case Qt::Key_Right: movement = QPointF(+GRILLE_X, 0.0); break;
|
||||
case Qt::Key_Up: movement = QPointF(0.0, -GRILLE_Y); break;
|
||||
case Qt::Key_Down: movement = QPointF(0.0, +GRILLE_Y); break;
|
||||
case Qt::Key_Left: movement = QPointF(-xGrid, 0.0); break;
|
||||
case Qt::Key_Right: movement = QPointF(+xGrid, 0.0); break;
|
||||
case Qt::Key_Up: movement = QPointF(0.0, -yGrid); break;
|
||||
case Qt::Key_Down: movement = QPointF(0.0, +yGrid); break;
|
||||
}
|
||||
if (!movement.isNull()) {
|
||||
QSet<Element *> moved_elements = elementsToMove();
|
||||
@ -136,15 +140,15 @@ bool Diagram::toPaintDevice(QPaintDevice &pix, int width, int height, Qt::Aspect
|
||||
QRectF source_area;
|
||||
if (!use_border) {
|
||||
source_area = itemsBoundingRect();
|
||||
source_area.translate(-MARGIN, -MARGIN);
|
||||
source_area.setWidth (source_area.width () + 2.0 * MARGIN);
|
||||
source_area.setHeight(source_area.height() + 2.0 * MARGIN);
|
||||
source_area.translate(-margin, -margin);
|
||||
source_area.setWidth (source_area.width () + 2.0 * margin);
|
||||
source_area.setHeight(source_area.height() + 2.0 * margin);
|
||||
} else {
|
||||
source_area = QRectF(
|
||||
0.0,
|
||||
0.0,
|
||||
border_and_inset.borderWidth () + 2.0 * MARGIN,
|
||||
border_and_inset.borderHeight() + 2.0 * MARGIN
|
||||
border_and_inset.borderWidth () + 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_width += 2.0 * MARGIN;
|
||||
image_height += 2.0 * MARGIN;
|
||||
image_width += 2.0 * margin;
|
||||
image_height += 2.0 * margin;
|
||||
|
||||
// renvoie la taille de la zone source
|
||||
return(QSizeF(image_width, image_height).toSize());
|
||||
@ -448,8 +452,8 @@ void Diagram::slot_checkSelectionEmptinessChange() {
|
||||
QRectF Diagram::border() const {
|
||||
return(
|
||||
QRectF(
|
||||
MARGIN,
|
||||
MARGIN,
|
||||
margin,
|
||||
margin,
|
||||
border_and_inset.borderWidth(),
|
||||
border_and_inset.borderHeight()
|
||||
)
|
||||
|
@ -1,8 +1,5 @@
|
||||
#ifndef SCHEMA_H
|
||||
#define SCHEMA_H
|
||||
#define GRILLE_X 10
|
||||
#define GRILLE_Y 10
|
||||
#define MARGIN 5.0
|
||||
#include <QtGui>
|
||||
#include <QtXml>
|
||||
#include "qetdiagrameditor.h"
|
||||
@ -32,6 +29,12 @@ class Diagram : public QGraphicsScene {
|
||||
enum BorderOptions { EmptyBorder, Inset, Columns };
|
||||
BorderInset border_and_inset;
|
||||
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:
|
||||
QGraphicsLineItem *conductor_setter;
|
||||
|
@ -47,7 +47,9 @@ DiagramView::~DiagramView() {
|
||||
*/
|
||||
void DiagramView::selectAll() {
|
||||
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() {
|
||||
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();
|
||||
|
||||
// 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
|
||||
QRectF new_scene_rect = elements_bounding_rect.united(border_bounding_rect);
|
||||
|
@ -11,8 +11,9 @@
|
||||
#include "partarc.h"
|
||||
#include "hotspoteditor.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) :
|
||||
QGraphicsScene(parent),
|
||||
@ -248,12 +249,12 @@ void ElementScene::drawBackground(QPainter *p, const QRectF &r) {
|
||||
qreal limite_y = r.y() + r.height();
|
||||
|
||||
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());
|
||||
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 gy = g_y ; gy < limite_y ; gy += GRILLE_Y) {
|
||||
for (int gx = g_x ; gx < limite_x ; gx += xGrid) {
|
||||
for (int gy = g_y ; gy < limite_y ; gy += yGrid) {
|
||||
p -> drawPoint(gx, gy);
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,10 @@ class ElementScene : public QGraphicsScene {
|
||||
ElementScene(const ElementScene &);
|
||||
|
||||
// attributs
|
||||
public:
|
||||
static const int xGrid;
|
||||
static const int yGrid;
|
||||
|
||||
private:
|
||||
/// longueur de l'element en dizaines de pixels
|
||||
uint _width;
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef PART_TEXT
|
||||
#define PART_TEXT
|
||||
#ifndef PART_TEXT_H
|
||||
#define PART_TEXT_H
|
||||
#include <QtGui>
|
||||
#include "customelementpart.h"
|
||||
class TextEditor;
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef PART_TEXTFIELD
|
||||
#define PART_TEXTFIELD
|
||||
#ifndef PART_TEXTFIELD_H
|
||||
#define PART_TEXTFIELD_H
|
||||
#include <QtGui>
|
||||
#include "customelementpart.h"
|
||||
class TextFieldEditor;
|
||||
|
@ -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
|
||||
if (scene()) {
|
||||
// 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
|
||||
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);
|
||||
} else QGraphicsItem::setPos(p);
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ HotspotEditor::HotspotEditor(QWidget *parent) :
|
||||
|
||||
diagram_view = new QGraphicsView(diagram_scene);
|
||||
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
|
||||
);
|
||||
diagram_view -> setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
|
||||
|
@ -8,6 +8,7 @@ QColor Terminal::couleur_neutre = QColor(Qt::blue);
|
||||
QColor Terminal::couleur_autorise = QColor(Qt::darkGreen);
|
||||
QColor Terminal::couleur_prudence = QColor("#ff8000");
|
||||
QColor Terminal::couleur_interdit = QColor(Qt::red);
|
||||
const qreal Terminal::terminalSize = 4.0;
|
||||
|
||||
/**
|
||||
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
|
||||
amarrage_elmt = amarrage_conductor;
|
||||
switch(sens) {
|
||||
case QET::North: amarrage_elmt += QPointF(0, TAILLE_BORNE); break;
|
||||
case QET::East : amarrage_elmt += QPointF(-TAILLE_BORNE, 0); break;
|
||||
case QET::West : amarrage_elmt += QPointF(TAILLE_BORNE, 0); break;
|
||||
case QET::North: amarrage_elmt += QPointF(0, Terminal::terminalSize); break;
|
||||
case QET::East : amarrage_elmt += QPointF(-Terminal::terminalSize, 0); break;
|
||||
case QET::West : amarrage_elmt += QPointF(Terminal::terminalSize, 0); break;
|
||||
case QET::South:
|
||||
default : amarrage_elmt += QPointF(0, -TAILLE_BORNE);
|
||||
default : amarrage_elmt += QPointF(0, -Terminal::terminalSize);
|
||||
}
|
||||
|
||||
// par defaut : pas de conducteur
|
||||
|
@ -61,6 +61,7 @@ class Terminal : public QGraphicsItem {
|
||||
// attributs
|
||||
public:
|
||||
enum { Type = UserType + 1002 };
|
||||
static const qreal terminalSize;
|
||||
|
||||
// differentes couleurs statiques utilisables pour l'effet "hover"
|
||||
static QColor couleur_neutre;
|
||||
|
Loading…
x
Reference in New Issue
Block a user