forked from qt-creator/qt-creator
macOS: Support gestures for going back and forward
in the editor and help viewer, when setting macOS Trackpad preferences to "Swipe between pages: Swipe with Three Fingers". Fixes: QTCREATORBUG-7387 Change-Id: I1c2684f846d72bb98ba6626c3a04f01fb57b8e24 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
@@ -324,6 +324,23 @@ void EditorView::focusInEvent(QFocusEvent *)
|
|||||||
EditorManagerPrivate::setCurrentView(this);
|
EditorManagerPrivate::setCurrentView(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool EditorView::event(QEvent *e)
|
||||||
|
{
|
||||||
|
if (e->type() == QEvent::NativeGesture) {
|
||||||
|
auto ev = static_cast<QNativeGestureEvent *>(e);
|
||||||
|
if (ev->gestureType() == Qt::SwipeNativeGesture) {
|
||||||
|
if (ev->value() > 0 && canGoBack()) { // swipe from right to left == go back
|
||||||
|
goBackInNavigationHistory();
|
||||||
|
return true;
|
||||||
|
} else if (ev->value() <= 0 && canGoForward()) {
|
||||||
|
goForwardInNavigationHistory();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void EditorView::addEditor(IEditor *editor)
|
void EditorView::addEditor(IEditor *editor)
|
||||||
{
|
{
|
||||||
if (m_editors.contains(editor))
|
if (m_editors.contains(editor))
|
||||||
|
@@ -111,6 +111,7 @@ protected:
|
|||||||
void paintEvent(QPaintEvent *) override;
|
void paintEvent(QPaintEvent *) override;
|
||||||
void mousePressEvent(QMouseEvent *e) override;
|
void mousePressEvent(QMouseEvent *e) override;
|
||||||
void focusInEvent(QFocusEvent *) override;
|
void focusInEvent(QFocusEvent *) override;
|
||||||
|
bool event(QEvent *e) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class SplitterOrView; // for setParentSplitterOrView
|
friend class SplitterOrView; // for setParentSplitterOrView
|
||||||
|
@@ -15,9 +15,10 @@
|
|||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
#include <QGuiApplication>
|
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
|
#include <QGuiApplication>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
#include <QNativeGestureEvent>
|
||||||
|
|
||||||
#include <QHelpEngine>
|
#include <QHelpEngine>
|
||||||
|
|
||||||
@@ -189,6 +190,23 @@ void HelpViewer::wheelEvent(QWheelEvent *event)
|
|||||||
QWidget::wheelEvent(event);
|
QWidget::wheelEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool HelpViewer::event(QEvent *e)
|
||||||
|
{
|
||||||
|
if (e->type() == QEvent::NativeGesture) {
|
||||||
|
auto ev = static_cast<QNativeGestureEvent *>(e);
|
||||||
|
if (ev->gestureType() == Qt::SwipeNativeGesture) {
|
||||||
|
if (ev->value() > 0 && isBackwardAvailable()) { // swipe from right to left == go back
|
||||||
|
backward();
|
||||||
|
return true;
|
||||||
|
} else if (ev->value() <= 0 && isForwardAvailable()) {
|
||||||
|
forward();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void HelpViewer::incrementZoom(int steps)
|
void HelpViewer::incrementZoom(int steps)
|
||||||
{
|
{
|
||||||
const int incrementPercentage = 10 * steps; // 10 percent increase by single step
|
const int incrementPercentage = 10 * steps; // 10 percent increase by single step
|
||||||
|
@@ -88,6 +88,7 @@ signals:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void wheelEvent(QWheelEvent *event) override;
|
void wheelEvent(QWheelEvent *event) override;
|
||||||
|
bool event(QEvent *e) override;
|
||||||
|
|
||||||
void slotLoadStarted();
|
void slotLoadStarted();
|
||||||
void slotLoadFinished();
|
void slotLoadFinished();
|
||||||
|
Reference in New Issue
Block a user