aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qmldesigner/components/componentcore
diff options
context:
space:
mode:
authorKnud Dollereder <knud.dollereder@qt.io>2020-10-07 13:05:50 +0200
committerKnud Dollereder <knud.dollereder@qt.io>2020-10-12 16:39:04 +0000
commit19f2d3a7a8ed1be36835f5e363796c915dc1207e (patch)
treea456d7f96ed2aa3eea18cbb0ac368c5b4d0773b3 /src/plugins/qmldesigner/components/componentcore
parent4ba6c7988ee877d9cebddd181dfad55c0ecec91a (diff)
Enable touch-pad navigation
For the curve-editor, transition-editor and timeline Renamed ruler-scaling-factor to zoom in order to not confuse it with ruler-scale-factor Change-Id: I099e8e9a1e6092c9abb0a1a935fb8510aa90d5e4 Reviewed-by: Henning Gründl <henning.gruendl@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Diffstat (limited to 'src/plugins/qmldesigner/components/componentcore')
-rw-r--r--src/plugins/qmldesigner/components/componentcore/componentcore.pri2
-rw-r--r--src/plugins/qmldesigner/components/componentcore/navigation2d.cpp91
-rw-r--r--src/plugins/qmldesigner/components/componentcore/navigation2d.h67
3 files changed, 160 insertions, 0 deletions
diff --git a/src/plugins/qmldesigner/components/componentcore/componentcore.pri b/src/plugins/qmldesigner/components/componentcore/componentcore.pri
index 14337508ec..decf24a5a8 100644
--- a/src/plugins/qmldesigner/components/componentcore/componentcore.pri
+++ b/src/plugins/qmldesigner/components/componentcore/componentcore.pri
@@ -14,6 +14,7 @@ SOURCES += modelnodecontextmenu_helper.cpp
SOURCES += selectioncontext.cpp
SOURCES += designeractionmanager.cpp
SOURCES += modelnodeoperations.cpp
+SOURCES += navigation2d.cpp
SOURCES += crumblebar.cpp
SOURCES += qmldesignericonprovider.cpp
SOURCES += zoomaction.cpp
@@ -33,6 +34,7 @@ HEADERS += selectioncontext.h
HEADERS += componentcore_constants.h
HEADERS += designeractionmanager.h
HEADERS += modelnodeoperations.h
+HEADERS += navigation2d.h
HEADERS += actioninterface.h
HEADERS += crumblebar.h
HEADERS += qmldesignericonprovider.h
diff --git a/src/plugins/qmldesigner/components/componentcore/navigation2d.cpp b/src/plugins/qmldesigner/components/componentcore/navigation2d.cpp
new file mode 100644
index 0000000000..94d6b5ad38
--- /dev/null
+++ b/src/plugins/qmldesigner/components/componentcore/navigation2d.cpp
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+#include "navigation2d.h"
+
+#include <QGestureEvent>
+#include <QWheelEvent>
+
+namespace QmlDesigner {
+
+Navigation2dScrollBar::Navigation2dScrollBar(QWidget *parent)
+ : QScrollBar(parent)
+{}
+
+bool Navigation2dScrollBar::postEvent(QEvent *event)
+{
+ if (event->type() == QEvent::Wheel) {
+ wheelEvent(static_cast<QWheelEvent *>(event));
+ return true;
+ }
+ return false;
+}
+
+void Navigation2dScrollBar::wheelEvent(QWheelEvent *event)
+{
+ if (!event->angleDelta().isNull())
+ QScrollBar::wheelEvent(event);
+}
+
+
+Navigation2dFilter::Navigation2dFilter(QWidget *parent, Navigation2dScrollBar *scrollbar)
+ : QObject(parent)
+ , m_scrollbar(scrollbar)
+{
+ if (parent)
+ parent->grabGesture(Qt::PinchGesture);
+}
+
+bool Navigation2dFilter::eventFilter(QObject *, QEvent *event)
+{
+ if (event->type() == QEvent::Gesture)
+ return gestureEvent(static_cast<QGestureEvent *>(event));
+ else if (event->type() == QEvent::Wheel && m_scrollbar)
+ return wheelEvent(static_cast<QWheelEvent *>(event));
+
+ return QObject::event(event);
+}
+
+bool Navigation2dFilter::gestureEvent(QGestureEvent *event)
+{
+ if (QPinchGesture *pinch = static_cast<QPinchGesture *>(event->gesture(Qt::PinchGesture))) {
+ QPinchGesture::ChangeFlags changeFlags = pinch->changeFlags();
+ if (changeFlags & QPinchGesture::ScaleFactorChanged) {
+ emit zoomChanged(-(1.0 - pinch->scaleFactor()), pinch->startCenterPoint());
+ event->accept();
+ return true;
+ }
+ }
+ return false;
+}
+
+bool Navigation2dFilter::wheelEvent(QWheelEvent *event)
+{
+ if (m_scrollbar->postEvent(event))
+ event->ignore();
+
+ return false;
+}
+
+} // End namespace QmlDesigner.
diff --git a/src/plugins/qmldesigner/components/componentcore/navigation2d.h b/src/plugins/qmldesigner/components/componentcore/navigation2d.h
new file mode 100644
index 0000000000..434b59055c
--- /dev/null
+++ b/src/plugins/qmldesigner/components/componentcore/navigation2d.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+#pragma once
+
+#include <QScrollBar>
+
+QT_FORWARD_DECLARE_CLASS(QGestureEvent)
+QT_FORWARD_DECLARE_CLASS(QWheelEvent)
+
+namespace QmlDesigner {
+
+class Navigation2dScrollBar : public QScrollBar
+{
+ Q_OBJECT
+
+public:
+ Navigation2dScrollBar(QWidget *parent = nullptr);
+
+ bool postEvent(QEvent *event);
+
+protected:
+ void wheelEvent(QWheelEvent *event) override;
+};
+
+
+class Navigation2dFilter : public QObject
+{
+ Q_OBJECT
+
+signals:
+ void zoomChanged(double scale, const QPointF &pos);
+
+public:
+ Navigation2dFilter(QWidget *parent = nullptr, Navigation2dScrollBar *scrollbar = nullptr);
+
+protected:
+ bool eventFilter(QObject *obj, QEvent *event) override;
+
+private:
+ bool gestureEvent(QGestureEvent *event);
+ bool wheelEvent(QWheelEvent *event);
+ Navigation2dScrollBar *m_scrollbar = nullptr;
+};
+
+} // namespace QmlDesigner