QElectroTech  0.70
imagepropertieswidget.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 "imagepropertieswidget.h"
19 #include "ui_imagepropertieswidget.h"
20 #include "diagramimageitem.h"
21 #include "diagram.h"
23 
31  PropertiesEditorWidget(parent),
32  ui(new Ui::ImagePropertiesWidget),
33  m_image(nullptr)
34 {
35  ui->setupUi(this);
36  this->setDisabled(true);
37  setImageItem(image);
38 }
39 
45  delete ui;
46 }
47 
54 {
55  if(!image) return;
56  this->setEnabled(true);
57  if (m_image == image) return;
58  if (m_image)
59  disconnect(m_image, &QGraphicsObject::scaleChanged, this, &ImagePropertiesWidget::updateUi);
60 
61  m_image = image;
62  connect(m_image, &QGraphicsObject::scaleChanged, this, &ImagePropertiesWidget::updateUi);
63  m_movable = image->isMovable();
64  m_scale = m_image->scale();
65  updateUi();
66 }
67 
73 {
74  if(!m_image) return;
75 
76  if (m_image->diagram())
77  {
78  if (m_live_edit) disconnect(m_image, &QGraphicsObject::scaleChanged, this, &ImagePropertiesWidget::updateUi);
79 
80  QUndoCommand *undo = associatedUndo();
81  if (undo)
82  m_image->diagram()->undoStack().push(undo);
83 
84  if (m_live_edit) connect(m_image, &QGraphicsObject::scaleChanged, this, &ImagePropertiesWidget::updateUi);
85  }
86 
87  m_scale = m_image->scale();
88 }
89 
95 {
96  if(!m_image) return;
97 
98  m_image->setScale(m_scale);
100  updateUi();
101 }
102 
110 {
111  if (m_live_edit == live_edit) return true;
112  m_live_edit = live_edit;
113 
114  if (m_live_edit)
115  {
116  connect (ui->m_scale_slider, &QSlider::sliderReleased, this, &ImagePropertiesWidget::apply);
117  connect (ui->m_scale_sb, &QSpinBox::editingFinished, this, &ImagePropertiesWidget::apply);
118  }
119  else
120  {
121  disconnect (ui->m_scale_slider, &QSlider::sliderReleased, this, &ImagePropertiesWidget::apply);
122  disconnect (ui->m_scale_sb, &QSpinBox::editingFinished, this, &ImagePropertiesWidget::apply);
123  }
124 
125  return true;
126 }
127 
134 {
135 
136  qreal value = ui->m_scale_slider->value();
137  value /= 100;
138  if (m_scale == value) return nullptr;
139  QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_image, "scale", m_scale, value);
140  undo->enableAnimation();
141  undo->setText(tr("Modifier la taille d'une image"));
142  return undo;
143 }
144 
150 {
151  if (!m_image) return;
152  ui->m_scale_slider->setValue(m_image->scale() * 100);
153  ui->m_lock_pos_cb->setChecked(!m_image->isMovable());
154 }
155 
162 {
163  qreal scale = value;
164  m_image->setScale(scale / 100);
165 }
166 
172  m_image->setMovable(!ui->m_lock_pos_cb->isChecked());
173 }
The QPropertyUndoCommand class This undo command manage QProperty of a QObject. This undo command can...
The ImagePropertiesWidget class This class provide a widget to edit the propertie of a DiagramImageIt...
void updateUi() override
ImagePropertiesWidget::updateUi Udpdate the ui, notably when the image to edit change.
Diagram * diagram() const
QetGraphicsItem::diagram return the diagram of this item.
void setImageItem(DiagramImageItem *image)
ImagePropertiesWidget::setImageItem Set the image to edit properties.
void enableAnimation(bool animate=true)
QPropertyUndoCommand::enableAnimation True to enable animation.
The PropertiesEditorWidget class This class extend QWidget method for have common way to edit propert...
void on_m_lock_pos_cb_clicked()
ImagePropertiesWidget::on_m_lock_pos_cb_clicked Set movable or not the image according to correspondi...
QIcon tr
Definition: qeticons.cpp:204
DiagramImageItem * m_image
void reset() override
ImagePropertiesWidget::reset Reset the change.
~ImagePropertiesWidget() override
ImagePropertiesWidget::~ImagePropertiesWidget Destructor.
bool setLiveEdit(bool live_edit) override
ImagePropertiesWidget::setLiveEdit.
virtual bool isMovable() const
QUndoStack & undoStack()
Definition: diagram.h:337
Ui::ImagePropertiesWidget * ui
ImagePropertiesWidget(DiagramImageItem *image=nullptr, QWidget *parent=nullptr)
ImagePropertiesWidget::ImagePropertiesWidget Constructor.
void apply() override
ImagePropertiesWidget::apply Apply the change.
QUndoCommand * associatedUndo() const override
ImagePropertiesWidget::associatedUndo.
void on_m_scale_slider_valueChanged(int value)
ImagePropertiesWidget::on_m_scale_slider_valueChanged Update the size of image when move slider...
virtual void setMovable(bool movable)