[qet] [3284] Mac os X add QAbstractScrollArea::wheelEvent(e) only, and gestureEvent, thank Yoann

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


Revision: 3284
Author:   scorpio810
Date:     2014-08-18 20:26:38 +0200 (Mon, 18 Aug 2014)
Log Message:
-----------
Mac os X add QAbstractScrollArea::wheelEvent(e) only, and gestureEvent, thank Yoann

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

Modified: trunk/sources/diagramview.cpp
===================================================================
--- trunk/sources/diagramview.cpp	2014-08-18 17:15:49 UTC (rev 3283)
+++ trunk/sources/diagramview.cpp	2014-08-18 18:26:38 UTC (rev 3284)
@@ -43,13 +43,13 @@
 #include "factory/elementfactory.h"
 #include "diagrampropertiesdialog.h"
 
-
 /**
 	Constructeur
 	@param diagram Schema a afficher ; si diagram vaut 0, un nouveau Diagram est utilise
 	@param parent Le QWidget parent de cette vue de schema
 */
 DiagramView::DiagramView(Diagram *diagram, QWidget *parent) : QGraphicsView(parent), newShapeItem(nullptr){
+	grabGesture(Qt::PinchGesture);
 	setAttribute(Qt::WA_DeleteOnClose, true);
 	setInteractive(true);
 	current_behavior = noAction;
@@ -356,6 +356,26 @@
 }
 
 /**
+	Agrandit le schema avec le trackpad
+*/
+void DiagramView::zoomInSlowly() {
+	scale(1.02, 1.02);
+	adjustGridToZoom();
+}
+
+/**
+	Retrecit le schema avec le trackpad
+*/
+void DiagramView::zoomOutSlowly() {
+	scale(0.98, 0.98);
+	// Interdit le dezoome plus grand que le schéma
+	if ((mapFromScene(0,0).rx() == 0) && (mapFromScene(0,0).ry() == 0)){
+		fitInView(sceneRect(), Qt::KeepAspectRatio);
+	}
+	adjustGridToZoom();
+}
+
+/**
 	Agrandit ou rectrecit le schema de facon a ce que tous les elements du
 	schema soient visibles a l'ecran. S'il n'y a aucun element sur le schema,
 	le zoom est reinitialise
@@ -563,20 +583,53 @@
 void DiagramView::wheelEvent(QWheelEvent *e) {
 	//Zoom and scrolling
 	if (e->buttons() != Qt::MidButton) {
-		if (!(e -> modifiers() & Qt::ControlModifier)) {
-			if (e -> delta() > 0){
-				zoomIn();
+
+#if defined(__APPLE__) && defined(__MACH__)
+			QAbstractScrollArea::wheelEvent(e);
+		#else
+		if (e->buttons() != Qt::MidButton) {
+			if (!(e -> modifiers() & Qt::ControlModifier)) {
+				if (e -> delta() > 0){
+					zoomIn();
+				}
+				else{
+					zoomOut();
+				}
+				}
+				else {
+					QAbstractScrollArea::wheelEvent(e);
+				}
 			}
-			else{
-				zoomOut();
+		}
+		#endif
+}
+
+
+/**
+ * Utilise le pincement du trackpad pour zoomer
+ * @brief DiagramView::gestureEvent
+ * @param event
+ * @return
+ */
+
+
+bool DiagramView::gestureEvent(QGestureEvent *event){
+	if (QGesture *gesture = event->gesture(Qt::PinchGesture)) {
+		QPinchGesture *pinch = static_cast<QPinchGesture *>(gesture);
+		if (pinch->changeFlags() & QPinchGesture::ScaleFactorChanged){
+			qreal value = gesture->property("scaleFactor").toReal();
+			if (value > 1){
+				zoomInSlowly();
+			}else{
+				zoomOutSlowly();
 			}
 		}
-		else {
-			QAbstractScrollArea::wheelEvent(e);
-		}
 	}
+	return true;
 }
 
+
+
 /**
 	Handles "Focus in" events. Reimplemented here to store the fact the focus
 	was freshly acquired again using the mouse. This information is later used
@@ -1044,6 +1097,13 @@
 	@param e Evenement
 */
 bool DiagramView::event(QEvent *e) {
+	// By default touch events are converted to mouse events. So
+	// after this event we will get a mouse event also but we want
+	// to handle touch events as gestures only. So we need this safeguard
+	// to block mouse events that are actually generated from touch.
+	if (e->type() == QEvent::Gesture)
+		return gestureEvent(static_cast<QGestureEvent *>(e));
+
 	// fait en sorte que les raccourcis clavier arrivent prioritairement sur la
 	// vue plutot que de remonter vers les QMenu / QAction
 	if (

Modified: trunk/sources/diagramview.h
===================================================================
--- trunk/sources/diagramview.h	2014-08-18 17:15:49 UTC (rev 3283)
+++ trunk/sources/diagramview.h	2014-08-18 18:26:38 UTC (rev 3284)
@@ -121,6 +121,7 @@
 	void handleElementDrop(QDropEvent *);
 	void handleTitleBlockDrop(QDropEvent *);
 	void handleTextDrop(QDropEvent *);
+	bool gestureEvent(QGestureEvent *event);
 	QRectF viewedSceneRect() const;
 	bool mustIntegrateElement(const ElementsLocation &) const;
 	bool mustIntegrateTitleBlockTemplate(const TitleBlockTemplateLocation &) const;
@@ -161,6 +162,8 @@
 	void setSelectionMode();
 	void zoomIn();
 	void zoomOut();
+	void zoomInSlowly();
+	void zoomOutSlowly();
 	void zoomFit();
 	void zoomContent();
 	void zoomReset();


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