[qet] [2115] Clean wheelEvent in diagramview and add the same system to element Editor

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


Revision: 2115
Author:   cfdev
Date:     2013-04-16 14:00:41 +0200 (Tue, 16 Apr 2013)
Log Message:
-----------
Clean wheelEvent in diagramview and add the same system to element Editor

Modified Paths:
--------------
    trunk/sources/diagramview.cpp
    trunk/sources/editor/elementview.cpp
    trunk/sources/editor/elementview.h

Modified: trunk/sources/diagramview.cpp
===================================================================
--- trunk/sources/diagramview.cpp	2013-04-15 20:44:19 UTC (rev 2114)
+++ trunk/sources/diagramview.cpp	2013-04-16 12:00:41 UTC (rev 2115)
@@ -293,7 +293,7 @@
 }
 
 /**
-	Passe le Diagram en mode visualisation
+	Set the Diagram in visualisation mode
 */
 void DiagramView::setVisualisationMode() {
 	setDragMode(ScrollHandDrag);
@@ -303,7 +303,7 @@
 }
 
 /**
-	Passe le Diagram en mode Selection
+	Set the Diagram in Selection mode
 */
 void DiagramView::setSelectionMode() {
 	setDragMode(RubberBandDrag);
@@ -457,17 +457,6 @@
 			QAbstractScrollArea::wheelEvent(e);
 		}
 	}
-	// Or select visualisation or selection mode
-	else{
-		if (!is_moving_view_) {
-			setVisualisationMode();
-			is_moving_view_ = true;
-		}
-		else{
-			setSelectionMode();
-			is_moving_view_ = false;
-		}
-	}
 }
 
 /**

Modified: trunk/sources/editor/elementview.cpp
===================================================================
--- trunk/sources/editor/elementview.cpp	2013-04-15 20:44:19 UTC (rev 2114)
+++ trunk/sources/editor/elementview.cpp	2013-04-16 12:00:41 UTC (rev 2115)
@@ -75,6 +75,24 @@
 }
 
 /**
+	Set the Diagram in visualisation mode
+*/
+void ElementView::setVisualisationMode() {
+	setDragMode(ScrollHandDrag);
+	setInteractive(false);
+	emit(modeChanged());
+}
+
+/**
+	Set the Diagram in Selection mode
+*/
+void ElementView::setSelectionMode() {
+	setDragMode(RubberBandDrag);
+	setInteractive(true);
+	emit(modeChanged());
+}
+
+/**
 	Agrandit le schema (+33% = inverse des -25 % de zoomMoins())
 */
 void ElementView::zoomIn() {
@@ -316,8 +334,16 @@
 	@param e QMouseEvent decrivant l'evenement souris
 */
 void ElementView::mousePressEvent(QMouseEvent *e) {
-	if (e -> buttons() & Qt::MidButton) {
-		paste(mapToScene(e -> pos()));
+	// Select visualisation or selection mode
+	if (e -> buttons() == Qt::MidButton) {
+		if (!is_moving_view_) {
+			setVisualisationMode();
+			is_moving_view_ = true;
+		}
+		else{
+			setSelectionMode();
+			is_moving_view_ = false;
+		}
 	}
 	QGraphicsView::mousePressEvent(e);
 }
@@ -327,15 +353,19 @@
 	@param e QWheelEvent decrivant l'evenement rollette
 */
 void ElementView::wheelEvent(QWheelEvent *e) {
-	// si la touche Ctrl est enfoncee, on zoome / dezoome
-	if (e -> modifiers() & Qt::ControlModifier) {
-		if (e -> delta() > 0) {
-			zoomIn();
-		} else {
-			zoomOut();
+	//Zoom and scrolling
+	if (e->buttons() != Qt::MidButton) {
+		if (!(e -> modifiers() & Qt::ControlModifier)) {
+			if (e -> delta() > 0){
+				zoomIn();
+			}
+			else{
+				zoomOut();
+			}
 		}
-	} else {
-		QAbstractScrollArea::wheelEvent(e);
+		else {
+			QAbstractScrollArea::wheelEvent(e);
+		}
 	}
 }
 

Modified: trunk/sources/editor/elementview.h
===================================================================
--- trunk/sources/editor/elementview.h	2013-04-15 20:44:19 UTC (rev 2114)
+++ trunk/sources/editor/elementview.h	2013-04-16 12:00:41 UTC (rev 2115)
@@ -50,6 +50,8 @@
 	QRectF applyMovement(const QRectF &, const QET::OrientedMovement &, const QPointF &);
 	
 	public slots:
+	void setVisualisationMode();
+	void setSelectionMode();
 	void zoomIn();
 	void zoomOut();
 	void zoomFit();
@@ -60,6 +62,10 @@
 	void paste();
 	void pasteInArea();
 	
+	signals:
+	/// Signal emitted after the mode changed
+	void modeChanged();
+	
 	private slots:
 	void getPasteArea(const QRectF &);
 	ElementContent pasteAreaDefined(const QRectF &);
@@ -73,5 +79,6 @@
 	QString to_paste_in_area_;
 	int offset_paste_count_;
 	QPointF start_top_left_corner_;
+	bool is_moving_view_;               ///< Indicate whether the visualisation mode has been enabled due to mouse/keyboard interactions
 };
 #endif


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