[qet] [4257] Replace DVEventAddImage by DiagramEventAddImage.

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


Revision: 4257
Author:   blacksun
Date:     2015-11-12 18:01:08 +0100 (Thu, 12 Nov 2015)
Log Message:
-----------
Replace DVEventAddImage by DiagramEventAddImage.
Use is unchanged.

Modified Paths:
--------------
    trunk/sources/diagramview.cpp
    trunk/sources/qetdiagrameditor.cpp

Added Paths:
-----------
    trunk/sources/diagramevent/diagrameventaddimage.cpp
    trunk/sources/diagramevent/diagrameventaddimage.h

Removed Paths:
-------------
    trunk/sources/dvevent/dveventaddimage.cpp
    trunk/sources/dvevent/dveventaddimage.h

Added: trunk/sources/diagramevent/diagrameventaddimage.cpp
===================================================================
--- trunk/sources/diagramevent/diagrameventaddimage.cpp	                        (rev 0)
+++ trunk/sources/diagramevent/diagrameventaddimage.cpp	2015-11-12 17:01:08 UTC (rev 4257)
@@ -0,0 +1,173 @@
+/*
+        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 "diagrameventaddimage.h"
+#include "diagram.h"
+#include "diagramimageitem.h"
+#include "diagramcommands.h"
+
+/**
+ * @brief DiagramEventAddImage::DiagramEventAddImage
+ * Default constructor
+ * @param diagram : diagram where operate this event
+ */
+DiagramEventAddImage::DiagramEventAddImage(Diagram *diagram) :
+    DiagramEventInterface(diagram),
+    m_image (nullptr),
+    m_is_added (false)
+{
+    openDialog();
+}
+
+/**
+ * @brief DiagramEventAddImage::~DiagramEventAddImage
+ */
+DiagramEventAddImage::~DiagramEventAddImage()
+{
+    if (m_running || m_abort)
+    {
+        if (m_is_added) m_diagram->removeItem(m_image);
+        delete m_image;
+    }
+
+    foreach (QGraphicsView *view, m_diagram->views())
+        view->setContextMenuPolicy((Qt::DefaultContextMenu));
+}
+
+/**
+ * @brief DiagramEventAddImage::mousePressEvent
+ * Action when mouse is pressed
+ * @param event : event of mouse pressed
+ * @return : true if this event is handled, otherwise false
+ */
+bool DiagramEventAddImage::mousePressEvent(QGraphicsSceneMouseEvent *event)
+{
+    if (m_image && event -> button() == Qt::LeftButton)
+    {
+        QPointF pos = event->scenePos();
+        pos.rx() -= m_image->boundingRect().width()/2;
+        pos.ry() -= m_image->boundingRect().height()/2;
+        m_diagram -> undoStack().push (new AddItemCommand<DiagramImageItem *>(m_image, m_diagram, pos));
+
+        foreach (QGraphicsView *view, m_diagram->views())
+            view->setContextMenuPolicy((Qt::DefaultContextMenu));
+
+        m_running = false;
+        emit finish();
+        return true;
+    }
+
+    if (m_image && event -> button() == Qt::RightButton)
+    {
+            m_image -> rotateBy(90);
+            return true;
+    }
+
+    return false;
+}
+
+/**
+ * @brief DiagramEventAddImage::mouseMoveEvent
+ * Action when mouse move
+ * @param event : event of mouse move
+ * @return : true if this event is handled, otherwise false
+ */
+bool DiagramEventAddImage::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
+{
+    if (!m_image || event -> buttons() != Qt::NoButton) return false;
+
+    QPointF pos = event->scenePos();
+
+    if (!m_is_added)
+    {
+        foreach (QGraphicsView *view, m_diagram->views())
+            view->setContextMenuPolicy((Qt::NoContextMenu));
+
+        m_diagram -> addItem(m_image);
+        m_is_added = true;
+    }
+
+    m_image -> setPos(pos - m_image -> boundingRect().center());
+    return true;
+}
+
+/**
+ * @brief DiagramEventAddImage::mouseDoubleClickEvent
+ * This method is only use to overwrite double click.
+ * When double click, image propertie dialog isn't open.
+ * @param event : event of mouse double click.
+ * @return : true if this event is handled, otherwise false
+ */
+bool DiagramEventAddImage::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
+{
+    Q_UNUSED(event);
+    return true;
+}
+
+/**
+ * @brief DiagramEventAddImage::wheelEvent
+ * Action when mouse wheel is rotate
+ * @param event: evet of mouse wheel
+ * @return : true if this event is handled, otherwise false
+ */
+bool DiagramEventAddImage::wheelEvent(QGraphicsSceneWheelEvent *event)
+{
+    if (!m_is_added || !m_image || event -> modifiers() != Qt::CTRL) return false;
+
+    qreal scaling = m_image->scale();
+    event->delta() > 1? scaling += 0.01 : scaling -= 0.01;
+    if (scaling>0.01 && scaling <= 2)
+            m_image->setScale(scaling);
+
+    return true;
+}
+
+/**
+ * @brief DiagramEventAddImage::isNull
+ * @return : true if image can't be loaded, otherwise return false.
+ */
+bool DiagramEventAddImage::isNull() const
+{
+    if (!m_image) return true;
+    return false;
+}
+
+/**
+ * @brief DiagramEventAddImage::openDialog
+ * Open dialog for select the image to add.
+ */
+void DiagramEventAddImage::openDialog()
+{
+    if (m_diagram -> isReadOnly()) return;
+
+        //Open dialog for select image
+    QString pathPictures = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
+    QString fileName = QFileDialog::getOpenFileName(m_diagram->views().isEmpty()? nullptr : m_diagram->views().first(), QObject::tr("Selectionner une image..."), pathPictures, QObject::tr("Image Files (*.png *.jpg *.bmp *.svg)"));
+
+    if (fileName.isEmpty()) return;
+
+    QImage image(fileName);
+    if(image.isNull())
+    {
+            QMessageBox::critical(m_diagram->views().isEmpty()? nullptr : m_diagram->views().first(), QObject::tr("Erreur"), QObject::tr("Impossible de charger l'image."));
+            return;
+    }
+
+    m_image = new DiagramImageItem (QPixmap::fromImage(image));
+    m_running = true;
+}

