mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-03-25 00:39:58 +01:00
Texts group item can be rotate.
The keybord shortcut for texts group alignment change. Now it's ctrl + arrow-left/up/right git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5141 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
154
sources/undocommand/rotateselectioncommand.cpp
Normal file
154
sources/undocommand/rotateselectioncommand.cpp
Normal file
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
Copyright 2006-2017 The QElectroTech Team
|
||||
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"
|
||||
#include "element.h"
|
||||
#include "conductortextitem.h"
|
||||
#include "independenttextitem.h"
|
||||
#include "elementtextitem.h"
|
||||
#include "dynamicelementtextitem.h"
|
||||
#include "elementtextitemgroup.h"
|
||||
#include "diagramimageitem.h"
|
||||
#include "diagram.h"
|
||||
#include "conductor.h"
|
||||
|
||||
#include <QGraphicsItem>
|
||||
|
||||
RotateSelectionCommand::RotateSelectionCommand(Diagram *diagram, qreal angle, QUndoCommand *parent) :
|
||||
QUndoCommand(parent),
|
||||
m_diagram(diagram),
|
||||
m_angle(angle)
|
||||
{
|
||||
setText(QObject::tr("Pivoter la selection"));
|
||||
|
||||
if(!m_diagram->isReadOnly())
|
||||
{
|
||||
for (QGraphicsItem *item : m_diagram->selectedItems())
|
||||
{
|
||||
switch (item->type())
|
||||
{
|
||||
case Element::Type:
|
||||
m_element << static_cast<Element *>(item);
|
||||
break;
|
||||
case ConductorTextItem::Type:
|
||||
m_text << static_cast<DiagramTextItem *>(item);
|
||||
break;
|
||||
case IndependentTextItem::Type:
|
||||
m_text << static_cast<DiagramTextItem *>(item);
|
||||
break;
|
||||
case ElementTextItem::Type:
|
||||
if(item->parentItem() && !item->parentItem()->isSelected())
|
||||
m_text << static_cast<DiagramTextItem *>(item);
|
||||
break;
|
||||
case DynamicElementTextItem::Type:
|
||||
if(item->parentItem() && !item->parentItem()->isSelected())
|
||||
m_text << static_cast<DiagramTextItem *>(item);
|
||||
break;
|
||||
case QGraphicsItemGroup::Type:
|
||||
if(ElementTextItemGroup *grp = dynamic_cast<ElementTextItemGroup *>(item))
|
||||
if(grp->parentElement() && !grp->parentElement()->isSelected())
|
||||
m_group << grp;
|
||||
break;
|
||||
case DiagramImageItem::Type:
|
||||
m_image << static_cast<DiagramImageItem *>(item);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief RotateSelectionCommand::undo
|
||||
*/
|
||||
void RotateSelectionCommand::undo()
|
||||
{
|
||||
m_diagram->showMe();
|
||||
|
||||
for(QPointer<Element> elmt : m_element)
|
||||
if(elmt)
|
||||
elmt.data()->rotateBy(-m_angle);
|
||||
for(QPointer<DiagramTextItem> text : m_text)
|
||||
{
|
||||
if(text)
|
||||
{
|
||||
if(text.data()->type() == ConductorTextItem::Type)
|
||||
{
|
||||
ConductorTextItem *cti = static_cast<ConductorTextItem *>(text.data());
|
||||
cti->forceRotateByUser(m_rotate_by_user.value(text.data()));
|
||||
if(cti->wasRotateByUser())
|
||||
cti->rotateBy(-m_angle);
|
||||
else
|
||||
cti->parentConductor()->calculateTextItemPosition();
|
||||
}
|
||||
else
|
||||
text.data()->rotateBy(-m_angle);
|
||||
}
|
||||
}
|
||||
for(QPointer<DiagramImageItem> image : m_image)
|
||||
if(image)
|
||||
image.data()->rotateBy(-m_angle);
|
||||
for(QPointer<ElementTextItemGroup> group : m_group)
|
||||
if(group)
|
||||
group.data()->setRotation(group.data()->rotation() - m_angle);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief RotateSelectionCommand::redo
|
||||
*/
|
||||
void RotateSelectionCommand::redo()
|
||||
{
|
||||
m_diagram->showMe();
|
||||
|
||||
for(QPointer<Element> elmt : m_element)
|
||||
if(elmt)
|
||||
elmt.data()->rotateBy(m_angle);
|
||||
for(QPointer<DiagramTextItem> text : m_text)
|
||||
{
|
||||
if(text)
|
||||
{
|
||||
if(text.data()->type() == ConductorTextItem::Type)
|
||||
{
|
||||
ConductorTextItem *cti = static_cast<ConductorTextItem *>(text.data());
|
||||
m_rotate_by_user.insert(text.data(), cti->wasRotateByUser());
|
||||
cti->forceRotateByUser(true);
|
||||
}
|
||||
text.data()->rotateBy(m_angle);
|
||||
}
|
||||
}
|
||||
for(QPointer<DiagramImageItem> image : m_image)
|
||||
if(image)
|
||||
image.data()->rotateBy(m_angle);
|
||||
for(QPointer<ElementTextItemGroup> group : m_group)
|
||||
if(group)
|
||||
group.data()->setRotation(group.data()->rotation() + m_angle);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief RotateSelectionCommand::isValid
|
||||
* @return true if this command rotate a least one item.
|
||||
*/
|
||||
bool RotateSelectionCommand::isValid()
|
||||
{
|
||||
if(m_element.size()) return true;
|
||||
if(m_image.size()) return true;
|
||||
if(m_group.size()) return true;
|
||||
if(m_text.size()) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
56
sources/undocommand/rotateselectioncommand.h
Normal file
56
sources/undocommand/rotateselectioncommand.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
Copyright 2006-2017 The QElectroTech Team
|
||||
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/>.
|
||||
*/
|
||||
#ifndef ROTATESELECTIONCOMMAND_H
|
||||
#define ROTATESELECTIONCOMMAND_H
|
||||
|
||||
#include <QUndoCommand>
|
||||
#include <QPointer>
|
||||
|
||||
class Diagram;
|
||||
class Element;
|
||||
class QGraphicsObject;
|
||||
class ElementTextItemGroup;
|
||||
class DiagramTextItem;
|
||||
class DiagramImageItem;
|
||||
|
||||
/**
|
||||
* @brief The RotateSelectionCommand class
|
||||
* Rotate the selected items in the given diagram
|
||||
*/
|
||||
class RotateSelectionCommand : public QUndoCommand
|
||||
{
|
||||
public:
|
||||
RotateSelectionCommand(Diagram *diagram, qreal angle=90, QUndoCommand *parent=nullptr);
|
||||
void undo() override;
|
||||
void redo() override;
|
||||
|
||||
bool isValid();
|
||||
|
||||
private:
|
||||
Diagram *m_diagram =nullptr;
|
||||
qreal m_angle;
|
||||
|
||||
QList<QPointer<Element>> m_element;
|
||||
QList<QPointer<DiagramImageItem>> m_image;
|
||||
QList<QPointer<ElementTextItemGroup>> m_group;
|
||||
QList<QPointer<DiagramTextItem>> m_text;
|
||||
QHash<DiagramTextItem *, bool> m_rotate_by_user;
|
||||
|
||||
};
|
||||
|
||||
#endif // ROTATESELECTIONCOMMAND_H
|
||||
152
sources/undocommand/rotatetextscommand.cpp
Normal file
152
sources/undocommand/rotatetextscommand.cpp
Normal file
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
Copyright 2006-2017 The QElectroTech Team
|
||||
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 "rotatetextscommand.h"
|
||||
#include "diagramcontent.h"
|
||||
#include "diagram.h"
|
||||
#include "diagramtextitem.h"
|
||||
#include "elementtextitemgroup.h"
|
||||
#include "conductortextitem.h"
|
||||
#include "qetapp.h"
|
||||
#include "qtextorientationspinboxwidget.h"
|
||||
|
||||
/**
|
||||
* @brief RotateTextsCommand::RotateTextsCommand
|
||||
* @param diagram : Apply the rotation to the selected texts and group of texts
|
||||
* of diagram at construction time.
|
||||
* @param parent : undo parent
|
||||
*/
|
||||
RotateTextsCommand::RotateTextsCommand(Diagram *diagram, QUndoCommand *parent) :
|
||||
QUndoCommand(parent),
|
||||
m_diagram(diagram)
|
||||
{
|
||||
DiagramContent dc(m_diagram);
|
||||
QList <DiagramTextItem *> texts_list;
|
||||
QList <ElementTextItemGroup *> groups_list;
|
||||
|
||||
for(DiagramTextItem *dti : dc.selectedTexts())
|
||||
{
|
||||
texts_list << dti;
|
||||
if(dti->type() == ConductorTextItem::Type)
|
||||
{
|
||||
ConductorTextItem *cti = static_cast<ConductorTextItem *>(dti);
|
||||
m_cond_texts.insert(cti, cti->wasRotateByUser());
|
||||
}
|
||||
}
|
||||
for(ElementTextItemGroup *etig : dc.selectedTextsGroup())
|
||||
groups_list << etig;
|
||||
|
||||
if(texts_list.count() || groups_list.count())
|
||||
{
|
||||
openDialog();
|
||||
|
||||
QString text;
|
||||
if(texts_list.count())
|
||||
text.append(QObject::tr("Pivoter %1 textes").arg(texts_list.count()));
|
||||
if(groups_list.count())
|
||||
{
|
||||
if(text.isEmpty())
|
||||
text.append(QObject::tr("Pivoter"));
|
||||
else
|
||||
text.append(QObject::tr(" et"));
|
||||
|
||||
text.append(QObject::tr(" %1 groupes de textes").arg(groups_list.count()));
|
||||
}
|
||||
if(!text.isNull())
|
||||
setText(text);
|
||||
|
||||
for(DiagramTextItem *dti : texts_list)
|
||||
setupAnimation(dti, "rotation", dti->rotation(), m_rotation);
|
||||
for(ElementTextItemGroup *grp : groups_list)
|
||||
setupAnimation(grp, "rotation", grp->rotation(), m_rotation);
|
||||
}
|
||||
#if QT_VERSION >= 0x050900
|
||||
else
|
||||
setObsolete(true);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void RotateTextsCommand::undo()
|
||||
{
|
||||
if(m_diagram)
|
||||
m_diagram.data()->showMe();
|
||||
|
||||
m_anim_group->setDirection(QAnimationGroup::Backward);
|
||||
m_anim_group->start();
|
||||
|
||||
for(ConductorTextItem *cti : m_cond_texts.keys())
|
||||
cti->forceMovedByUser(m_cond_texts.value(cti));
|
||||
}
|
||||
|
||||
void RotateTextsCommand::redo()
|
||||
{
|
||||
if(m_diagram)
|
||||
m_diagram.data()->showMe();
|
||||
|
||||
m_anim_group->setDirection(QAnimationGroup::Forward);
|
||||
m_anim_group->start();
|
||||
|
||||
for(ConductorTextItem *cti : m_cond_texts.keys())
|
||||
cti->forceMovedByUser(true);
|
||||
}
|
||||
|
||||
void RotateTextsCommand::openDialog()
|
||||
{
|
||||
//Open the dialog
|
||||
QDialog ori_text_dialog;
|
||||
ori_text_dialog.setSizeGripEnabled(false);
|
||||
#ifdef Q_OS_MAC
|
||||
ori_text_dialog.setWindowFlags(Qt::Sheet);
|
||||
#endif
|
||||
ori_text_dialog.setWindowTitle(QObject::tr("Orienter les textes sélectionnés", "window title"));
|
||||
|
||||
|
||||
QTextOrientationSpinBoxWidget *ori_widget = QETApp::createTextOrientationSpinBoxWidget();
|
||||
ori_widget->setParent(&ori_text_dialog);
|
||||
ori_widget->spinBox()->selectAll();
|
||||
|
||||
QDialogButtonBox buttons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
QObject::connect(&buttons, SIGNAL(accepted()), &ori_text_dialog, SLOT(accept()));
|
||||
QObject::connect(&buttons, SIGNAL(rejected()), &ori_text_dialog, SLOT(reject()));
|
||||
|
||||
QVBoxLayout layout_v(&ori_text_dialog);
|
||||
layout_v.setSizeConstraint(QLayout::SetFixedSize);
|
||||
layout_v.addWidget(ori_widget);
|
||||
layout_v.addStretch();
|
||||
layout_v.addWidget(&buttons);
|
||||
|
||||
if (ori_text_dialog.exec() == QDialog::Accepted)
|
||||
m_rotation = ori_widget->orientation();
|
||||
#if QT_VERSION >= 0x050900
|
||||
else
|
||||
setObsolete(true);
|
||||
#endif
|
||||
}
|
||||
|
||||
void RotateTextsCommand::setupAnimation(QObject *target, const QByteArray &propertyName, const QVariant start, const QVariant end)
|
||||
{
|
||||
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);
|
||||
}
|
||||
52
sources/undocommand/rotatetextscommand.h
Normal file
52
sources/undocommand/rotatetextscommand.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
Copyright 2006-2017 The QElectroTech Team
|
||||
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/>.
|
||||
*/
|
||||
#ifndef ROTATETEXTSCOMMAND_H
|
||||
#define ROTATETEXTSCOMMAND_H
|
||||
|
||||
#include <QUndoCommand>
|
||||
#include <QPointer>
|
||||
|
||||
class ConductorTextItem;
|
||||
class Diagram;
|
||||
class QParallelAnimationGroup;
|
||||
|
||||
/**
|
||||
* @brief The RotateTextsCommand class
|
||||
* Open a dialog for edit the rotation of the current selected texts and texts group in diagram.
|
||||
* Just instantiate this undo command and push it in a QUndoStack.
|
||||
*/
|
||||
class RotateTextsCommand : public QUndoCommand
|
||||
{
|
||||
public:
|
||||
RotateTextsCommand(Diagram *diagram, QUndoCommand *parent=nullptr);
|
||||
|
||||
void undo() override;
|
||||
void redo() override;
|
||||
|
||||
private:
|
||||
void openDialog();
|
||||
void setupAnimation(QObject *target, const QByteArray &propertyName, const QVariant start, const QVariant end);
|
||||
|
||||
private:
|
||||
QPointer<Diagram> m_diagram;
|
||||
QHash<ConductorTextItem *, bool> m_cond_texts;
|
||||
qreal m_rotation=0;
|
||||
QParallelAnimationGroup *m_anim_group = nullptr;
|
||||
};
|
||||
|
||||
#endif // ROTATETEXTSCOMMAND_H
|
||||
Reference in New Issue
Block a user