QElectroTech  0.70
rectangleeditor.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 "rectangleeditor.h"
19 #include "ui_rectangleeditor.h"
20 #include "styleeditor.h"
21 #include "partrectangle.h"
23 #include "elementscene.h"
24 #include "qeticons.h"
25 
33  ElementItemEditor(editor, parent),
34  m_part(rect),
35  ui(new Ui::RectangleEditor)
36 {
37  ui->setupUi(this);
38  m_style = new StyleEditor(editor);
39  ui->verticalLayout->insertWidget(0, m_style);
40 }
41 
46  delete ui;
47 }
48 
55 {
56  if (!part)
57  {
58  if (m_part)
59  {
63  disconnect(m_part, &PartRectangle::xChanged, this, &RectangleEditor::updateForm);
64  disconnect(m_part, &PartRectangle::yChanged, this, &RectangleEditor::updateForm);
65  }
66  m_part = nullptr;
67  m_style->setPart(nullptr);
68  return(true);
69  }
70 
71  if (PartRectangle *part_rectangle = dynamic_cast<PartRectangle *>(part))
72  {
73  if (m_part == part_rectangle) {
74  return true;
75  }
76  if (m_part)
77  {
81  disconnect(m_part, &PartRectangle::xChanged, this, &RectangleEditor::updateForm);
82  disconnect(m_part, &PartRectangle::yChanged, this, &RectangleEditor::updateForm);
83  }
84  m_part = part_rectangle;
86  updateForm();
90  connect(m_part, &PartRectangle::xChanged, this, &RectangleEditor::updateForm);
91  connect(m_part, &PartRectangle::yChanged, this, &RectangleEditor::updateForm);
92  return(true);
93  }
94 
95  return(false);
96 }
97 
103  return m_part;
104 }
105 
111  return m_part->mapFromScene(ui->m_x_sb->value(), ui->m_y_sb->value());
112 }
113 
118 {
119  if (!m_part) {
120  return;
121  }
122  activeConnections(false);
123 
124  QRectF rect = m_part->property("rect").toRectF();
125  QPointF p = m_part->mapToScene(rect.topLeft());
126  ui->m_x_sb->setValue(p.x());
127  ui->m_y_sb->setValue(p.y());
128  ui->m_width_sb->setValue(rect.width());
129  ui->m_height_sb->setValue(rect.height());
130  ui->m_rx_sb->setValue(m_part->XRadius());
131  ui->m_rx_sb->setMaximum(rect.width()/2);
132  ui->m_ry_sb->setValue(m_part->YRadius());
133  ui->m_ry_sb->setMaximum(rect.height()/2);
134 
135  activeConnections(true);
136 }
137 
144 {
145  if (m_locked) {
146  return;
147  }
148  m_locked = true;
149 
150  QUndoCommand *undo = new QUndoCommand();
151  undo->setText(tr("Modifier un rectangle"));
152 
153  QRectF rect(editedTopLeft(), QSizeF(ui->m_width_sb->value(), ui->m_height_sb->value()));
154  if (m_part->rect() != rect)
155  {
156  QPropertyUndoCommand *u = new QPropertyUndoCommand(m_part, "rect", m_part->rect(), rect, undo);
157  u->enableAnimation();
158  }
159  if (m_part->XRadius() != ui->m_rx_sb->value())
160  {
161  QPropertyUndoCommand *u = new QPropertyUndoCommand(m_part, "xRadius", m_part->XRadius(), ui->m_rx_sb->value(), undo);
162  u->setAnimated();
163  }
164  if (m_part->YRadius() != ui->m_ry_sb->value())
165  {
166  QPropertyUndoCommand *u = new QPropertyUndoCommand(m_part, "yRadius", m_part->YRadius(), ui->m_ry_sb->value(), undo);
167  u->setAnimated();
168  }
169  elementScene()->undoStack().push(undo);
170 
171  m_locked = false;
172 }
173 
181 {
182  if (active)
183  {
184  connect(ui->m_x_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::editingFinished);
185  connect(ui->m_y_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::editingFinished);
186  connect(ui->m_width_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::editingFinished);
187  connect(ui->m_height_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::editingFinished);
188  connect(ui->m_rx_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::editingFinished);
189  connect(ui->m_ry_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::editingFinished);
190  }
191  else
192  {
193  disconnect(ui->m_x_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::editingFinished);
194  disconnect(ui->m_y_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::editingFinished);
195  disconnect(ui->m_width_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::editingFinished);
196  disconnect(ui->m_height_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::editingFinished);
197  disconnect(ui->m_rx_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::editingFinished);
198  disconnect(ui->m_ry_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::editingFinished);
199  }
200 }
The QPropertyUndoCommand class This undo command manage QProperty of a QObject. This undo command can...
~RectangleEditor()
RectangleEditor::~RectangleEditor.
bool setPart(CustomElementPart *) override
StyleEditor::setPart Set the part to edit by this editor. Note : editor can accept or refuse to edit ...
The RectangleEditor class This class provides a widget to edit rectangles within the element editor...
CustomElementPart * currentPart() const override
RectangleEditor::currentPart.
void XRadiusChanged()
void enableAnimation(bool animate=true)
QPropertyUndoCommand::enableAnimation True to enable animation.
RectangleEditor(QETElementEditor *editor, PartRectangle *rect=nullptr, QWidget *parent=nullptr)
RectangleEditor::RectangleEditor.
qreal XRadius() const
Definition: partrectangle.h:68
PartRectangle * m_part
QPointF editedTopLeft() const
RectangleEditor::topLeft.
QUndoStack & undoStack()
StyleEditor * m_style
void editingFinished()
RectangleEditor::editingFinished Slot called when a editor widget is finish to be edited Update the g...
QIcon tr
Definition: qeticons.cpp:204
void YRadiusChanged()
QVariant property(const char *name) const override
void rectChanged()
virtual ElementScene * elementScene() const
void updateForm() override
RectangleEditor::updateForm.
Ui::RectangleEditor * ui
qreal YRadius() const
Definition: partrectangle.h:70
void setAnimated(bool animate=true, bool first_time=true)
QPropertyUndoCommand::setAnimated.
bool setPart(CustomElementPart *part) override
RectangleEditor::setPart.
void activeConnections(bool active)
RectangleEditor::activeConnections Enable/disable connection between editor widget and slot editingFi...
QRectF rect
PartRectangle::rect.
Definition: partrectangle.h:34