[qet] [4266] Improve the gesture event with a trackpad (better zoom behavior, and add the scroll with two fingers) |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 4266
Author: blacksun
Date: 2015-11-18 10:51:53 +0100 (Wed, 18 Nov 2015)
Log Message:
-----------
Improve the gesture event with a trackpad (better zoom behavior, and add the scroll with two fingers)
Modified Paths:
--------------
trunk/sources/diagramview.cpp
trunk/sources/diagramview.h
trunk/sources/qetdiagrameditor.cpp
Modified: trunk/sources/diagramview.cpp
===================================================================
--- trunk/sources/diagramview.cpp 2015-11-17 14:34:05 UTC (rev 4265)
+++ trunk/sources/diagramview.cpp 2015-11-18 09:51:53 UTC (rev 4266)
@@ -244,7 +244,7 @@
}
/**
- Gere les dragleaveevent
+ Gere les dragleave
@param e le QDragEnterEvent correspondant au drag'n drop sortant
*/
void DiagramView::dragLeaveEvent(QDragLeaveEvent *e) {
@@ -345,54 +345,27 @@
}
/**
- * @brief DiagramView::zoomIn
- * Zoom in the current folio
+ * @brief DiagramView::zoom
+ * Zomm the view.
+ * A zoom_factor > 1 zoom in.
+ * A zoom_factor < 1 zoom out
+ * @param zoom_factor
*/
-void DiagramView::zoomIn() {
- scale(1.15, 1.15);
- adjustGridToZoom();
-}
-
-/**
- * @brief DiagramView::zoomOut
- * Zoom out the current folio.
- * If zoom-out-beyond-of-folio is true in common setting, the zoom out is infinite
- * else zoom out is stopped when the entire folio is visible.
- */
-void DiagramView::zoomOut()
+void DiagramView::zoom(const qreal zoom_factor)
{
- QSettings settings;
- if (settings.value("diagrameditor/zoom-out-beyond-of-folio", false).toBool() ||
- (horizontalScrollBar()->maximum() || verticalScrollBar()->maximum()) )
- scale(0.85, 0.85);
-
+ if (zoom_factor >= 1)
+ scale(zoom_factor, zoom_factor);
+ else
+ {
+ QSettings settings;
+ if (settings.value("diagrameditor/zoom-out-beyond-of-folio", false).toBool() ||
+ (horizontalScrollBar()->maximum() || verticalScrollBar()->maximum()) )
+ scale(zoom_factor, zoom_factor);
+ }
adjustGridToZoom();
}
/**
- * @brief DiagramView::zoomInSlowly
- * Like zoomIn but more slowly
- */
-void DiagramView::zoomInSlowly() {
- scale(1.02, 1.02);
- adjustGridToZoom();
-}
-
-/**
- * @brief DiagramView::zoomOutSlowly
- * Like zoomOut but more slowly
- */
-void DiagramView::zoomOutSlowly()
-{
- QSettings settings;
- if (settings.value("diagrameditor/zoom-out-beyond-of-folio", false).toBool() ||
- (horizontalScrollBar()->maximum() || verticalScrollBar()->maximum()) )
- scale(0.98, 0.98);
-
- 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
@@ -547,38 +520,50 @@
Manage wheel event of mouse
@param e QWheelEvent
*/
-void DiagramView::wheelEvent(QWheelEvent *e)
+void DiagramView::wheelEvent(QWheelEvent *event)
{
- if (m_event_interface && m_event_interface->wheelEvent(e)) return;
+ if (m_event_interface && m_event_interface->wheelEvent(event)) return;
//Zoom and scrolling
- if (gestures() && (e->modifiers() & Qt::ControlModifier))
- e -> delta() > 0 ? zoomInSlowly() : zoomOutSlowly();
- else if (e->modifiers() == Qt::NoModifier)
- e -> delta() > 0 ? zoomIn(): zoomOut();
+ QPoint angle = event->angleDelta();
+
+ if (gestures()) //When gesture mode is enable, we suppose the wheel event are made from a trackpad.
+ {
+ if (event->modifiers() == Qt::ControlModifier) //zoom
+ {
+ qreal value = angle.y();
+ zoom(1 + value/1000);
+ }
+ else //scroll
+ {
+ horizontalScrollBar()->setValue(horizontalScrollBar()->value() - angle.x());
+ verticalScrollBar()->setValue(verticalScrollBar()->value() - angle.y());
+ }
+ }
+ else if (event->modifiers() == Qt::NoModifier) //Else we suppose the wheel event are made from a mouse.
+ {
+ qreal value = angle.y();
+ zoom(1 + value/1000);
+ }
else
- QGraphicsView::wheelEvent(e);
+ QGraphicsView::wheelEvent(event);
}
-
/**
- * Utilise le pincement du trackpad pour zoomer
* @brief DiagramView::gestureEvent
+ * Use the pinch of the trackpad for zoom
* @param event
* @return
*/
-
-
-bool DiagramView::gestureEvent(QGestureEvent *event){
- if (QGesture *gesture = event->gesture(Qt::PinchGesture)) {
+bool DiagramView::gestureEvent(QGestureEvent *event)
+{
+ if (QGesture *gesture = event->gesture(Qt::PinchGesture))
+ {
QPinchGesture *pinch = static_cast<QPinchGesture *>(gesture);
- if (pinch->changeFlags() & QPinchGesture::ScaleFactorChanged){
+ if (pinch->changeFlags() & QPinchGesture::ScaleFactorChanged)
+ {
qreal value = gesture->property("scaleFactor").toReal();
- if (value > 1){
- zoomInSlowly();
- }else{
- zoomOutSlowly();
- }
+ value > 1 ? zoom(1.02) : zoom(0.98);
}
}
return true;
Modified: trunk/sources/diagramview.h
===================================================================
--- trunk/sources/diagramview.h 2015-11-17 14:34:05 UTC (rev 4265)
+++ trunk/sources/diagramview.h 2015-11-18 09:51:53 UTC (rev 4266)
@@ -132,10 +132,7 @@
void rotateTexts();
void setVisualisationMode();
void setSelectionMode();
- void zoomIn();
- void zoomOut();
- void zoomInSlowly();
- void zoomOutSlowly();
+ void zoom(const qreal zoom_factor);
void zoomFit();
void zoomContent();
void zoomReset();
Modified: trunk/sources/qetdiagrameditor.cpp
===================================================================
--- trunk/sources/qetdiagrameditor.cpp 2015-11-17 14:34:05 UTC (rev 4265)
+++ trunk/sources/qetdiagrameditor.cpp 2015-11-18 09:51:53 UTC (rev 4266)
@@ -1098,9 +1098,9 @@
if (!dv || value.isEmpty()) return;
if (value == "zoom_in")
- dv->zoomIn();
+ dv->zoom(1.15);
else if (value == "zoom_out")
- dv->zoomOut();
+ dv->zoom(0.85);
else if (value == "zoom_content")
dv->zoomContent();
else if (value == "zoom_fit")