[qet] [3369] DVEvent: press key escape, abort the curent action

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


Revision: 3369
Author:   blacksun
Date:     2014-10-10 20:16:02 +0200 (Fri, 10 Oct 2014)
Log Message:
-----------
DVEvent: press key escape, abort the curent action

Modified Paths:
--------------
    trunk/sources/diagramview.cpp
    trunk/sources/dvevent/dveventaddimage.cpp
    trunk/sources/dvevent/dveventaddshape.cpp
    trunk/sources/dvevent/dveventinterface.cpp
    trunk/sources/dvevent/dveventinterface.h

Modified: trunk/sources/diagramview.cpp
===================================================================
--- trunk/sources/diagramview.cpp	2014-10-10 08:58:44 UTC (rev 3368)
+++ trunk/sources/diagramview.cpp	2014-10-10 18:16:02 UTC (rev 3369)
@@ -609,6 +609,15 @@
 	mode if needed.
 */
 void DiagramView::keyPressEvent(QKeyEvent *e) {
+	if (m_event_interface) {
+		if (m_event_interface -> keyPressEvent(e)) {
+			if (m_event_interface->isFinish()) {
+				emit (itemAdded());
+				delete m_event_interface; m_event_interface = nullptr;
+			}
+			return;
+		}
+	}
 	switchToVisualisationModeIfNeeded(e);
 	QGraphicsView::keyPressEvent(e);
 }
@@ -618,6 +627,15 @@
 	mode if needed.
 */
 void DiagramView::keyReleaseEvent(QKeyEvent *e) {
+	if (m_event_interface) {
+		if (m_event_interface -> KeyReleaseEvent(e)) {
+			if (m_event_interface->isFinish()) {
+				emit (itemAdded());
+				delete m_event_interface; m_event_interface = nullptr;
+			}
+			return;
+		}
+	}
 	switchToSelectionModeIfNeeded(e);
 	QGraphicsView::keyReleaseEvent(e);
 }

Modified: trunk/sources/dvevent/dveventaddimage.cpp
===================================================================
--- trunk/sources/dvevent/dveventaddimage.cpp	2014-10-10 08:58:44 UTC (rev 3368)
+++ trunk/sources/dvevent/dveventaddimage.cpp	2014-10-10 18:16:02 UTC (rev 3369)
@@ -39,7 +39,7 @@
  * @brief DVEventAddImage::~DVEventAddImage
  */
 DVEventAddImage::~DVEventAddImage() {
-	if (m_running) {
+	if (m_running || m_abort) {
 		if (m_is_added) m_diagram -> removeItem(m_image);
 		delete m_image;
 	}

Modified: trunk/sources/dvevent/dveventaddshape.cpp
===================================================================
--- trunk/sources/dvevent/dveventaddshape.cpp	2014-10-10 08:58:44 UTC (rev 3368)
+++ trunk/sources/dvevent/dveventaddshape.cpp	2014-10-10 18:16:02 UTC (rev 3369)
@@ -40,7 +40,7 @@
  * @brief DVEventAddShape::~DVEventAddShape
  */
 DVEventAddShape::~DVEventAddShape() {
-	if (m_running) {
+	if (m_running || m_abort) {
 		m_diagram -> removeItem(m_shape_item);
 		delete m_shape_item;
 	}

Modified: trunk/sources/dvevent/dveventinterface.cpp
===================================================================
--- trunk/sources/dvevent/dveventinterface.cpp	2014-10-10 08:58:44 UTC (rev 3368)
+++ trunk/sources/dvevent/dveventinterface.cpp	2014-10-10 18:16:02 UTC (rev 3369)
@@ -22,7 +22,8 @@
 DVEventInterface::DVEventInterface(DiagramView *dv) :
 	m_dv(dv),
 	m_diagram(dv->diagram()),
-	m_running(false)
+	m_running(false),
+	m_abort(false)
 {
 }
 
@@ -53,6 +54,26 @@
 	return false;
 }
 
+/**
+ * @brief DVEventInterface::keyPressEvent
+ * By default, press escape key abort the curent action
+ * @param event
+ * @return
+ */
+bool DVEventInterface::keyPressEvent(QKeyEvent *event) {
+	if (event->key() == Qt::Key_Escape) {
+		m_running = false;
+		m_abort = true;
+		return true;
+	}
+	return false;
+}
+
+bool DVEventInterface::KeyReleaseEvent(QKeyEvent *event) {
+	Q_UNUSED (event);
+	return false;
+}
+
 bool DVEventInterface::isRunning() const {
 	return m_running;
 }

Modified: trunk/sources/dvevent/dveventinterface.h
===================================================================
--- trunk/sources/dvevent/dveventinterface.h	2014-10-10 08:58:44 UTC (rev 3368)
+++ trunk/sources/dvevent/dveventinterface.h	2014-10-10 18:16:02 UTC (rev 3369)
@@ -20,6 +20,7 @@
 
 class QMouseEvent;
 class QWheelEvent;
+class QKeyEvent;
 class DiagramView;
 class Diagram;
 
@@ -42,6 +43,8 @@
 		virtual bool mouseMoveEvent        (QMouseEvent *event);
 		virtual bool mouseReleaseEvent     (QMouseEvent *event);
 		virtual bool wheelEvent            (QWheelEvent *event);
+		virtual bool keyPressEvent         (QKeyEvent *event);
+		virtual bool KeyReleaseEvent       (QKeyEvent *event);
 		virtual bool isRunning () const;
 		virtual bool isFinish  () const;
 
@@ -49,6 +52,7 @@
 		DiagramView *m_dv;
 		Diagram *m_diagram;
 		bool m_running;
+		bool m_abort;
 };
 
 #endif // DVEVENTINTERFACE_H


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