mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 05:00:33 +01:00
Element editor: removed the "circle" tool because it was incompatible with non 1:1 scaling operations.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2039 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -1,140 +0,0 @@
|
||||
/*
|
||||
Copyright 2006-2012 Xavier Guerrin
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "circleeditor.h"
|
||||
#include "styleeditor.h"
|
||||
#include "partcircle.h"
|
||||
|
||||
/**
|
||||
Constructeur
|
||||
@param editor L'editeur d'element concerne
|
||||
@param circle Le cercle a editer
|
||||
@param parent le Widget parent
|
||||
*/
|
||||
CircleEditor::CircleEditor(QETElementEditor *editor, PartCircle *circle, QWidget *parent) :
|
||||
ElementItemEditor(editor, parent),
|
||||
part(circle)
|
||||
{
|
||||
style_ = new StyleEditor(editor);
|
||||
|
||||
x = new QLineEdit();
|
||||
y = new QLineEdit();
|
||||
r = new QLineEdit();
|
||||
|
||||
x -> setValidator(new QDoubleValidator(x));
|
||||
y -> setValidator(new QDoubleValidator(y));
|
||||
r -> setValidator(new QDoubleValidator(r));
|
||||
|
||||
QVBoxLayout *v_layout = new QVBoxLayout(this);
|
||||
|
||||
QGridLayout *grid = new QGridLayout();
|
||||
grid -> addWidget(new QLabel(tr("Centre : ")), 0, 0);
|
||||
grid -> addWidget(new QLabel("x"), 1, 0, Qt::AlignRight);
|
||||
grid -> addWidget(x, 1, 1);
|
||||
grid -> addWidget(new QLabel("y"), 1, 2);
|
||||
grid -> addWidget(y, 1, 3);
|
||||
grid -> addWidget(new QLabel(tr("Diam\350tre : ")), 2, 0);
|
||||
grid -> addWidget(r, 2, 1);
|
||||
|
||||
v_layout -> addWidget(style_);
|
||||
v_layout -> addLayout(grid);
|
||||
|
||||
activeConnections(true);
|
||||
updateForm();
|
||||
}
|
||||
|
||||
/// Destructeur
|
||||
CircleEditor::~CircleEditor() {
|
||||
}
|
||||
|
||||
/**
|
||||
Permet de specifier a cet editeur quelle primitive il doit editer. A noter
|
||||
qu'un editeur peut accepter ou refuser d'editer une primitive.
|
||||
L'editeur de cercle acceptera d'editer la primitive new_part s'il s'agit
|
||||
d'un objet de la classe PartCircle.
|
||||
@param new_part Nouvelle primitive a editer
|
||||
@return true si l'editeur a accepter d'editer la primitive, false sinon
|
||||
*/
|
||||
bool CircleEditor::setPart(CustomElementPart *new_part) {
|
||||
if (!new_part) {
|
||||
part = 0;
|
||||
style_ -> setPart(0);
|
||||
return(true);
|
||||
}
|
||||
if (PartCircle *part_circle = dynamic_cast<PartCircle *>(new_part)) {
|
||||
part = part_circle;
|
||||
style_ -> setPart(part);
|
||||
updateForm();
|
||||
return(true);
|
||||
} else {
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@return la primitive actuellement editee, ou 0 si ce widget n'en edite pas
|
||||
*/
|
||||
CustomElementPart *CircleEditor::currentPart() const {
|
||||
return(part);
|
||||
}
|
||||
|
||||
/**
|
||||
met a jour le cercle a partir des donnees du formulaire
|
||||
*/
|
||||
void CircleEditor::updateCircle() {
|
||||
if (!part) return;
|
||||
part -> setProperty("x", x -> text().toDouble());
|
||||
part -> setProperty("y", y -> text().toDouble());
|
||||
part -> setProperty("diameter", r -> text().toDouble());
|
||||
}
|
||||
|
||||
/// Met a jour l'abscisse du cercle et cree un objet d'annulation
|
||||
void CircleEditor::updateCircleX() { addChangePartCommand(tr("abscisse"), part, "x", x -> text().toDouble()); }
|
||||
|
||||
/// Met a jour l'ordonnee du cercle et cree un objet d'annulation
|
||||
void CircleEditor::updateCircleY() { addChangePartCommand(tr("ordonn\351e"), part, "y", y -> text().toDouble()); }
|
||||
|
||||
/// Met a jour le diametre du cercle et cree un objet d'annulation
|
||||
void CircleEditor::updateCircleD() { addChangePartCommand(tr("diam\350tre"), part, "diameter", r -> text().toDouble()); }
|
||||
|
||||
/**
|
||||
Met a jour le formulaire d'edition
|
||||
*/
|
||||
void CircleEditor::updateForm() {
|
||||
if (!part) return;
|
||||
activeConnections(false);
|
||||
x -> setText(part -> property("x").toString());
|
||||
y -> setText(part -> property("y").toString());
|
||||
r -> setText(part -> property("diameter").toString());
|
||||
activeConnections(true);
|
||||
}
|
||||
|
||||
/**
|
||||
Active ou desactive les connexionx signaux/slots entre les widgets internes.
|
||||
@param active true pour activer les connexions, false pour les desactiver
|
||||
*/
|
||||
void CircleEditor::activeConnections(bool active) {
|
||||
if (active) {
|
||||
connect(x, SIGNAL(editingFinished()), this, SLOT(updateCircleX()));
|
||||
connect(y, SIGNAL(editingFinished()), this, SLOT(updateCircleY()));
|
||||
connect(r, SIGNAL(editingFinished()), this, SLOT(updateCircleD()));
|
||||
} else {
|
||||
disconnect(x, SIGNAL(editingFinished()), this, SLOT(updateCircleX()));
|
||||
disconnect(y, SIGNAL(editingFinished()), this, SLOT(updateCircleY()));
|
||||
disconnect(r, SIGNAL(editingFinished()), this, SLOT(updateCircleD()));
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
Copyright 2006-2012 Xavier Guerrin
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef CIRCLE_EDITOR_H
|
||||
#define CIRCLE_EDITOR_H
|
||||
#include <QtGui>
|
||||
#include "elementitemeditor.h"
|
||||
class PartCircle;
|
||||
class StyleEditor;
|
||||
/**
|
||||
This class provides a widget to edit circles within the element editor.
|
||||
*/
|
||||
class CircleEditor : public ElementItemEditor {
|
||||
Q_OBJECT
|
||||
// Constructeurs, destructeur
|
||||
public:
|
||||
CircleEditor(QETElementEditor *, PartCircle * = 0, QWidget * = 0);
|
||||
virtual ~CircleEditor();
|
||||
private:
|
||||
CircleEditor(const CircleEditor &);
|
||||
|
||||
// attributes
|
||||
private:
|
||||
PartCircle *part;
|
||||
StyleEditor *style_;
|
||||
QLineEdit *x, *y, *r;
|
||||
|
||||
// methods
|
||||
public:
|
||||
virtual bool setPart(CustomElementPart *);
|
||||
virtual CustomElementPart *currentPart() const;
|
||||
|
||||
public slots:
|
||||
void updateCircle();
|
||||
void updateCircleX();
|
||||
void updateCircleY();
|
||||
void updateCircleD();
|
||||
void updateForm();
|
||||
|
||||
private:
|
||||
void activeConnections(bool);
|
||||
};
|
||||
#endif
|
||||
@@ -22,7 +22,6 @@
|
||||
#include "partline.h"
|
||||
#include "partrectangle.h"
|
||||
#include "partellipse.h"
|
||||
#include "partcircle.h"
|
||||
#include "partpolygon.h"
|
||||
#include "partterminal.h"
|
||||
#include "parttext.h"
|
||||
@@ -151,7 +150,6 @@ void ElementScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
||||
}
|
||||
|
||||
QRectF temp_rect;
|
||||
qreal radius;
|
||||
QPointF temp_point;
|
||||
QPolygonF temp_polygon;
|
||||
if (e -> buttons() & Qt::LeftButton) {
|
||||
@@ -174,16 +172,6 @@ void ElementScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
||||
temp_rect.setBottomRight(event_pos);
|
||||
current_arc -> setRect(temp_rect);
|
||||
break;
|
||||
case Circle:
|
||||
temp_rect = current_circle -> rect();
|
||||
temp_point = event_pos - current_circle -> mapToScene(temp_rect.center());
|
||||
radius = sqrt(pow(temp_point.x(), 2) + pow(temp_point.y(), 2));
|
||||
temp_rect = QRectF(
|
||||
temp_rect.center() - QPointF(radius, radius),
|
||||
QSizeF(2.0 * radius, 2.0 * radius)
|
||||
);
|
||||
current_circle -> setRect(temp_rect);
|
||||
break;
|
||||
case Polygon:
|
||||
if (current_polygon == NULL) break;
|
||||
temp_polygon = current_polygon -> polygon();
|
||||
@@ -233,11 +221,6 @@ void ElementScene::mousePressEvent(QGraphicsSceneMouseEvent *e) {
|
||||
current_arc -> setRect(QRectF(event_pos, QSizeF(0.0, 0.0)));
|
||||
current_arc -> setProperty("antialias", true);
|
||||
break;
|
||||
case Circle:
|
||||
current_circle = new PartCircle(element_editor, 0, this);
|
||||
current_circle -> setRect(QRectF(event_pos, QSizeF(0.0, 0.0)));
|
||||
current_circle -> setProperty("antialias", true);
|
||||
break;
|
||||
case Polygon:
|
||||
if (current_polygon == NULL) {
|
||||
current_polygon = new PartPolygon(element_editor, 0, this);
|
||||
@@ -305,13 +288,6 @@ void ElementScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
|
||||
emit(partsAdded());
|
||||
endCurrentBehavior(e);
|
||||
break;
|
||||
case Circle:
|
||||
if (qgiManager().manages(current_circle)) break;
|
||||
current_circle -> setRect(current_circle -> rect().normalized());
|
||||
undo_stack.push(new AddPartCommand(tr("cercle"), this, current_circle));
|
||||
emit(partsAdded());
|
||||
endCurrentBehavior(e);
|
||||
break;
|
||||
case Terminal:
|
||||
terminal = new PartTerminal(element_editor, 0, this);
|
||||
terminal -> setPos(event_pos);
|
||||
@@ -1167,7 +1143,7 @@ ElementContent ElementScene::loadContent(const QDomDocument &xml_document, QStri
|
||||
if (qde.tagName() == "line") cep = new PartLine (element_editor, 0, 0);
|
||||
else if (qde.tagName() == "rect") cep = new PartRectangle(element_editor, 0, 0);
|
||||
else if (qde.tagName() == "ellipse") cep = new PartEllipse (element_editor, 0, 0);
|
||||
else if (qde.tagName() == "circle") cep = new PartCircle (element_editor, 0, 0);
|
||||
else if (qde.tagName() == "circle") cep = new PartEllipse (element_editor, 0, 0);
|
||||
else if (qde.tagName() == "polygon") cep = new PartPolygon (element_editor, 0, 0);
|
||||
else if (qde.tagName() == "terminal") cep = new PartTerminal (element_editor, 0, 0);
|
||||
else if (qde.tagName() == "text") cep = new PartText (element_editor, 0, 0);
|
||||
|
||||
@@ -30,7 +30,6 @@ class QETElementEditor;
|
||||
class PartLine;
|
||||
class PartRectangle;
|
||||
class PartEllipse;
|
||||
class PartCircle;
|
||||
class PartPolygon;
|
||||
class PartArc;
|
||||
/**
|
||||
@@ -96,7 +95,6 @@ class ElementScene : public QGraphicsScene {
|
||||
PartLine *current_line;
|
||||
PartRectangle *current_rectangle;
|
||||
PartEllipse *current_ellipse;
|
||||
PartCircle *current_circle;
|
||||
PartPolygon *current_polygon;
|
||||
PartArc *current_arc;
|
||||
QETElementEditor *element_editor;
|
||||
|
||||
@@ -1,237 +0,0 @@
|
||||
/*
|
||||
Copyright 2006-2012 Xavier Guerrin
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "partcircle.h"
|
||||
|
||||
/**
|
||||
Constructeur
|
||||
@param editor L'editeur d'element concerne
|
||||
@param parent Le QGraphicsItem parent de ce cercle
|
||||
@param scene La scene sur laquelle figure ce cercle
|
||||
*/
|
||||
PartCircle::PartCircle(QETElementEditor *editor, QGraphicsItem *parent, QGraphicsScene *scene) : QGraphicsEllipseItem(parent, scene), CustomElementGraphicPart(editor) {
|
||||
setFlags(QGraphicsItem::ItemIsSelectable);
|
||||
#if QT_VERSION >= 0x040600
|
||||
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
||||
#endif
|
||||
setAcceptedMouseButtons(Qt::LeftButton);
|
||||
}
|
||||
|
||||
/// Destructeur
|
||||
PartCircle::~PartCircle() {
|
||||
}
|
||||
|
||||
/**
|
||||
Dessine le cercle
|
||||
@param painter QPainter a utiliser pour rendre le dessin
|
||||
@param options Options pour affiner le rendu
|
||||
@param widget Widget sur lequel le rendu est effectue
|
||||
*/
|
||||
void PartCircle::paint(QPainter *painter, const QStyleOptionGraphicsItem *options, QWidget *widget) {
|
||||
Q_UNUSED(widget);
|
||||
applyStylesToQPainter(*painter);
|
||||
QPen t = painter -> pen();
|
||||
t.setCosmetic(options && options -> levelOfDetail < 1.0);
|
||||
if (isSelected()) {
|
||||
t.setColor(Qt::red);
|
||||
}
|
||||
painter -> setPen(t);
|
||||
painter -> drawEllipse(rect());
|
||||
if (isSelected()) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Exporte le cercle en XML
|
||||
@param xml_document Document XML a utiliser pour creer l'element XML
|
||||
@return un element XML decrivant le cercle
|
||||
*/
|
||||
const QDomElement PartCircle::toXml(QDomDocument &xml_document) const {
|
||||
QDomElement xml_element = xml_document.createElement("circle");
|
||||
QPointF top_left(sceneTopLeft());
|
||||
xml_element.setAttribute("x", QString("%1").arg(top_left.x()));
|
||||
xml_element.setAttribute("y", QString("%1").arg(top_left.y()));
|
||||
xml_element.setAttribute("diameter", QString("%1").arg(rect().width()));
|
||||
stylesToXml(xml_element);
|
||||
return(xml_element);
|
||||
}
|
||||
|
||||
/**
|
||||
Importe les proprietes d'un cercle depuis un element XML
|
||||
@param qde Element XML a lire
|
||||
*/
|
||||
void PartCircle::fromXml(const QDomElement &qde) {
|
||||
stylesFromXml(qde);
|
||||
qreal diameter = qde.attribute("diameter", "0").toDouble();
|
||||
setRect(
|
||||
QRectF(
|
||||
mapFromScene(
|
||||
qde.attribute("x", "0").toDouble(),
|
||||
qde.attribute("y", "0").toDouble()
|
||||
),
|
||||
QSizeF(
|
||||
diameter,
|
||||
diameter
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
Specifie la valeur d'une propriete donnee du cercle
|
||||
@param property propriete a modifier. Valeurs acceptees :
|
||||
* x : abscisse du centre du cercle
|
||||
* y : ordonnee du centre du cercle
|
||||
* diameter : diametre du cercle
|
||||
@param value Valeur a attribuer a la propriete
|
||||
*/
|
||||
void PartCircle::setProperty(const QString &property, const QVariant &value) {
|
||||
CustomElementGraphicPart::setProperty(property, value);
|
||||
if (!value.canConvert(QVariant::Double)) return;
|
||||
if (property == "x") {
|
||||
QRectF current_rect = rect();
|
||||
QPointF current_pos = mapToScene(current_rect.center());
|
||||
setRect(current_rect.translated(value.toDouble() - current_pos.x(), 0.0));
|
||||
} else if (property == "y") {
|
||||
QRectF current_rect = rect();
|
||||
QPointF current_pos = mapToScene(current_rect.center());
|
||||
setRect(current_rect.translated(0.0, value.toDouble() - current_pos.y()));
|
||||
} else if (property == "diameter") {
|
||||
QRectF current_rect = rect();
|
||||
qreal new_diameter = qAbs(value.toDouble());
|
||||
current_rect.translate(
|
||||
(new_diameter - current_rect.width()) / -2.0,
|
||||
(new_diameter - current_rect.height()) / -2.0
|
||||
);
|
||||
current_rect.setSize(QSizeF(new_diameter, new_diameter));
|
||||
setRect(current_rect);
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
/**
|
||||
Permet d'acceder a la valeur d'une propriete de style donnee.
|
||||
@param property propriete lue. Valeurs acceptees :
|
||||
* x : abscisse du centre du cercle
|
||||
* y : ordonnee du centre du cercle
|
||||
* diameter : diametre du cercle
|
||||
@return La valeur de la propriete property
|
||||
*/
|
||||
QVariant PartCircle::property(const QString &property) {
|
||||
// appelle la methode property de CustomElementGraphicpart pour les styles
|
||||
QVariant style_property = CustomElementGraphicPart::property(property);
|
||||
if (style_property != QVariant()) return(style_property);
|
||||
|
||||
if (property == "x") {
|
||||
return(mapToScene(rect().center()).x());
|
||||
} else if (property == "y") {
|
||||
return(mapToScene(rect().center()).y());
|
||||
} else if (property == "diameter") {
|
||||
return(rect().width());
|
||||
}
|
||||
return(QVariant());
|
||||
}
|
||||
|
||||
/**
|
||||
Gere les changements intervenant sur cette partie
|
||||
@param change Type de changement
|
||||
@param value Valeur numerique relative au changement
|
||||
*/
|
||||
QVariant PartCircle::itemChange(GraphicsItemChange change, const QVariant &value) {
|
||||
if (scene()) {
|
||||
if (change == QGraphicsItem::ItemPositionChange || change == QGraphicsItem::ItemPositionHasChanged) {
|
||||
updateCurrentPartEditor();
|
||||
}
|
||||
}
|
||||
return(QGraphicsEllipseItem::itemChange(change, value));
|
||||
}
|
||||
|
||||
/**
|
||||
@return le coin superieur gauche du rectangle dans lequel s'inscrit
|
||||
le cercle, dans les coordonnees de la scene.
|
||||
*/
|
||||
QPointF PartCircle::sceneTopLeft() const {
|
||||
return(mapToScene(rect().topLeft()));
|
||||
}
|
||||
|
||||
/**
|
||||
@return le centre du cercle, dans les coordonnees de la scene.
|
||||
*/
|
||||
QPointF PartCircle::sceneCenter() const {
|
||||
return(mapToScene(rect().center()));
|
||||
}
|
||||
|
||||
/**
|
||||
@return le rectangle delimitant cette partie.
|
||||
*/
|
||||
QRectF PartCircle::boundingRect() const {
|
||||
qreal adjust = 1.5;
|
||||
QRectF r(QGraphicsEllipseItem::boundingRect());
|
||||
r.adjust(-adjust, -adjust, adjust, adjust);
|
||||
return(r);
|
||||
}
|
||||
|
||||
/**
|
||||
@return true si cette partie n'est pas pertinente et ne merite pas d'etre
|
||||
conservee / enregistree.
|
||||
Un cercle est pertinent des lors que son rayon n'est pas nul
|
||||
*/
|
||||
bool PartCircle::isUseless() const {
|
||||
return(rect().isNull());
|
||||
}
|
||||
|
||||
/**
|
||||
@return the minimum, margin-less rectangle this part can fit into, in scene
|
||||
coordinates. It is different from boundingRect() because it is not supposed
|
||||
to imply any margin, and it is different from shape because it is a regular
|
||||
rectangle, not a complex shape.
|
||||
*/
|
||||
QRectF PartCircle::sceneGeometricRect() const {
|
||||
return(mapToScene(rect()).boundingRect());
|
||||
}
|
||||
|
||||
/**
|
||||
Start the user-induced transformation, provided this primitive is contained
|
||||
within the \a initial_selection_rect bounding rectangle.
|
||||
*/
|
||||
void PartCircle::startUserTransformation(const QRectF &initial_selection_rect) {
|
||||
Q_UNUSED(initial_selection_rect)
|
||||
saved_center_ = mapToScene(rect().center());
|
||||
saved_diameter_ = rect().width();
|
||||
}
|
||||
|
||||
/**
|
||||
Handle the user-induced transformation from \a initial_selection_rect to \a new_selection_rect
|
||||
*/
|
||||
void PartCircle::handleUserTransformation(const QRectF &initial_selection_rect, const QRectF &new_selection_rect) {
|
||||
QPointF new_center = mapPoints(initial_selection_rect, new_selection_rect, QList<QPointF>() << saved_center_).first();
|
||||
|
||||
qreal sx = new_selection_rect.width() / initial_selection_rect.width();
|
||||
qreal sy = new_selection_rect.height() / initial_selection_rect.height();
|
||||
qreal smallest_scale_factor = sx > sy ? sy : sx;
|
||||
qreal new_diameter = saved_diameter_ * smallest_scale_factor;
|
||||
|
||||
QRectF new_rect(QPointF(), QSizeF(new_diameter, new_diameter));
|
||||
new_rect.moveCenter(mapFromScene(new_center));
|
||||
|
||||
setRect(new_rect);
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
Copyright 2006-2012 Xavier Guerrin
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef PART_CIRCLE_H
|
||||
#define PART_CIRCLE_H
|
||||
#include <QtGui>
|
||||
#include "customelementgraphicpart.h"
|
||||
/**
|
||||
This class represents a circle primitive which may be used to compose the
|
||||
drawing of an electrical element within the element editor.
|
||||
*/
|
||||
class PartCircle : public QGraphicsEllipseItem, public CustomElementGraphicPart {
|
||||
// constructors, destructor
|
||||
public:
|
||||
PartCircle(QETElementEditor *, QGraphicsItem * = 0, QGraphicsScene * = 0);
|
||||
virtual ~PartCircle();
|
||||
|
||||
private:
|
||||
PartCircle(const PartCircle &);
|
||||
|
||||
// methods
|
||||
public:
|
||||
enum { Type = UserType + 1102 };
|
||||
/**
|
||||
Enable the use of qgraphicsitem_cast to safely cast a QGraphicsItem into a
|
||||
PartCircle.
|
||||
@return the QGraphicsItem type
|
||||
*/
|
||||
virtual int type() const { return Type; }
|
||||
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = 0);
|
||||
virtual QString name() const { return(QObject::tr("cercle", "element part name")); }
|
||||
virtual QString xmlName() const { return(QString("circle")); }
|
||||
virtual const QDomElement toXml(QDomDocument &) const;
|
||||
virtual void fromXml(const QDomElement &);
|
||||
virtual QPointF sceneTopLeft() const;
|
||||
virtual QRectF boundingRect() const;
|
||||
QPointF sceneCenter() const;
|
||||
virtual void setProperty(const QString &, const QVariant &);
|
||||
virtual QVariant property(const QString &);
|
||||
virtual bool isUseless() const;
|
||||
virtual QRectF sceneGeometricRect() const;
|
||||
virtual void startUserTransformation(const QRectF &);
|
||||
virtual void handleUserTransformation(const QRectF &, const QRectF &);
|
||||
|
||||
protected:
|
||||
QVariant itemChange(GraphicsItemChange, const QVariant &);
|
||||
|
||||
private:
|
||||
QPointF saved_center_;
|
||||
qreal saved_diameter_;
|
||||
};
|
||||
#endif
|
||||
@@ -66,12 +66,18 @@ void PartEllipse::paint(QPainter *painter, const QStyleOptionGraphicsItem *optio
|
||||
@return un element XML decrivant l'ellipse
|
||||
*/
|
||||
const QDomElement PartEllipse::toXml(QDomDocument &xml_document) const {
|
||||
QDomElement xml_element = xml_document.createElement("ellipse");
|
||||
QDomElement xml_element;
|
||||
if (qFuzzyCompare(rect().width(), rect().height())) {
|
||||
xml_element = xml_document.createElement("circle");
|
||||
xml_element.setAttribute("diameter", QString("%1").arg(rect().width()));
|
||||
} else {
|
||||
xml_element = xml_document.createElement("ellipse");
|
||||
xml_element.setAttribute("width", QString("%1").arg(rect().width()));
|
||||
xml_element.setAttribute("height", QString("%1").arg(rect().height()));
|
||||
}
|
||||
QPointF top_left(sceneTopLeft());
|
||||
xml_element.setAttribute("x", QString("%1").arg(top_left.x()));
|
||||
xml_element.setAttribute("y", QString("%1").arg(top_left.y()));
|
||||
xml_element.setAttribute("width", QString("%1").arg(rect().width()));
|
||||
xml_element.setAttribute("height", QString("%1").arg(rect().height()));
|
||||
stylesToXml(xml_element);
|
||||
return(xml_element);
|
||||
}
|
||||
@@ -82,16 +88,20 @@ const QDomElement PartEllipse::toXml(QDomDocument &xml_document) const {
|
||||
*/
|
||||
void PartEllipse::fromXml(const QDomElement &qde) {
|
||||
stylesFromXml(qde);
|
||||
qreal width, height;
|
||||
if (qde.tagName() == "ellipse") {
|
||||
width = qde.attribute("width", "0").toDouble();
|
||||
height = qde.attribute("height", "0").toDouble();
|
||||
} else {
|
||||
width = height = qde.attribute("diameter", "0").toDouble();
|
||||
}
|
||||
setRect(
|
||||
QRectF(
|
||||
mapFromScene(
|
||||
qde.attribute("x", "0").toDouble(),
|
||||
qde.attribute("y", "0").toDouble()
|
||||
),
|
||||
QSizeF(
|
||||
qde.attribute("width", "0").toDouble(),
|
||||
qde.attribute("height", "0").toDouble()
|
||||
)
|
||||
QSizeF(width, height)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
|
||||
// editeurs de primitives
|
||||
#include "arceditor.h"
|
||||
#include "circleeditor.h"
|
||||
#include "ellipseeditor.h"
|
||||
#include "lineeditor.h"
|
||||
#include "polygoneditor.h"
|
||||
@@ -157,7 +156,6 @@ void QETElementEditor::setupActions() {
|
||||
add_line = new QAction(QET::Icons::PartLine, tr("Ajouter une ligne"), this);
|
||||
add_rectangle = new QAction(QET::Icons::PartRectangle, tr("Ajouter un rectangle"), this);
|
||||
add_ellipse = new QAction(QET::Icons::PartEllipse, tr("Ajouter une ellipse"), this);
|
||||
add_circle = new QAction(QET::Icons::PartCircle, tr("Ajouter un cercle"), this);
|
||||
add_polygon = new QAction(QET::Icons::PartPolygon, tr("Ajouter un polygone"), this);
|
||||
add_text = new QAction(QET::Icons::PartText, tr("Ajouter du texte"), this);
|
||||
add_arc = new QAction(QET::Icons::PartArc, tr("Ajouter un arc de cercle"), this);
|
||||
@@ -168,7 +166,6 @@ void QETElementEditor::setupActions() {
|
||||
add_line -> setStatusTip(add_status_tip);
|
||||
add_rectangle -> setStatusTip(add_status_tip);
|
||||
add_ellipse -> setStatusTip(add_status_tip);
|
||||
add_circle -> setStatusTip(add_status_tip);
|
||||
add_text -> setStatusTip(add_status_tip);
|
||||
add_arc -> setStatusTip(add_status_tip);
|
||||
add_terminal -> setStatusTip(add_status_tip);
|
||||
@@ -251,7 +248,6 @@ void QETElementEditor::setupActions() {
|
||||
connect(add_line, SIGNAL(triggered()), ce_scene, SLOT(slot_addLine()));
|
||||
connect(add_rectangle, SIGNAL(triggered()), ce_scene, SLOT(slot_addRectangle()));
|
||||
connect(add_ellipse, SIGNAL(triggered()), ce_scene, SLOT(slot_addEllipse()));
|
||||
connect(add_circle, SIGNAL(triggered()), ce_scene, SLOT(slot_addCircle()));
|
||||
connect(add_polygon, SIGNAL(triggered()), ce_scene, SLOT(slot_addPolygon()));
|
||||
connect(add_text, SIGNAL(triggered()), ce_scene, SLOT(slot_addText()));
|
||||
connect(add_arc, SIGNAL(triggered()), ce_scene, SLOT(slot_addArc()));
|
||||
@@ -262,7 +258,6 @@ void QETElementEditor::setupActions() {
|
||||
connect(add_line, SIGNAL(triggered()), this, SLOT(slot_setNoDragToView()));
|
||||
connect(add_rectangle, SIGNAL(triggered()), this, SLOT(slot_setNoDragToView()));
|
||||
connect(add_ellipse, SIGNAL(triggered()), this, SLOT(slot_setNoDragToView()));
|
||||
connect(add_circle, SIGNAL(triggered()), this, SLOT(slot_setNoDragToView()));
|
||||
connect(add_polygon, SIGNAL(triggered()), this, SLOT(slot_setNoDragToView()));
|
||||
connect(add_text, SIGNAL(triggered()), this, SLOT(slot_setNoDragToView()));
|
||||
connect(add_arc, SIGNAL(triggered()), this, SLOT(slot_setNoDragToView()));
|
||||
@@ -275,7 +270,6 @@ void QETElementEditor::setupActions() {
|
||||
add_line -> setCheckable(true);
|
||||
add_rectangle -> setCheckable(true);
|
||||
add_ellipse -> setCheckable(true);
|
||||
add_circle -> setCheckable(true);
|
||||
add_polygon -> setCheckable(true);
|
||||
add_text -> setCheckable(true);
|
||||
add_arc -> setCheckable(true);
|
||||
@@ -287,7 +281,6 @@ void QETElementEditor::setupActions() {
|
||||
parts -> addAction(add_line);
|
||||
parts -> addAction(add_rectangle);
|
||||
parts -> addAction(add_ellipse);
|
||||
parts -> addAction(add_circle);
|
||||
parts -> addAction(add_polygon);
|
||||
parts -> addAction(add_arc);
|
||||
parts -> addAction(add_text);
|
||||
@@ -502,7 +495,6 @@ void QETElementEditor::setupInterface() {
|
||||
|
||||
// widgets d'editions pour les parties
|
||||
editors_["arc"] = new ArcEditor(this);
|
||||
editors_["circle"] = new CircleEditor(this);
|
||||
editors_["ellipse"] = new EllipseEditor(this);
|
||||
editors_["line"] = new LineEditor(this);
|
||||
editors_["polygon"] = new PolygonEditor(this);
|
||||
|
||||
@@ -79,7 +79,7 @@ class QETElementEditor : public QETMainWindow {
|
||||
QToolBar *parts_toolbar, *main_toolbar, *view_toolbar, *depth_toolbar, *element_toolbar;
|
||||
/// toolbars actions
|
||||
QActionGroup *parts;
|
||||
QAction *move, *add_line, *add_circle, *add_rectangle, *add_ellipse, *add_polygon, *add_text;
|
||||
QAction *move, *add_line, *add_rectangle, *add_ellipse, *add_polygon, *add_text;
|
||||
QAction *add_arc, *add_terminal, *add_textfield;
|
||||
/// minimum window title
|
||||
QString min_title;
|
||||
|
||||
Reference in New Issue
Block a user