QElectroTech  0.70
arceditor.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 "arceditor.h"
19 #include "styleeditor.h"
20 #include "partarc.h"
22 #include "elementscene.h"
23 
30 ArcEditor::ArcEditor(QETElementEditor *editor, PartArc *arc, QWidget *parent) :
31  ElementItemEditor(editor, parent),
32  part(arc),
33  m_locked(false)
34 {
35  style_ = new StyleEditor(editor);
36  x = new QDoubleSpinBox();
37  y = new QDoubleSpinBox();
38  h = new QDoubleSpinBox();
39  v = new QDoubleSpinBox();
40  start_angle = new QSpinBox();
41  angle = new QSpinBox();
42  start_angle -> setRange(-360, 360);
43  angle -> setRange(-360, 360);
44 
45  x->setRange(-5000, 5000);
46  y->setRange(-5000, 5000);
47  h->setRange(-5000, 5000);
48  v->setRange(-5000, 5000);
49 
50  QVBoxLayout *v_layout = new QVBoxLayout(this);
51 
52  QGridLayout *grid = new QGridLayout();
53  grid -> addWidget(new QLabel(tr("Centre : ")), 0, 0);
54  grid -> addWidget(new QLabel("x"), 1, 0, Qt::AlignRight);
55  grid -> addWidget(x, 1, 1);
56  grid -> addWidget(new QLabel("y"), 1, 2);
57  grid -> addWidget(y, 1, 3);
58  grid -> addWidget(new QLabel(tr("Diamètres : ")), 2, 0);
59  grid -> addWidget(new QLabel(tr("horizontal :")), 3, 0);
60  grid -> addWidget(h, 3, 1);
61  grid -> addWidget(new QLabel(tr("vertical :")), 4, 0);
62  grid -> addWidget(v, 4, 1);
63  grid -> addWidget(new QLabel(tr("Angle de départ :")), 5, 0);
64  grid -> addWidget(start_angle, 5, 1);
65  grid -> addWidget(new QLabel(tr("Angle :")), 6, 0);
66  grid -> addWidget(angle, 6, 1);
67 
68  v_layout -> addWidget(style_);
69  v_layout -> addLayout(grid);
70  v_layout->addStretch();
71 
72  updateForm();
73 
74  activeConnections(true);
75 }
76 
79 
88 {
89  if (!new_part)
90  {
91  if (part)
92  {
93  disconnect(part, &PartArc::rectChanged, this, &ArcEditor::updateForm);
96  }
97  part = nullptr;
98  style_ -> setPart(nullptr);
99  return(true);
100  }
101 
102  if (PartArc *part_arc = dynamic_cast<PartArc *>(new_part))
103  {
104  if (part == part_arc) return true;
105  if (part)
106  {
107  disconnect(part, &PartArc::rectChanged, this, &ArcEditor::updateForm);
110  }
111  part = part_arc;
112  style_ -> setPart(part);
113  updateForm();
117  return(true);
118  }
119 
120  return(false);
121 }
122 
128  return(part);
129 }
130 
136 {
137  if (m_locked) return;
138  m_locked = true;
139  double value = start_angle->value() * 16;
140 
141  if (value != part->property("startAngle"))
142  {
143  QPropertyUndoCommand *undo= new QPropertyUndoCommand(part, "startAngle", part->property("startAngle"), value);
144  undo->setText("Modifier l'angle de depart d'un arc");
145  undo->enableAnimation();
146  elementScene()->undoStack().push(undo);
147  }
148 
149  m_locked = false;
150 }
151 
157 {
158  if (m_locked) return;
159  m_locked = true;
160  double value = angle->value() * 16;
161 
162  if (value != part->property("spanAngle"))
163  {
164  QPropertyUndoCommand *undo= new QPropertyUndoCommand(part, "spanAngle", part->property("spanAngle"), value);
165  undo->setText("Modifier l'angle d'un arc");
166  undo->enableAnimation();
167  elementScene()->undoStack().push(undo);
168  }
169 
170  m_locked = false;
171 }
172 
178 {
179  if (m_locked) return;
180  m_locked = true;
181  QPointF point = part->mapFromScene(x->value() - h->value()/2, y->value() - v->value()/2);
182  QRectF rect(point, QSizeF(h->value(), v->value()));
183 
184  if (rect != part->property("rect"))
185  {
186  QPropertyUndoCommand *undo= new QPropertyUndoCommand(part, "rect", part->property("rect"), rect);
187  undo->setText("Modifier un arc");
188  undo->enableAnimation();
189  elementScene()->undoStack().push(undo);
190  }
191 
192  m_locked = false;
193 }
194 
200 {
201  if (!part) return;
202  activeConnections(false);
203  QRectF rect = part->property("rect").toRectF();
204  x->setValue(part->mapToScene(rect.topLeft()).x() + (rect.width()/2));
205  y->setValue(part->mapToScene(rect.topLeft()).y() + (rect.height()/2));
206  h->setValue(rect.width());
207  v->setValue(rect.height());
208  start_angle->setValue(part->property("startAngle").toInt()/16);
209  angle->setValue(part->property("spanAngle").toInt()/16);
210  activeConnections(true);
211 }
212 
220 {
221  if (active)
222  {
223  connect(x, SIGNAL(editingFinished()), this, SLOT(updateArcRect()));
224  connect(y, SIGNAL(editingFinished()), this, SLOT(updateArcRect()));
225  connect(h, SIGNAL(editingFinished()), this, SLOT(updateArcRect()));
226  connect(v, SIGNAL(editingFinished()), this, SLOT(updateArcRect()));
227  connect(start_angle, SIGNAL(editingFinished()), this, SLOT(updateArcS()));
228  connect(angle, SIGNAL(editingFinished()), this, SLOT(updateArcA()));
229  }
230  else
231  {
232  disconnect(x, SIGNAL(editingFinished()), this, SLOT(updateArcRect()));
233  disconnect(y, SIGNAL(editingFinished()), this, SLOT(updateArcRect()));
234  disconnect(h, SIGNAL(editingFinished()), this, SLOT(updateArcRect()));
235  disconnect(v, SIGNAL(editingFinished()), this, SLOT(updateArcRect()));
236  disconnect(start_angle, SIGNAL(editingFinished()), this, SLOT(updateArcS()));
237  disconnect(angle, SIGNAL(editingFinished()), this, SLOT(updateArcA()));
238  }
239 }
QSpinBox * angle
Definition: arceditor.h:47
The QPropertyUndoCommand class This undo command manage QProperty of a QObject. This undo command can...
bool setPart(CustomElementPart *) override
ArcEditor::setPart Specifie to this editor the part to edit. Note that an editor can accept or refuse...
Definition: arceditor.cpp:87
StyleEditor * style_
Definition: arceditor.h:45
QDoubleSpinBox * h
Definition: arceditor.h:46
ArcEditor(QETElementEditor *, PartArc *=nullptr, QWidget *=nullptr)
Definition: arceditor.cpp:30
void updateArcA()
ArcEditor::updateArcA Update the span angle of the arc according to the edited value.
Definition: arceditor.cpp:156
QDoubleSpinBox * x
Definition: arceditor.h:46
void enableAnimation(bool animate=true)
QPropertyUndoCommand::enableAnimation True to enable animation.
PartArc * part
Definition: arceditor.h:44
void updateForm() override
ArcEditor::updateForm Update the value of the widgets.
Definition: arceditor.cpp:199
QUndoStack & undoStack()
QDoubleSpinBox * v
Definition: arceditor.h:46
QSpinBox * start_angle
Definition: arceditor.h:47
void updateArcS()
ArcEditor::updateArcS Update the start angle of the arc according to the edited value.
Definition: arceditor.cpp:135
void activeConnections(bool)
ArcEditor::activeConnections Enable/disable connection between editor widget and slot editingFinished...
Definition: arceditor.cpp:219
QIcon tr
Definition: qeticons.cpp:204
QVariant property(const char *name) const override
~ArcEditor() override
Destructeur.
Definition: arceditor.cpp:78
virtual ElementScene * elementScene() const
bool m_locked
Definition: arceditor.h:48
void updateArcRect()
ArcEditor::updateArcRect Update the geometrie of the rect that define this arc according the the edit...
Definition: arceditor.cpp:177
The PartArc class This class represents an elliptical arc primitive which may be used to compose the ...
Definition: partarc.h:31
QDoubleSpinBox * y
Definition: arceditor.h:46
CustomElementPart * currentPart() const override
ArcEditor::currentPart.
Definition: arceditor.cpp:127