2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2021-02-20 12:13:46 +01:00
|
|
|
Copyright 2006-2021 The QElectroTech Team
|
2007-12-01 10:47:15 +00:00
|
|
|
This file is part of QElectroTech.
|
2020-09-24 17:01:33 +02:00
|
|
|
|
2007-12-01 10:47:15 +00:00
|
|
|
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.
|
2020-09-24 17:01:33 +02:00
|
|
|
|
2007-12-01 10:47:15 +00:00
|
|
|
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.
|
2020-09-24 17:01:33 +02:00
|
|
|
|
2007-12-01 10:47:15 +00:00
|
|
|
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"
|
2020-12-09 15:28:43 +01:00
|
|
|
|
|
|
|
#include "../QPropertyUndoCommand/qpropertyundocommand.h"
|
2015-07-23 09:32:21 +00:00
|
|
|
#include "elementscene.h"
|
2020-12-10 18:44:03 +01:00
|
|
|
#include "graphicspart/partarc.h"
|
2020-12-09 15:28:43 +01:00
|
|
|
#include "styleeditor.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),
|
2021-01-28 19:25:42 +01:00
|
|
|
m_part(arc),
|
2015-07-23 09:32:21 +00:00
|
|
|
m_locked(false)
|
2010-02-18 00:42:41 +00:00
|
|
|
{
|
2021-01-28 19:25:42 +01:00
|
|
|
m_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);
|
2020-09-24 17:01:33 +02: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);
|
2020-09-24 17:01:33 +02:00
|
|
|
|
2018-07-30 15:24:29 +00:00
|
|
|
QVBoxLayout *v_layout = new QVBoxLayout(this);
|
2020-09-24 17:01:33 +02: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);
|
2020-09-24 17:01:33 +02:00
|
|
|
|
2021-01-28 19:25:42 +01:00
|
|
|
v_layout -> addWidget(m_style);
|
2010-02-18 00:42:41 +00:00
|
|
|
v_layout -> addLayout(grid);
|
2018-07-17 12:19:56 +00:00
|
|
|
v_layout->addStretch();
|
2020-09-24 17:01:33 +02:00
|
|
|
|
2007-07-10 22:54:22 +00:00
|
|
|
updateForm();
|
2020-09-24 17:01:33 +02:00
|
|
|
|
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
|
2020-09-07 22:03:40 +02:00
|
|
|
ArcEditor::~ArcEditor()
|
|
|
|
{}
|
2007-07-10 22:54:22 +00:00
|
|
|
|
2020-06-22 23:25:11 +02:00
|
|
|
void ArcEditor::setUpChangeConnections()
|
|
|
|
{
|
2021-01-28 19:25:42 +01:00
|
|
|
m_change_connections << connect(m_part, &PartArc::rectChanged, this, &ArcEditor::updateForm);
|
|
|
|
m_change_connections << connect(m_part, &PartArc::spanAngleChanged, this, &ArcEditor::updateForm);
|
|
|
|
m_change_connections << connect(m_part, &PartArc::startAngleChanged, this, &ArcEditor::updateForm);
|
2020-09-24 17:01:33 +02:00
|
|
|
#if TODO_LIST
|
|
|
|
#pragma message("@TODO implement position changes!")
|
|
|
|
#endif
|
2020-06-22 23:25:11 +02:00
|
|
|
// TODO: implement position changes!
|
|
|
|
//m_change_connections << connect(part, &PartArc::)
|
|
|
|
}
|
|
|
|
|
|
|
|
void ArcEditor::disconnectChangeConnections()
|
|
|
|
{
|
|
|
|
for (QMetaObject::Connection c : m_change_connections) {
|
2020-09-24 17:01:33 +02:00
|
|
|
disconnect(c);
|
2020-06-22 23:25:11 +02:00
|
|
|
}
|
|
|
|
m_change_connections.clear();
|
|
|
|
}
|
|
|
|
|
2010-02-18 00:42:41 +00:00
|
|
|
/**
|
2020-08-16 11:19:36 +02: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
|
|
|
|
*/
|
2015-07-23 09:32:21 +00:00
|
|
|
bool ArcEditor::setPart(CustomElementPart *new_part)
|
|
|
|
{
|
|
|
|
if (!new_part)
|
|
|
|
{
|
2021-01-28 19:25:42 +01:00
|
|
|
if (m_part)
|
2020-07-15 20:20:07 +02:00
|
|
|
disconnectChangeConnections();
|
2020-06-22 23:25:11 +02:00
|
|
|
|
2021-01-28 19:25:42 +01:00
|
|
|
m_part = 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
|
|
|
{
|
2021-01-28 19:25:42 +01:00
|
|
|
if (m_part == part_arc) return true;
|
|
|
|
if (m_part)
|
2020-07-15 20:20:07 +02:00
|
|
|
disconnectChangeConnections();
|
2021-01-28 19:25:42 +01:00
|
|
|
m_part = part_arc;
|
2010-02-18 00:42:41 +00:00
|
|
|
updateForm();
|
2020-07-15 20:20:07 +02:00
|
|
|
setUpChangeConnections();
|
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
|
|
|
}
|
|
|
|
|
2020-06-22 23:25:11 +02:00
|
|
|
bool ArcEditor::setParts(QList <CustomElementPart *> parts)
|
|
|
|
{
|
2020-07-15 20:20:07 +02:00
|
|
|
if (parts.isEmpty())
|
|
|
|
return false;
|
2020-06-22 23:25:11 +02:00
|
|
|
|
2020-07-15 20:20:07 +02:00
|
|
|
if (!setPart(parts.first()))
|
|
|
|
return false;
|
2021-01-28 19:25:42 +01:00
|
|
|
return m_style->setParts(parts);
|
2020-06-22 23:25:11 +02:00
|
|
|
}
|
|
|
|
|
2010-02-18 00:42:41 +00:00
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief ArcEditor::currentPart
|
|
|
|
@return the curent edited part, or 0 if there is no edited part
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
CustomElementPart *ArcEditor::currentPart() const
|
|
|
|
{
|
2021-01-28 19:25:42 +01:00
|
|
|
return(m_part);
|
2010-02-18 00:42:41 +00:00
|
|
|
}
|
|
|
|
|
2020-09-07 22:03:40 +02:00
|
|
|
QList<CustomElementPart*> ArcEditor::currentParts() const
|
|
|
|
{
|
2021-01-28 19:25:42 +01:00
|
|
|
return m_style->currentParts();
|
2020-06-01 20:45:01 +02:00
|
|
|
}
|
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief ArcEditor::updateArcS
|
|
|
|
Update the start angle of the arc according to the edited value.
|
|
|
|
*/
|
2015-07-23 09:32:21 +00:00
|
|
|
void ArcEditor::updateArcS()
|
|
|
|
{
|
|
|
|
if (m_locked) return;
|
|
|
|
m_locked = true;
|
2020-07-15 20:20:07 +02:00
|
|
|
double value = start_angle->value() * 16;
|
2015-07-23 09:57:09 +00:00
|
|
|
|
2021-01-28 19:25:42 +01:00
|
|
|
for (auto part: m_style->currentParts()) {
|
2020-06-22 23:25:11 +02:00
|
|
|
|
2020-07-15 20:20:07 +02:00
|
|
|
PartArc* arc = static_cast<PartArc*>(part);
|
2020-06-22 23:25:11 +02:00
|
|
|
|
2020-07-15 20:20:07 +02:00
|
|
|
if (value != arc->property("startAngle"))
|
|
|
|
{
|
|
|
|
QPropertyUndoCommand *undo= new QPropertyUndoCommand(arc, "startAngle", arc->property("startAngle"), value);
|
|
|
|
undo->setText("Modifier l'angle de depart d'un arc");
|
|
|
|
undo->enableAnimation();
|
|
|
|
elementScene()->undoStack().push(undo);
|
|
|
|
}
|
|
|
|
}
|
2015-07-23 09:57:09 +00:00
|
|
|
|
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
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief ArcEditor::updateArcA
|
|
|
|
Update the span angle of the arc according to the edited value.
|
|
|
|
*/
|
2015-07-23 09:32:21 +00:00
|
|
|
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
|
|
|
|
2021-01-28 19:25:42 +01:00
|
|
|
for (auto part: m_style->currentParts()) {
|
2020-06-22 23:25:11 +02:00
|
|
|
|
2020-07-15 20:20:07 +02:00
|
|
|
PartArc* arc = static_cast<PartArc*>(part);
|
|
|
|
if (value != arc->property("spanAngle"))
|
|
|
|
{
|
|
|
|
QPropertyUndoCommand *undo= new QPropertyUndoCommand(arc, "spanAngle", arc->property("spanAngle"), value);
|
|
|
|
undo->setText("Modifier l'angle d'un arc");
|
|
|
|
undo->enableAnimation();
|
|
|
|
elementScene()->undoStack().push(undo);
|
|
|
|
}
|
|
|
|
}
|
2015-07-23 09:57:09 +00:00
|
|
|
|
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
|
|
|
/**
|
2021-01-28 19:25:42 +01:00
|
|
|
@brief ArcEditor::updateForm
|
|
|
|
Update the value of the widgets
|
2020-08-16 11:19:36 +02:00
|
|
|
*/
|
2021-03-11 19:52:50 +01:00
|
|
|
void ArcEditor::updateForm()
|
2020-06-22 23:25:11 +02:00
|
|
|
{
|
2021-01-28 19:25:42 +01:00
|
|
|
if (!m_part) return;
|
|
|
|
activeConnections(false);
|
|
|
|
QRectF rect = m_part->property("rect").toRectF();
|
|
|
|
x->setValue(m_part->mapToScene(rect.topLeft()).x() + (rect.width()/2));
|
|
|
|
y->setValue(m_part->mapToScene(rect.topLeft()).y() + (rect.height()/2));
|
|
|
|
h->setValue(rect.width());
|
|
|
|
v->setValue(rect.height());
|
|
|
|
start_angle->setValue(m_part->property("startAngle").toInt()/16);
|
|
|
|
angle->setValue(m_part->property("spanAngle").toInt()/16);
|
|
|
|
activeConnections(true);
|
2020-06-22 23:25:11 +02:00
|
|
|
}
|
|
|
|
|
2021-01-28 19:25:42 +01:00
|
|
|
void ArcEditor::updateRect()
|
2020-06-22 23:25:11 +02:00
|
|
|
{
|
2021-01-28 19:25:42 +01:00
|
|
|
QRectF rect;
|
2020-07-15 20:20:07 +02:00
|
|
|
|
2021-01-28 19:25:42 +01:00
|
|
|
auto pos_ = m_part->mapFromScene(QPointF(x->value(), y->value()));
|
|
|
|
rect.setX(pos_.x() - h->value()/2);
|
|
|
|
rect.setY(pos_.y() - v->value()/2);
|
|
|
|
rect.setWidth(h->value());
|
|
|
|
rect.setHeight(v->value());
|
2020-06-22 23:25:11 +02:00
|
|
|
|
2021-01-28 19:25:42 +01:00
|
|
|
for (auto part: m_style->currentParts())
|
|
|
|
{
|
|
|
|
auto ellipse = static_cast<PartArc*>(part);
|
|
|
|
if (rect != part->property("rect"))
|
2020-07-15 20:20:07 +02:00
|
|
|
{
|
2021-01-28 19:25:42 +01:00
|
|
|
auto undo= new QPropertyUndoCommand(ellipse, "rect", ellipse->property("rect"), rect);
|
2020-07-15 20:20:07 +02:00
|
|
|
undo->setText("Modifier un arc");
|
|
|
|
undo->enableAnimation();
|
|
|
|
elementScene()->undoStack().push(undo);
|
|
|
|
}
|
|
|
|
}
|
2007-08-25 03:43:05 +00:00
|
|
|
}
|
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief ArcEditor::activeConnections
|
|
|
|
Enable/disable connection between editor widget and slot editingFinished
|
|
|
|
True == enable | false == disable
|
|
|
|
@param active
|
|
|
|
*/
|
2015-07-23 09:32:21 +00:00
|
|
|
void ArcEditor::activeConnections(bool active)
|
|
|
|
{
|
|
|
|
if (active)
|
|
|
|
{
|
2021-01-28 19:25:42 +01:00
|
|
|
connect(x, &QDoubleSpinBox::editingFinished, this, &ArcEditor::updateRect);
|
|
|
|
connect(y, &QDoubleSpinBox::editingFinished, this, &ArcEditor::updateRect);
|
|
|
|
connect(h, &QDoubleSpinBox::editingFinished, this, &ArcEditor::updateRect);
|
|
|
|
connect(v, &QDoubleSpinBox::editingFinished, this, &ArcEditor::updateRect);
|
|
|
|
connect(start_angle, &QDoubleSpinBox::editingFinished, this, &ArcEditor::updateArcS);
|
|
|
|
connect(angle, &QDoubleSpinBox::editingFinished, this, &ArcEditor::updateArcA);
|
2015-07-23 09:32:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-28 19:25:42 +01:00
|
|
|
disconnect(x, &QDoubleSpinBox::editingFinished, this, &ArcEditor::updateRect);
|
|
|
|
disconnect(y, &QDoubleSpinBox::editingFinished, this, &ArcEditor::updateRect);
|
|
|
|
disconnect(h, &QDoubleSpinBox::editingFinished, this, &ArcEditor::updateRect);
|
|
|
|
disconnect(v, &QDoubleSpinBox::editingFinished, this, &ArcEditor::updateRect);
|
|
|
|
disconnect(start_angle, &QDoubleSpinBox::editingFinished, this, &ArcEditor::updateArcS);
|
|
|
|
disconnect(angle, &QDoubleSpinBox::editingFinished, this, &ArcEditor::updateArcA);
|
2007-08-25 03:43:05 +00:00
|
|
|
}
|
2007-07-10 22:54:22 +00:00
|
|
|
}
|