forked from qt-creator/qt-creator
Improve 2d view navigation
- Get rid of lag when two-finger-swiping - Enable one finger swipe and scroll gestures for the magic mouse - Fixed a bug where the toolbar zoom slider from the transition.- and timeline editor where not updated when zooming with a gesture. - When scrolling the curve editor, its toolbar was scrolling together with the rest of the view. This is now fixed in order to be consistent with the timeline view and transition editor. Change-Id: I611015af134976588fbcada0bc5ccfdcf8039c27 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -134,7 +134,6 @@ extend_qtc_plugin(QmlDesigner
|
|||||||
modelnodeoperations.cpp modelnodeoperations.h
|
modelnodeoperations.cpp modelnodeoperations.h
|
||||||
formatoperation.cpp formatoperation.h
|
formatoperation.cpp formatoperation.h
|
||||||
navigation2d.cpp navigation2d.h
|
navigation2d.cpp navigation2d.h
|
||||||
gestures.cpp gestures.h
|
|
||||||
qmldesignericonprovider.cpp qmldesignericonprovider.h
|
qmldesignericonprovider.cpp qmldesignericonprovider.h
|
||||||
selectioncontext.cpp selectioncontext.h
|
selectioncontext.cpp selectioncontext.h
|
||||||
theme.cpp theme.h
|
theme.cpp theme.h
|
||||||
|
@@ -5,7 +5,6 @@ SOURCES += addimagesdialog.cpp
|
|||||||
SOURCES += changestyleaction.cpp
|
SOURCES += changestyleaction.cpp
|
||||||
SOURCES += theme.cpp
|
SOURCES += theme.cpp
|
||||||
SOURCES += findimplementation.cpp
|
SOURCES += findimplementation.cpp
|
||||||
SOURCES += gestures.cpp
|
|
||||||
SOURCES += addsignalhandlerdialog.cpp
|
SOURCES += addsignalhandlerdialog.cpp
|
||||||
SOURCES += layoutingridlayout.cpp
|
SOURCES += layoutingridlayout.cpp
|
||||||
SOURCES += abstractactiongroup.cpp
|
SOURCES += abstractactiongroup.cpp
|
||||||
@@ -27,7 +26,6 @@ HEADERS += addimagesdialog.h
|
|||||||
HEADERS += changestyleaction.h
|
HEADERS += changestyleaction.h
|
||||||
HEADERS += theme.h
|
HEADERS += theme.h
|
||||||
HEADERS += findimplementation.h
|
HEADERS += findimplementation.h
|
||||||
HEADERS += gestures.h
|
|
||||||
HEADERS += addsignalhandlerdialog.h
|
HEADERS += addsignalhandlerdialog.h
|
||||||
HEADERS += layoutingridlayout.h
|
HEADERS += layoutingridlayout.h
|
||||||
HEADERS += abstractactiongroup.h
|
HEADERS += abstractactiongroup.h
|
||||||
|
@@ -1,156 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2020 The Qt Company Ltd.
|
|
||||||
** Contact: https://www.qt.io/licensing/
|
|
||||||
**
|
|
||||||
** This file is part of the Qt Design Tooling
|
|
||||||
**
|
|
||||||
** 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 "gestures.h"
|
|
||||||
|
|
||||||
#include <QWidget>
|
|
||||||
|
|
||||||
namespace QmlDesigner {
|
|
||||||
|
|
||||||
Qt::GestureType TwoFingerSwipe::m_type = static_cast<Qt::GestureType>(0);
|
|
||||||
|
|
||||||
TwoFingerSwipe::TwoFingerSwipe() {}
|
|
||||||
|
|
||||||
Qt::GestureType TwoFingerSwipe::type()
|
|
||||||
{
|
|
||||||
return m_type;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TwoFingerSwipe::registerRecognizer()
|
|
||||||
{
|
|
||||||
m_type = QGestureRecognizer::registerRecognizer(new TwoFingerSwipeRecognizer());
|
|
||||||
}
|
|
||||||
|
|
||||||
QPointF TwoFingerSwipe::direction() const
|
|
||||||
{
|
|
||||||
return m_current.center() - m_last.center();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TwoFingerSwipe::reset()
|
|
||||||
{
|
|
||||||
m_start = QLineF();
|
|
||||||
m_current = QLineF();
|
|
||||||
m_last = QLineF();
|
|
||||||
}
|
|
||||||
|
|
||||||
QGestureRecognizer::Result TwoFingerSwipe::begin(QTouchEvent *event)
|
|
||||||
{
|
|
||||||
Q_UNUSED(event);
|
|
||||||
return QGestureRecognizer::MayBeGesture;
|
|
||||||
}
|
|
||||||
|
|
||||||
QGestureRecognizer::Result TwoFingerSwipe::update(QTouchEvent *event)
|
|
||||||
{
|
|
||||||
if (event->touchPoints().size() != 2) {
|
|
||||||
if (state() == Qt::NoGesture)
|
|
||||||
return QGestureRecognizer::Ignore;
|
|
||||||
else
|
|
||||||
return QGestureRecognizer::FinishGesture;
|
|
||||||
}
|
|
||||||
|
|
||||||
QTouchEvent::TouchPoint p0 = event->touchPoints().at(0);
|
|
||||||
QTouchEvent::TouchPoint p1 = event->touchPoints().at(1);
|
|
||||||
|
|
||||||
QLineF line(p0.scenePos(), p1.screenPos());
|
|
||||||
|
|
||||||
if (m_start.isNull()) {
|
|
||||||
m_start = line;
|
|
||||||
m_current = line;
|
|
||||||
m_last = line;
|
|
||||||
} else {
|
|
||||||
auto deltaLength = line.length() - m_current.length();
|
|
||||||
auto deltaCenter = QLineF(line.center(), m_current.center()).length();
|
|
||||||
if (deltaLength > deltaCenter)
|
|
||||||
return QGestureRecognizer::CancelGesture;
|
|
||||||
|
|
||||||
m_last = m_current;
|
|
||||||
m_current = line;
|
|
||||||
}
|
|
||||||
|
|
||||||
setHotSpot(m_current.center());
|
|
||||||
|
|
||||||
return QGestureRecognizer::TriggerGesture;
|
|
||||||
}
|
|
||||||
|
|
||||||
QGestureRecognizer::Result TwoFingerSwipe::end(QTouchEvent *event)
|
|
||||||
{
|
|
||||||
Q_UNUSED(event);
|
|
||||||
bool finish = state() != Qt::NoGesture;
|
|
||||||
|
|
||||||
reset();
|
|
||||||
|
|
||||||
if (finish)
|
|
||||||
return QGestureRecognizer::FinishGesture;
|
|
||||||
else
|
|
||||||
return QGestureRecognizer::CancelGesture;
|
|
||||||
}
|
|
||||||
|
|
||||||
TwoFingerSwipeRecognizer::TwoFingerSwipeRecognizer()
|
|
||||||
: QGestureRecognizer()
|
|
||||||
{}
|
|
||||||
|
|
||||||
QGesture *TwoFingerSwipeRecognizer::create(QObject *target)
|
|
||||||
{
|
|
||||||
if (target && target->isWidgetType())
|
|
||||||
qobject_cast<QWidget *>(target)->setAttribute(Qt::WA_AcceptTouchEvents);
|
|
||||||
|
|
||||||
return new TwoFingerSwipe;
|
|
||||||
}
|
|
||||||
|
|
||||||
QGestureRecognizer::Result TwoFingerSwipeRecognizer::recognize(QGesture *gesture,
|
|
||||||
QObject *,
|
|
||||||
QEvent *event)
|
|
||||||
{
|
|
||||||
if (gesture->gestureType() != TwoFingerSwipe::type())
|
|
||||||
return QGestureRecognizer::Ignore;
|
|
||||||
|
|
||||||
TwoFingerSwipe *swipe = static_cast<TwoFingerSwipe *>(gesture);
|
|
||||||
QTouchEvent *touch = static_cast<QTouchEvent *>(event);
|
|
||||||
|
|
||||||
switch (event->type()) {
|
|
||||||
case QEvent::TouchBegin:
|
|
||||||
return swipe->begin(touch);
|
|
||||||
|
|
||||||
case QEvent::TouchUpdate:
|
|
||||||
return swipe->update(touch);
|
|
||||||
|
|
||||||
case QEvent::TouchEnd:
|
|
||||||
return swipe->end(touch);
|
|
||||||
|
|
||||||
default:
|
|
||||||
return QGestureRecognizer::Ignore;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TwoFingerSwipeRecognizer::reset(QGesture *gesture)
|
|
||||||
{
|
|
||||||
if (gesture->gestureType() == TwoFingerSwipe::type()) {
|
|
||||||
TwoFingerSwipe *swipe = static_cast<TwoFingerSwipe *>(gesture);
|
|
||||||
swipe->reset();
|
|
||||||
}
|
|
||||||
QGestureRecognizer::reset(gesture);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // End namespace QmlDesigner.
|
|
@@ -1,72 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2020 The Qt Company Ltd.
|
|
||||||
** Contact: https://www.qt.io/licensing/
|
|
||||||
**
|
|
||||||
** This file is part of the Qt Design Tooling
|
|
||||||
**
|
|
||||||
** 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 <QGesture>
|
|
||||||
#include <QGestureRecognizer>
|
|
||||||
#include <QLineF>
|
|
||||||
|
|
||||||
QT_FORWARD_DECLARE_CLASS(QTouchEvent)
|
|
||||||
|
|
||||||
namespace QmlDesigner {
|
|
||||||
|
|
||||||
class TwoFingerSwipe : public QGesture
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
TwoFingerSwipe();
|
|
||||||
|
|
||||||
static Qt::GestureType type();
|
|
||||||
static void registerRecognizer();
|
|
||||||
|
|
||||||
QPointF direction() const;
|
|
||||||
|
|
||||||
void reset();
|
|
||||||
QGestureRecognizer::Result begin(QTouchEvent *event);
|
|
||||||
QGestureRecognizer::Result update(QTouchEvent *event);
|
|
||||||
QGestureRecognizer::Result end(QTouchEvent *event);
|
|
||||||
|
|
||||||
private:
|
|
||||||
static Qt::GestureType m_type;
|
|
||||||
|
|
||||||
QLineF m_start;
|
|
||||||
QLineF m_current;
|
|
||||||
QLineF m_last;
|
|
||||||
};
|
|
||||||
|
|
||||||
class TwoFingerSwipeRecognizer : public QGestureRecognizer
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
TwoFingerSwipeRecognizer();
|
|
||||||
|
|
||||||
QGesture *create(QObject *target) override;
|
|
||||||
|
|
||||||
QGestureRecognizer::Result recognize(QGesture *gesture, QObject *watched, QEvent *event) override;
|
|
||||||
|
|
||||||
void reset(QGesture *gesture) override;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace QmlDesigner
|
|
@@ -23,44 +23,38 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include "navigation2d.h"
|
#include "navigation2d.h"
|
||||||
#include "gestures.h"
|
|
||||||
|
|
||||||
#include <QGestureEvent>
|
#include <QGestureEvent>
|
||||||
|
#include <QScrollBar>
|
||||||
#include <QWheelEvent>
|
#include <QWheelEvent>
|
||||||
|
#include <QMetaMethod>
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
Navigation2dScrollBar::Navigation2dScrollBar(QWidget *parent)
|
void Navigation2dFilter::scroll(const QPointF &direction, QScrollBar *sbx, QScrollBar *sby)
|
||||||
: QScrollBar(parent)
|
|
||||||
{}
|
|
||||||
|
|
||||||
bool Navigation2dScrollBar::postEvent(QEvent *event)
|
|
||||||
{
|
{
|
||||||
if (event->type() == QEvent::Wheel) {
|
auto doScroll = [](QScrollBar *sb, float distance) {
|
||||||
wheelEvent(static_cast<QWheelEvent *>(event));
|
if (sb) {
|
||||||
return true;
|
// max - min + pageStep = sceneRect.size * scale
|
||||||
}
|
float d1 = sb->maximum() - sb->minimum();
|
||||||
return false;
|
float d2 = d1 + sb->pageStep();
|
||||||
|
|
||||||
|
float val = (distance / d2) * d1;
|
||||||
|
sb->setValue(sb->value() - val);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
doScroll(sbx, direction.x());
|
||||||
|
doScroll(sby, direction.y());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Navigation2dScrollBar::wheelEvent(QWheelEvent *event)
|
Navigation2dFilter::Navigation2dFilter(QWidget *parent)
|
||||||
{
|
|
||||||
if (!event->angleDelta().isNull())
|
|
||||||
QScrollBar::wheelEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Navigation2dFilter::Navigation2dFilter(QWidget *parent, Navigation2dScrollBar *scrollbar)
|
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, m_scrollbar(scrollbar)
|
|
||||||
{
|
{
|
||||||
if (parent) {
|
if (parent)
|
||||||
parent->grabGesture(Qt::PinchGesture);
|
parent->grabGesture(Qt::PinchGesture);
|
||||||
if (!scrollbar)
|
|
||||||
parent->grabGesture(TwoFingerSwipe::type());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Navigation2dFilter::eventFilter(QObject *object, QEvent *event)
|
bool Navigation2dFilter::eventFilter(QObject *object, QEvent *event)
|
||||||
@@ -82,34 +76,39 @@ bool Navigation2dFilter::gestureEvent(QGestureEvent *event)
|
|||||||
event->accept();
|
event->accept();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (TwoFingerSwipe *swipe = static_cast<TwoFingerSwipe *>(
|
|
||||||
event->gesture(TwoFingerSwipe::type()))) {
|
|
||||||
emit panChanged(swipe->direction());
|
|
||||||
event->accept();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Navigation2dFilter::wheelEvent(QWheelEvent *event)
|
bool Navigation2dFilter::wheelEvent(QWheelEvent *event)
|
||||||
{
|
{
|
||||||
if (m_scrollbar) {
|
if (event->source() == Qt::MouseEventSynthesizedBySystem) {
|
||||||
if (m_scrollbar->postEvent(event))
|
emit panChanged(QPointF(event->pixelDelta()));
|
||||||
event->ignore();
|
event->accept();
|
||||||
|
return true;
|
||||||
} else if (event->source() == Qt::MouseEventNotSynthesized) {
|
} else if (event->source() == Qt::MouseEventNotSynthesized) {
|
||||||
if (event->modifiers().testFlag(Qt::ControlModifier)) {
|
|
||||||
if (QPointF angle = event->angleDelta(); !angle.isNull()) {
|
auto zoomInSignal = QMetaMethod::fromSignal(&Navigation2dFilter::zoomIn);
|
||||||
double delta = std::abs(angle.x()) > std::abs(angle.y()) ? angle.x() : angle.y();
|
bool zoomInConnected = QObject::isSignalConnected(zoomInSignal);
|
||||||
if (delta > 0)
|
|
||||||
emit zoomIn();
|
auto zoomOutSignal = QMetaMethod::fromSignal(&Navigation2dFilter::zoomOut);
|
||||||
else
|
bool zoomOutConnected = QObject::isSignalConnected(zoomOutSignal);
|
||||||
emit zoomOut();
|
|
||||||
event->accept();
|
if (zoomInConnected && zoomOutConnected) {
|
||||||
return true;
|
if (event->modifiers().testFlag(Qt::ControlModifier)) {
|
||||||
|
if (QPointF angle = event->angleDelta(); !angle.isNull()) {
|
||||||
|
double delta = std::abs(angle.x()) > std::abs(angle.y()) ? angle.x() : angle.y();
|
||||||
|
if (delta > 0)
|
||||||
|
emit zoomIn();
|
||||||
|
else
|
||||||
|
emit zoomOut();
|
||||||
|
event->accept();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // End namespace QmlDesigner.
|
} // End namespace QmlDesigner.
|
||||||
|
@@ -24,27 +24,14 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QScrollBar>
|
#include <QObject>
|
||||||
|
|
||||||
QT_FORWARD_DECLARE_CLASS(QGestureEvent)
|
QT_FORWARD_DECLARE_CLASS(QGestureEvent)
|
||||||
|
QT_FORWARD_DECLARE_CLASS(QScrollBar)
|
||||||
QT_FORWARD_DECLARE_CLASS(QWheelEvent)
|
QT_FORWARD_DECLARE_CLASS(QWheelEvent)
|
||||||
|
|
||||||
namespace QmlDesigner {
|
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
|
class Navigation2dFilter : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -57,7 +44,9 @@ signals:
|
|||||||
void zoomOut();
|
void zoomOut();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Navigation2dFilter(QWidget *parent = nullptr, Navigation2dScrollBar *scrollbar = nullptr);
|
static void scroll(const QPointF &direction, QScrollBar *sbx, QScrollBar *sby);
|
||||||
|
|
||||||
|
Navigation2dFilter(QWidget *parent);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||||
@@ -65,7 +54,6 @@ protected:
|
|||||||
private:
|
private:
|
||||||
bool gestureEvent(QGestureEvent *event);
|
bool gestureEvent(QGestureEvent *event);
|
||||||
bool wheelEvent(QWheelEvent *event);
|
bool wheelEvent(QWheelEvent *event);
|
||||||
Navigation2dScrollBar *m_scrollbar = nullptr;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
@@ -32,6 +32,7 @@
|
|||||||
#include <QDoubleSpinBox>
|
#include <QDoubleSpinBox>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
#include <QScrollArea>
|
||||||
#include <QSplitter>
|
#include <QSplitter>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
@@ -40,16 +41,20 @@ namespace QmlDesigner {
|
|||||||
CurveEditor::CurveEditor(CurveEditorModel *model, QWidget *parent)
|
CurveEditor::CurveEditor(CurveEditorModel *model, QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
, m_tree(new TreeView(model, this))
|
, m_tree(new TreeView(model, this))
|
||||||
, m_view(new GraphicsView(model))
|
, m_view(new GraphicsView(model, this))
|
||||||
{
|
{
|
||||||
auto *splitter = new QSplitter;
|
auto *splitter = new QSplitter;
|
||||||
splitter->addWidget(m_tree);
|
splitter->addWidget(m_tree);
|
||||||
splitter->addWidget(m_view);
|
splitter->addWidget(m_view);
|
||||||
splitter->setStretchFactor(1, 2);
|
splitter->setStretchFactor(1, 2);
|
||||||
|
|
||||||
|
QScrollArea* area = new QScrollArea;
|
||||||
|
area->setWidget(splitter);
|
||||||
|
area->setWidgetResizable(true);
|
||||||
|
|
||||||
auto *box = new QVBoxLayout;
|
auto *box = new QVBoxLayout;
|
||||||
box->addWidget(createToolBar(model));
|
box->addWidget(createToolBar(model));
|
||||||
box->addWidget(splitter);
|
box->addWidget(area);
|
||||||
setLayout(box);
|
setLayout(box);
|
||||||
|
|
||||||
connect(m_tree, &TreeView::treeItemLocked, model, &CurveEditorModel::setLocked);
|
connect(m_tree, &TreeView::treeItemLocked, model, &CurveEditorModel::setLocked);
|
||||||
|
@@ -45,6 +45,18 @@
|
|||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
|
template< typename T >
|
||||||
|
T* nextParentOfType(QWidget* widget)
|
||||||
|
{
|
||||||
|
auto* p = widget->parent();
|
||||||
|
while (p) {
|
||||||
|
if (T* w = qobject_cast<T*>(p))
|
||||||
|
return w;
|
||||||
|
p = p->parent();
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
GraphicsView::GraphicsView(CurveEditorModel *model, QWidget *parent)
|
GraphicsView::GraphicsView(CurveEditorModel *model, QWidget *parent)
|
||||||
: QGraphicsView(parent)
|
: QGraphicsView(parent)
|
||||||
, m_dragging(false)
|
, m_dragging(false)
|
||||||
@@ -65,7 +77,7 @@ GraphicsView::GraphicsView(CurveEditorModel *model, QWidget *parent)
|
|||||||
setResizeAnchor(QGraphicsView::NoAnchor);
|
setResizeAnchor(QGraphicsView::NoAnchor);
|
||||||
setRenderHint(QPainter::Antialiasing, true);
|
setRenderHint(QPainter::Antialiasing, true);
|
||||||
setTransformationAnchor(QGraphicsView::NoAnchor);
|
setTransformationAnchor(QGraphicsView::NoAnchor);
|
||||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
||||||
setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
|
setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
|
||||||
|
|
||||||
@@ -78,12 +90,19 @@ GraphicsView::GraphicsView(CurveEditorModel *model, QWidget *parent)
|
|||||||
|
|
||||||
connect(m_scene, &GraphicsScene::curveChanged, itemSlot);
|
connect(m_scene, &GraphicsScene::curveChanged, itemSlot);
|
||||||
|
|
||||||
QmlDesigner::Navigation2dFilter *filter = new QmlDesigner::Navigation2dFilter(this);
|
QmlDesigner::Navigation2dFilter *filter = new QmlDesigner::Navigation2dFilter(viewport());
|
||||||
|
connect(filter, &Navigation2dFilter::panChanged, [this](const QPointF &direction) {
|
||||||
|
QScrollBar* verticalBar = nullptr;
|
||||||
|
if (QScrollArea* area = nextParentOfType< QScrollArea >(this))
|
||||||
|
verticalBar = area->verticalScrollBar();
|
||||||
|
Navigation2dFilter::scroll(direction, horizontalScrollBar(), verticalBar);
|
||||||
|
});
|
||||||
|
|
||||||
auto zoomChanged = &QmlDesigner::Navigation2dFilter::zoomChanged;
|
auto zoomChanged = &QmlDesigner::Navigation2dFilter::zoomChanged;
|
||||||
connect(filter, zoomChanged, [this](double scale, const QPointF &pos) {
|
connect(filter, zoomChanged, [this](double scale, const QPointF &pos) {
|
||||||
applyZoom(m_zoomX + scale, m_zoomY, mapToGlobal(pos.toPoint()));
|
applyZoom(m_zoomX + scale, m_zoomY, mapToGlobal(pos.toPoint()));
|
||||||
});
|
});
|
||||||
installEventFilter(filter);
|
viewport()->installEventFilter(filter);
|
||||||
|
|
||||||
applyZoom(m_zoomX, m_zoomY);
|
applyZoom(m_zoomX, m_zoomY);
|
||||||
update();
|
update();
|
||||||
|
@@ -62,28 +62,12 @@ FormEditorGraphicsView::FormEditorGraphicsView(QWidget *parent)
|
|||||||
// eventFilter method so it works also for the space scrolling case as expected
|
// eventFilter method so it works also for the space scrolling case as expected
|
||||||
QCoreApplication::instance()->installEventFilter(this);
|
QCoreApplication::instance()->installEventFilter(this);
|
||||||
|
|
||||||
QmlDesigner::Navigation2dFilter *filter = new QmlDesigner::Navigation2dFilter(this);
|
QmlDesigner::Navigation2dFilter *filter = new QmlDesigner::Navigation2dFilter(viewport());
|
||||||
connect(filter, &Navigation2dFilter::zoomIn, this, &FormEditorGraphicsView::zoomIn);
|
connect(filter, &Navigation2dFilter::zoomIn, this, &FormEditorGraphicsView::zoomIn);
|
||||||
connect(filter, &Navigation2dFilter::zoomOut, this, &FormEditorGraphicsView::zoomOut);
|
connect(filter, &Navigation2dFilter::zoomOut, this, &FormEditorGraphicsView::zoomOut);
|
||||||
|
|
||||||
auto panChanged = &Navigation2dFilter::panChanged;
|
connect(filter, &Navigation2dFilter::panChanged, [this](const QPointF &direction) {
|
||||||
connect(filter, panChanged, [this](const QPointF &direction) {
|
Navigation2dFilter::scroll(direction, horizontalScrollBar(), verticalScrollBar());
|
||||||
QScrollBar *sbx = horizontalScrollBar();
|
|
||||||
QScrollBar *sby = verticalScrollBar();
|
|
||||||
|
|
||||||
// max - min + pageStep = sceneRect.size * scale
|
|
||||||
QPointF min(sbx->minimum(), sby->minimum());
|
|
||||||
QPointF max(sbx->maximum(), sby->maximum());
|
|
||||||
QPointF step(sbx->pageStep(), sby->pageStep());
|
|
||||||
|
|
||||||
QPointF d1 = max - min;
|
|
||||||
QPointF d2 = d1 + step;
|
|
||||||
|
|
||||||
QPoint val = QPointF((direction.x() / d2.x()) * d1.x(), (direction.y() / d2.y()) * d1.y())
|
|
||||||
.toPoint();
|
|
||||||
|
|
||||||
sbx->setValue(sbx->value() - val.x());
|
|
||||||
sby->setValue(sby->value() - val.y());
|
|
||||||
});
|
});
|
||||||
|
|
||||||
auto zoomChanged = &Navigation2dFilter::zoomChanged;
|
auto zoomChanged = &Navigation2dFilter::zoomChanged;
|
||||||
@@ -93,7 +77,7 @@ FormEditorGraphicsView::FormEditorGraphicsView(QWidget *parent)
|
|||||||
emit this->zoomChanged(transform().m11());
|
emit this->zoomChanged(transform().m11());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
installEventFilter(filter);
|
viewport()->installEventFilter(filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FormEditorGraphicsView::eventFilter(QObject *watched, QEvent *event)
|
bool FormEditorGraphicsView::eventFilter(QObject *watched, QEvent *event)
|
||||||
@@ -123,8 +107,8 @@ void FormEditorGraphicsView::wheelEvent(QWheelEvent *event)
|
|||||||
{
|
{
|
||||||
if (event->modifiers().testFlag(Qt::ControlModifier))
|
if (event->modifiers().testFlag(Qt::ControlModifier))
|
||||||
event->ignore();
|
event->ignore();
|
||||||
else if (event->source() == Qt::MouseEventNotSynthesized)
|
|
||||||
QGraphicsView::wheelEvent(event);
|
QGraphicsView::wheelEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormEditorGraphicsView::mousePressEvent(QMouseEvent *event)
|
void FormEditorGraphicsView::mousePressEvent(QMouseEvent *event)
|
||||||
|
@@ -118,7 +118,7 @@ TimelineWidget::TimelineWidget(TimelineView *view)
|
|||||||
, m_toolbar(new TimelineToolBar(this))
|
, m_toolbar(new TimelineToolBar(this))
|
||||||
, m_rulerView(new QGraphicsView(this))
|
, m_rulerView(new QGraphicsView(this))
|
||||||
, m_graphicsView(new QGraphicsView(this))
|
, m_graphicsView(new QGraphicsView(this))
|
||||||
, m_scrollbar(new Navigation2dScrollBar(this))
|
, m_scrollbar(new QScrollBar(this))
|
||||||
, m_statusBar(new QLabel(this))
|
, m_statusBar(new QLabel(this))
|
||||||
, m_timelineView(view)
|
, m_timelineView(view)
|
||||||
, m_graphicsScene(new TimelineGraphicsScene(this))
|
, m_graphicsScene(new TimelineGraphicsScene(this))
|
||||||
@@ -160,7 +160,6 @@ TimelineWidget::TimelineWidget(TimelineView *view)
|
|||||||
m_graphicsView->setFrameShape(QFrame::NoFrame);
|
m_graphicsView->setFrameShape(QFrame::NoFrame);
|
||||||
m_graphicsView->setFrameShadow(QFrame::Plain);
|
m_graphicsView->setFrameShadow(QFrame::Plain);
|
||||||
m_graphicsView->setLineWidth(0);
|
m_graphicsView->setLineWidth(0);
|
||||||
m_graphicsView->setVerticalScrollBar(new Navigation2dScrollBar);
|
|
||||||
m_graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
m_graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
||||||
m_graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
m_graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
|
|
||||||
@@ -274,13 +273,19 @@ TimelineWidget::TimelineWidget(TimelineView *view)
|
|||||||
m_timelineView->addNewTimelineDialog();
|
m_timelineView->addNewTimelineDialog();
|
||||||
});
|
});
|
||||||
|
|
||||||
Navigation2dFilter *filter = new Navigation2dFilter(this, m_scrollbar);
|
Navigation2dFilter *filter = new Navigation2dFilter(m_graphicsView->viewport());
|
||||||
connect(filter, &Navigation2dFilter::zoomChanged, [this](double scale, const QPointF& pos) {
|
connect(filter, &Navigation2dFilter::panChanged, [this](const QPointF &direction) {
|
||||||
int s = static_cast<int>(std::round(scale*100.));
|
Navigation2dFilter::scroll(direction, m_scrollbar, m_graphicsView->verticalScrollBar());
|
||||||
double ps = m_graphicsScene->mapFromScene(pos.x());
|
|
||||||
m_graphicsScene->setZoom(std::clamp(m_graphicsScene->zoom() + s, 0, 100), ps);
|
|
||||||
});
|
});
|
||||||
installEventFilter(filter);
|
|
||||||
|
connect(filter, &Navigation2dFilter::zoomChanged, [this](double scale, const QPointF &pos) {
|
||||||
|
int s = static_cast<int>(std::round(scale*100.));
|
||||||
|
int scaleFactor = std::clamp(m_graphicsScene->zoom() + s, 0, 100);
|
||||||
|
double ps = m_graphicsScene->mapFromScene(pos.x());
|
||||||
|
m_graphicsScene->setZoom(scaleFactor, ps);
|
||||||
|
m_toolbar->setScaleFactor(scaleFactor);
|
||||||
|
});
|
||||||
|
m_graphicsView->viewport()->installEventFilter(filter);
|
||||||
|
|
||||||
m_playbackAnimation->stop();
|
m_playbackAnimation->stop();
|
||||||
auto playAnimation = [this](QVariant frame) { graphicsScene()->setCurrentFrame(qRound(frame.toDouble())); };
|
auto playAnimation = [this](QVariant frame) { graphicsScene()->setCurrentFrame(qRound(frame.toDouble())); };
|
||||||
|
@@ -40,6 +40,7 @@ QT_FORWARD_DECLARE_CLASS(QShowEvent)
|
|||||||
QT_FORWARD_DECLARE_CLASS(QString)
|
QT_FORWARD_DECLARE_CLASS(QString)
|
||||||
QT_FORWARD_DECLARE_CLASS(QPushButton)
|
QT_FORWARD_DECLARE_CLASS(QPushButton)
|
||||||
QT_FORWARD_DECLARE_CLASS(QVariantAnimation)
|
QT_FORWARD_DECLARE_CLASS(QVariantAnimation)
|
||||||
|
QT_FORWARD_DECLARE_CLASS(QScrollBar)
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
@@ -97,7 +98,7 @@ private:
|
|||||||
|
|
||||||
QGraphicsView *m_graphicsView = nullptr;
|
QGraphicsView *m_graphicsView = nullptr;
|
||||||
|
|
||||||
Navigation2dScrollBar *m_scrollbar = nullptr;
|
QScrollBar *m_scrollbar = nullptr;
|
||||||
|
|
||||||
QLabel *m_statusBar = nullptr;
|
QLabel *m_statusBar = nullptr;
|
||||||
|
|
||||||
|
@@ -90,7 +90,7 @@ TransitionEditorWidget::TransitionEditorWidget(TransitionEditorView *view)
|
|||||||
, m_toolbar(new TransitionEditorToolBar(this))
|
, m_toolbar(new TransitionEditorToolBar(this))
|
||||||
, m_rulerView(new QGraphicsView(this))
|
, m_rulerView(new QGraphicsView(this))
|
||||||
, m_graphicsView(new QGraphicsView(this))
|
, m_graphicsView(new QGraphicsView(this))
|
||||||
, m_scrollbar(new Navigation2dScrollBar(this))
|
, m_scrollbar(new QScrollBar(this))
|
||||||
, m_statusBar(new QLabel(this))
|
, m_statusBar(new QLabel(this))
|
||||||
, m_transitionEditorView(view)
|
, m_transitionEditorView(view)
|
||||||
, m_graphicsScene(new TransitionEditorGraphicsScene(this))
|
, m_graphicsScene(new TransitionEditorGraphicsScene(this))
|
||||||
@@ -129,7 +129,6 @@ TransitionEditorWidget::TransitionEditorWidget(TransitionEditorView *view)
|
|||||||
m_graphicsView->setFrameShape(QFrame::NoFrame);
|
m_graphicsView->setFrameShape(QFrame::NoFrame);
|
||||||
m_graphicsView->setFrameShadow(QFrame::Plain);
|
m_graphicsView->setFrameShadow(QFrame::Plain);
|
||||||
m_graphicsView->setLineWidth(0);
|
m_graphicsView->setLineWidth(0);
|
||||||
m_graphicsView->setVerticalScrollBar(new Navigation2dScrollBar);
|
|
||||||
m_graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
m_graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
||||||
m_graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
m_graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
|
|
||||||
@@ -223,13 +222,19 @@ TransitionEditorWidget::TransitionEditorWidget(TransitionEditorView *view)
|
|||||||
m_transitionEditorView->addNewTransition();
|
m_transitionEditorView->addNewTransition();
|
||||||
});
|
});
|
||||||
|
|
||||||
Navigation2dFilter *filter = new Navigation2dFilter(this, m_scrollbar);
|
Navigation2dFilter *filter = new Navigation2dFilter(m_graphicsView->viewport());
|
||||||
connect(filter, &Navigation2dFilter::zoomChanged, [this](double scale, const QPointF& pos) {
|
connect(filter, &Navigation2dFilter::panChanged, [this](const QPointF &direction) {
|
||||||
int s = static_cast<int>(std::round(scale*100.));
|
Navigation2dFilter::scroll(direction, m_scrollbar, m_graphicsView->verticalScrollBar());
|
||||||
double ps = m_graphicsScene->mapFromScene(pos.x());
|
|
||||||
m_graphicsScene->setZoom(std::clamp(m_graphicsScene->zoom() + s, 0, 100), ps);
|
|
||||||
});
|
});
|
||||||
installEventFilter(filter);
|
|
||||||
|
connect(filter, &Navigation2dFilter::zoomChanged, [this](double scale, const QPointF &pos) {
|
||||||
|
int s = static_cast<int>(std::round(scale*100.));
|
||||||
|
int scaleFactor = std::clamp(m_graphicsScene->zoom() + s, 0, 100);
|
||||||
|
double ps = m_graphicsScene->mapFromScene(pos.x());
|
||||||
|
m_graphicsScene->setZoom(scaleFactor, ps);
|
||||||
|
m_toolbar->setScaleFactor(scaleFactor);
|
||||||
|
});
|
||||||
|
m_graphicsView->viewport()->installEventFilter(filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransitionEditorWidget::setTransitionActive(bool b)
|
void TransitionEditorWidget::setTransitionActive(bool b)
|
||||||
|
@@ -40,6 +40,7 @@ QT_FORWARD_DECLARE_CLASS(QResizeEvent)
|
|||||||
QT_FORWARD_DECLARE_CLASS(QShowEvent)
|
QT_FORWARD_DECLARE_CLASS(QShowEvent)
|
||||||
QT_FORWARD_DECLARE_CLASS(QString)
|
QT_FORWARD_DECLARE_CLASS(QString)
|
||||||
QT_FORWARD_DECLARE_CLASS(QPushButton)
|
QT_FORWARD_DECLARE_CLASS(QPushButton)
|
||||||
|
QT_FORWARD_DECLARE_CLASS(QScrollBar)
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
@@ -47,7 +48,6 @@ class TransitionEditorView;
|
|||||||
class TransitionEditorToolBar;
|
class TransitionEditorToolBar;
|
||||||
class TransitionEditorGraphicsScene;
|
class TransitionEditorGraphicsScene;
|
||||||
class ModelNode;
|
class ModelNode;
|
||||||
class Navigation2dScrollBar;
|
|
||||||
|
|
||||||
class TransitionEditorWidget : public QWidget
|
class TransitionEditorWidget : public QWidget
|
||||||
{
|
{
|
||||||
@@ -88,7 +88,7 @@ private:
|
|||||||
|
|
||||||
QGraphicsView *m_graphicsView = nullptr;
|
QGraphicsView *m_graphicsView = nullptr;
|
||||||
|
|
||||||
Navigation2dScrollBar *m_scrollbar = nullptr;
|
QScrollBar *m_scrollbar = nullptr;
|
||||||
|
|
||||||
QLabel *m_statusBar = nullptr;
|
QLabel *m_statusBar = nullptr;
|
||||||
|
|
||||||
|
@@ -33,7 +33,6 @@
|
|||||||
#include "generateresource.h"
|
#include "generateresource.h"
|
||||||
#include "generatecmakelists.h"
|
#include "generatecmakelists.h"
|
||||||
#include "nodeinstanceview.h"
|
#include "nodeinstanceview.h"
|
||||||
#include "gestures.h"
|
|
||||||
|
|
||||||
#include <metainfo.h>
|
#include <metainfo.h>
|
||||||
#include <connectionview.h>
|
#include <connectionview.h>
|
||||||
@@ -232,8 +231,6 @@ bool QmlDesignerPlugin::initialize(const QStringList & /*arguments*/, QString *e
|
|||||||
if (QFontDatabase::addApplicationFont(fontPath) < 0)
|
if (QFontDatabase::addApplicationFont(fontPath) < 0)
|
||||||
qCWarning(qmldesignerLog) << "Could not add font " << fontPath << "to font database";
|
qCWarning(qmldesignerLog) << "Could not add font " << fontPath << "to font database";
|
||||||
|
|
||||||
TwoFingerSwipe::registerRecognizer();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -461,8 +461,6 @@ Project {
|
|||||||
"componentcore/findimplementation.h",
|
"componentcore/findimplementation.h",
|
||||||
"componentcore/formatoperation.cpp",
|
"componentcore/formatoperation.cpp",
|
||||||
"componentcore/formatoperation.h",
|
"componentcore/formatoperation.h",
|
||||||
"componentcore/gestures.cpp",
|
|
||||||
"componentcore/gestures.h",
|
|
||||||
"componentcore/layoutingridlayout.cpp",
|
"componentcore/layoutingridlayout.cpp",
|
||||||
"componentcore/layoutingridlayout.h",
|
"componentcore/layoutingridlayout.h",
|
||||||
"componentcore/theme.cpp",
|
"componentcore/theme.cpp",
|
||||||
|
Reference in New Issue
Block a user