2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2020-06-15 17:42:37 +02:00
|
|
|
Copyright 2006-2020 The QElectroTech Team
|
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"
|
2015-07-23 09:57:09 +00:00
|
|
|
#include "QPropertyUndoCommand/qpropertyundocommand.h"
|
|
|
|
#include "elementscene.h"
|
2007-06-30 17:41:07 +00:00
|
|
|
|
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),
|
2015-07-23 09:57:09 +00:00
|
|
|
part(ellipse),
|
|
|
|
m_locked(false)
|
2010-02-18 00:42:41 +00:00
|
|
|
{
|
|
|
|
style_ = new StyleEditor(editor);
|
2007-06-30 17:41:07 +00:00
|
|
|
|
2014-05-29 13:46:04 +00:00
|
|
|
x = new QDoubleSpinBox();
|
|
|
|
y = new QDoubleSpinBox();
|
|
|
|
h = new QDoubleSpinBox();
|
|
|
|
v = new QDoubleSpinBox();
|
2007-06-30 17:41:07 +00:00
|
|
|
|
2016-08-08 08:15:22 +00:00
|
|
|
x->setRange(-5000, 5000);
|
|
|
|
y->setRange(-5000, 5000);
|
|
|
|
h->setRange(-5000, 5000);
|
|
|
|
v->setRange(-5000, 5000);
|
2007-06-30 17:41:07 +00:00
|
|
|
|
2018-07-30 15:24:29 +00:00
|
|
|
QVBoxLayout *v_layout = new QVBoxLayout(this);
|
2010-02-18 00:42:41 +00:00
|
|
|
|
2018-07-30 15:24:29 +00:00
|
|
|
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);
|
2015-03-02 20:14:56 +00:00
|
|
|
grid -> addWidget(new QLabel(tr("Diamètres : ")), 2, 0);
|
2007-06-30 17:41:07 +00:00
|
|
|
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);
|
2018-07-17 12:19:56 +00:00
|
|
|
v_layout->addStretch();
|
2010-02-18 00:42:41 +00:00
|
|
|
|
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() {
|
|
|
|
}
|
|
|
|
|
2020-06-22 23:25:11 +02:00
|
|
|
void EllipseEditor::setUpChangeConnections()
|
|
|
|
{
|
|
|
|
m_change_connections << connect(part, &PartEllipse::rectChanged, this, &EllipseEditor::updateForm);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EllipseEditor::disconnectChangeConnections()
|
|
|
|
{
|
|
|
|
for (QMetaObject::Connection c : m_change_connections) {
|
|
|
|
disconnect(c);
|
|
|
|
}
|
|
|
|
m_change_connections.clear();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*/
|
2015-07-23 09:57:09 +00:00
|
|
|
bool EllipseEditor::setPart(CustomElementPart *new_part)
|
|
|
|
{
|
|
|
|
if (!new_part)
|
|
|
|
{
|
|
|
|
if (part)
|
2020-06-22 23:25:11 +02:00
|
|
|
disconnectChangeConnections();
|
2017-08-05 02:06:59 +00:00
|
|
|
part = nullptr;
|
|
|
|
style_ -> setPart(nullptr);
|
2010-02-18 00:42:41 +00:00
|
|
|
return(true);
|
|
|
|
}
|
2018-07-30 15:24:29 +00:00
|
|
|
if (PartEllipse *part_ellipse = dynamic_cast<PartEllipse *>(new_part))
|
2015-07-23 09:57:09 +00:00
|
|
|
{
|
|
|
|
if (part == part_ellipse) return true;
|
|
|
|
if (part)
|
2020-06-22 23:25:11 +02:00
|
|
|
disconnectChangeConnections();
|
2010-02-18 00:42:41 +00:00
|
|
|
part = part_ellipse;
|
|
|
|
style_ -> setPart(part);
|
|
|
|
updateForm();
|
2020-06-22 23:25:11 +02:00
|
|
|
setUpChangeConnections();
|
2010-02-18 00:42:41 +00:00
|
|
|
return(true);
|
|
|
|
}
|
2015-07-23 09:57:09 +00:00
|
|
|
return(false);
|
2010-02-18 00:42:41 +00:00
|
|
|
}
|
|
|
|
|
2020-06-22 23:25:11 +02:00
|
|
|
bool EllipseEditor::setParts(QList <CustomElementPart *> parts)
|
|
|
|
{
|
|
|
|
if (parts.isEmpty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!setPart(parts.first()))
|
|
|
|
return false;
|
|
|
|
return style_->setParts(parts);
|
|
|
|
}
|
|
|
|
|
2010-02-18 00:42:41 +00:00
|
|
|
/**
|
|
|
|
@return la primitive actuellement editee, ou 0 si ce widget n'en edite pas
|
|
|
|
*/
|
|
|
|
CustomElementPart *EllipseEditor::currentPart() const {
|
|
|
|
return(part);
|
|
|
|
}
|
|
|
|
|
2020-06-01 20:45:01 +02:00
|
|
|
QList<CustomElementPart*> EllipseEditor::currentParts() const {
|
|
|
|
return style_->currentParts();
|
|
|
|
}
|
|
|
|
|
2020-06-22 23:25:11 +02:00
|
|
|
void EllipseEditor::editingFinishedX()
|
2015-07-23 09:57:09 +00:00
|
|
|
{
|
2020-06-22 23:25:11 +02:00
|
|
|
if (m_locked) return;
|
|
|
|
m_locked = true;
|
2007-06-30 17:41:07 +00:00
|
|
|
|
2020-06-22 23:25:11 +02:00
|
|
|
for (auto part: style_->currentParts()) {
|
|
|
|
|
|
|
|
PartEllipse* ell = static_cast<PartEllipse*>(part);
|
|
|
|
QRectF rect = ell->property("rect").toRectF();
|
|
|
|
QPointF point = ell->mapFromScene(x->value() - h->value()/2, y->value() - v->value()/2); // does not matter which value y is, because only the x value is used
|
|
|
|
rect.setX(point.x()); // change only the x value
|
|
|
|
|
|
|
|
if (rect != part->property("rect"))
|
|
|
|
{
|
|
|
|
QPropertyUndoCommand *undo= new QPropertyUndoCommand(ell, "rect", ell->property("rect"), rect);
|
|
|
|
undo->setText("Modifier un arc");
|
|
|
|
undo->enableAnimation();
|
|
|
|
elementScene()->undoStack().push(undo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_locked = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EllipseEditor::editingFinishedY()
|
|
|
|
{
|
|
|
|
if (m_locked) return;
|
|
|
|
m_locked = true;
|
|
|
|
|
|
|
|
for (auto part: style_->currentParts()) {
|
|
|
|
|
|
|
|
PartEllipse* ell = static_cast<PartEllipse*>(part);
|
|
|
|
QRectF rect = ell->property("rect").toRectF();
|
|
|
|
|
|
|
|
QPointF point = ell->mapFromScene(x->value() - h->value()/2, y->value() - v->value()/2);
|
|
|
|
rect.setY(point.y());
|
|
|
|
|
|
|
|
if (rect != ell->property("rect"))
|
|
|
|
{
|
|
|
|
QPropertyUndoCommand *undo= new QPropertyUndoCommand(ell, "rect", ell->property("rect"), rect);
|
|
|
|
undo->setText("Modifier un arc");
|
|
|
|
undo->enableAnimation();
|
|
|
|
elementScene()->undoStack().push(undo);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
m_locked = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EllipseEditor::editingFinishedH()
|
|
|
|
{
|
|
|
|
if (m_locked) return;
|
|
|
|
m_locked = true;
|
|
|
|
|
|
|
|
for (auto part: style_->currentParts()) {
|
|
|
|
|
|
|
|
PartEllipse* ell = static_cast<PartEllipse*>(part);
|
|
|
|
QRectF rect = ell->property("rect").toRectF();
|
|
|
|
|
|
|
|
if (rect.width() != h->value())
|
|
|
|
{
|
|
|
|
rect.setWidth(h->value());
|
|
|
|
QPropertyUndoCommand *undo= new QPropertyUndoCommand(ell, "rect", ell->property("rect"), rect);
|
|
|
|
undo->setText("Modifier un arc");
|
|
|
|
undo->enableAnimation();
|
|
|
|
elementScene()->undoStack().push(undo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_locked = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EllipseEditor::editingFinishedV()
|
|
|
|
{
|
|
|
|
if (m_locked) return;
|
|
|
|
m_locked = true;
|
|
|
|
|
|
|
|
for (auto part: style_->currentParts()) {
|
|
|
|
|
|
|
|
PartEllipse* ell = static_cast<PartEllipse*>(part);
|
|
|
|
QRectF rect = ell->property("rect").toRectF();
|
|
|
|
|
|
|
|
if (rect.height() != v->value())
|
|
|
|
{
|
|
|
|
rect.setHeight(v->value());
|
|
|
|
QPropertyUndoCommand *undo= new QPropertyUndoCommand(ell, "rect", ell->property("rect"), rect);
|
|
|
|
undo->setText("Modifier un arc");
|
|
|
|
undo->enableAnimation();
|
|
|
|
elementScene()->undoStack().push(undo);
|
|
|
|
}
|
|
|
|
}
|
2015-07-23 09:57:09 +00:00
|
|
|
|
2020-06-22 23:25:11 +02:00
|
|
|
m_locked = false;
|
2015-07-23 09:57:09 +00:00
|
|
|
}
|
2007-08-25 03:43:05 +00:00
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/**
|
|
|
|
Met a jour le formulaire d'edition
|
|
|
|
*/
|
2015-07-23 09:57:09 +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);
|
2015-07-23 09:57:09 +00:00
|
|
|
QRectF rect = part->property("rect").toRectF();
|
|
|
|
x->setValue(part->mapToScene(rect.topLeft()).x() + (rect.width()/2));
|
|
|
|
y->setValue(part->mapToScene(rect.topLeft()).y() + (rect.height()/2));
|
|
|
|
h->setValue(rect.width());
|
|
|
|
v->setValue(rect.height());
|
2007-08-25 03:43:05 +00:00
|
|
|
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
|
|
|
|
*/
|
2015-07-23 09:57:09 +00:00
|
|
|
void EllipseEditor::activeConnections(bool active)
|
|
|
|
{
|
|
|
|
if (active)
|
|
|
|
{
|
2020-06-22 23:25:11 +02:00
|
|
|
connect(x, SIGNAL(editingFinished()), this, SLOT(editingFinishedX()));
|
|
|
|
connect(y, SIGNAL(editingFinished()), this, SLOT(editingFinishedY()));
|
|
|
|
connect(h, SIGNAL(editingFinished()), this, SLOT(editingFinishedH()));
|
|
|
|
connect(v, SIGNAL(editingFinished()), this, SLOT(editingFinishedV()));
|
2015-07-23 09:57:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-22 23:25:11 +02:00
|
|
|
disconnect(x, SIGNAL(editingFinished()), this, SLOT(editingFinishedX()));
|
|
|
|
disconnect(y, SIGNAL(editingFinished()), this, SLOT(editingFinishedY()));
|
|
|
|
disconnect(h, SIGNAL(editingFinished()), this, SLOT(editingFinishedH()));
|
|
|
|
disconnect(v, SIGNAL(editingFinished()), this, SLOT(editingFinishedV()));
|
2007-08-25 03:43:05 +00:00
|
|
|
}
|
2007-06-30 17:41:07 +00:00
|
|
|
}
|