Added: trunk/sources/diagramevent/diagrameventaddimage.h
===================================================================
--- trunk/sources/diagramevent/diagrameventaddimage.h	                        (rev 0)
+++ trunk/sources/diagramevent/diagrameventaddimage.h	2015-11-12 17:01:08 UTC (rev 4257)
@@ -0,0 +1,51 @@
+/*
+        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 DIAGRAMEVENTADDIMAGE_H
+#define DIAGRAMEVENTADDIMAGE_H
+
+#include "diagrameventinterface.h"
+
+class Diagram;
+class DiagramImageItem;
+
+/**
+ * @brief The DiagramEventAddImage class
+ * This diagram event, handle the adding of an image in a diagram.
+ */
+class DiagramEventAddImage : public DiagramEventInterface
+{
+        Q_OBJECT
+
+        public:
+            DiagramEventAddImage(Diagram *diagram);
+            virtual ~DiagramEventAddImage();
+
+            virtual bool mousePressEvent       (QGraphicsSceneMouseEvent *event);
+            virtual bool mouseMoveEvent        (QGraphicsSceneMouseEvent *event);
+            virtual bool mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event);
+            virtual bool wheelEvent            (QGraphicsSceneWheelEvent *event);
+
+            bool isNull () const;
+    private:
+            void openDialog();
+
+            DiagramImageItem *m_image;
+            bool m_is_added;
+};
+
+#endif // DIAGRAMEVENTADDIMAGE_H

Modified: trunk/sources/diagramview.cpp
===================================================================
--- trunk/sources/diagramview.cpp	2015-11-11 21:17:51 UTC (rev 4256)
+++ trunk/sources/diagramview.cpp	2015-11-12 17:01:08 UTC (rev 4257)
@@ -551,15 +551,13 @@
 {
 	if (m_event_interface && m_event_interface->wheelEvent(e)) return;
 
-	//Zoom and scrolling
-	if ( gestures() ) {
-		if (e -> modifiers() & Qt::ControlModifier)
-			e -> delta() > 0 ? zoomInSlowly() : zoomOutSlowly();
-		else
-			QGraphicsView::wheelEvent(e);
-	} else {
+		//Zoom and scrolling
+	if (gestures() && (e->modifiers() & Qt::ControlModifier))
+		e -> delta() > 0 ? zoomInSlowly() : zoomOutSlowly();
+	else if (e->modifiers() == Qt::NoModifier)
 		e -> delta() > 0 ? zoomIn(): zoomOut();
-	}
+	else
+		QGraphicsView::wheelEvent(e);
 }
 
 

