aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKnud Dollereder <knud.dollereder@qt.io>2020-09-10 12:27:03 +0200
committerKnud Dollereder <knud.dollereder@qt.io>2020-09-15 10:58:23 +0000
commitf4a2e0a5d3dd4701a154745c458e357115177dbf (patch)
tree41587864a990878e66609e76a2108ff4d96840c9
parent116fb0895d054b13d3cc99763ed1569a0964eb85 (diff)
Disable "insert keyframe" context menu when applicable
Fixes: QDS-2727 Change-Id: I0072e77e56f6bbb893e382fbeb39861d2d5e6a61 Reviewed-by: Henning Gründl <henning.gruendl@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
-rw-r--r--src/plugins/qmldesigner/components/curveeditor/detail/curveitem.cpp5
-rw-r--r--src/plugins/qmldesigner/components/curveeditor/detail/curveitem.h2
-rw-r--r--src/plugins/qmldesigner/components/curveeditor/detail/graphicsscene.cpp9
-rw-r--r--src/plugins/qmldesigner/components/curveeditor/detail/graphicsscene.h2
-rw-r--r--src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.cpp9
5 files changed, 24 insertions, 3 deletions
diff --git a/src/plugins/qmldesigner/components/curveeditor/detail/curveitem.cpp b/src/plugins/qmldesigner/components/curveeditor/detail/curveitem.cpp
index 9f5ed0b7af..6c9eebec3c 100644
--- a/src/plugins/qmldesigner/components/curveeditor/detail/curveitem.cpp
+++ b/src/plugins/qmldesigner/components/curveeditor/detail/curveitem.cpp
@@ -173,6 +173,11 @@ bool CurveItem::hasSelectedKeyframe() const
return false;
}
+bool CurveItem::hasEditableSegment(double time) const
+{
+ return curve().segment(time).interpolation() != Keyframe::Interpolation::Easing;
+}
+
unsigned int CurveItem::id() const
{
return m_id;
diff --git a/src/plugins/qmldesigner/components/curveeditor/detail/curveitem.h b/src/plugins/qmldesigner/components/curveeditor/detail/curveitem.h
index 02d1bf0401..04fba5ec81 100644
--- a/src/plugins/qmldesigner/components/curveeditor/detail/curveitem.h
+++ b/src/plugins/qmldesigner/components/curveeditor/detail/curveitem.h
@@ -79,6 +79,8 @@ public:
bool hasSelectedKeyframe() const;
+ bool hasEditableSegment(double time) const;
+
unsigned int id() const;
ValueType valueType() const;
diff --git a/src/plugins/qmldesigner/components/curveeditor/detail/graphicsscene.cpp b/src/plugins/qmldesigner/components/curveeditor/detail/graphicsscene.cpp
index f0a9629528..aca41b4d6d 100644
--- a/src/plugins/qmldesigner/components/curveeditor/detail/graphicsscene.cpp
+++ b/src/plugins/qmldesigner/components/curveeditor/detail/graphicsscene.cpp
@@ -85,6 +85,15 @@ bool GraphicsScene::hasSelectedKeyframe() const
return false;
}
+bool GraphicsScene::hasEditableSegment(double time) const
+{
+ for (auto *curve : m_curves) {
+ if (curve->hasEditableSegment(time))
+ return true;
+ }
+ return false;
+}
+
double GraphicsScene::minimumTime() const
{
return limits().left();
diff --git a/src/plugins/qmldesigner/components/curveeditor/detail/graphicsscene.h b/src/plugins/qmldesigner/components/curveeditor/detail/graphicsscene.h
index 15433909a0..9443130b3e 100644
--- a/src/plugins/qmldesigner/components/curveeditor/detail/graphicsscene.h
+++ b/src/plugins/qmldesigner/components/curveeditor/detail/graphicsscene.h
@@ -57,6 +57,8 @@ public:
bool hasSelectedKeyframe() const;
+ bool hasEditableSegment(double time) const;
+
double minimumTime() const;
double maximumTime() const;
diff --git a/src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.cpp b/src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.cpp
index 95ba22831f..36bae9be0c 100644
--- a/src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.cpp
+++ b/src/plugins/qmldesigner/components/curveeditor/detail/graphicsview.cpp
@@ -350,13 +350,16 @@ void GraphicsView::contextMenuEvent(QContextMenuEvent *event)
connect(openEditorAction, &QAction::triggered, openStyleEditor);
}
+ QPointF rasterPos = globalToRaster(event->globalPos());
+
menu.addSeparator();
- auto insertKeyframes = [this, event]() {
- m_scene->insertKeyframe(globalToRaster(event->globalPos()).x(), true);
- };
+ auto insertKeyframes = [this, rasterPos]() { m_scene->insertKeyframe(rasterPos.x(), true); };
QAction *insertKeyframeAction = menu.addAction(tr("Insert Keyframe"));
connect(insertKeyframeAction, &QAction::triggered, insertKeyframes);
+ if (!m_scene->hasEditableSegment(rasterPos.x()))
+ insertKeyframeAction->setEnabled(false);
+
auto deleteKeyframes = [this] { m_scene->deleteSelectedKeyframes(); };
QAction *deleteKeyframeAction = menu.addAction(tr("Delete Selected Keyframes"));
connect(deleteKeyframeAction, &QAction::triggered, deleteKeyframes);