mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-22 09:40:52 +01:00
allow multiedit also for arceditor, ellipse, line, rectangle and show properties when single polygon is selected
This commit is contained in:
committed by
Laurent Trinques
parent
0ed9ac393c
commit
6c84b55586
@@ -77,6 +77,23 @@ ArcEditor::ArcEditor(QETElementEditor *editor, PartArc *arc, QWidget *parent) :
|
||||
/// Destructeur
|
||||
ArcEditor::~ArcEditor() {}
|
||||
|
||||
void ArcEditor::setUpChangeConnections()
|
||||
{
|
||||
m_change_connections << connect(part, &PartArc::rectChanged, this, &ArcEditor::updateForm);
|
||||
m_change_connections << connect(part, &PartArc::spanAngleChanged, this, &ArcEditor::updateForm);
|
||||
m_change_connections << connect(part, &PartArc::startAngleChanged, this, &ArcEditor::updateForm);
|
||||
// TODO: implement position changes!
|
||||
//m_change_connections << connect(part, &PartArc::)
|
||||
}
|
||||
|
||||
void ArcEditor::disconnectChangeConnections()
|
||||
{
|
||||
for (QMetaObject::Connection c : m_change_connections) {
|
||||
disconnect(c);
|
||||
}
|
||||
m_change_connections.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ArcEditor::setPart
|
||||
* Specifie to this editor the part to edit.
|
||||
@@ -89,11 +106,8 @@ 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);
|
||||
}
|
||||
disconnectChangeConnections();
|
||||
|
||||
part = nullptr;
|
||||
style_ -> setPart(nullptr);
|
||||
return(true);
|
||||
@@ -103,23 +117,27 @@ bool ArcEditor::setPart(CustomElementPart *new_part)
|
||||
{
|
||||
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);
|
||||
}
|
||||
disconnectChangeConnections();
|
||||
part = part_arc;
|
||||
style_ -> setPart(part);
|
||||
updateForm();
|
||||
connect(part, &PartArc::rectChanged, this, &ArcEditor::updateForm);
|
||||
connect(part, &PartArc::spanAngleChanged, this, &ArcEditor::updateForm);
|
||||
connect(part, &PartArc::startAngleChanged, this, &ArcEditor::updateForm);
|
||||
setUpChangeConnections();
|
||||
return(true);
|
||||
}
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
bool ArcEditor::setParts(QList <CustomElementPart *> parts)
|
||||
{
|
||||
if (parts.isEmpty())
|
||||
return false;
|
||||
|
||||
if (!setPart(parts.first()))
|
||||
return false;
|
||||
return style_->setParts(parts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ArcEditor::currentPart
|
||||
* @return the curent edited part, or 0 if there is no edited part
|
||||
@@ -140,15 +158,20 @@ void ArcEditor::updateArcS()
|
||||
{
|
||||
if (m_locked) return;
|
||||
m_locked = true;
|
||||
double value = start_angle->value() * 16;
|
||||
double value = start_angle->value() * 16;
|
||||
|
||||
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);
|
||||
}
|
||||
for (auto part: style_->currentParts()) {
|
||||
|
||||
PartArc* arc = static_cast<PartArc*>(part);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
m_locked = false;
|
||||
}
|
||||
@@ -163,13 +186,17 @@ void ArcEditor::updateArcA()
|
||||
m_locked = true;
|
||||
double value = angle->value() * 16;
|
||||
|
||||
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);
|
||||
}
|
||||
for (auto part: style_->currentParts()) {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
m_locked = false;
|
||||
}
|
||||
@@ -178,24 +205,102 @@ void ArcEditor::updateArcA()
|
||||
* @brief ArcEditor::updateArcRect
|
||||
* Update the geometrie of the rect that define this arc according the the edited values
|
||||
*/
|
||||
void ArcEditor::updateArcRect()
|
||||
void ArcEditor::updateArcRectX()
|
||||
{
|
||||
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()));
|
||||
|
||||
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);
|
||||
}
|
||||
for (auto part: style_->currentParts()) {
|
||||
|
||||
PartArc* arc = static_cast<PartArc*>(part);
|
||||
QRectF rect = arc->property("rect").toRectF();
|
||||
QPointF point = arc->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(arc, "rect", arc->property("rect"), rect);
|
||||
undo->setText("Modifier un arc");
|
||||
undo->enableAnimation();
|
||||
elementScene()->undoStack().push(undo);
|
||||
}
|
||||
}
|
||||
|
||||
m_locked = false;
|
||||
}
|
||||
|
||||
void ArcEditor::updateArcRectY()
|
||||
{
|
||||
if (m_locked) return;
|
||||
m_locked = true;
|
||||
|
||||
for (auto part: style_->currentParts()) {
|
||||
|
||||
PartArc* arc = static_cast<PartArc*>(part);
|
||||
QRectF rect = arc->property("rect").toRectF();
|
||||
|
||||
QPointF point = arc->mapFromScene(x->value() - h->value()/2, y->value() - v->value()/2);
|
||||
rect.setY(point.y());
|
||||
|
||||
if (rect != arc->property("rect"))
|
||||
{
|
||||
QPropertyUndoCommand *undo= new QPropertyUndoCommand(arc, "rect", arc->property("rect"), rect);
|
||||
undo->setText("Modifier un arc");
|
||||
undo->enableAnimation();
|
||||
elementScene()->undoStack().push(undo);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
m_locked = false;
|
||||
}
|
||||
|
||||
void ArcEditor::updateArcRectH()
|
||||
{
|
||||
if (m_locked) return;
|
||||
m_locked = true;
|
||||
|
||||
for (auto part: style_->currentParts()) {
|
||||
|
||||
PartArc* arc = static_cast<PartArc*>(part);
|
||||
QRectF rect = arc->property("rect").toRectF();
|
||||
|
||||
if (rect.width() != h->value())
|
||||
{
|
||||
rect.setWidth(h->value());
|
||||
QPropertyUndoCommand *undo= new QPropertyUndoCommand(arc, "rect", arc->property("rect"), rect);
|
||||
undo->setText("Modifier un arc");
|
||||
undo->enableAnimation();
|
||||
elementScene()->undoStack().push(undo);
|
||||
}
|
||||
}
|
||||
|
||||
m_locked = false;
|
||||
}
|
||||
|
||||
void ArcEditor::updateArcRectV()
|
||||
{
|
||||
if (m_locked) return;
|
||||
m_locked = true;
|
||||
|
||||
for (auto part: style_->currentParts()) {
|
||||
|
||||
PartArc* arc = static_cast<PartArc*>(part);
|
||||
QRectF rect = arc->property("rect").toRectF();
|
||||
|
||||
if (rect.height() != v->value())
|
||||
{
|
||||
rect.setHeight(v->value());
|
||||
QPropertyUndoCommand *undo= new QPropertyUndoCommand(arc, "rect", arc->property("rect"), rect);
|
||||
undo->setText("Modifier un arc");
|
||||
undo->enableAnimation();
|
||||
elementScene()->undoStack().push(undo);
|
||||
}
|
||||
}
|
||||
|
||||
m_locked = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ArcEditor::updateForm
|
||||
* Update the value of the widgets
|
||||
@@ -224,19 +329,19 @@ 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()));
|
||||
connect(x, SIGNAL(editingFinished()), this, SLOT(updateArcRectX()));
|
||||
connect(y, SIGNAL(editingFinished()), this, SLOT(updateArcRectY()));
|
||||
connect(h, SIGNAL(editingFinished()), this, SLOT(updateArcRectH()));
|
||||
connect(v, SIGNAL(editingFinished()), this, SLOT(updateArcRectV()));
|
||||
connect(start_angle, SIGNAL(editingFinished()), this, SLOT(updateArcS()));
|
||||
connect(angle, SIGNAL(editingFinished()), this, SLOT(updateArcA()));
|
||||
}
|
||||
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()));
|
||||
disconnect(x, SIGNAL(editingFinished()), this, SLOT(updateArcRectX()));
|
||||
disconnect(y, SIGNAL(editingFinished()), this, SLOT(updateArcRectY()));
|
||||
disconnect(h, SIGNAL(editingFinished()), this, SLOT(updateArcRectH()));
|
||||
disconnect(v, SIGNAL(editingFinished()), this, SLOT(updateArcRectV()));
|
||||
disconnect(start_angle, SIGNAL(editingFinished()), this, SLOT(updateArcS()));
|
||||
disconnect(angle, SIGNAL(editingFinished()), this, SLOT(updateArcA()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user