QElectroTech  0.70
rotatetextscommand.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2006-2019 The QElectroTech Team
3  This file is part of QElectroTech.
4 
5  QElectroTech is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 2 of the License, or
8  (at your option) any later version.
9 
10  QElectroTech is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "rotatetextscommand.h"
19 #include "diagramcontent.h"
20 #include "diagram.h"
21 #include "diagramtextitem.h"
22 #include "elementtextitemgroup.h"
23 #include "conductortextitem.h"
24 #include "qetapp.h"
26 
33 RotateTextsCommand::RotateTextsCommand(Diagram *diagram, QUndoCommand *parent) :
34 QUndoCommand(parent),
35 m_diagram(diagram)
36 {
38  QList <DiagramTextItem *> texts_list;
39  QList <ElementTextItemGroup *> groups_list;
40 
41  for(DiagramTextItem *dti : dc.selectedTexts())
42  {
43  texts_list << dti;
44  if(dti->type() == ConductorTextItem::Type)
45  {
46  ConductorTextItem *cti = static_cast<ConductorTextItem *>(dti);
47  m_cond_texts.insert(cti, cti->wasRotateByUser());
48  }
49  }
51  groups_list << etig;
52 
53  if(texts_list.count() || groups_list.count())
54  {
55  openDialog();
56 
57  QString text;
58  if(texts_list.count())
59  text.append(QObject::tr("Pivoter %1 textes").arg(texts_list.count()));
60  if(groups_list.count())
61  {
62  if(text.isEmpty())
63  text.append(QObject::tr("Pivoter"));
64  else
65  text.append(QObject::tr(" et"));
66 
67  text.append(QObject::tr(" %1 groupes de textes").arg(groups_list.count()));
68  }
69  if(!text.isNull())
70  setText(text);
71 
72  for(DiagramTextItem *dti : texts_list)
73  setupAnimation(dti, "rotation", dti->rotation(), m_rotation);
74  for(ElementTextItemGroup *grp : groups_list)
75  setupAnimation(grp, "rotation", grp->rotation(), m_rotation);
76  }
77 #if QT_VERSION >= 0x050900
78  else
79  setObsolete(true);
80 #endif
81 
82 }
83 
85 {
86  if(m_diagram)
87  m_diagram.data()->showMe();
88 
89  m_anim_group->setDirection(QAnimationGroup::Backward);
90  m_anim_group->start();
91 
92  for(ConductorTextItem *cti : m_cond_texts.keys())
93  cti->forceMovedByUser(m_cond_texts.value(cti));
94 }
95 
97 {
98  if(m_diagram)
99  m_diagram.data()->showMe();
100 
101  m_anim_group->setDirection(QAnimationGroup::Forward);
102  m_anim_group->start();
103 
104  for(ConductorTextItem *cti : m_cond_texts.keys())
105  cti->forceMovedByUser(true);
106 }
107 
109 {
110  //Open the dialog
111  QDialog ori_text_dialog;
112  ori_text_dialog.setSizeGripEnabled(false);
113 #ifdef Q_OS_MAC
114  ori_text_dialog.setWindowFlags(Qt::Sheet);
115 #endif
116  ori_text_dialog.setWindowTitle(QObject::tr("Orienter les textes sélectionnés", "window title"));
117 
118 
120  ori_widget->setParent(&ori_text_dialog);
121  ori_widget->spinBox()->selectAll();
122 
123  QDialogButtonBox buttons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
124  QObject::connect(&buttons, SIGNAL(accepted()), &ori_text_dialog, SLOT(accept()));
125  QObject::connect(&buttons, SIGNAL(rejected()), &ori_text_dialog, SLOT(reject()));
126 
127  QVBoxLayout layout_v(&ori_text_dialog);
128  layout_v.setSizeConstraint(QLayout::SetFixedSize);
129  layout_v.addWidget(ori_widget);
130  layout_v.addStretch();
131  layout_v.addWidget(&buttons);
132 
133  if (ori_text_dialog.exec() == QDialog::Accepted)
134  m_rotation = ori_widget->orientation();
135 #if QT_VERSION >= 0x050900
136  else
137  setObsolete(true);
138 #endif
139 }
140 
141 void RotateTextsCommand::setupAnimation(QObject *target, const QByteArray &propertyName, const QVariant& start, const QVariant& end)
142 {
143  if(m_anim_group == nullptr)
144  m_anim_group = new QParallelAnimationGroup();
145 
146  QPropertyAnimation *animation = new QPropertyAnimation(target, propertyName);
147  animation->setDuration(300);
148  animation->setStartValue(start);
149  animation->setEndValue(end);
150  animation->setEasingCurve(QEasingCurve::OutQuad);
151  m_anim_group->addAnimation(animation);
152 }
static QTextOrientationSpinBoxWidget * createTextOrientationSpinBoxWidget()
Definition: qetapp.cpp:1072
QList< DiagramTextItem * > selectedTexts() const
DiagramContent::selectedTexts.
QHash< ConductorTextItem *, bool > m_cond_texts
void setupAnimation(QObject *target, const QByteArray &propertyName, const QVariant &start, const QVariant &end)
QPointer< Diagram > m_diagram
QIcon tr
Definition: qeticons.cpp:204
QList< ElementTextItemGroup * > selectedTextsGroup() const
DiagramContent::selectedTextsGroup.
The ElementTextItemGroup class This class represent a group of element text Texts in the group can be...
QParallelAnimationGroup * m_anim_group
virtual bool wasRotateByUser() const
ConductorTextItem::wasRotateByUser.
RotateTextsCommand(Diagram *diagram, QUndoCommand *parent=nullptr)
RotateTextsCommand::RotateTextsCommand.
QIcon Cancel
Definition: qeticons.cpp:34