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-07-10 22:54:22 +00:00
|
|
|
#include "arceditor.h"
|
2010-02-18 00:42:41 +00:00
|
|
|
#include "styleeditor.h"
|
2007-07-10 22:54:22 +00:00
|
|
|
#include "partarc.h"
|
2015-07-23 09:32:21 +00:00
|
|
|
#include "QPropertyUndoCommand/qpropertyundocommand.h"
|
|
|
|
#include "elementscene.h"
|
2007-07-10 22:54:22 +00:00
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/**
|
|
|
|
Constructeur
|
|
|
|
@param editor L'editeur d'element concerne
|
|
|
|
@param arc L'arc a editer
|
|
|
|
@param parent le Widget parent
|
|
|
|
*/
|
2010-02-18 00:42:41 +00:00
|
|
|
ArcEditor::ArcEditor(QETElementEditor *editor, PartArc *arc, QWidget *parent) :
|
|
|
|
ElementItemEditor(editor, parent),
|
2015-07-23 09:32:21 +00:00
|
|
|
part(arc),
|
|
|
|
m_locked(false)
|
2010-02-18 00:42:41 +00:00
|
|
|
{
|
|
|
|
style_ = new StyleEditor(editor);
|
2014-05-29 13:46:04 +00:00
|
|
|
x = new QDoubleSpinBox();
|
|
|
|
y = new QDoubleSpinBox();
|
|
|
|
h = new QDoubleSpinBox();
|
|
|
|
v = new QDoubleSpinBox();
|
2007-07-10 22:54:22 +00:00
|
|
|
start_angle = new QSpinBox();
|
|
|
|
angle = new QSpinBox();
|
|
|
|
start_angle -> setRange(-360, 360);
|
|
|
|
angle -> setRange(-360, 360);
|
|
|
|
|
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-12-17 20:37:10 +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-07-10 22:54:22 +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-07-10 22:54:22 +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-07-10 22:54:22 +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);
|
2015-03-02 20:14:56 +00:00
|
|
|
grid -> addWidget(new QLabel(tr("Angle de départ :")), 5, 0);
|
2007-07-10 22:54:22 +00:00
|
|
|
grid -> addWidget(start_angle, 5, 1);
|
|
|
|
grid -> addWidget(new QLabel(tr("Angle :")), 6, 0);
|
|
|
|
grid -> addWidget(angle, 6, 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-07-10 22:54:22 +00:00
|
|
|
updateForm();
|
|
|
|
|
2007-08-25 03:43:05 +00:00
|
|
|
activeConnections(true);
|
2007-07-10 22:54:22 +00:00
|
|
|
}
|
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/// Destructeur
|
2015-07-23 09:32:21 +00:00
|
|
|
ArcEditor::~ArcEditor() {}
|
2007-07-10 22:54:22 +00:00
|
|
|
|
2010-02-18 00:42:41 +00:00
|
|
|
/**
|
2015-07-23 09:32:21 +00:00
|
|
|
* @brief ArcEditor::setPart
|
|
|
|
* Specifie to this editor the part to edit.
|
|
|
|
* Note that an editor can accept or refuse to edit a part. This editor accept only partArc.
|
|
|
|
* @param new_part
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
bool ArcEditor::setPart(CustomElementPart *new_part)
|
|
|
|
{
|
|
|
|
if (!new_part)
|
|
|
|
{
|
|
|
|
if (part)
|
|
|
|
{
|
|
|
|
disconnect(part, &PartArc::rectChanged, this, &ArcEditor::updateForm);
|
|
|
|
disconnect(part, &PartArc::spanAngleChanged, this, &ArcEditor::updateForm);
|
|
|
|
disconnect(part, &PartArc::startAngleChanged, this, &ArcEditor::updateForm);
|
|
|
|
}
|
2017-08-05 02:06:59 +00:00
|
|
|
part = nullptr;
|
|
|
|
style_ -> setPart(nullptr);
|
2010-02-18 00:42:41 +00:00
|
|
|
return(true);
|
|
|
|
}
|
2015-07-23 09:32:21 +00:00
|
|
|
|
2018-07-30 15:24:29 +00:00
|
|
|
if (PartArc *part_arc = dynamic_cast<PartArc *>(new_part))
|
2015-07-23 09:32:21 +00:00
|
|
|
{
|
|
|
|
if (part == part_arc) return true;
|
|
|
|
if (part)
|
|
|
|
{
|
|
|
|
disconnect(part, &PartArc::rectChanged, this, &ArcEditor::updateForm);
|
|
|
|
disconnect(part, &PartArc::spanAngleChanged, this, &ArcEditor::updateForm);
|
|
|
|
disconnect(part, &PartArc::startAngleChanged, this, &ArcEditor::updateForm);
|
|
|
|
}
|
2010-02-18 00:42:41 +00:00
|
|
|
part = part_arc;
|
|
|
|
style_ -> setPart(part);
|
|
|
|
updateForm();
|
2015-07-23 09:32:21 +00:00
|
|
|
connect(part, &PartArc::rectChanged, this, &ArcEditor::updateForm);
|
|
|
|
connect(part, &PartArc::spanAngleChanged, this, &ArcEditor::updateForm);
|
|
|
|
connect(part, &PartArc::startAngleChanged, this, &ArcEditor::updateForm);
|
2010-02-18 00:42:41 +00:00
|
|
|
return(true);
|
|
|
|
}
|
2015-07-23 09:32:21 +00:00
|
|
|
|
|
|
|
return(false);
|
2010-02-18 00:42:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-07-23 09:32:21 +00:00
|
|
|
* @brief ArcEditor::currentPart
|
|
|
|
* @return the curent edited part, or 0 if there is no edited part
|
|
|
|
*/
|
2010-02-18 00:42:41 +00:00
|
|
|
CustomElementPart *ArcEditor::currentPart() const {
|
|
|
|
return(part);
|
|
|
|
}
|
|
|
|
|
2020-06-01 20:45:01 +02:00
|
|
|
QList<CustomElementPart*> ArcEditor::currentParts() const {
|
|
|
|
return style_->currentParts();
|
|
|
|
}
|
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/**
|
2015-07-23 09:32:21 +00:00
|
|
|
* @brief ArcEditor::updateArcS
|
|
|
|
* Update the start angle of the arc according to the edited value.
|
|
|
|
*/
|
|
|
|
void ArcEditor::updateArcS()
|
|
|
|
{
|
|
|
|
if (m_locked) return;
|
|
|
|
m_locked = true;
|
2016-09-25 08:14:29 +00:00
|
|
|
double value = start_angle->value() * 16;
|
2015-07-23 09:57:09 +00:00
|
|
|
|
|
|
|
if (value != part->property("startAngle"))
|
|
|
|
{
|
|
|
|
QPropertyUndoCommand *undo= new QPropertyUndoCommand(part, "startAngle", part->property("startAngle"), value);
|
|
|
|
undo->setText("Modifier l'angle de depart d'un arc");
|
|
|
|
undo->enableAnimation();
|
|
|
|
elementScene()->undoStack().push(undo);
|
|
|
|
}
|
|
|
|
|
2015-07-23 09:32:21 +00:00
|
|
|
m_locked = false;
|
2007-07-10 22:54:22 +00:00
|
|
|
}
|
|
|
|
|
2015-07-23 09:32:21 +00:00
|
|
|
/**
|
|
|
|
* @brief ArcEditor::updateArcA
|
|
|
|
* Update the span angle of the arc according to the edited value.
|
|
|
|
*/
|
|
|
|
void ArcEditor::updateArcA()
|
|
|
|
{
|
|
|
|
if (m_locked) return;
|
|
|
|
m_locked = true;
|
2016-09-25 08:14:29 +00:00
|
|
|
double value = angle->value() * 16;
|
2015-07-23 09:57:09 +00:00
|
|
|
|
|
|
|
if (value != part->property("spanAngle"))
|
|
|
|
{
|
|
|
|
QPropertyUndoCommand *undo= new QPropertyUndoCommand(part, "spanAngle", part->property("spanAngle"), value);
|
|
|
|
undo->setText("Modifier l'angle d'un arc");
|
|
|
|
undo->enableAnimation();
|
|
|
|
elementScene()->undoStack().push(undo);
|
|
|
|
}
|
|
|
|
|
2015-07-23 09:32:21 +00:00
|
|
|
m_locked = false;
|
|
|
|
}
|
2007-08-25 03:43:05 +00:00
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/**
|
2015-07-23 09:32:21 +00:00
|
|
|
* @brief ArcEditor::updateArcRect
|
|
|
|
* Update the geometrie of the rect that define this arc according the the edited values
|
|
|
|
*/
|
|
|
|
void ArcEditor::updateArcRect()
|
|
|
|
{
|
|
|
|
if (m_locked) return;
|
|
|
|
m_locked = true;
|
|
|
|
QPointF point = part->mapFromScene(x->value() - h->value()/2, y->value() - v->value()/2);
|
|
|
|
QRectF rect(point, QSizeF(h->value(), v->value()));
|
2015-07-23 09:57:09 +00:00
|
|
|
|
|
|
|
if (rect != part->property("rect"))
|
|
|
|
{
|
|
|
|
QPropertyUndoCommand *undo= new QPropertyUndoCommand(part, "rect", part->property("rect"), rect);
|
|
|
|
undo->setText("Modifier un arc");
|
|
|
|
undo->enableAnimation();
|
|
|
|
elementScene()->undoStack().push(undo);
|
|
|
|
}
|
|
|
|
|
2015-07-23 09:32:21 +00:00
|
|
|
m_locked = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ArcEditor::updateForm
|
|
|
|
* Update the value of the widgets
|
|
|
|
*/
|
|
|
|
void ArcEditor::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:32:21 +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());
|
2016-09-25 08:14:29 +00:00
|
|
|
start_angle->setValue(part->property("startAngle").toInt()/16);
|
|
|
|
angle->setValue(part->property("spanAngle").toInt()/16);
|
2007-08-25 03:43:05 +00:00
|
|
|
activeConnections(true);
|
|
|
|
}
|
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/**
|
2015-07-23 09:32:21 +00:00
|
|
|
* @brief ArcEditor::activeConnections
|
|
|
|
* Enable/disable connection between editor widget and slot editingFinished
|
|
|
|
* True == enable | false == disable
|
|
|
|
* @param active
|
|
|
|
*/
|
|
|
|
void ArcEditor::activeConnections(bool active)
|
|
|
|
{
|
|
|
|
if (active)
|
|
|
|
{
|
|
|
|
connect(x, SIGNAL(editingFinished()), this, SLOT(updateArcRect()));
|
|
|
|
connect(y, SIGNAL(editingFinished()), this, SLOT(updateArcRect()));
|
|
|
|
connect(h, SIGNAL(editingFinished()), this, SLOT(updateArcRect()));
|
|
|
|
connect(v, SIGNAL(editingFinished()), this, SLOT(updateArcRect()));
|
2007-08-25 03:43:05 +00:00
|
|
|
connect(start_angle, SIGNAL(editingFinished()), this, SLOT(updateArcS()));
|
|
|
|
connect(angle, SIGNAL(editingFinished()), this, SLOT(updateArcA()));
|
2015-07-23 09:32:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
disconnect(x, SIGNAL(editingFinished()), this, SLOT(updateArcRect()));
|
|
|
|
disconnect(y, SIGNAL(editingFinished()), this, SLOT(updateArcRect()));
|
|
|
|
disconnect(h, SIGNAL(editingFinished()), this, SLOT(updateArcRect()));
|
|
|
|
disconnect(v, SIGNAL(editingFinished()), this, SLOT(updateArcRect()));
|
2007-08-25 03:43:05 +00:00
|
|
|
disconnect(start_angle, SIGNAL(editingFinished()), this, SLOT(updateArcS()));
|
|
|
|
disconnect(angle, SIGNAL(editingFinished()), this, SLOT(updateArcA()));
|
|
|
|
}
|
2007-07-10 22:54:22 +00:00
|
|
|
}
|