r23591 by craig - Add in touch pad pinch to zoom

scribus-commit scribus-commit at lists.scribus.net
Sat Apr 11 16:08:55 UTC 2020


Author: craig
Date: Sat Apr 11 16:08:55 2020
New Revision: 23591

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23591
Log:
Add in touch pad pinch to zoom

Modified:
    trunk/Scribus/scribus/scribusview.cpp
    trunk/Scribus/scribus/scribusview.h

Modified: trunk/Scribus/scribus/scribusview.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23591&path=/trunk/Scribus/scribus/scribusview.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusview.cpp	(original)
+++ trunk/Scribus/scribus/scribusview.cpp	Sat Apr 11 16:08:55 2020
@@ -30,10 +30,6 @@
 #include <QCursor>
 #include <QDebug>
 #include <QDrag>
-#include <QDragEnterEvent>
-#include <QDragLeaveEvent>
-#include <QDragMoveEvent>
-#include <QDropEvent>
 #include <QEvent>
 #include <QFile>
 #include <QFileInfo>
@@ -41,19 +37,15 @@
 #include <QFontMetrics>
 #include <QImage>
 #include <QImageReader>
-#include <QLabel>
 #include <QList>
 #include <QMenu>
 #include <QMessageBox>
 #include <QMimeData>
-#include <QMouseEvent>
-#include <QPaintEvent>
 #include <QPixmap>
 #include <QPolygon>
 #include <QStack>
 #include <QStringList>
 #include <QStyleOptionRubberBand>
-#include <QWheelEvent>
 #include <QWidgetAction>
 
 #include <cstdio>
@@ -239,6 +231,16 @@
 	}
 	else
 		QFrame::changeEvent(e);
+}
+
+void ScribusView::nativeGestureEvent(QNativeGestureEvent *e)
+{
+	if (e->gestureType() == Qt::ZoomNativeGesture)
+	{
+		double delta = 1 + e->value();
+		FPoint mp = m_canvas->globalToCanvas(e->globalPos());
+		zoom(mp.x(), mp.y(), m_canvas->scale() * delta, true);
+	}
 }
 
 void ScribusView::iconSetChange()
@@ -2322,9 +2324,9 @@
 	}
 	rememberOldZoomLocation(oldZoomX, oldZoomY);
 
-	double newScale = m_canvas->scale() * (1 + static_cast<double>(m_doc->opToolPrefs().magStep)/100.0);
-	if (static_cast<int>(newScale * 100) > static_cast<int>(100 * static_cast<double>(m_doc->opToolPrefs().magStep) * Prefs->displayPrefs.displayScale / 100))
-		newScale = m_canvas->scale() + static_cast<double>(m_doc->opToolPrefs().magStep) * Prefs->displayPrefs.displayScale / 100;
+	double newScale = m_canvas->scale() * (1 + static_cast<double>(m_doc->opToolPrefs().magStep) / 100.0);
+	if (static_cast<int>(newScale * 100.0) > static_cast<int>(100.0 * static_cast<double>(m_doc->opToolPrefs().magStep) * Prefs->displayPrefs.displayScale / 100.0))
+		newScale = m_canvas->scale() + static_cast<double>(m_doc->opToolPrefs().magStep) * Prefs->displayPrefs.displayScale / 100.0;
 
 	int zoomPointX(m_oldZoomX), zoomPointY(m_oldZoomY);
 	if (!preservePoint)
@@ -2355,10 +2357,10 @@
 	}
 	rememberOldZoomLocation(oldZoomX, oldZoomY);
 
-	double newScale = m_canvas->scale() - static_cast<double>(m_doc->opToolPrefs().magStep) * Prefs->displayPrefs.displayScale/100;
-	if (newScale <= Prefs->displayPrefs.displayScale / 100)
+	double newScale = m_canvas->scale() - static_cast<double>(m_doc->opToolPrefs().magStep) * Prefs->displayPrefs.displayScale / 100.0;
+	if (newScale <= Prefs->displayPrefs.displayScale / 100.0)
 		newScale = m_canvas->scale() / (1 + static_cast<double>(m_doc->opToolPrefs().magStep) / 100.0);
-	if (newScale <= Prefs->displayPrefs.displayScale / 100)
+	if (newScale <= Prefs->displayPrefs.displayScale / 100.0)
 		newScale = m_canvas->scale();
 
 	int zoomPointX(m_oldZoomX), zoomPointY(m_oldZoomY);
@@ -3469,11 +3471,11 @@
 	}
 	if (event->type() == QEvent::KeyPress)
 	{
-		auto* m = dynamic_cast<QKeyEvent*> (event);
+		auto* k = dynamic_cast<QKeyEvent*> (event);
 		if (m_canvasMode->handleKeyEvents())
-			m_canvasMode->keyPressEvent(m);
+			m_canvasMode->keyPressEvent(k);
 		else
-			m_ScMW->keyPressEvent(m);
+			m_ScMW->keyPressEvent(k);
 		return true;
 	}
 	if (event->type() == QEvent::KeyRelease)
@@ -3507,6 +3509,12 @@
 	{
 		auto* d = dynamic_cast<QDropEvent*> (event);
 		contentsDropEvent(d);
+		return true;
+	}
+	if (event->type() == QEvent::NativeGesture)
+	{
+		auto *ng = static_cast<QNativeGestureEvent*>(event);
+		nativeGestureEvent(ng);
 		return true;
 	}
 

Modified: trunk/Scribus/scribus/scribusview.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23591&path=/trunk/Scribus/scribus/scribusview.h
==============================================================================
--- trunk/Scribus/scribus/scribusview.h	(original)
+++ trunk/Scribus/scribus/scribusview.h	Sat Apr 11 16:08:55 2020
@@ -35,6 +35,7 @@
 #include <QLineEdit>
 #include <QMap>
 #include <QMouseEvent>
+#include <QNativeGestureEvent>
 #include <QPaintEvent>
 #include <QPoint>
 #include <QPushButton>
@@ -260,7 +261,7 @@
 	void PasteToPage();
 	void TextToPath();
 
-//for linking frame after draw new frame
+	//for linking frame after draw new frame
 private:
 	PageItem * firstFrame;
 
@@ -295,13 +296,13 @@
 	void dragTimerTimeOut();
 
 public:
-	virtual void wheelEvent ( QWheelEvent *ev );
+	virtual void wheelEvent(QWheelEvent *ev);
 	virtual void changeEvent(QEvent *e);
-
+	void nativeGestureEvent(QNativeGestureEvent *e);
 	void keyPressEvent(QKeyEvent *k);
 	void keyReleaseEvent(QKeyEvent *k);
-	void inputMethodEvent ( QInputMethodEvent * event );
-	QVariant inputMethodQuery ( Qt::InputMethodQuery query ) const ;
+	void inputMethodEvent(QInputMethodEvent * event);
+	QVariant inputMethodQuery(Qt::InputMethodQuery query) const ;
 	
 	inline void registerMousePress(QPoint p);
 	bool mousePressed();




More information about the scribus-commit mailing list