mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-22 09:40:52 +01:00
Correction d'un bug lors de l'enregistrement des polygones.
Ajout de la gestion des arcs de cercle dans l'editeur d'element. git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@95 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
76
editor/arceditor.cpp
Normal file
76
editor/arceditor.cpp
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
#include "arceditor.h"
|
||||||
|
#include "partarc.h"
|
||||||
|
|
||||||
|
ArcEditor::ArcEditor(PartArc *arc, QWidget *parent) : QWidget(parent) {
|
||||||
|
|
||||||
|
part = arc;
|
||||||
|
|
||||||
|
x = new QLineEdit();
|
||||||
|
y = new QLineEdit();
|
||||||
|
h = new QLineEdit();
|
||||||
|
v = new QLineEdit();
|
||||||
|
start_angle = new QSpinBox();
|
||||||
|
angle = new QSpinBox();
|
||||||
|
start_angle -> setRange(-360, 360);
|
||||||
|
angle -> setRange(-360, 360);
|
||||||
|
|
||||||
|
QGridLayout *grid = new QGridLayout(this);
|
||||||
|
grid -> addWidget(new QLabel(tr("Centre : ")), 0, 0);
|
||||||
|
grid -> addWidget(new QLabel("x"), 1, 0);
|
||||||
|
grid -> addWidget(x, 1, 1);
|
||||||
|
grid -> addWidget(new QLabel("y"), 1, 2);
|
||||||
|
grid -> addWidget(y, 1, 3);
|
||||||
|
grid -> addWidget(new QLabel(tr("Diam\350tres : ")), 2, 0);
|
||||||
|
grid -> addWidget(new QLabel(tr("horizontal :")), 3, 0);
|
||||||
|
grid -> addWidget(h, 3, 1);
|
||||||
|
grid -> addWidget(new QLabel(tr("vertical :")), 4, 0);
|
||||||
|
grid -> addWidget(v, 4, 1);
|
||||||
|
grid -> addWidget(new QLabel(tr("Angle de d\351part :")), 5, 0);
|
||||||
|
grid -> addWidget(start_angle, 5, 1);
|
||||||
|
grid -> addWidget(new QLabel(tr("Angle :")), 6, 0);
|
||||||
|
grid -> addWidget(angle, 6, 1);
|
||||||
|
updateForm();
|
||||||
|
|
||||||
|
connect(x, SIGNAL(editingFinished()), this, SLOT(updateArc()));
|
||||||
|
connect(y, SIGNAL(editingFinished()), this, SLOT(updateArc()));
|
||||||
|
connect(h, SIGNAL(editingFinished()), this, SLOT(updateArc()));
|
||||||
|
connect(v, SIGNAL(editingFinished()), this, SLOT(updateArc()));
|
||||||
|
connect(start_angle, SIGNAL(valueChanged(int)), this, SLOT(updateArc()));
|
||||||
|
connect(angle, SIGNAL(valueChanged(int)), this, SLOT(updateArc()));
|
||||||
|
}
|
||||||
|
|
||||||
|
ArcEditor::~ArcEditor() {
|
||||||
|
qDebug() << "~ArcEditor()";
|
||||||
|
}
|
||||||
|
|
||||||
|
void ArcEditor::updateArc() {
|
||||||
|
qreal _x = x -> text().toDouble();
|
||||||
|
qreal _y = y -> text().toDouble();
|
||||||
|
qreal _h = h -> text().toDouble();
|
||||||
|
qreal _v = v -> text().toDouble();
|
||||||
|
_v = _v < 0 ? -_v : _v;
|
||||||
|
part -> setRect(
|
||||||
|
QRectF(
|
||||||
|
part -> mapFromScene(QPointF(_x - (_h / 2.0), _y - (_v / 2.0))),
|
||||||
|
QSizeF(_h, _v)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
part -> setStartAngle(-start_angle -> value() + 90);
|
||||||
|
part -> setAngle(-angle -> value());
|
||||||
|
}
|
||||||
|
|
||||||
|
void ArcEditor::updateForm() {
|
||||||
|
qreal _h = part -> rect().width();
|
||||||
|
qreal _v = part -> rect().height();
|
||||||
|
QPointF top_left(part -> sceneTopLeft());
|
||||||
|
x -> setText(QString("%1").arg(top_left.x() + (_h / 2.0)));
|
||||||
|
y -> setText(QString("%1").arg(top_left.y() + (_v / 2.0)));
|
||||||
|
h -> setText(QString("%1").arg(_h));
|
||||||
|
v -> setText(QString("%1").arg(_v));
|
||||||
|
disconnect(start_angle, SIGNAL(valueChanged(int)), this, SLOT(updateArc()));
|
||||||
|
disconnect(angle, SIGNAL(valueChanged(int)), this, SLOT(updateArc()));
|
||||||
|
start_angle -> setValue(-part -> startAngle() + 90);
|
||||||
|
angle -> setValue(-part -> angle());
|
||||||
|
connect(start_angle, SIGNAL(valueChanged(int)), this, SLOT(updateArc()));
|
||||||
|
connect(angle, SIGNAL(valueChanged(int)), this, SLOT(updateArc()));
|
||||||
|
}
|
||||||
25
editor/arceditor.h
Normal file
25
editor/arceditor.h
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#ifndef ARC_EDITOR_H
|
||||||
|
#define ARC_EDITOR_H
|
||||||
|
#include <QtGui>
|
||||||
|
class PartArc;
|
||||||
|
class ArcEditor : public QWidget {
|
||||||
|
Q_OBJECT
|
||||||
|
//constructeurs, destructeur
|
||||||
|
public:
|
||||||
|
ArcEditor(PartArc *, QWidget * = 0);
|
||||||
|
~ArcEditor();
|
||||||
|
private:
|
||||||
|
ArcEditor(const ArcEditor &);
|
||||||
|
|
||||||
|
// attributs
|
||||||
|
private:
|
||||||
|
PartArc *part;
|
||||||
|
QLineEdit *x, *y, *h, *v;
|
||||||
|
QSpinBox *angle, *start_angle;
|
||||||
|
|
||||||
|
// methodes
|
||||||
|
public slots:
|
||||||
|
void updateArc();
|
||||||
|
void updateForm();
|
||||||
|
};
|
||||||
|
#endif
|
||||||
@@ -22,19 +22,6 @@ CustomElementEditor::CustomElementEditor(QWidget *parent) :
|
|||||||
|
|
||||||
CustomElementEditor::~CustomElementEditor() {
|
CustomElementEditor::~CustomElementEditor() {
|
||||||
qDebug() << "~CustomElementEditor()";
|
qDebug() << "~CustomElementEditor()";
|
||||||
// recupere le layout
|
|
||||||
// QLayout *layout = tools_dock -> widget() -> layout();
|
|
||||||
//
|
|
||||||
// // enleve les widgets deja presents
|
|
||||||
// QLayoutItem *qli;
|
|
||||||
// while ((qli = layout -> takeAt(0)) != 0) {
|
|
||||||
// if (qli -> widget()) {
|
|
||||||
// layout -> removeWidget(qli -> widget());
|
|
||||||
// qli -> widget() -> setParent(0);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CustomElementEditor::setupActions() {
|
void CustomElementEditor::setupActions() {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include "partpolygon.h"
|
#include "partpolygon.h"
|
||||||
#include "partterminal.h"
|
#include "partterminal.h"
|
||||||
#include "parttext.h"
|
#include "parttext.h"
|
||||||
|
#include "partarc.h"
|
||||||
#define GRILLE_X 10
|
#define GRILLE_X 10
|
||||||
#define GRILLE_Y 10
|
#define GRILLE_Y 10
|
||||||
|
|
||||||
@@ -78,6 +79,11 @@ void EditorScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
|||||||
temp_rect.setBottomRight(e -> scenePos());
|
temp_rect.setBottomRight(e -> scenePos());
|
||||||
current_ellipse -> setRect(temp_rect);
|
current_ellipse -> setRect(temp_rect);
|
||||||
break;
|
break;
|
||||||
|
case Arc:
|
||||||
|
temp_rect = current_arc -> rect();
|
||||||
|
temp_rect.setBottomRight(e -> scenePos());
|
||||||
|
current_arc -> setRect(temp_rect);
|
||||||
|
break;
|
||||||
case Circle:
|
case Circle:
|
||||||
temp_rect = current_circle -> rect();
|
temp_rect = current_circle -> rect();
|
||||||
temp_point = e -> scenePos() - current_circle -> mapToScene(temp_rect.center());
|
temp_point = e -> scenePos() - current_circle -> mapToScene(temp_rect.center());
|
||||||
@@ -122,6 +128,10 @@ void EditorScene::mousePressEvent(QGraphicsSceneMouseEvent *e) {
|
|||||||
current_ellipse = new PartEllipse(0, this);
|
current_ellipse = new PartEllipse(0, this);
|
||||||
current_ellipse -> setRect(QRectF(e -> scenePos(), QSizeF(0.0, 0.0)));
|
current_ellipse -> setRect(QRectF(e -> scenePos(), QSizeF(0.0, 0.0)));
|
||||||
break;
|
break;
|
||||||
|
case Arc:
|
||||||
|
current_arc = new PartArc(0, this);
|
||||||
|
current_arc -> setRect(QRectF(e -> scenePos(), QSizeF(0.0, 0.0)));
|
||||||
|
break;
|
||||||
case Circle:
|
case Circle:
|
||||||
current_circle = new PartCircle(0, this);
|
current_circle = new PartCircle(0, this);
|
||||||
current_circle -> setRect(QRectF(e -> scenePos(), QSizeF(0.0, 0.0)));
|
current_circle -> setRect(QRectF(e -> scenePos(), QSizeF(0.0, 0.0)));
|
||||||
@@ -156,6 +166,9 @@ void EditorScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
|
|||||||
case Ellipse:
|
case Ellipse:
|
||||||
current_ellipse -> setRect(current_ellipse -> rect().normalized());
|
current_ellipse -> setRect(current_ellipse -> rect().normalized());
|
||||||
break;
|
break;
|
||||||
|
case Arc:
|
||||||
|
current_arc-> setRect(current_arc -> rect().normalized());
|
||||||
|
break;
|
||||||
case Circle:
|
case Circle:
|
||||||
current_circle -> setRect(current_circle -> rect().normalized());
|
current_circle -> setRect(current_circle -> rect().normalized());
|
||||||
break;
|
break;
|
||||||
@@ -336,6 +349,7 @@ void EditorScene::fromXml(const QDomDocument &xml_document) {
|
|||||||
else if (qde.tagName() == "polygon") cep = new PartPolygon (0, this);
|
else if (qde.tagName() == "polygon") cep = new PartPolygon (0, this);
|
||||||
else if (qde.tagName() == "terminal") cep = new PartTerminal(0, this);
|
else if (qde.tagName() == "terminal") cep = new PartTerminal(0, this);
|
||||||
else if (qde.tagName() == "text") cep = new PartText (0, this);
|
else if (qde.tagName() == "text") cep = new PartText (0, this);
|
||||||
|
else if (qde.tagName() == "arc") cep = new PartArc (0, this);
|
||||||
else continue;
|
else continue;
|
||||||
if (QGraphicsItem *qgi = dynamic_cast<QGraphicsItem *>(cep)) qgi -> setZValue(z++);
|
if (QGraphicsItem *qgi = dynamic_cast<QGraphicsItem *>(cep)) qgi -> setZValue(z++);
|
||||||
cep -> fromXml(qde);
|
cep -> fromXml(qde);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ class PartLine;
|
|||||||
class PartEllipse;
|
class PartEllipse;
|
||||||
class PartCircle;
|
class PartCircle;
|
||||||
class PartPolygon;
|
class PartPolygon;
|
||||||
|
class PartArc;
|
||||||
class EditorScene : public QGraphicsScene {
|
class EditorScene : public QGraphicsScene {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@@ -41,6 +42,7 @@ class EditorScene : public QGraphicsScene {
|
|||||||
PartEllipse *current_ellipse;
|
PartEllipse *current_ellipse;
|
||||||
PartCircle *current_circle;
|
PartCircle *current_circle;
|
||||||
PartPolygon *current_polygon;
|
PartPolygon *current_polygon;
|
||||||
|
PartArc *current_arc;
|
||||||
|
|
||||||
// methodes
|
// methodes
|
||||||
public:
|
public:
|
||||||
|
|||||||
98
editor/partarc.cpp
Normal file
98
editor/partarc.cpp
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
#include "partarc.h"
|
||||||
|
#include "arceditor.h"
|
||||||
|
|
||||||
|
PartArc::PartArc(QGraphicsItem *parent, QGraphicsScene *scene) :
|
||||||
|
QGraphicsEllipseItem(parent, scene),
|
||||||
|
CustomElementGraphicPart(),
|
||||||
|
_angle(-90),
|
||||||
|
start_angle(0)
|
||||||
|
{
|
||||||
|
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
|
||||||
|
setAcceptedMouseButtons(Qt::LeftButton);
|
||||||
|
informations = new ArcEditor(this);
|
||||||
|
style_editor -> appendWidget(informations);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PartArc::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) {
|
||||||
|
applyStylesToQPainter(*painter);
|
||||||
|
// enleve systematiquement la couleur de fond
|
||||||
|
painter -> setBrush(Qt::NoBrush);
|
||||||
|
QPen t = painter -> pen();
|
||||||
|
if (isSelected()) {
|
||||||
|
// dessine l'ellipse en noir
|
||||||
|
painter -> drawEllipse(rect());
|
||||||
|
|
||||||
|
// dessine l'arc en rouge
|
||||||
|
t.setColor(Qt::red);
|
||||||
|
painter -> setPen(t);
|
||||||
|
}
|
||||||
|
painter -> drawArc(rect(), start_angle * 16, _angle * 16);
|
||||||
|
if (isSelected()) {
|
||||||
|
// dessine la croix au centre de l'ellipse
|
||||||
|
painter -> setRenderHint(QPainter::Antialiasing, false);
|
||||||
|
painter -> setPen((painter -> brush().color() == QColor(Qt::black) && painter -> brush().isOpaque()) ? Qt::yellow : Qt::blue);
|
||||||
|
QPointF center = rect().center();
|
||||||
|
painter -> drawLine(QLineF(center.x() - 2.0, center.y(), center.x() + 2.0, center.y()));
|
||||||
|
painter -> drawLine(QLineF(center.x(), center.y() - 2.0, center.x(), center.y() + 2.0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const QDomElement PartArc::toXml(QDomDocument &xml_document) const {
|
||||||
|
QDomElement xml_element = xml_document.createElement("arc");
|
||||||
|
QPointF top_left(sceneTopLeft());
|
||||||
|
xml_element.setAttribute("x", top_left.x());
|
||||||
|
xml_element.setAttribute("y", top_left.y());
|
||||||
|
xml_element.setAttribute("width", rect().width());
|
||||||
|
xml_element.setAttribute("height", rect().height());
|
||||||
|
xml_element.setAttribute("start", start_angle);
|
||||||
|
xml_element.setAttribute("angle", _angle);
|
||||||
|
stylesToXml(xml_element);
|
||||||
|
return(xml_element);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PartArc::fromXml(const QDomElement &qde) {
|
||||||
|
stylesFromXml(qde);
|
||||||
|
setRect(
|
||||||
|
QRectF(
|
||||||
|
mapFromScene(
|
||||||
|
qde.attribute("x", "0").toDouble(),
|
||||||
|
qde.attribute("y", "0").toDouble()
|
||||||
|
),
|
||||||
|
QSizeF(
|
||||||
|
qde.attribute("width", "0").toDouble(),
|
||||||
|
qde.attribute("height", "0").toDouble()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
setStartAngle(qde.attribute("start", "0").toInt());
|
||||||
|
setAngle(qde.attribute("angle", "-90").toInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
QPointF PartArc::sceneTopLeft() const {
|
||||||
|
return(mapToScene(rect().topLeft()));
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant PartArc::itemChange(GraphicsItemChange change, const QVariant &value) {
|
||||||
|
if (scene()) {
|
||||||
|
if (change == QGraphicsItem::ItemPositionChange || change == QGraphicsItem::ItemSelectedChange) {
|
||||||
|
informations -> updateForm();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return(QGraphicsEllipseItem::itemChange(change, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
void PartArc::setAngle(int a) {
|
||||||
|
_angle = a;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PartArc::setStartAngle(int a) {
|
||||||
|
start_angle = a;
|
||||||
|
}
|
||||||
|
|
||||||
|
int PartArc::angle() const {
|
||||||
|
return(_angle);
|
||||||
|
}
|
||||||
|
|
||||||
|
int PartArc::startAngle() const {
|
||||||
|
return(start_angle);
|
||||||
|
}
|
||||||
37
editor/partarc.h
Normal file
37
editor/partarc.h
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#ifndef PART_ARC_H
|
||||||
|
#define PART_ARC_H
|
||||||
|
#include <QtGui>
|
||||||
|
#include "customelementgraphicpart.h"
|
||||||
|
class ArcEditor;
|
||||||
|
class PartArc : public QGraphicsEllipseItem, public CustomElementGraphicPart {
|
||||||
|
// constructeurs, destructeur
|
||||||
|
public:
|
||||||
|
PartArc(QGraphicsItem * = 0, QGraphicsScene * = 0);
|
||||||
|
virtual ~PartArc() {
|
||||||
|
qDebug() << "~PartArc()";
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
PartArc(const PartArc &);
|
||||||
|
|
||||||
|
// attributs
|
||||||
|
private:
|
||||||
|
ArcEditor *informations;
|
||||||
|
int _angle;
|
||||||
|
int start_angle;
|
||||||
|
|
||||||
|
// methodes
|
||||||
|
public:
|
||||||
|
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = 0);
|
||||||
|
virtual const QDomElement toXml(QDomDocument &) const;
|
||||||
|
virtual void fromXml(const QDomElement &);
|
||||||
|
virtual QPointF sceneTopLeft() const;
|
||||||
|
virtual void setAngle(int);
|
||||||
|
virtual void setStartAngle(int);
|
||||||
|
virtual int angle() const;
|
||||||
|
virtual int startAngle() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QVariant itemChange(GraphicsItemChange, const QVariant &);
|
||||||
|
};
|
||||||
|
#endif
|
||||||
@@ -39,6 +39,7 @@ const QDomElement PartPolygon::toXml(QDomDocument &xml_document) const {
|
|||||||
QDomElement xml_element = xml_document.createElement("polygon");
|
QDomElement xml_element = xml_document.createElement("polygon");
|
||||||
int i = 1;
|
int i = 1;
|
||||||
foreach(QPointF point, polygon()) {
|
foreach(QPointF point, polygon()) {
|
||||||
|
point = mapToScene(point);
|
||||||
xml_element.setAttribute(QString("x%1").arg(i), point.x());
|
xml_element.setAttribute(QString("x%1").arg(i), point.x());
|
||||||
xml_element.setAttribute(QString("y%1").arg(i), point.y());
|
xml_element.setAttribute(QString("y%1").arg(i), point.y());
|
||||||
++ i;
|
++ i;
|
||||||
|
|||||||
@@ -49,7 +49,9 @@ HEADERS += aboutqet.h \
|
|||||||
editor/partterminal.h \
|
editor/partterminal.h \
|
||||||
editor/terminaleditor.h \
|
editor/terminaleditor.h \
|
||||||
editor/parttext.h \
|
editor/parttext.h \
|
||||||
editor/texteditor.h
|
editor/texteditor.h \
|
||||||
|
editor/partarc.h \
|
||||||
|
editor/arceditor.h
|
||||||
SOURCES += aboutqet.cpp \
|
SOURCES += aboutqet.cpp \
|
||||||
borderinset.cpp \
|
borderinset.cpp \
|
||||||
conducer.cpp \
|
conducer.cpp \
|
||||||
@@ -92,7 +94,9 @@ SOURCES += aboutqet.cpp \
|
|||||||
editor/partterminal.cpp \
|
editor/partterminal.cpp \
|
||||||
editor/terminaleditor.cpp \
|
editor/terminaleditor.cpp \
|
||||||
editor/parttext.cpp \
|
editor/parttext.cpp \
|
||||||
editor/texteditor.cpp
|
editor/texteditor.cpp \
|
||||||
|
editor/partarc.cpp \
|
||||||
|
editor/arceditor.cpp
|
||||||
RESOURCES += qelectrotech.qrc
|
RESOURCES += qelectrotech.qrc
|
||||||
TRANSLATIONS += lang/qet_en.ts lang/qt_fr.ts
|
TRANSLATIONS += lang/qet_en.ts lang/qt_fr.ts
|
||||||
QT += xml
|
QT += xml
|
||||||
|
|||||||
Reference in New Issue
Block a user