[qet] [2153] element editor and diagram view, now can move view by holding wheel click and drag mouse

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


Revision: 2153
Author:   blacksun
Date:     2013-05-11 20:20:26 +0200 (Sat, 11 May 2013)
Log Message:
-----------
element editor and diagram view, now can move view by holding wheel click and drag mouse

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

Modified: trunk/sources/diagramview.cpp
===================================================================
--- trunk/sources/diagramview.cpp	2013-05-10 03:53:46 UTC (rev 2152)
+++ trunk/sources/diagramview.cpp	2013-05-11 18:20:26 UTC (rev 2153)
@@ -409,7 +409,7 @@
 }
 
 /**
-	Manage the events click mouse :
+	Manage the events press click mouse :
 	 *  click to add an independent text field
 */
 void DiagramView::mousePressEvent(QMouseEvent *e) {
@@ -423,21 +423,44 @@
 			is_adding_text = false;
 		}
 	}
-	// Select visualisation or selection mode
+	// workaround for drag view with hold wheel click and drag mouse
+	// see also mouseMoveEvent() and mouseReleaseEvent()
 	if (e -> buttons() == Qt::MidButton) {
-		if (!is_moving_view_) {
-			setVisualisationMode();
-			is_moving_view_ = true;
-		}
-		else{
-			setSelectionMode();
-			is_moving_view_ = false;
-		}
+		setCursor(Qt::ClosedHandCursor);
+		reference_view_ = mapToScene(e -> pos());
+		center_view_ = mapToScene(this -> viewport() -> rect()).boundingRect().center();
+		return;
 	}
 	QGraphicsView::mousePressEvent(e);
 }
 
 /**
+ * @brief DiagramView::mouseMoveEvent
+ * Manage the event move mouse
+ */
+void DiagramView::mouseMoveEvent(QMouseEvent *e) {
+	if ((e -> buttons() & Qt::MidButton) == Qt::MidButton) {
+		QPointF move = reference_view_ - mapToScene(e -> pos());
+		this -> centerOn(center_view_ + move);
+		center_view_ = mapToScene(this -> viewport() -> rect()).boundingRect().center();
+		return;
+	}
+	QGraphicsView::mouseMoveEvent(e);
+}
+
+/**
+ * @brief DiagramView::mouseReleaseEvent
+ * Manage event release click mouse
+ */
+void DiagramView::mouseReleaseEvent(QMouseEvent *e) {
+	if (e -> button() == Qt::MidButton) {
+		setCursor(Qt::ArrowCursor);
+		return;
+	}
+	QGraphicsView::mouseReleaseEvent(e);
+}
+
+/**
 	Manage wheel event of mouse
 	@param e QWheelEvent
 */

Modified: trunk/sources/diagramview.h
===================================================================
--- trunk/sources/diagramview.h	2013-05-10 03:53:46 UTC (rev 2152)
+++ trunk/sources/diagramview.h	2013-05-11 18:20:26 UTC (rev 2153)
@@ -52,6 +52,8 @@
 	bool fresh_focus_in_;               ///< Indicate the focus was freshly gained
 	ElementsLocation next_location_;
 	QPoint next_position_;
+	QPointF reference_view_;
+	QPointF center_view_;
 	
 	// methods
 	public:
@@ -86,6 +88,8 @@
 	
 	private:
 	void mousePressEvent(QMouseEvent *);
+	void mouseMoveEvent(QMouseEvent *);
+	void mouseReleaseEvent(QMouseEvent *);
 	void dragEnterEvent(QDragEnterEvent *);
 	void dragLeaveEvent(QDragLeaveEvent *);
 	void dragMoveEvent(QDragMoveEvent *);

Modified: trunk/sources/editor/elementview.cpp
===================================================================
--- trunk/sources/editor/elementview.cpp	2013-05-10 03:53:46 UTC (rev 2152)
+++ trunk/sources/editor/elementview.cpp	2013-05-11 18:20:26 UTC (rev 2153)
@@ -336,19 +336,41 @@
 void ElementView::mousePressEvent(QMouseEvent *e) {
 	// 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;
-		}
+		setCursor(Qt::ClosedHandCursor);
+		reference_view_ = mapToScene(e -> pos());
+		center_view_ = mapToScene(this -> viewport() -> rect()).boundingRect().center();
+		return;
 	}
 	QGraphicsView::mousePressEvent(e);
 }
 
 /**
+ * @brief ElementView::mouseMoveEvent
+ * Manage the event move mouse
+ */
+void ElementView::mouseMoveEvent(QMouseEvent *e) {
+	if ((e -> buttons() & Qt::MidButton) == Qt::MidButton) {
+		QPointF move = reference_view_ - mapToScene(e -> pos());
+		this -> centerOn(center_view_ + move);
+		center_view_ = mapToScene(this -> viewport() -> rect()).boundingRect().center();
+		return;
+	}
+	QGraphicsView::mouseMoveEvent(e);
+}
+
+/**
+ * @brief ElementView::mouseReleaseEvent
+ * Manage event release click mouse
+ */
+void ElementView::mouseReleaseEvent(QMouseEvent *e) {
+	if (e -> button() == Qt::MidButton) {
+		setCursor(Qt::ArrowCursor);
+		return;
+	}
+	QGraphicsView::mouseReleaseEvent(e);
+}
+
+/**
 	Gere les actions liees a la rollette de la souris
 	@param e QWheelEvent decrivant l'evenement rollette
 */

Modified: trunk/sources/editor/elementview.h
===================================================================
--- trunk/sources/editor/elementview.h	2013-05-10 03:53:46 UTC (rev 2152)
+++ trunk/sources/editor/elementview.h	2013-05-11 18:20:26 UTC (rev 2153)
@@ -43,6 +43,8 @@
 	
 	protected:
 	void mousePressEvent(QMouseEvent *);
+	void mouseMoveEvent(QMouseEvent *);
+	void mouseReleaseEvent(QMouseEvent *);
 	void wheelEvent(QWheelEvent *);
 	virtual void drawBackground(QPainter *, const QRectF &);
 	
@@ -79,6 +81,8 @@
 	QString to_paste_in_area_;
 	int offset_paste_count_;
 	QPointF start_top_left_corner_;
+	QPointF reference_view_;
+	QPointF center_view_;
 	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/