diff --git a/sources/ui/imagepropertieswidget.cpp b/sources/ui/imagepropertieswidget.cpp index 0ec0b70b4..ffcab74ca 100644 --- a/sources/ui/imagepropertieswidget.cpp +++ b/sources/ui/imagepropertieswidget.cpp @@ -18,9 +18,8 @@ #include "imagepropertieswidget.h" #include "ui_imagepropertieswidget.h" #include "diagramimageitem.h" -#include -#include "itemresizercommand.h" #include "diagram.h" +#include "QPropertyUndoCommand/qpropertyundocommand.h" /** * @brief ImagePropertiesWidget::ImagePropertiesWidget @@ -57,13 +56,9 @@ void ImagePropertiesWidget::setImageItem(DiagramImageItem *image) this->setEnabled(true); if (m_image == image) return; if (m_image) - { - disconnect(m_image, SIGNAL(destroyed()), this, SLOT(imageWasDeleted())); disconnect(m_image, &QGraphicsObject::scaleChanged, this, &ImagePropertiesWidget::updateUi); - } m_image = image; - connect(m_image, SIGNAL(destroyed()), this, SLOT(imageWasDeleted())); connect(m_image, &QGraphicsObject::scaleChanged, this, &ImagePropertiesWidget::updateUi); m_movable = image->isMovable(); m_scale = m_image->scale(); @@ -82,7 +77,9 @@ void ImagePropertiesWidget::apply() { if (m_live_edit) disconnect(m_image, &QGraphicsObject::scaleChanged, this, &ImagePropertiesWidget::updateUi); - m_image->diagram()->undoStack().push(associatedUndo()); + QUndoCommand *undo = associatedUndo(); + if (undo) + m_image->diagram()->undoStack().push(undo); if (m_live_edit) connect(m_image, &QGraphicsObject::scaleChanged, this, &ImagePropertiesWidget::updateUi); } @@ -130,13 +127,19 @@ bool ImagePropertiesWidget::setLiveEdit(bool live_edit) /** * @brief ImagePropertiesWidget::associatedUndo - * @return the change in an undo command (ItemResizerCommand) + * @return the change in an undo command (ItemResizerCommand). + * If there is no change return nullptr */ QUndoCommand* ImagePropertiesWidget::associatedUndo() { + qreal value = ui->m_scale_slider->value(); value /= 100; - return new ItemResizerCommand(m_image, m_scale, value, tr("une image")); + 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; } /** @@ -161,10 +164,6 @@ void ImagePropertiesWidget::on_m_scale_slider_valueChanged(int value) m_image->setScale(scale / 100); } -void ImagePropertiesWidget::imageWasDeleted() { - m_image = nullptr; -} - /** * @brief ImagePropertiesWidget::on_m_lock_pos_cb_clicked * Set movable or not the image according to corresponding check box diff --git a/sources/ui/imagepropertieswidget.h b/sources/ui/imagepropertieswidget.h index 1ee9ced33..8876cd156 100644 --- a/sources/ui/imagepropertieswidget.h +++ b/sources/ui/imagepropertieswidget.h @@ -18,7 +18,6 @@ #ifndef IMAGEPROPERTIESWIDGET_H #define IMAGEPROPERTIESWIDGET_H -#include #include "PropertiesEditor/propertieseditorwidget.h" class DiagramImageItem; @@ -50,8 +49,6 @@ class ImagePropertiesWidget : public PropertiesEditorWidget private slots: void on_m_scale_slider_valueChanged(int value); - void imageWasDeleted(); - void on_m_lock_pos_cb_clicked(); private: diff --git a/sources/undocommand/itemresizercommand.cpp b/sources/undocommand/itemresizercommand.cpp deleted file mode 100644 index 1724da1a3..000000000 --- a/sources/undocommand/itemresizercommand.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* - Copyright 2006-2015 The QElectroTech Team - 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 . -*/ -#include "itemresizercommand.h" -#include "qetgraphicsitem.h" -#include "diagram.h" - -/** - * @brief ItemResizerCommand::ItemResizerCommand - * Change the size of @qgi - * @param qgi item to resize - * @param old_ old size - * @param new_ new size - * @param text text to display - * @param parent undo parent - */ -ItemResizerCommand::ItemResizerCommand (QetGraphicsItem *qgi, const qreal &old_, const qreal &new_, const QString &text, QUndoCommand *parent): - QUndoCommand(parent), - m_qgi (qgi), - m_old_size (old_), - m_new_size (new_), - m_diagram (qgi->diagram()), - m_text (text), - m_first_redo(true) -{ - m_animation.setTargetObject(m_qgi); - m_animation.setPropertyName("scale"); - m_animation.setStartValue(m_old_size); - m_animation.setEndValue(m_new_size); -} - -/** - * @brief ItemResizerCommand::~ItemResizerCommand - */ -ItemResizerCommand::~ItemResizerCommand() {} - -/** - * @brief ItemResizerCommand::mergeWith - * Try to merge this command with other command - * @param other - * @return true if was merged, else false - */ -bool ItemResizerCommand::mergeWith(const QUndoCommand *other) -{ - if (id() != other->id() || other->childCount()) return false; - ItemResizerCommand const *undo = static_cast(other); - if (m_qgi != undo->m_qgi) return false; - m_new_size = undo->m_new_size; - m_animation.setEndValue(m_new_size); - return true; -} - -/** - * @brief ItemResizerCommand::undo - */ -void ItemResizerCommand::undo() -{ - m_diagram -> showMe(); - m_animation.setDirection(QAnimationGroup::Backward); - m_animation.start(); - QUndoCommand::undo(); -} - -/** - * @brief ItemResizerCommand::redo - */ -void ItemResizerCommand::redo() -{ - m_diagram -> showMe(); - setText(m_old_size < m_new_size ? QObject::tr("Agrandire %1 à %2 %").arg(m_text).arg(m_new_size*100) : - QObject::tr("Réduire %1 à %2 %").arg(m_text).arg(m_new_size*100)); - if(m_first_redo) - { - m_qgi -> setScale(m_new_size); - m_first_redo = false; - } - else - { - m_animation.setDirection(QAnimationGroup::Forward); - m_animation.start(); - } - QUndoCommand::redo(); -} diff --git a/sources/undocommand/itemresizercommand.h b/sources/undocommand/itemresizercommand.h deleted file mode 100644 index 6e9bac338..000000000 --- a/sources/undocommand/itemresizercommand.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - Copyright 2006-2015 The QElectroTech Team - 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 . -*/ -#ifndef ITEMRESIZERCOMMAND_H -#define ITEMRESIZERCOMMAND_H - -#include -#include - -class QetGraphicsItem; -class Diagram; - -/** - * @brief The ItemResizerCommand class - * This Undo command manage the scale of QetGraphicsItem. - */ -class ItemResizerCommand : public QUndoCommand -{ - public: - ItemResizerCommand (QetGraphicsItem *qgi, const qreal &old_, const qreal &new_,const QString &text, QUndoCommand *parent = 0); - virtual ~ItemResizerCommand(); - - public: - virtual int id() const {return 3;} - virtual bool mergeWith(const QUndoCommand *other); - virtual void undo(); - virtual void redo(); - - private: - QetGraphicsItem *m_qgi; - qreal m_old_size, m_new_size; - Diagram *m_diagram; - QString m_text; - QPropertyAnimation m_animation; - bool m_first_redo; -}; - -#endif // ITEMRESIZERCOMMAND_H