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>
This commit is contained in:
Knud Dollereder
2020-09-10 12:27:03 +02:00
parent 116fb0895d
commit f4a2e0a5d3
5 changed files with 24 additions and 3 deletions

View File

@@ -173,6 +173,11 @@ bool CurveItem::hasSelectedKeyframe() const
return false; return false;
} }
bool CurveItem::hasEditableSegment(double time) const
{
return curve().segment(time).interpolation() != Keyframe::Interpolation::Easing;
}
unsigned int CurveItem::id() const unsigned int CurveItem::id() const
{ {
return m_id; return m_id;

View File

@@ -79,6 +79,8 @@ public:
bool hasSelectedKeyframe() const; bool hasSelectedKeyframe() const;
bool hasEditableSegment(double time) const;
unsigned int id() const; unsigned int id() const;
ValueType valueType() const; ValueType valueType() const;

View File

@@ -85,6 +85,15 @@ bool GraphicsScene::hasSelectedKeyframe() const
return false; 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 double GraphicsScene::minimumTime() const
{ {
return limits().left(); return limits().left();

View File

@@ -57,6 +57,8 @@ public:
bool hasSelectedKeyframe() const; bool hasSelectedKeyframe() const;
bool hasEditableSegment(double time) const;
double minimumTime() const; double minimumTime() const;
double maximumTime() const; double maximumTime() const;

View File

@@ -350,13 +350,16 @@ void GraphicsView::contextMenuEvent(QContextMenuEvent *event)
connect(openEditorAction, &QAction::triggered, openStyleEditor); connect(openEditorAction, &QAction::triggered, openStyleEditor);
} }
QPointF rasterPos = globalToRaster(event->globalPos());
menu.addSeparator(); menu.addSeparator();
auto insertKeyframes = [this, event]() { auto insertKeyframes = [this, rasterPos]() { m_scene->insertKeyframe(rasterPos.x(), true); };
m_scene->insertKeyframe(globalToRaster(event->globalPos()).x(), true);
};
QAction *insertKeyframeAction = menu.addAction(tr("Insert Keyframe")); QAction *insertKeyframeAction = menu.addAction(tr("Insert Keyframe"));
connect(insertKeyframeAction, &QAction::triggered, insertKeyframes); connect(insertKeyframeAction, &QAction::triggered, insertKeyframes);
if (!m_scene->hasEditableSegment(rasterPos.x()))
insertKeyframeAction->setEnabled(false);
auto deleteKeyframes = [this] { m_scene->deleteSelectedKeyframes(); }; auto deleteKeyframes = [this] { m_scene->deleteSelectedKeyframes(); };
QAction *deleteKeyframeAction = menu.addAction(tr("Delete Selected Keyframes")); QAction *deleteKeyframeAction = menu.addAction(tr("Delete Selected Keyframes"));
connect(deleteKeyframeAction, &QAction::triggered, deleteKeyframes); connect(deleteKeyframeAction, &QAction::triggered, deleteKeyframes);