2015-05-08 17:49:29 +00:00
|
|
|
/*
|
2023-01-01 17:05:57 +01:00
|
|
|
Copyright 2006-2023 The QElectroTech Team
|
2015-05-08 17:49:29 +00:00
|
|
|
This file is part of QElectroTech.
|
|
|
|
|
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
QElectroTech is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include "imagepropertieswidget.h"
|
2020-12-08 19:57:35 +01:00
|
|
|
|
|
|
|
#include "../QPropertyUndoCommand/qpropertyundocommand.h"
|
|
|
|
#include "../diagram.h"
|
2020-12-10 21:19:45 +01:00
|
|
|
#include "../qetgraphicsitem/diagramimageitem.h"
|
2020-12-08 19:57:35 +01:00
|
|
|
#include "../ui_imagepropertieswidget.h"
|
2015-05-08 17:49:29 +00:00
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief ImagePropertiesWidget::ImagePropertiesWidget
|
|
|
|
Constructor
|
|
|
|
@param image : image to edit properties
|
|
|
|
@param parent : parent widget
|
|
|
|
*/
|
2015-05-08 17:49:29 +00:00
|
|
|
ImagePropertiesWidget::ImagePropertiesWidget(DiagramImageItem *image, QWidget *parent) :
|
|
|
|
PropertiesEditorWidget(parent),
|
|
|
|
ui(new Ui::ImagePropertiesWidget),
|
|
|
|
m_image(nullptr)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
this->setDisabled(true);
|
|
|
|
setImageItem(image);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief ImagePropertiesWidget::~ImagePropertiesWidget
|
|
|
|
Destructor
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
ImagePropertiesWidget::~ImagePropertiesWidget()
|
|
|
|
{
|
2015-05-08 17:49:29 +00:00
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief ImagePropertiesWidget::setImageItem
|
|
|
|
Set the image to edit properties
|
|
|
|
@param image : image to edit
|
|
|
|
*/
|
2015-05-08 17:49:29 +00:00
|
|
|
void ImagePropertiesWidget::setImageItem(DiagramImageItem *image)
|
|
|
|
{
|
|
|
|
if(!image) return;
|
|
|
|
this->setEnabled(true);
|
|
|
|
if (m_image == image) return;
|
|
|
|
if (m_image)
|
2015-06-11 18:03:58 +00:00
|
|
|
disconnect(m_image, &QGraphicsObject::scaleChanged, this, &ImagePropertiesWidget::updateUi);
|
2015-05-08 17:49:29 +00:00
|
|
|
|
|
|
|
m_image = image;
|
2015-06-11 18:03:58 +00:00
|
|
|
connect(m_image, &QGraphicsObject::scaleChanged, this, &ImagePropertiesWidget::updateUi);
|
2015-05-08 17:49:29 +00:00
|
|
|
m_movable = image->isMovable();
|
|
|
|
m_scale = m_image->scale();
|
|
|
|
updateUi();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief ImagePropertiesWidget::apply
|
|
|
|
Apply the change
|
|
|
|
*/
|
2015-05-08 17:49:29 +00:00
|
|
|
void ImagePropertiesWidget::apply()
|
|
|
|
{
|
|
|
|
if(!m_image) return;
|
|
|
|
|
|
|
|
if (m_image->diagram())
|
2015-06-11 18:03:58 +00:00
|
|
|
{
|
|
|
|
if (m_live_edit) disconnect(m_image, &QGraphicsObject::scaleChanged, this, &ImagePropertiesWidget::updateUi);
|
|
|
|
|
2015-08-06 17:08:45 +00:00
|
|
|
QUndoCommand *undo = associatedUndo();
|
|
|
|
if (undo)
|
|
|
|
m_image->diagram()->undoStack().push(undo);
|
2015-05-08 17:49:29 +00:00
|
|
|
|
2015-06-11 18:03:58 +00:00
|
|
|
if (m_live_edit) connect(m_image, &QGraphicsObject::scaleChanged, this, &ImagePropertiesWidget::updateUi);
|
|
|
|
}
|
|
|
|
|
2015-05-08 17:49:29 +00:00
|
|
|
m_scale = m_image->scale();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief ImagePropertiesWidget::reset
|
|
|
|
Reset the change
|
|
|
|
*/
|
2015-05-08 17:49:29 +00:00
|
|
|
void ImagePropertiesWidget::reset()
|
|
|
|
{
|
|
|
|
if(!m_image) return;
|
|
|
|
|
|
|
|
m_image->setScale(m_scale);
|
|
|
|
m_image->setMovable(m_movable);
|
|
|
|
updateUi();
|
|
|
|
}
|
|
|
|
|
2015-06-11 18:03:58 +00:00
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief ImagePropertiesWidget::setLiveEdit
|
|
|
|
@param live_edit true -> enable live edit
|
2015-06-11 18:03:58 +00:00
|
|
|
* false -> disable live edit
|
2020-08-16 11:19:36 +02:00
|
|
|
@return always true
|
|
|
|
*/
|
2015-06-11 18:03:58 +00:00
|
|
|
bool ImagePropertiesWidget::setLiveEdit(bool live_edit)
|
|
|
|
{
|
|
|
|
if (m_live_edit == live_edit) return true;
|
|
|
|
m_live_edit = live_edit;
|
|
|
|
|
|
|
|
if (m_live_edit)
|
|
|
|
{
|
|
|
|
connect (ui->m_scale_slider, &QSlider::sliderReleased, this, &ImagePropertiesWidget::apply);
|
|
|
|
connect (ui->m_scale_sb, &QSpinBox::editingFinished, this, &ImagePropertiesWidget::apply);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
disconnect (ui->m_scale_slider, &QSlider::sliderReleased, this, &ImagePropertiesWidget::apply);
|
|
|
|
disconnect (ui->m_scale_sb, &QSpinBox::editingFinished, this, &ImagePropertiesWidget::apply);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-05-08 17:49:29 +00:00
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief ImagePropertiesWidget::associatedUndo
|
|
|
|
@return the change in an undo command (ItemResizerCommand).
|
|
|
|
If there is no change return nullptr
|
|
|
|
*/
|
2018-04-05 18:49:28 +00:00
|
|
|
QUndoCommand* ImagePropertiesWidget::associatedUndo() const
|
2015-05-08 17:49:29 +00:00
|
|
|
{
|
2015-08-06 17:08:45 +00:00
|
|
|
|
2015-05-08 17:49:29 +00:00
|
|
|
qreal value = ui->m_scale_slider->value();
|
|
|
|
value /= 100;
|
2015-08-06 17:08:45 +00:00
|
|
|
if (m_scale == value) return nullptr;
|
|
|
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_image, "scale", m_scale, value);
|
|
|
|
undo->enableAnimation();
|
|
|
|
undo->setText(tr("Modifier la taille d'une image"));
|
|
|
|
return undo;
|
2015-05-08 17:49:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief ImagePropertiesWidget::updateUi
|
|
|
|
Udpdate the ui, notably when the image to edit change
|
|
|
|
*/
|
2015-05-08 17:49:29 +00:00
|
|
|
void ImagePropertiesWidget::updateUi()
|
|
|
|
{
|
2015-06-11 18:03:58 +00:00
|
|
|
if (!m_image) return;
|
|
|
|
ui->m_scale_slider->setValue(m_image->scale() * 100);
|
|
|
|
ui->m_lock_pos_cb->setChecked(!m_image->isMovable());
|
2015-05-08 17:49:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief ImagePropertiesWidget::on_m_scale_slider_valueChanged
|
|
|
|
Update the size of image when move slider.
|
|
|
|
@param value
|
|
|
|
*/
|
2015-05-08 17:49:29 +00:00
|
|
|
void ImagePropertiesWidget::on_m_scale_slider_valueChanged(int value)
|
|
|
|
{
|
2015-06-11 18:03:58 +00:00
|
|
|
qreal scale = value;
|
|
|
|
m_image->setScale(scale / 100);
|
2015-05-08 17:49:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief ImagePropertiesWidget::on_m_lock_pos_cb_clicked
|
|
|
|
Set movable or not the image according to corresponding check box
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
void ImagePropertiesWidget::on_m_lock_pos_cb_clicked()
|
|
|
|
{
|
2015-05-08 17:49:29 +00:00
|
|
|
m_image->setMovable(!ui->m_lock_pos_cb->isChecked());
|
|
|
|
}
|