mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
Image properties widget: enable the use of live edit mode
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4005 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -1,2 +1,3 @@
|
|||||||
ChangeElementInformationCommand = 1
|
ChangeElementInformationCommand = 1
|
||||||
LinkElementCommand = 2
|
LinkElementCommand = 2
|
||||||
|
ItemResizerCommand = 3
|
||||||
|
|||||||
@@ -1054,49 +1054,6 @@ void ChangeSeveralConductorsPropertiesCommand::redo() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @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, qreal &old_, qreal &new_, const QString &text, QUndoCommand *parent):
|
|
||||||
QUndoCommand(parent),
|
|
||||||
m_qgi ( qgi ),
|
|
||||||
old_size ( old_ ),
|
|
||||||
new_size ( new_ ),
|
|
||||||
diagram ( qgi->diagram() ),
|
|
||||||
m_text ( text )
|
|
||||||
{}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief ItemResizerCommand::~ItemResizerCommand
|
|
||||||
*/
|
|
||||||
ItemResizerCommand::~ItemResizerCommand() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief ItemResizerCommand::undo
|
|
||||||
*/
|
|
||||||
void ItemResizerCommand::undo() {
|
|
||||||
diagram -> showMe();
|
|
||||||
m_qgi -> setScale(old_size);
|
|
||||||
QUndoCommand::undo();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief ItemResizerCommand::redo
|
|
||||||
*/
|
|
||||||
void ItemResizerCommand::redo() {
|
|
||||||
diagram -> showMe();
|
|
||||||
if (old_size<new_size) setText(QObject::tr("Agrandire %1 à %2 %").arg(m_text).arg(new_size*100));
|
|
||||||
else setText(QObject::tr("Réduire %1 à %2 %").arg(m_text).arg(new_size*100));
|
|
||||||
m_qgi -> setScale(new_size);
|
|
||||||
QUndoCommand::redo();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ChangeShapeStyleCommand::ChangeShapeStyleCommand Constructor
|
* @brief ChangeShapeStyleCommand::ChangeShapeStyleCommand Constructor
|
||||||
|
|||||||
@@ -510,25 +510,6 @@ class ChangeSeveralConductorsPropertiesCommand : public QUndoCommand {
|
|||||||
bool new_settings_set;
|
bool new_settings_set;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ItemResizerCommand : public QUndoCommand {
|
|
||||||
//constructor and destructor
|
|
||||||
public:
|
|
||||||
ItemResizerCommand (QetGraphicsItem *qgi, qreal &old_, qreal &new_,const QString &text, QUndoCommand *parent = 0);
|
|
||||||
virtual ~ItemResizerCommand();
|
|
||||||
|
|
||||||
//methods
|
|
||||||
public:
|
|
||||||
virtual void undo();
|
|
||||||
virtual void redo();
|
|
||||||
|
|
||||||
//attributes
|
|
||||||
private:
|
|
||||||
QetGraphicsItem *m_qgi;
|
|
||||||
qreal old_size, new_size;
|
|
||||||
Diagram *diagram;
|
|
||||||
QString m_text;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class ChangeShapeStyleCommand : public QUndoCommand {
|
class ChangeShapeStyleCommand : public QUndoCommand {
|
||||||
//constructor and destructor
|
//constructor and destructor
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#include "qetshapeitem.h"
|
#include "qetshapeitem.h"
|
||||||
|
#include "itemresizercommand.h"
|
||||||
#include "diagramcommands.h"
|
#include "diagramcommands.h"
|
||||||
#include "createdxf.h"
|
#include "createdxf.h"
|
||||||
#include "diagram.h"
|
#include "diagram.h"
|
||||||
|
|||||||
@@ -18,8 +18,9 @@
|
|||||||
#include "imagepropertieswidget.h"
|
#include "imagepropertieswidget.h"
|
||||||
#include "ui_imagepropertieswidget.h"
|
#include "ui_imagepropertieswidget.h"
|
||||||
#include "diagramimageitem.h"
|
#include "diagramimageitem.h"
|
||||||
#include "diagramcommands.h"
|
|
||||||
#include <QUndoCommand>
|
#include <QUndoCommand>
|
||||||
|
#include "itemresizercommand.h"
|
||||||
|
#include "diagram.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ImagePropertiesWidget::ImagePropertiesWidget
|
* @brief ImagePropertiesWidget::ImagePropertiesWidget
|
||||||
@@ -56,10 +57,14 @@ void ImagePropertiesWidget::setImageItem(DiagramImageItem *image)
|
|||||||
this->setEnabled(true);
|
this->setEnabled(true);
|
||||||
if (m_image == image) return;
|
if (m_image == image) return;
|
||||||
if (m_image)
|
if (m_image)
|
||||||
|
{
|
||||||
disconnect(m_image, SIGNAL(destroyed()), this, SLOT(imageWasDeleted()));
|
disconnect(m_image, SIGNAL(destroyed()), this, SLOT(imageWasDeleted()));
|
||||||
|
disconnect(m_image, &QGraphicsObject::scaleChanged, this, &ImagePropertiesWidget::updateUi);
|
||||||
|
}
|
||||||
|
|
||||||
m_image = image;
|
m_image = image;
|
||||||
connect(m_image, SIGNAL(destroyed()), this, SLOT(imageWasDeleted()));
|
connect(m_image, SIGNAL(destroyed()), this, SLOT(imageWasDeleted()));
|
||||||
|
connect(m_image, &QGraphicsObject::scaleChanged, this, &ImagePropertiesWidget::updateUi);
|
||||||
m_movable = image->isMovable();
|
m_movable = image->isMovable();
|
||||||
m_scale = m_image->scale();
|
m_scale = m_image->scale();
|
||||||
updateUi();
|
updateUi();
|
||||||
@@ -74,8 +79,14 @@ void ImagePropertiesWidget::apply()
|
|||||||
if(!m_image) return;
|
if(!m_image) return;
|
||||||
|
|
||||||
if (m_image->diagram())
|
if (m_image->diagram())
|
||||||
|
{
|
||||||
|
if (m_live_edit) disconnect(m_image, &QGraphicsObject::scaleChanged, this, &ImagePropertiesWidget::updateUi);
|
||||||
|
|
||||||
m_image->diagram()->undoStack().push(associatedUndo());
|
m_image->diagram()->undoStack().push(associatedUndo());
|
||||||
|
|
||||||
|
if (m_live_edit) connect(m_image, &QGraphicsObject::scaleChanged, this, &ImagePropertiesWidget::updateUi);
|
||||||
|
}
|
||||||
|
|
||||||
m_scale = m_image->scale();
|
m_scale = m_image->scale();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,6 +103,31 @@ void ImagePropertiesWidget::reset()
|
|||||||
updateUi();
|
updateUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ImagePropertiesWidget::setLiveEdit
|
||||||
|
* @param live_edit true -> enable live edit
|
||||||
|
* false -> disable live edit
|
||||||
|
* @return always true
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ImagePropertiesWidget::associatedUndo
|
* @brief ImagePropertiesWidget::associatedUndo
|
||||||
* @return the change in an undo command (ItemResizerCommand)
|
* @return the change in an undo command (ItemResizerCommand)
|
||||||
@@ -109,8 +145,9 @@ QUndoCommand* ImagePropertiesWidget::associatedUndo()
|
|||||||
*/
|
*/
|
||||||
void ImagePropertiesWidget::updateUi()
|
void ImagePropertiesWidget::updateUi()
|
||||||
{
|
{
|
||||||
ui->m_scale_slider->setValue(m_scale * 100);
|
if (!m_image) return;
|
||||||
ui->m_lock_pos_cb->setChecked(!m_movable);
|
ui->m_scale_slider->setValue(m_image->scale() * 100);
|
||||||
|
ui->m_lock_pos_cb->setChecked(!m_image->isMovable());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ class ImagePropertiesWidget : public PropertiesEditorWidget
|
|||||||
|
|
||||||
void apply();
|
void apply();
|
||||||
void reset();
|
void reset();
|
||||||
|
bool setLiveEdit(bool live_edit);
|
||||||
QUndoCommand* associatedUndo();
|
QUndoCommand* associatedUndo();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
97
sources/undocommand/itemresizercommand.cpp
Normal file
97
sources/undocommand/itemresizercommand.cpp
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#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, qreal &old_, 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()) return false;
|
||||||
|
ItemResizerCommand const *undo = static_cast<const ItemResizerCommand *>(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();
|
||||||
|
}
|
||||||
52
sources/undocommand/itemresizercommand.h
Normal file
52
sources/undocommand/itemresizercommand.h
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#ifndef ITEMRESIZERCOMMAND_H
|
||||||
|
#define ITEMRESIZERCOMMAND_H
|
||||||
|
|
||||||
|
#include <QUndoCommand>
|
||||||
|
#include <QPropertyAnimation>
|
||||||
|
|
||||||
|
class QetGraphicsItem;
|
||||||
|
class Diagram;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The ItemResizerCommand class
|
||||||
|
* This Undo command manage the scale of QetGraphicsItem.
|
||||||
|
*/
|
||||||
|
class ItemResizerCommand : public QUndoCommand
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ItemResizerCommand (QetGraphicsItem *qgi, qreal &old_, 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
|
||||||
Reference in New Issue
Block a user