Commit 2e9710f8 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle

Switch timeline context menu to QWidget

parent 45282ce9
Pipeline #14054 passed with stage
in 25 minutes and 11 seconds
......@@ -505,26 +505,26 @@ void MainWindow::init()
loadClipActions();
// Timeline clip menu
QMenu *timelineMenu = new QMenu(this);
timelineMenu->addAction(actionCollection()->action(QStringLiteral("edit_copy")));
timelineMenu->addAction(actionCollection()->action(QStringLiteral("edit_paste")));
timelineMenu->addAction(actionCollection()->action(QStringLiteral("group_clip")));
timelineMenu->addAction(actionCollection()->action(QStringLiteral("ungroup_clip")));
timelineMenu->addAction(actionCollection()->action(QStringLiteral("edit_item_duration")));
timelineMenu->addAction(actionCollection()->action(QStringLiteral("clip_split")));
timelineMenu->addAction(actionCollection()->action(QStringLiteral("clip_switch")));
timelineMenu->addAction(actionCollection()->action(QStringLiteral("delete_timeline_clip")));
timelineMenu->addAction(actionCollection()->action(QStringLiteral("extract_clip")));
timelineMenu->addAction(actionCollection()->action(QStringLiteral("save_to_bin")));
QMenu *timelineClipMenu = new QMenu(this);
timelineClipMenu->addAction(actionCollection()->action(QStringLiteral("edit_copy")));
timelineClipMenu->addAction(actionCollection()->action(QStringLiteral("edit_paste")));
timelineClipMenu->addAction(actionCollection()->action(QStringLiteral("group_clip")));
timelineClipMenu->addAction(actionCollection()->action(QStringLiteral("ungroup_clip")));
timelineClipMenu->addAction(actionCollection()->action(QStringLiteral("edit_item_duration")));
timelineClipMenu->addAction(actionCollection()->action(QStringLiteral("clip_split")));
timelineClipMenu->addAction(actionCollection()->action(QStringLiteral("clip_switch")));
timelineClipMenu->addAction(actionCollection()->action(QStringLiteral("delete_timeline_clip")));
timelineClipMenu->addAction(actionCollection()->action(QStringLiteral("extract_clip")));
timelineClipMenu->addAction(actionCollection()->action(QStringLiteral("save_to_bin")));
QMenu *markerMenu = static_cast<QMenu *>(factory()->container(QStringLiteral("marker_menu"), this));
timelineMenu->addMenu(markerMenu);
timelineClipMenu->addMenu(markerMenu);
timelineMenu->addAction(actionCollection()->action(QStringLiteral("set_audio_align_ref")));
timelineMenu->addAction(actionCollection()->action(QStringLiteral("align_audio")));
timelineMenu->addAction(actionCollection()->action(QStringLiteral("edit_item_speed")));
timelineMenu->addAction(actionCollection()->action(QStringLiteral("clip_in_project_tree")));
timelineMenu->addAction(actionCollection()->action(QStringLiteral("cut_timeline_clip")));
timelineClipMenu->addAction(actionCollection()->action(QStringLiteral("set_audio_align_ref")));
timelineClipMenu->addAction(actionCollection()->action(QStringLiteral("align_audio")));
timelineClipMenu->addAction(actionCollection()->action(QStringLiteral("edit_item_speed")));
timelineClipMenu->addAction(actionCollection()->action(QStringLiteral("clip_in_project_tree")));
timelineClipMenu->addAction(actionCollection()->action(QStringLiteral("cut_timeline_clip")));
// Timeline composition menu
QMenu *compositionMenu = new QMenu(this);
......@@ -532,6 +532,18 @@ void MainWindow::init()
compositionMenu->addAction(actionCollection()->action(QStringLiteral("edit_copy")));
compositionMenu->addAction(actionCollection()->action(QStringLiteral("delete_timeline_clip")));
// Timeline main menu
QMenu *timelineMenu = new QMenu(this);
timelineMenu->addAction(actionCollection()->action(QStringLiteral("edit_paste")));
timelineMenu->addAction(actionCollection()->action(QStringLiteral("insert_space")));
timelineMenu->addAction(actionCollection()->action(QStringLiteral("delete_space")));
timelineMenu->addAction(actionCollection()->action(QStringLiteral("delete_space_all_tracks")));
timelineMenu->addAction(actionCollection()->action(QStringLiteral("add_guide")));
timelineMenu->addAction(actionCollection()->action(QStringLiteral("edit_guide")));
QMenu *guideMenu = new QMenu(i18n("Go to Guide..."), this);
timelineMenu->addMenu(guideMenu);
QMenu *openGLMenu = static_cast<QMenu *>(factory()->container(QStringLiteral("qt_opengl"), this));
#if defined(Q_OS_WIN)
connect(openGLMenu, &QMenu::triggered, [&](QAction *ac) {
......@@ -669,7 +681,7 @@ void MainWindow::init()
#ifdef USE_JOGSHUTTLE
new JogManager(this);
#endif
getMainTimeline()->setTimelineMenu(timelineMenu, compositionMenu);
getMainTimeline()->setTimelineMenu(timelineClipMenu, compositionMenu, timelineMenu, guideMenu, actionCollection()->action(QStringLiteral("edit_guide")));
scmanager->slotCheckActiveScopes();
// m_messageLabel->setMessage(QStringLiteral("This is a beta version. Always backup your data"), MltError);
}
......@@ -1522,7 +1534,7 @@ void MainWindow::setupActions()
QAction *insertTrack = new QAction(QIcon(), i18n("Insert Track"), this);
connect(insertTrack, &QAction::triggered, this, &MainWindow::slotInsertTrack);
timelineActions->addAction(QStringLiteral("insert_track"), insertTrack);
QAction *masterEffectStack = new QAction(QIcon::fromTheme(QStringLiteral("kdenlive-composite")), i18n("Master effects"), this);
connect(masterEffectStack, &QAction::triggered, [&]() {
pCore->monitorManager()->activateMonitor(Kdenlive::ProjectMonitor);
......
......@@ -249,7 +249,7 @@ Rectangle {
if (timeline.selection.indexOf(clipRoot.clipId) == -1) {
controller.requestAddToSelection(clipRoot.clipId, true)
}
root.clipFrame = Math.round(mouse.x / timeline.scaleFactor)
root.mainFrame = Math.round(mouse.x / timeline.scaleFactor)
root.showClipMenu()
}
}
......
......@@ -21,6 +21,7 @@ Rectangle {
signal mousePosChanged(int position)
signal showClipMenu()
signal showCompositionMenu()
signal showTimelineMenu()
signal zoomIn(bool onMouse)
signal zoomOut(bool onMouse)
signal processingDrag(bool dragging)
......@@ -236,7 +237,7 @@ Rectangle {
property color selectionColor: timeline.selectionColor
property color groupColor: timeline.groupColor
property int mainItemId: -1
property int clipFrame: 0
property int mainFrame: 0
property int clipBeingDroppedId: -1
property string clipBeingDroppedData
property int droppedPosition: -1
......@@ -579,95 +580,6 @@ Rectangle {
clearDropData()
}
}
OLD.Menu {
id: menu
property int clickedX
property int clickedY
onAboutToHide: {
timeline.ungrabHack()
editGuideMenu.visible = false
}
OLD.MenuItem {
text: i18n("Paste")
iconName: 'edit-paste'
visible: copiedClip != -1
onTriggered: {
var track = Logic.getTrackIdFromPos(menu.clickedY - ruler.height + scrollView.flickableItem.contentY)
var frame = Math.floor((menu.clickedX + scrollView.flickableItem.contentX) / timeline.scaleFactor)
timeline.pasteItem(frame, track)
}
}
OLD.MenuItem {
text: i18n("Insert Space")
onTriggered: {
var track = Logic.getTrackIdFromPos(menu.clickedY - ruler.height + scrollView.flickableItem.contentY)
var frame = Math.floor((menu.clickedX + scrollView.flickableItem.contentX) / timeline.scaleFactor)
timeline.insertSpace(track, frame);
}
}
OLD.MenuItem {
text: i18n("Remove Space On Active Track")
onTriggered: {
var track = Logic.getTrackIdFromPos(menu.clickedY - ruler.height + scrollView.flickableItem.contentY)
var frame = Math.floor((menu.clickedX + scrollView.flickableItem.contentX) / timeline.scaleFactor)
timeline.removeSpace(track, frame);
}
}
OLD.MenuItem {
text: i18n("Remove Space")
onTriggered: {
var track = Logic.getTrackIdFromPos(menu.clickedY - ruler.height + scrollView.flickableItem.contentY)
var frame = Math.floor((menu.clickedX + scrollView.flickableItem.contentX) / timeline.scaleFactor)
timeline.removeSpace(track, frame, true);
}
}
OLD.MenuItem {
id: addGuideMenu
text: i18n("Add Guide")
onTriggered: {
timeline.switchGuide(root.consumerPosition);
}
}
GuidesMenu {
title: i18n("Go to guide...")
menuModel: guidesModel
enabled: guidesDelegateModel.count > 0
onGuideSelected: {
proxy.position = assetFrame
}
}
OLD.MenuItem {
id: editGuideMenu
text: i18n("Edit Guide")
visible: false
onTriggered: {
timeline.editGuide(root.consumerPosition);
}
}
AssetMenu {
title: i18n("Insert a composition...")
menuModel: transitionModel
isTransition: true
onAssetSelected: {
var track = Logic.getTrackIdFromPos(menu.clickedY - ruler.height + scrollView.flickableItem.contentY)
var frame = Math.round((menu.clickedX + scrollView.flickableItem.contentX) / timeline.scaleFactor)
var id = timeline.insertComposition(track, frame, assetId, true)
if (id == -1) {
compositionFail.open()
}
}
}
onAboutToShow: {
if (guidesModel.hasMarker(root.consumerPosition)) {
// marker at timeline position
addGuideMenu.text = i18n("Remove Guide")
editGuideMenu.visible = true
} else {
addGuideMenu.text = i18n("Add Guide")
}
console.log("pop menu")
}
}
OLD.Menu {
id: rulermenu
property int clickedX
......@@ -1024,11 +936,10 @@ Rectangle {
proxy.position = Math.min((scrollView.flickableItem.contentX + mouse.x) / timeline.scaleFactor, timeline.fullDuration - 1)
}
} else if (mouse.button & Qt.RightButton) {
menu.clickedX = mouse.x
menu.clickedY = mouse.y
if (mouse.y > ruler.height) {
timeline.activeTrack = tracksRepeater.itemAt(Logic.getTrackIndexFromPos(mouse.y - ruler.height + scrollView.flickableItem.contentY)).trackInternalId
menu.popup()
root.mainFrame = Math.floor((mouse.x + scrollView.flickableItem.contentX) / timeline.scaleFactor)
root.showTimelineMenu()
} else {
// ruler menu
rulermenu.popup()
......
......@@ -356,8 +356,8 @@ int TimelineController::insertNewComposition(int tid, int position, const QStrin
int TimelineController::insertNewComposition(int tid, int clipId, int offset, const QString &transitionId, bool logUndo)
{
int id;
int minimumPos = m_model->getClipPosition(clipId);
int clip_duration = m_model->getClipPlaytime(clipId);
int minimumPos = clipId > -1 ? m_model->getClipPosition(clipId) : offset;
int clip_duration = clipId > -1 ? m_model->getClipPlaytime(clipId) : pCore->currentDoc()->getFramePos(KdenliveSettings::transition_duration());
int endPos = minimumPos + clip_duration;
int position = minimumPos;
int duration = qMin(clip_duration, pCore->currentDoc()->getFramePos(KdenliveSettings::transition_duration()));
......@@ -1881,9 +1881,9 @@ void TimelineController::addCompositionToClip(const QString &assetId, int clipId
clipId = m_root->property("mainItemId").toInt();
}
if (offset == -1) {
offset = m_root->property("clipFrame").toInt();
offset = m_root->property("mainFrame").toInt();
}
int track = m_model->getClipTrackId(clipId);
int track = clipId > -1 ? m_model->getClipTrackId(clipId) : m_activeTrack;
int compoId = -1;
if (assetId.isEmpty()) {
QStringList compositions = KdenliveSettings::favorite_transitions();
......
......@@ -133,10 +133,13 @@ const QMap<QString, QString> TimelineWidget::sortedItems(const QStringList &item
return sortedItems;
}
void TimelineWidget::setTimelineMenu(QMenu *clipMenu, QMenu *compositionMenu)
void TimelineWidget::setTimelineMenu(QMenu *clipMenu, QMenu *compositionMenu, QMenu *timelineMenu, QMenu *guideMenu, QAction *editGuideAction)
{
m_timelineClipMenu = clipMenu;
m_timelineCompositionMenu = compositionMenu;
m_timelineMenu = timelineMenu;
m_guideMenu = guideMenu;
m_editGuideAcion = editGuideAction;
updateEffectFavorites();
updateTransitionFavorites();
connect(m_favEffects, &QMenu::triggered, [&] (QAction *ac) {
......@@ -145,8 +148,12 @@ void TimelineWidget::setTimelineMenu(QMenu *clipMenu, QMenu *compositionMenu)
connect(m_favCompositions, &QMenu::triggered, [&] (QAction *ac) {
m_proxy->addCompositionToClip(ac->data().toString());
});
connect(m_guideMenu, &QMenu::triggered, [&] (QAction *ac) {
m_proxy->setPosition(ac->data().toInt());
});
m_timelineClipMenu->addMenu(m_favEffects);
m_timelineClipMenu->addMenu(m_favCompositions);
m_timelineMenu->addMenu(m_favCompositions);
}
void TimelineWidget::setModel(const std::shared_ptr<TimelineItemModel> &model, MonitorProxy *proxy)
......@@ -181,6 +188,7 @@ void TimelineWidget::setModel(const std::shared_ptr<TimelineItemModel> &model, M
rootObject()->setProperty("dar", pCore->getCurrentDar());
connect(rootObject(), SIGNAL(showClipMenu()), this, SLOT(showClipMenu()));
connect(rootObject(), SIGNAL(showCompositionMenu()), this, SLOT(showCompositionMenu()));
connect(rootObject(), SIGNAL(showTimelineMenu()), this, SLOT(showTimelineMenu()));
m_proxy->setRoot(rootObject());
setVisible(true);
loading = false;
......@@ -210,6 +218,29 @@ void TimelineWidget::showCompositionMenu()
});
}
void TimelineWidget::showTimelineMenu()
{
m_guideMenu->clear();
const QList<CommentedTime> guides = pCore->projectManager()->current()->getGuideModel()->getAllMarkers();
QAction *ac;
m_editGuideAcion->setEnabled(false);
double fps = pCore->getCurrentFps();
int currentPos = rootObject()->property("consumerPosition").toInt();
for (auto guide : guides) {
ac = new QAction(guide.comment(), this);
int frame = guide.time().frames(fps);
ac->setData(frame);
if (frame == currentPos) {
m_editGuideAcion->setEnabled(true);
}
m_guideMenu->addAction(ac);
}
m_timelineMenu->popup(m_clickPos);
connect(m_timelineMenu, &QMenu::aboutToHide, [this]() {
  • aboutToHide() signal is connected each time the menu is shown instead of being connected only once in setTimelineMenu(). This should result in slotUngrabHack() beign called multiple times when the menu is hidden

Please register or sign in to reply
slotUngrabHack();
});
}
void TimelineWidget::slotChangeZoom(int value, bool zoomOnMouse)
{
double pixelScale = QFontMetrics(font()).maxWidth() * 2;
......
......@@ -54,7 +54,7 @@ public:
/* @brief Give keyboard focus to timeline qml */
void focusTimeline();
/** @brief Initiate timeline clip context menu */
void setTimelineMenu(QMenu *clipMenu, QMenu *compositionMenu);
void setTimelineMenu(QMenu *clipMenu, QMenu *compositionMenu, QMenu *timelineMenu, QMenu *guideMenu, QAction *editGuideAction);
bool loading;
protected:
......@@ -73,13 +73,17 @@ private slots:
void slotUngrabHack();
void showClipMenu();
void showCompositionMenu();
void showTimelineMenu();
private:
TimelineController *m_proxy;
QMenu *m_timelineClipMenu;
QMenu *m_timelineCompositionMenu;
QMenu *m_timelineMenu;
QMenu *m_guideMenu;
QMenu *m_favEffects;
QMenu *m_favCompositions;
QAction *m_editGuideAcion;
static const int comboScale[];
std::shared_ptr<AssetTreeModel> m_transitionModel;
std::unique_ptr<AssetFilter> m_transitionProxyModel;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment