[qet] [4005] Image properties widget: enable the use of live edit mode

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 4005
Author:   blacksun
Date:     2015-06-11 20:03:58 +0200 (Thu, 11 Jun 2015)
Log Message:
-----------
Image properties widget: enable the use of live edit mode

Modified Paths:
--------------
    trunk/dev_doc/ID_of_QUndoCommand.txt
    trunk/sources/diagramcommands.cpp
    trunk/sources/diagramcommands.h
    trunk/sources/qetgraphicsitem/qetshapeitem.cpp
    trunk/sources/ui/imagepropertieswidget.cpp
    trunk/sources/ui/imagepropertieswidget.h

Added Paths:
-----------
    trunk/sources/undocommand/itemresizercommand.cpp
    trunk/sources/undocommand/itemresizercommand.h

Modified: trunk/dev_doc/ID_of_QUndoCommand.txt
===================================================================
--- trunk/dev_doc/ID_of_QUndoCommand.txt	2015-06-11 16:15:38 UTC (rev 4004)
+++ trunk/dev_doc/ID_of_QUndoCommand.txt	2015-06-11 18:03:58 UTC (rev 4005)
@@ -1,2 +1,3 @@
 ChangeElementInformationCommand  = 1
 LinkElementCommand = 2
+ItemResizerCommand = 3

Modified: trunk/sources/diagramcommands.cpp
===================================================================
--- trunk/sources/diagramcommands.cpp	2015-06-11 16:15:38 UTC (rev 4004)
+++ trunk/sources/diagramcommands.cpp	2015-06-11 18:03:58 UTC (rev 4005)
@@ -1054,51 +1054,8 @@
 	}
 }
 
-/**
- * @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
  * @param shape
  * @param old_ old style of shape

Modified: trunk/sources/diagramcommands.h
===================================================================
--- trunk/sources/diagramcommands.h	2015-06-11 16:15:38 UTC (rev 4004)
+++ trunk/sources/diagramcommands.h	2015-06-11 18:03:58 UTC (rev 4005)
@@ -510,26 +510,7 @@
 	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 {
 	//constructor and destructor
 	public:

Modified: trunk/sources/qetgraphicsitem/qetshapeitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/qetshapeitem.cpp	2015-06-11 16:15:38 UTC (rev 4004)
+++ trunk/sources/qetgraphicsitem/qetshapeitem.cpp	2015-06-11 18:03:58 UTC (rev 4005)
@@ -16,6 +16,7 @@
 	along with QElectroTech.  If not, see <http://www.gnu.org/licenses/>.
 */
 #include "qetshapeitem.h"
+#include "itemresizercommand.h"
 #include "diagramcommands.h"
 #include "createdxf.h"
 #include "diagram.h"

Modified: trunk/sources/ui/imagepropertieswidget.cpp
===================================================================
--- trunk/sources/ui/imagepropertieswidget.cpp	2015-06-11 16:15:38 UTC (rev 4004)
+++ trunk/sources/ui/imagepropertieswidget.cpp	2015-06-11 18:03:58 UTC (rev 4005)
@@ -18,8 +18,9 @@
 #include "imagepropertieswidget.h"
 #include "ui_imagepropertieswidget.h"
 #include "diagramimageitem.h"
-#include "diagramcommands.h"
 #include <QUndoCommand>
+#include "itemresizercommand.h"
+#include "diagram.h"
 
 /**
  * @brief ImagePropertiesWidget::ImagePropertiesWidget
@@ -56,10 +57,14 @@
 	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();
 	updateUi();
@@ -74,8 +79,14 @@
 	if(!m_image) return;
 
 	if (m_image->diagram())
+	{
+		if (m_live_edit) disconnect(m_image, &QGraphicsObject::scaleChanged, this, &ImagePropertiesWidget::updateUi);
+
 		m_image->diagram()->undoStack().push(associatedUndo());
 
+		if (m_live_edit) connect(m_image, &QGraphicsObject::scaleChanged, this, &ImagePropertiesWidget::updateUi);
+	}
+
 	m_scale = m_image->scale();
 }
 
@@ -93,6 +104,31 @@
 }
 
 /**
+ * @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
  * @return the change in an undo command (ItemResizerCommand)
  */
@@ -109,8 +145,9 @@
  */
 void ImagePropertiesWidget::updateUi()
 {
-	ui->m_scale_slider->setValue(m_scale * 100);
-	ui->m_lock_pos_cb->setChecked(!m_movable);
+	if (!m_image) return;
+	ui->m_scale_slider->setValue(m_image->scale() * 100);
+	ui->m_lock_pos_cb->setChecked(!m_image->isMovable());
 }
 
 /**
@@ -120,8 +157,8 @@
  */
 void ImagePropertiesWidget::on_m_scale_slider_valueChanged(int value)
 {
-	qreal scale = value;
-	m_image->setScale(scale / 100);
+		qreal scale = value;
+		m_image->setScale(scale / 100);
 }
 
 void ImagePropertiesWidget::imageWasDeleted() {

Modified: trunk/sources/ui/imagepropertieswidget.h
===================================================================
--- trunk/sources/ui/imagepropertieswidget.h	2015-06-11 16:15:38 UTC (rev 4004)
+++ trunk/sources/ui/imagepropertieswidget.h	2015-06-11 18:03:58 UTC (rev 4005)
@@ -42,6 +42,7 @@
 
 		void apply();
 		void reset();
+		bool setLiveEdit(bool live_edit);
 		QUndoCommand* associatedUndo();
 
 	private:

Added: trunk/sources/undocommand/itemresizercommand.cpp
===================================================================
--- trunk/sources/undocommand/itemresizercommand.cpp	                        (rev 0)
+++ trunk/sources/undocommand/itemresizercommand.cpp	2015-06-11 18:03:58 UTC (rev 4005)
@@ -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();
+}

Added: trunk/sources/undocommand/itemresizercommand.h
===================================================================
--- trunk/sources/undocommand/itemresizercommand.h	                        (rev 0)
+++ trunk/sources/undocommand/itemresizercommand.h	2015-06-11 18:03:58 UTC (rev 4005)
@@ -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


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/