Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Re-add menu to change a composition from one type to another. Related to #395

parent 55c9942b
......@@ -41,6 +41,7 @@
#include <QToolButton>
#include <QVBoxLayout>
#include <QScrollArea>
#include <QMenu>
#include <klocalizedstring.h>
AssetPanel::AssetPanel(QWidget *parent)
......@@ -56,6 +57,26 @@ AssetPanel::AssetPanel(QWidget *parent)
int size = style()->pixelMetric(QStyle::PM_SmallIconSize);
QSize iconSize(size, size);
buttonToolbar->setIconSize(iconSize);
// Edit composition button
m_switchCompoButton = new QToolButton(this);
QMenu *compoMenu = new QMenu(this);
auto allTransitions = TransitionsRepository::get()->getNames();
for (const auto &transition : allTransitions) {
auto *transAction = new QAction(transition.second, this);
transAction->setData(transition.first);
transAction->setIconVisibleInMenu(false);
compoMenu->addAction(transAction);
}
connect(compoMenu, &QMenu::triggered, [&](QAction *ac) {
if (m_transitionWidget->stackOwner().first == ObjectType::TimelineComposition) {
emit switchCurrentComposition(m_transitionWidget->stackOwner().second, ac->data().toString());
}
});
m_switchCompoButton->setMenu(compoMenu);
m_switchCompoButton->setPopupMode(QToolButton::InstantPopup);
m_switchCompoButton->setIcon(QIcon::fromTheme(QStringLiteral("go-down")));
m_switchCompoButton->setToolTip(i18n("Change composition type"));
buttonToolbar->addWidget(m_switchCompoButton);
// spacer
QWidget *empty = new QWidget();
......@@ -129,6 +150,7 @@ void AssetPanel::showTransition(int tid, const std::shared_ptr<AssetParameterMod
return;
}
clear();
m_switchCompoButton->setVisible(true);
QString transitionId = transitionModel->getAssetId();
QString transitionName = TransitionsRepository::get()->getName(transitionId);
m_assetTitle->setText(i18n("%1 properties", i18n(transitionName.toUtf8().data())));
......@@ -216,6 +238,7 @@ void AssetPanel::clearAssetPanel(int itemId)
void AssetPanel::clear()
{
m_switchCompoButton->setVisible(false);
m_transitionWidget->setVisible(false);
m_transitionWidget->unsetModel();
m_effectStackWidget->setVisible(false);
......
......@@ -82,6 +82,7 @@ protected:
private:
QToolButton *m_switchBuiltStack;
QToolButton *m_switchCompoButton;
KDualAction *m_splitButton;
KDualAction *m_enableStackButton;
KDualAction *m_timelineButton;
......@@ -98,6 +99,7 @@ signals:
void doSplitBinEffect(bool);
void seekToPos(int);
void reloadEffect(const QString &path);
void switchCurrentComposition(int tid, const QString &compoId);
};
#endif
......@@ -335,6 +335,10 @@ void MainWindow::init()
m_effectStackDock = addDock(i18n("Properties"), QStringLiteral("effect_stack"), m_assetPanel);
connect(m_assetPanel, &AssetPanel::doSplitEffect, m_projectMonitor, &Monitor::slotSwitchCompare);
connect(m_assetPanel, &AssetPanel::doSplitBinEffect, m_clipMonitor, &Monitor::slotSwitchCompare);
connect(m_assetPanel, &AssetPanel::switchCurrentComposition, [&](int cid, const QString &compositionId) {
getMainTimeline()->controller()->getModel()->switchComposition(cid, compositionId);
});
connect(m_timelineTabs, &TimelineTabs::showTransitionModel, m_assetPanel, &AssetPanel::showTransition);
connect(m_timelineTabs, &TimelineTabs::showTransitionModel, [&] () {
m_effectStackDock->raise();
......
......@@ -3534,3 +3534,33 @@ std::unordered_set<int> TimelineModel::getAllTracksIds() const
return result;
}
void TimelineModel::switchComposition(int cid, const QString &compoId)
{
Q_ASSERT(isComposition(cid));
std::shared_ptr<CompositionModel> compo = m_allCompositions.at(cid);
int currentPos = compo->getPosition();
int duration = compo->getPlaytime();
int currentTrack = compo->getCurrentTrackId();
int a_track = compo->getATrack();
Fun undo = []() { return true; };
Fun redo = []() { return true; };
bool res = requestCompositionDeletion(cid, undo, redo);
int newId;
res = res && requestCompositionInsertion(compoId, currentTrack, a_track, currentPos, duration, nullptr, newId, undo, redo);
if (res) {
Fun local_redo = [newId, this]() {
requestSetSelection({newId});
return true;
};
Fun local_undo = [cid, this]() {
requestSetSelection({cid});
return true;
};
local_redo();
PUSH_LAMBDA(local_redo, redo);
PUSH_LAMBDA(local_undo, undo);
PUSH_UNDO(undo, redo, i18n("Change composition"));
} else {
undo();
}
}
......@@ -397,6 +397,12 @@ public:
bool requestClipInsertion(const QString &binClipId, int trackId, int position, int &id, bool logUndo, bool refreshView, bool useTargets, Fun &undo,
Fun &redo, QVector<int> allowedTracks = QVector<int>());
/** @brief Switch current composition type
* @param cid the id of the composition we want to change
* @param compoId the name of the new composition we want to insert
*/
void switchComposition(int cid, const QString &compoId);
protected:
/* @brief Creates a new clip instance without inserting it.
This action is undoable, returns true on success
......@@ -405,7 +411,7 @@ protected:
@param state: The desired clip state (original, audio/video only).
*/
bool requestClipCreation(const QString &binClipId, int &id, PlaylistState::ClipState state, double speed, Fun &undo, Fun &redo);
/* @brief Switch item selection status */
void setSelected(int itemId, bool sel);
......
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