2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2011-03-02 00:16:40 +00:00
|
|
|
Copyright 2006-2011 Xavier Guerrin
|
2007-12-01 10:47:15 +00:00
|
|
|
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/>.
|
|
|
|
*/
|
2007-06-30 17:41:07 +00:00
|
|
|
#include "ellipseeditor.h"
|
2010-02-18 00:42:41 +00:00
|
|
|
#include "styleeditor.h"
|
2007-06-30 17:41:07 +00:00
|
|
|
#include "partellipse.h"
|
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/**
|
|
|
|
Constructeur
|
|
|
|
@param editor L'editeur d'element concerne
|
|
|
|
@param ellipse L'ellipse a editer
|
|
|
|
@param parent le Widget parent
|
|
|
|
*/
|
2010-02-18 00:42:41 +00:00
|
|
|
EllipseEditor::EllipseEditor(QETElementEditor *editor, PartEllipse *ellipse, QWidget *parent) :
|
|
|
|
ElementItemEditor(editor, parent),
|
|
|
|
part(ellipse)
|
|
|
|
{
|
|
|
|
style_ = new StyleEditor(editor);
|
2007-06-30 17:41:07 +00:00
|
|
|
|
|
|
|
x = new QLineEdit();
|
|
|
|
y = new QLineEdit();
|
|
|
|
h = new QLineEdit();
|
|
|
|
v = new QLineEdit();
|
|
|
|
|
2007-12-17 20:37:10 +00:00
|
|
|
x -> setValidator(new QDoubleValidator(x));
|
|
|
|
y -> setValidator(new QDoubleValidator(y));
|
|
|
|
h -> setValidator(new QDoubleValidator(h));
|
|
|
|
v -> setValidator(new QDoubleValidator(v));
|
2007-06-30 17:41:07 +00:00
|
|
|
|
2010-02-18 00:42:41 +00:00
|
|
|
QVBoxLayout *v_layout = new QVBoxLayout(this);
|
|
|
|
|
|
|
|
QGridLayout *grid = new QGridLayout();
|
2007-06-30 17:41:07 +00:00
|
|
|
grid -> addWidget(new QLabel(tr("Centre : ")), 0, 0);
|
2010-02-28 16:13:45 +00:00
|
|
|
grid -> addWidget(new QLabel("x"), 1, 0, Qt::AlignRight);
|
2007-06-30 17:41:07 +00:00
|
|
|
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);
|
|
|
|
|
2010-02-18 00:42:41 +00:00
|
|
|
v_layout -> addWidget(style_);
|
|
|
|
v_layout -> addLayout(grid);
|
|
|
|
|
2007-08-25 03:43:05 +00:00
|
|
|
activeConnections(true);
|
2007-06-30 17:41:07 +00:00
|
|
|
updateForm();
|
|
|
|
}
|
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/// Destructeur
|
2007-06-30 17:41:07 +00:00
|
|
|
EllipseEditor::~EllipseEditor() {
|
|
|
|
}
|
|
|
|
|
2010-02-18 00:42:41 +00:00
|
|
|
/**
|
|
|
|
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 d'ellipse acceptera d'editer la primitive new_part s'il s'agit
|
|
|
|
d'un objet de la classe PartEllipse.
|
|
|
|
@param new_part Nouvelle primitive a editer
|
|
|
|
@return true si l'editeur a accepter d'editer la primitive, false sinon
|
|
|
|
*/
|
|
|
|
bool EllipseEditor::setPart(CustomElementPart *new_part) {
|
|
|
|
if (!new_part) {
|
|
|
|
part = 0;
|
|
|
|
style_ -> setPart(0);
|
|
|
|
return(true);
|
|
|
|
}
|
|
|
|
if (PartEllipse *part_ellipse = dynamic_cast<PartEllipse *>(new_part)) {
|
|
|
|
part = part_ellipse;
|
|
|
|
style_ -> setPart(part);
|
|
|
|
updateForm();
|
|
|
|
return(true);
|
|
|
|
} else {
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@return la primitive actuellement editee, ou 0 si ce widget n'en edite pas
|
|
|
|
*/
|
|
|
|
CustomElementPart *EllipseEditor::currentPart() const {
|
|
|
|
return(part);
|
|
|
|
}
|
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/**
|
|
|
|
Met a jour l'ellipse a partir des donnees du formulaire
|
|
|
|
*/
|
2007-06-30 17:41:07 +00:00
|
|
|
void EllipseEditor::updateEllipse() {
|
2010-02-18 00:42:41 +00:00
|
|
|
if (!part) return;
|
2007-08-25 03:43:05 +00:00
|
|
|
part -> setProperty("x", x -> text().toDouble());
|
2009-04-03 19:30:25 +00:00
|
|
|
part -> setProperty("y", y -> text().toDouble());
|
|
|
|
part -> setProperty("diameter_h", h -> text().toDouble());
|
|
|
|
part -> setProperty("diameter_v", v -> text().toDouble());
|
2007-06-30 17:41:07 +00:00
|
|
|
}
|
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/// Met a jour l'abscisse du centre de l'ellipse et cree un objet d'annulation
|
2007-08-25 03:43:05 +00:00
|
|
|
void EllipseEditor::updateEllipseX() { addChangePartCommand(tr("abscisse"), part, "x", x -> text().toDouble()); }
|
2007-12-05 21:16:01 +00:00
|
|
|
/// Met a jour l'ordonnee du centre de l'ellipse et cree un objet d'annulation
|
2007-08-25 03:43:05 +00:00
|
|
|
void EllipseEditor::updateEllipseY() { addChangePartCommand(tr("ordonn\351e"), part, "y", y -> text().toDouble()); }
|
2007-12-05 21:16:01 +00:00
|
|
|
/// Met a jour le diametre horizontal de l'ellipse et cree un objet d'annulation
|
2007-08-25 03:43:05 +00:00
|
|
|
void EllipseEditor::updateEllipseH() { addChangePartCommand(tr("diam\350tre horizontal"), part, "diameter_h", h -> text().toDouble()); }
|
2007-12-05 21:16:01 +00:00
|
|
|
/// Met a jour le diametre vertical de l'ellipse et cree un objet d'annulation
|
2007-08-25 03:43:05 +00:00
|
|
|
void EllipseEditor::updateEllipseV() { addChangePartCommand(tr("diam\350tre vertical"), part, "diameter_v", v -> text().toDouble()); }
|
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/**
|
|
|
|
Met a jour le formulaire d'edition
|
|
|
|
*/
|
2007-06-30 17:41:07 +00:00
|
|
|
void EllipseEditor::updateForm() {
|
2010-02-18 00:42:41 +00:00
|
|
|
if (!part) return;
|
2007-08-25 03:43:05 +00:00
|
|
|
activeConnections(false);
|
|
|
|
x -> setText(part -> property("x").toString());
|
|
|
|
y -> setText(part -> property("y").toString());
|
|
|
|
h -> setText(part -> property("diameter_h").toString());
|
|
|
|
v -> setText(part -> property("diameter_v").toString());
|
|
|
|
activeConnections(true);
|
|
|
|
}
|
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/**
|
|
|
|
Active ou desactive les connexionx signaux/slots entre les widgets internes.
|
|
|
|
@param active true pour activer les connexions, false pour les desactiver
|
|
|
|
*/
|
2007-08-25 03:43:05 +00:00
|
|
|
void EllipseEditor::activeConnections(bool active) {
|
|
|
|
if (active) {
|
|
|
|
connect(x, SIGNAL(editingFinished()), this, SLOT(updateEllipseX()));
|
|
|
|
connect(y, SIGNAL(editingFinished()), this, SLOT(updateEllipseY()));
|
|
|
|
connect(h, SIGNAL(editingFinished()), this, SLOT(updateEllipseH()));
|
|
|
|
connect(v, SIGNAL(editingFinished()), this, SLOT(updateEllipseV()));
|
|
|
|
} else {
|
|
|
|
disconnect(x, SIGNAL(editingFinished()), this, SLOT(updateEllipseX()));
|
|
|
|
disconnect(y, SIGNAL(editingFinished()), this, SLOT(updateEllipseY()));
|
|
|
|
disconnect(h, SIGNAL(editingFinished()), this, SLOT(updateEllipseH()));
|
|
|
|
disconnect(v, SIGNAL(editingFinished()), this, SLOT(updateEllipseV()));
|
|
|
|
}
|
2007-06-30 17:41:07 +00:00
|
|
|
}
|