[qet] [2106] Set the wheelEvent Like libreCad or Autocad: Onclick select visu mode and drag schema.

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


Revision: 2106
Author:   cfdev
Date:     2013-04-13 14:26:42 +0200 (Sat, 13 Apr 2013)
Log Message:
-----------
Set the wheelEvent Like libreCad or Autocad: Onclick select visu mode and drag schema.

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

Modified: trunk/sources/diagramview.cpp
===================================================================
--- trunk/sources/diagramview.cpp	2013-04-11 15:23:46 UTC (rev 2105)
+++ trunk/sources/diagramview.cpp	2013-04-13 12:26:42 UTC (rev 2106)
@@ -410,10 +410,12 @@
 }
 
 /**
-	Manage the events click mouse :
+	Manage the press events click mouse :
 	 *  click to add an independent text field
 */
 void DiagramView::mousePressEvent(QMouseEvent *e) {
+	// Save the button in flag
+	FlagMouseButtons_ = e->buttons();
 	if (fresh_focus_in_) {
 		switchToVisualisationModeIfNeeded(e);
 		fresh_focus_in_ = false;
@@ -424,34 +426,47 @@
 			is_adding_text = false;
 		}
 	}
+	// Select visualisation
+	if (e->buttons() == Qt::MidButton){
+		if (!is_moving_view_) {
+			setVisualisationMode();
+			is_moving_view_ = true;
+			// And Simulate the left click
+			QGraphicsView::mousePressEvent( new QMouseEvent(QEvent::MouseButtonPress, e->pos(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier) );
+		}
+	}
 	QGraphicsView::mousePressEvent(e);
 }
 
 /**
-	Manage wheel event of mouse
+	Manage the release events click mouse :
+*/
+void DiagramView::mouseReleaseEvent(QMouseEvent *e) {
+	// Selection mode
+	if (FlagMouseButtons_ == Qt::MidButton){
+		if (is_moving_view_) {
+			setSelectionMode();
+			is_moving_view_ = false;
+		}
+	}
+	QGraphicsView::mousePressEvent(e);
+}
+
+/**
+	Manage wheel event of mouse for Zoom and scrolling
 	@param e QWheelEvent
 */
 void DiagramView::wheelEvent(QWheelEvent *e) {
-	//Zoom and scrolling
-	if (e->buttons() != Qt::MidButton) {
-		if (!(e -> modifiers() & Qt::ControlModifier)) {
-			if (e -> delta() > 0)	zoomIn();
-			else					zoomOut();
+	if (!(e -> modifiers() & Qt::ControlModifier)) {
+		if (e -> delta() > 0) {
+			zoomIn();
 		}
 		else {
-			QAbstractScrollArea::wheelEvent(e);
+			zoomOut();
 		}
 	}
-	// Or select visualisation or selection mode
-	else{
-		if (!is_moving_view_) {
-			setVisualisationMode();
-			is_moving_view_ = true;
-		}
-		else{
-			setSelectionMode();
-			is_moving_view_ = false;
-		}
+	else {
+		QAbstractScrollArea::wheelEvent(e);
 	}
 }
 

Modified: trunk/sources/diagramview.h
===================================================================
--- trunk/sources/diagramview.h	2013-04-11 15:23:46 UTC (rev 2105)
+++ trunk/sources/diagramview.h	2013-04-13 12:26:42 UTC (rev 2106)
@@ -52,6 +52,7 @@
 	bool fresh_focus_in_;               ///< Indicate the focus was freshly gained
 	ElementsLocation next_location_;
 	QPoint next_position_;
+	int FlagMouseButtons_;               ///< save the buttons of mouse
 	
 	// methods
 	public:
@@ -86,6 +87,7 @@
 	
 	private:
 	void mousePressEvent(QMouseEvent *);
+	void mouseReleaseEvent(QMouseEvent *);
 	void dragEnterEvent(QDragEnterEvent *);
 	void dragLeaveEvent(QDragLeaveEvent *);
 	void dragMoveEvent(QDragMoveEvent *);


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