QElectroTech  0.70
ellipseeditor.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 "ellipseeditor.h"
19 #include "styleeditor.h"
20 #include "partellipse.h"
22 #include "elementscene.h"
23 
30 EllipseEditor::EllipseEditor(QETElementEditor *editor, PartEllipse *ellipse, QWidget *parent) :
31  ElementItemEditor(editor, parent),
32  part(ellipse),
33  m_locked(false)
34 {
35  style_ = new StyleEditor(editor);
36 
37  x = new QDoubleSpinBox();
38  y = new QDoubleSpinBox();
39  h = new QDoubleSpinBox();
40  v = new QDoubleSpinBox();
41 
42  x->setRange(-5000, 5000);
43  y->setRange(-5000, 5000);
44  h->setRange(-5000, 5000);
45  v->setRange(-5000, 5000);
46 
47  QVBoxLayout *v_layout = new QVBoxLayout(this);
48 
49  QGridLayout *grid = new QGridLayout();
50  grid -> addWidget(new QLabel(tr("Centre : ")), 0, 0);
51  grid -> addWidget(new QLabel("x"), 1, 0, Qt::AlignRight);
52  grid -> addWidget(x, 1, 1);
53  grid -> addWidget(new QLabel("y"), 1, 2);
54  grid -> addWidget(y, 1, 3);
55  grid -> addWidget(new QLabel(tr("Diamètres : ")), 2, 0);
56  grid -> addWidget(new QLabel(tr("horizontal :")), 3, 0);
57  grid -> addWidget(h, 3, 1);
58  grid -> addWidget(new QLabel(tr("vertical :")), 4, 0);
59  grid -> addWidget(v, 4, 1);
60 
61  v_layout -> addWidget(style_);
62  v_layout -> addLayout(grid);
63  v_layout->addStretch();
64 
65  activeConnections(true);
66  updateForm();
67 }
68 
71 }
72 
82 {
83  if (!new_part)
84  {
85  if (part)
87  part = nullptr;
88  style_ -> setPart(nullptr);
89  return(true);
90  }
91  if (PartEllipse *part_ellipse = dynamic_cast<PartEllipse *>(new_part))
92  {
93  if (part == part_ellipse) return true;
94  if (part)
96  part = part_ellipse;
97  style_ -> setPart(part);
98  updateForm();
100  return(true);
101  }
102  return(false);
103 }
104 
109  return(part);
110 }
111 
113 {
114  if (m_locked) return;
115  m_locked = true;
116  QPointF point = part->mapFromScene(x->value() - h->value()/2, y->value() - v->value()/2);
117  QRectF rect(point, QSizeF(h->value(), v->value()));
118 
119  if (rect != part->property("rect"))
120  {
121  QPropertyUndoCommand *undo= new QPropertyUndoCommand(part, "rect", part->property("rect"), rect);
122  undo->setText("Modifier une ellipse");
123  undo->enableAnimation();
124  elementScene()->undoStack().push(undo);
125  }
126 
127  m_locked = false;
128 }
129 
134 {
135  if (!part) return;
136  activeConnections(false);
137  QRectF rect = part->property("rect").toRectF();
138  x->setValue(part->mapToScene(rect.topLeft()).x() + (rect.width()/2));
139  y->setValue(part->mapToScene(rect.topLeft()).y() + (rect.height()/2));
140  h->setValue(rect.width());
141  v->setValue(rect.height());
142  activeConnections(true);
143 }
144 
150 {
151  if (active)
152  {
153  connect(x, SIGNAL(editingFinished()), this, SLOT(editingFinished()));
154  connect(y, SIGNAL(editingFinished()), this, SLOT(editingFinished()));
155  connect(h, SIGNAL(editingFinished()), this, SLOT(editingFinished()));
156  connect(v, SIGNAL(editingFinished()), this, SLOT(editingFinished()));
157  }
158  else
159  {
160  disconnect(x, SIGNAL(editingFinished()), this, SLOT(editingFinished()));
161  disconnect(y, SIGNAL(editingFinished()), this, SLOT(editingFinished()));
162  disconnect(h, SIGNAL(editingFinished()), this, SLOT(editingFinished()));
163  disconnect(v, SIGNAL(editingFinished()), this, SLOT(editingFinished()));
164  }
165 }
The QPropertyUndoCommand class This undo command manage QProperty of a QObject. This undo command can...
void undo() override
annule le coller
void editingFinished()
QDoubleSpinBox * y
Definition: ellipseeditor.h:45
QDoubleSpinBox * v
Definition: ellipseeditor.h:45
bool setPart(CustomElementPart *) override
~EllipseEditor() override
Destructeur.
QUndoStack & undoStack()
PartEllipse * part
Definition: ellipseeditor.h:43
EllipseEditor(QETElementEditor *, PartEllipse *=nullptr, QWidget *=nullptr)
QDoubleSpinBox * h
Definition: ellipseeditor.h:45
QIcon tr
Definition: qeticons.cpp:204
void activeConnections(bool)
CustomElementPart * currentPart() const override
QVariant property(const char *name) const override
QDoubleSpinBox * x
Definition: ellipseeditor.h:45
StyleEditor * style_
Definition: ellipseeditor.h:44
virtual ElementScene * elementScene() const
The PartEllipse class This class represents an ellipse primitive which may be used to compose the dra...
Definition: partellipse.h:30
void updateForm() override