Deleted: trunk/sources/dvevent/dveventaddimage.cpp
===================================================================
--- trunk/sources/dvevent/dveventaddimage.cpp	2015-11-11 21:17:51 UTC (rev 4256)
+++ trunk/sources/dvevent/dveventaddimage.cpp	2015-11-12 17:01:08 UTC (rev 4257)
@@ -1,162 +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 <http://www.gnu.org/licenses/>.
-*/
-#include "diagramimageitem.h"
-#include "diagramcommands.h"
-#include "dveventaddimage.h"
-#include "diagramview.h"
-#include "diagram.h"
-#include <QObject>
-#include <QStandardPaths>
-
-/**
- * @brief DVEventAddImage::DVEventAddImage
- * Defaultconstructor
- * @param dv : diagram view where operate this event
- */
-DVEventAddImage::DVEventAddImage(DiagramView *dv) :
-	DVEventInterface (dv),
-	m_image (nullptr),
-	m_is_added (false)
-{
-	openDialog();
-}
-
-/**
- * @brief DVEventAddImage::~DVEventAddImage
- */
-DVEventAddImage::~DVEventAddImage() {
-	if (m_running || m_abort) {
-		if (m_is_added) m_diagram -> removeItem(m_image);
-		delete m_image;
-	}
-	m_dv -> setContextMenuPolicy(Qt::DefaultContextMenu);
-}
-
-/**
- * @brief DVEventAddImage::mousePressEvent
- * Action when mouse is pressed
- * @param event : event of mouse pressed
- * @return : true if this event is managed, otherwise false
- */
-bool DVEventAddImage::mousePressEvent(QMouseEvent *event)
-{
-	if (m_image && event -> button() == Qt::LeftButton)
-	{
-		QPointF pos = m_dv -> mapToScene(event -> pos());
-		pos.rx() -= m_image->boundingRect().width()/2;
-		pos.ry() -= m_image->boundingRect().height()/2;
-		m_diagram -> undoStack().push (new AddItemCommand<DiagramImageItem *>(m_image, m_diagram, pos));
-		m_dv -> setContextMenuPolicy(Qt::DefaultContextMenu);
-		m_running = false;
-		emit finish();
-		return true;
-	}
-
-	if (m_image && event -> button() == Qt::RightButton) {
-		m_image -> rotateBy(90);
-		return true;
-	}
-
-	return false;
-}
-
-/**
- * @brief DVEventAddImage::mouseMoveEvent
- * Action when mouse move
- * @param event : event of mouse move
- * @return : true if this event is managed, otherwise false
- */
-bool DVEventAddImage::mouseMoveEvent(QMouseEvent *event) {
-	//@m_image isn't loaded, we return true and @m_running return
-	//so the diagram view owner of this DVEevent will delete it.
-	//if (!m_image) return true;
-
-	if (!m_image || event -> buttons() != Qt::NoButton) return false;
-
-	QPointF pos = m_dv -> mapToScene(event -> pos());
-
-	if (!m_is_added) {
-		m_dv -> setContextMenuPolicy(Qt::NoContextMenu);
-		m_diagram -> addItem(m_image);
-		m_is_added = true;
-	}
-	m_image -> setPos(pos - m_image -> boundingRect().center());
-	return true;
-}
-
-/**
- * @brief DVEventAddImage::mouseDoubleClickEvent
- * This methode is only use to overwrite double click.
- * When double clic, image propertie dialog isn't open.
- * @param event : event of mouse double click
- * @return : true if this event is managed, otherwise false
- */
-bool DVEventAddImage::mouseDoubleClickEvent(QMouseEvent *event) {
-	Q_UNUSED(event);
-	return true;
-}
-
-/**
- * @brief DVEventAddImage::wheelEvent
- * Action when mouse wheel is rotate
- * @param event : event of mouse wheel
- * @return : true if this event is managed, otherwise false
- */
-bool DVEventAddImage::wheelEvent(QWheelEvent *event) {
-
-	if (!m_is_added || !m_image || event -> modifiers() != Qt::CTRL) return false;
-
-	qreal scaling = m_image->scale();
-	event->delta() > 1? scaling += 0.01 : scaling -= 0.01;
-	if (scaling>0.01 && scaling <= 2)
-		m_image->setScale(scaling);
-
-	return true;
-}
-
-/**
- * @brief DVEventAddImage::isNull
- * @return true if image can't be loaded, otherwise return false.
- */
-bool DVEventAddImage::isNull() const {
-	if (!m_image) return true;
-	return false;
-}
-
-/**
- * @brief DVEventAddImage::openDialog
- * Open dialog for select the image to add.
- */
-void DVEventAddImage::openDialog() {
-	if (m_diagram -> isReadOnly()) return;
-
-	//Open dialog for select image
-	QString pathPictures = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
-	QString fileName = QFileDialog::getOpenFileName(m_dv, QObject::tr("Selectionner une image..."), pathPictures, QObject::tr("Image Files (*.png *.jpg *.bmp *.svg)"));
-
-	if (fileName.isEmpty()) return;
-
-	QImage image(fileName);
-	if(image.isNull()) {
-		QMessageBox::critical(m_dv, QObject::tr("Erreur"), QObject::tr("Impossible de charger l'image."));
-		return;
-	}
-
-	m_image = new DiagramImageItem (QPixmap::fromImage(image));
-	m_running = true;
-}

