From a07112258b47d4953f6e6b2f486dba75c4fc6159 Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Tue, 28 Sep 2021 17:54:31 +0200 Subject: [PATCH] QmlDesigner: Disable Timeview and CurveEditorView when widget is invisble Task-number: QDS-5159 Change-Id: Ibae0b9742d4aaac6a1def1c84342a031baf75256 Reviewed-by: Knud Dollereder Reviewed-by: Qt CI Bot --- .../components/curveeditor/curveeditor.cpp | 12 ++++++++++ .../components/curveeditor/curveeditor.h | 7 ++++++ .../curveeditor/curveeditorview.cpp | 22 +++++++++++++++---- .../components/curveeditor/curveeditorview.h | 1 + .../timelineeditor/timelineview.cpp | 1 + .../timelineeditor/timelinewidget.cpp | 12 +++++----- 6 files changed, 44 insertions(+), 11 deletions(-) diff --git a/src/plugins/qmldesigner/components/curveeditor/curveeditor.cpp b/src/plugins/qmldesigner/components/curveeditor/curveeditor.cpp index 23623ae3095..acc77acf0a5 100644 --- a/src/plugins/qmldesigner/components/curveeditor/curveeditor.cpp +++ b/src/plugins/qmldesigner/components/curveeditor/curveeditor.cpp @@ -81,6 +81,18 @@ void CurveEditor::clearCanvas() m_view->reset({}); } +void CurveEditor::showEvent(QShowEvent *event) +{ + emit viewEnabledChanged(true); + QWidget::showEvent(event); +} + +void CurveEditor::hideEvent(QHideEvent *event) +{ + emit viewEnabledChanged(false); + QWidget::hideEvent(event); +} + QToolBar *CurveEditor::createToolBar(CurveEditorModel *model) { auto *bar = new QToolBar; diff --git a/src/plugins/qmldesigner/components/curveeditor/curveeditor.h b/src/plugins/qmldesigner/components/curveeditor/curveeditor.h index f248a0ed080..e297e31a9bc 100644 --- a/src/plugins/qmldesigner/components/curveeditor/curveeditor.h +++ b/src/plugins/qmldesigner/components/curveeditor/curveeditor.h @@ -49,6 +49,13 @@ public: void clearCanvas(); +signals: + void viewEnabledChanged(const bool); + +protected: + void showEvent(QShowEvent *event) override; + void hideEvent(QHideEvent *event) override; + private: QToolBar *createToolBar(CurveEditorModel *model); diff --git a/src/plugins/qmldesigner/components/curveeditor/curveeditorview.cpp b/src/plugins/qmldesigner/components/curveeditor/curveeditorview.cpp index 5172d10d8db..bddb6536c7c 100644 --- a/src/plugins/qmldesigner/components/curveeditor/curveeditorview.cpp +++ b/src/plugins/qmldesigner/components/curveeditor/curveeditorview.cpp @@ -51,6 +51,13 @@ CurveEditorView::CurveEditorView(QObject *parent) connect(m_model, &CurveEditorModel::commitStartFrame, this, &CurveEditorView::commitStartFrame); connect(m_model, &CurveEditorModel::commitEndFrame, this, &CurveEditorView::commitEndFrame); connect(m_model, &CurveEditorModel::curveChanged, this, &CurveEditorView::commitKeyframes); + + connect(m_editor, &CurveEditor::viewEnabledChanged, this, [this](bool enabled){ + setEnabled(enabled); + if (enabled) + init(); + }); + setEnabled(false); } CurveEditorView::~CurveEditorView() {} @@ -70,10 +77,8 @@ void CurveEditorView::modelAttached(Model *model) { AbstractView::modelAttached(model); - QmlTimeline timeline = activeTimeline(); - if (timeline.isValid()) { - m_model->setTimeline(timeline); - } + if (isEnabled()) + init(); } void CurveEditorView::modelAboutToBeDetached(Model *model) @@ -389,4 +394,13 @@ void CurveEditorView::commitEndFrame(int frame) timeline.modelNode().variantProperty("endFrame").setValue(frame); } +void CurveEditorView::init() +{ + QmlTimeline timeline = activeTimeline(); + if (timeline.isValid()) { + m_model->setTimeline(timeline); + } + +} + } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/curveeditor/curveeditorview.h b/src/plugins/qmldesigner/components/curveeditor/curveeditorview.h index e774d2bc434..cdfc762191a 100644 --- a/src/plugins/qmldesigner/components/curveeditor/curveeditorview.h +++ b/src/plugins/qmldesigner/components/curveeditor/curveeditorview.h @@ -85,6 +85,7 @@ private: void commitCurrentFrame(int frame); void commitStartFrame(int frame); void commitEndFrame(int frame); + void init(); private: bool m_block; diff --git a/src/plugins/qmldesigner/components/timelineeditor/timelineview.cpp b/src/plugins/qmldesigner/components/timelineeditor/timelineview.cpp index cb9ed8f0cd4..1f1bef923d5 100644 --- a/src/plugins/qmldesigner/components/timelineeditor/timelineview.cpp +++ b/src/plugins/qmldesigner/components/timelineeditor/timelineview.cpp @@ -71,6 +71,7 @@ TimelineView::TimelineView(QObject *parent) , m_timelineWidget(nullptr) { EasingCurve::registerStreamOperators(); + setEnabled(false); } TimelineView::~TimelineView() = default; diff --git a/src/plugins/qmldesigner/components/timelineeditor/timelinewidget.cpp b/src/plugins/qmldesigner/components/timelineeditor/timelinewidget.cpp index 149d1fd7e97..b583863015f 100644 --- a/src/plugins/qmldesigner/components/timelineeditor/timelinewidget.cpp +++ b/src/plugins/qmldesigner/components/timelineeditor/timelinewidget.cpp @@ -606,13 +606,7 @@ void TimelineWidget::showEvent(QShowEvent *event) { Q_UNUSED(event) - /* m_timelineView->setEnabled(true); - TODO See QDS-4191 - */ - - if (m_timelineView->model()) - init(); graphicsScene()->setWidth(m_graphicsView->viewport()->width()); graphicsScene()->invalidateLayout(); @@ -620,6 +614,10 @@ void TimelineWidget::showEvent(QShowEvent *event) graphicsScene()->onShow(); QWidget::showEvent(event); + + //All the events have to be fully processed before we call init() + if (m_timelineView->model()) + QTimer::singleShot(0, [this]() { init(); }); } void TimelineWidget::resizeEvent(QResizeEvent *event) @@ -630,7 +628,7 @@ void TimelineWidget::resizeEvent(QResizeEvent *event) void TimelineWidget::hideEvent(QHideEvent *event) { - /* m_timelineView->setEnabled(false); TODO See QDS-4191 */ + m_timelineView->setEnabled(false); QWidget::hideEvent(event); }