2017-12-05 20:51:54 +00:00
|
|
|
/*
|
2024-03-29 10:09:48 +01:00
|
|
|
Copyright 2006-2024 The QElectroTech Team
|
2017-12-05 20:51:54 +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/>.
|
|
|
|
*/
|
|
|
|
#include "rotateselectioncommand.h"
|
2020-12-08 19:57:35 +01:00
|
|
|
|
|
|
|
#include "../QPropertyUndoCommand/qpropertyundocommand.h"
|
|
|
|
#include "../diagram.h"
|
|
|
|
#include "../qet.h"
|
|
|
|
#include "../qetgraphicsitem/conductor.h"
|
2020-12-10 21:19:45 +01:00
|
|
|
#include "../qetgraphicsitem/conductortextitem.h"
|
|
|
|
#include "../qetgraphicsitem/diagramimageitem.h"
|
|
|
|
#include "../qetgraphicsitem/dynamicelementtextitem.h"
|
2020-12-08 19:57:35 +01:00
|
|
|
#include "../qetgraphicsitem/element.h"
|
2020-12-10 21:19:45 +01:00
|
|
|
#include "../qetgraphicsitem/elementtextitemgroup.h"
|
|
|
|
#include "../qetgraphicsitem/independenttextitem.h"
|
2017-12-05 20:51:54 +00:00
|
|
|
|
|
|
|
#include <QGraphicsItem>
|
|
|
|
|
|
|
|
RotateSelectionCommand::RotateSelectionCommand(Diagram *diagram, qreal angle, QUndoCommand *parent) :
|
|
|
|
QUndoCommand(parent),
|
2018-04-05 18:49:28 +00:00
|
|
|
m_diagram(diagram)
|
2017-12-05 20:51:54 +00:00
|
|
|
{
|
|
|
|
setText(QObject::tr("Pivoter la selection"));
|
|
|
|
|
|
|
|
if(!m_diagram->isReadOnly())
|
|
|
|
{
|
|
|
|
for (QGraphicsItem *item : m_diagram->selectedItems())
|
|
|
|
{
|
|
|
|
switch (item->type())
|
|
|
|
{
|
|
|
|
case Element::Type:
|
2018-04-04 16:55:59 +00:00
|
|
|
m_undo << new QPropertyUndoCommand(item->toGraphicsObject(), "rotation", QVariant(item->rotation()), QVariant(item->rotation()+angle), this);
|
2017-12-05 20:51:54 +00:00
|
|
|
break;
|
|
|
|
case ConductorTextItem::Type:
|
2018-04-04 16:55:59 +00:00
|
|
|
{
|
|
|
|
m_cond_text << static_cast<ConductorTextItem *>(item);
|
|
|
|
m_undo << new QPropertyUndoCommand(item->toGraphicsObject(), "rotation", QVariant(item->rotation()), QVariant(item->rotation()+angle), this);
|
|
|
|
}
|
2017-12-05 20:51:54 +00:00
|
|
|
break;
|
|
|
|
case IndependentTextItem::Type:
|
2018-04-04 16:55:59 +00:00
|
|
|
m_undo << new QPropertyUndoCommand(item->toGraphicsObject(), "rotation", QVariant(item->rotation()), QVariant(item->rotation()+angle), this);
|
2017-12-05 20:51:54 +00:00
|
|
|
break;
|
|
|
|
case DynamicElementTextItem::Type:
|
2018-04-04 16:55:59 +00:00
|
|
|
{
|
2017-12-05 20:51:54 +00:00
|
|
|
if(item->parentItem() && !item->parentItem()->isSelected())
|
2018-04-04 16:55:59 +00:00
|
|
|
m_undo << new QPropertyUndoCommand(item->toGraphicsObject(), "rotation", QVariant(item->rotation()), QVariant(item->rotation()+angle), this);
|
|
|
|
}
|
2017-12-05 20:51:54 +00:00
|
|
|
break;
|
|
|
|
case QGraphicsItemGroup::Type:
|
2018-04-04 16:55:59 +00:00
|
|
|
{
|
2018-07-30 15:24:29 +00:00
|
|
|
if(ElementTextItemGroup *grp = dynamic_cast<ElementTextItemGroup *>(item))
|
2017-12-05 20:51:54 +00:00
|
|
|
if(grp->parentElement() && !grp->parentElement()->isSelected())
|
2018-04-04 16:55:59 +00:00
|
|
|
m_undo << new QPropertyUndoCommand(grp, "rotation", QVariant(item->rotation()), QVariant(item->rotation()+angle), this);
|
|
|
|
}
|
2017-12-05 20:51:54 +00:00
|
|
|
break;
|
|
|
|
case DiagramImageItem::Type:
|
2018-04-04 16:55:59 +00:00
|
|
|
m_undo << new QPropertyUndoCommand(item->toGraphicsObject(), "rotation", QVariant(item->rotation()), QVariant(item->rotation()+angle), this);
|
2017-12-05 20:51:54 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-04-04 16:55:59 +00:00
|
|
|
|
|
|
|
for (QPropertyUndoCommand *undo : m_undo)
|
|
|
|
undo->setAnimated(true, false);
|
2017-12-05 20:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief RotateSelectionCommand::undo
|
|
|
|
*/
|
2017-12-05 20:51:54 +00:00
|
|
|
void RotateSelectionCommand::undo()
|
|
|
|
{
|
|
|
|
m_diagram->showMe();
|
2018-04-04 16:55:59 +00:00
|
|
|
QUndoCommand::undo();
|
2017-12-05 20:51:54 +00:00
|
|
|
|
2018-07-19 14:14:31 +00:00
|
|
|
for(const QPointer<ConductorTextItem>& cti : m_cond_text)
|
2017-12-05 20:51:54 +00:00
|
|
|
{
|
2018-04-04 16:55:59 +00:00
|
|
|
cti->forceRotateByUser(m_rotate_by_user.value(cti.data()));
|
|
|
|
if(!cti->wasRotateByUser())
|
|
|
|
cti->parentConductor()->calculateTextItemPosition();
|
2017-12-05 20:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief RotateSelectionCommand::redo
|
|
|
|
*/
|
2017-12-05 20:51:54 +00:00
|
|
|
void RotateSelectionCommand::redo()
|
|
|
|
{
|
|
|
|
m_diagram->showMe();
|
2018-04-04 16:55:59 +00:00
|
|
|
QUndoCommand::redo();
|
2017-12-05 20:51:54 +00:00
|
|
|
|
2018-07-19 14:14:31 +00:00
|
|
|
for(const QPointer<ConductorTextItem>& cti : m_cond_text)
|
2017-12-05 20:51:54 +00:00
|
|
|
{
|
2018-04-04 16:55:59 +00:00
|
|
|
m_rotate_by_user.insert(cti, cti->wasRotateByUser());
|
|
|
|
cti->forceRotateByUser(true);
|
2017-12-05 20:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief RotateSelectionCommand::isValid
|
|
|
|
@return true if this command rotate a least one item.
|
|
|
|
*/
|
2017-12-05 20:51:54 +00:00
|
|
|
bool RotateSelectionCommand::isValid()
|
|
|
|
{
|
2018-04-04 16:55:59 +00:00
|
|
|
if(childCount())
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
2017-12-05 20:51:54 +00:00
|
|
|
}
|