Deleted: trunk/sources/dvevent/dveventaddimage.h
===================================================================
--- trunk/sources/dvevent/dveventaddimage.h	2015-11-11 21:17:51 UTC (rev 4256)
+++ trunk/sources/dvevent/dveventaddimage.h	2015-11-12 17:01:08 UTC (rev 4257)
@@ -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 <http://www.gnu.org/licenses/>.
-*/
-#ifndef DVEVENTADDIMAGE_H
-#define DVEVENTADDIMAGE_H
-
-#include "dveventinterface.h"
-
-class DiagramImageItem;
-
-/**
- * @brief The DVEventAddImage class
- * This dv event, open an image and add it to diagram view.
- */
-class DVEventAddImage : public DVEventInterface
-{
-	Q_OBJECT
-
-	public:
-		DVEventAddImage(DiagramView *dv);
-		virtual ~DVEventAddImage();
-
-		virtual bool mousePressEvent       (QMouseEvent *event);
-		virtual bool mouseMoveEvent        (QMouseEvent *event);
-		virtual bool mouseDoubleClickEvent (QMouseEvent *event);
-		virtual bool wheelEvent            (QWheelEvent *event);
-
-		bool isNull () const;
-
-	private:
-		void openDialog();
-
-		DiagramImageItem *m_image;
-		bool m_is_added;
-
-};
-
-#endif // DVEVENTADDIMAGE_H

Modified: trunk/sources/qetdiagrameditor.cpp
===================================================================
--- trunk/sources/qetdiagrameditor.cpp	2015-11-11 21:17:51 UTC (rev 4256)
+++ trunk/sources/qetdiagrameditor.cpp	2015-11-12 17:01:08 UTC (rev 4257)
@@ -35,11 +35,11 @@
 #include "nomenclature.h"
 #include "diagramfoliolist.h"
 #include "qetshapeitem.h"
-#include "dveventaddimage.h"
 #include "dveventaddtext.h"
 #include "reportproperties.h"
 #include "diagrampropertieseditordockwidget.h"
 #include "diagrameventaddshape.h"
+#include "diagrameventaddimage.h"
 
 #include "ui/dialogautonum.h"
 
@@ -1146,18 +1146,6 @@
 
 	if (value == "text")
 		dvevent = new DVEventAddText(dv);
-	else if (value == "image")
-	{
-		DVEventAddImage *event = new DVEventAddImage(dv);
-		if (event -> isNull())
-		{
-			delete event;
-			action->setChecked(false);
-			return;
-		}
-		else
-			dvevent = event;
-	}
 
 	if (dvevent)
 	{
@@ -1179,6 +1167,18 @@
 		diagram_event = new DiagramEventAddShape (d, QetShapeItem::Ellipse);
 	else if (value == "polyline")
 		diagram_event = new DiagramEventAddShape (d, QetShapeItem::Polygon);
+	else if (value == "image")
+	{
+		DiagramEventAddImage *deai = new DiagramEventAddImage(d);
+		if (deai->isNull())
+		{
+			delete deai;
+			action->setChecked(false);
+			return;
+		}
+		else
+			diagram_event = deai;
+	}
 
 	if (diagram_event)
 	{


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