Merge branch 'terminal_strip'

* terminal_strip:
  Terminal strip item can saved / loaded to .qet file
  See previous commit...
  Move terminal strip drawer class in is own file
  Fix wrong use of QStringLiteral and QLatin1String
  Double click a TerminalStripItem open the editor
  Minor change about checkable QAction of QetDiagramEditor
  Minor : corrects a minor aesthetic defect when unbridge terminals
  Revamp code
  Add and move terminal strip item are now managed by undo command
  TerminalStripItem : Draw terminal bridge
  Terminal strip item can be added to diagram
  Minor : add QGIUtility namespace
This commit is contained in:
joshua
2023-01-02 19:40:08 +01:00
45 changed files with 1628 additions and 276 deletions

View File

@@ -148,153 +148,6 @@ CutDiagramCommand::~CutDiagramCommand()
{
}
/**
@brief MoveElementsCommand::MoveElementsCommand
Constructor
@param dia diagram
@param diagram_content diagram content (contain all items to be moved)
@param m movement to applied
@param parent parent undo command
*/
MoveElementsCommand::MoveElementsCommand(
Diagram *dia,
const DiagramContent &diagram_content,
const QPointF &m,
QUndoCommand *parent
) :
QUndoCommand (parent),
diagram (dia),
content_to_move (diagram_content),
movement (m),
m_anim_group (nullptr),
first_redo (true)
{
QString moved_content_sentence = content_to_move.sentence(
DiagramContent::Elements |
DiagramContent::TextFields |
DiagramContent::ConductorsToUpdate |
DiagramContent::ConductorsToMove |
DiagramContent::Images |
DiagramContent::Shapes |
DiagramContent::ElementTextFields
);
setText(
QString(
QObject::tr(
"déplacer %1",
"undo caption - %1 is a sentence listing the moved content"
).arg(moved_content_sentence)
)
);
}
/**
@brief MoveElementsCommand::~MoveElementsCommand
Destructor
*/
MoveElementsCommand::~MoveElementsCommand()
{
delete m_anim_group;
}
/**
@brief MoveElementsCommand::undo
*/
void MoveElementsCommand::undo()
{
diagram -> showMe();
m_anim_group->setDirection(QAnimationGroup::Forward);
m_anim_group->start();
QUndoCommand::undo();
}
/**
@brief MoveElementsCommand::redo
*/
void MoveElementsCommand::redo()
{
diagram -> showMe();
if (first_redo) {
first_redo = false;
move(-movement);
}
else {
m_anim_group->setDirection(QAnimationGroup::Backward);
m_anim_group->start();
}
QUndoCommand::redo();
}
/**
@brief MoveElementsCommand::move
Move item and conductor to actual_movement
@param actual_movement movement to be applied
*/
void MoveElementsCommand::move(const QPointF &actual_movement)
{
typedef DiagramContent dc;
//Move every movable items, except conductor
for (QGraphicsItem *qgi : content_to_move.items(dc::Elements
| dc::TextFields
| dc::Images
| dc::Shapes
| dc::TextGroup
| dc::ElementTextFields
| dc::Tables))
{
//If current item has parent, and parent item is in content_to_move
//we don't apply movement to this item, because this item will be moved by is parent.
if (qgi->parentItem())
if (content_to_move.items().contains(qgi->parentItem()))
continue;
if(qgi->toGraphicsObject())
setupAnimation(qgi->toGraphicsObject(), "pos",
qgi->pos(), qgi->pos() + actual_movement);
else if(qgi->type() == QGraphicsItemGroup::Type)
{
//ElementTextItemGroup is a QObject but not a QGraphicsObject
if(ElementTextItemGroup *etig = dynamic_cast<ElementTextItemGroup *>(qgi))
setupAnimation(etig, "pos", etig->pos(),
etig->pos() + actual_movement);
}
else qgi -> setPos(qgi->pos() + actual_movement);
}
// Move some conductors
for (Conductor *conductor : content_to_move.m_conductors_to_move)
setupAnimation(conductor, "pos", conductor->pos(),
conductor->pos() + actual_movement);
// Recalcul the path of other conductor
for (Conductor *conductor : content_to_move.m_conductors_to_update)
setupAnimation(conductor, "animPath", 1, 1);
}
/**
@brief MoveElementsCommand::setupAnimation
Set up the animation for this undo command
@param target object to anim
@param propertyName property to animate
@param start value at start
@param end value at end
*/
void MoveElementsCommand::setupAnimation(QObject *target,
const QByteArray &propertyName,
const QVariant& start,
const QVariant& end) {
//create animation group if not yet.
if (m_anim_group == nullptr) m_anim_group = new QParallelAnimationGroup();
QPropertyAnimation *animation = new QPropertyAnimation(target, propertyName);
animation->setDuration(300);
animation->setStartValue(start);
animation->setEndValue(end);
animation->setEasingCurve(QEasingCurve::OutQuad);
m_anim_group->addAnimation(animation);
}
/**
@brief MoveConductorsTextsCommand::MoveConductorsTextsCommand
Constructeur