Commit 6f7df8c3 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Mix alignment: remember and adjust resize accordingly

parent 5869fd57
......@@ -1055,7 +1055,12 @@ void Core::testProxies()
dialog->exec();
}
void Core::resizeMix(int duration, MixAlignment align)
void Core::resizeMix(int cid, int duration, MixAlignment align)
{
m_mainWindow->getCurrentTimeline()->controller()->resizeMix(duration, align);
m_mainWindow->getCurrentTimeline()->controller()->resizeMix(cid, duration, align);
}
MixAlignment Core::getMixAlign(int cid) const
{
return m_mainWindow->getCurrentTimeline()->controller()->getMixAlign(cid);
}
......@@ -256,7 +256,9 @@ public:
/** @brief The number of clip load jobs changed */
void loadingClips(int);
/** @brief Resize current mix item */
void resizeMix(int duration, MixAlignment align);
void resizeMix(int cid, int duration, MixAlignment align);
/** @brief Get alignment info for a mix item */
MixAlignment getMixAlign(int cid) const;
private:
explicit Core();
......
......@@ -5334,6 +5334,24 @@ std::pair<int, int> TimelineModel::getMixInOut(int cid) const
return {-1,-1};
}
MixAlignment TimelineModel::getMixAlign(int cid) const
{
Q_ASSERT(isClip(cid));
int tid = m_allClips.at(cid)->getCurrentTrackId();
if (tid > -1) {
int mixDuration = m_allClips.at(cid)->getMixDuration();
int mixCutPos = m_allClips.at(cid)->getMixCutPosition();
if (mixCutPos == 0) {
return MixAlignment::AlignRight;
} else if (mixCutPos == mixDuration) {
return MixAlignment::AlignLeft;
} else if (mixCutPos == mixDuration - mixDuration / 2) {
return MixAlignment::AlignCenter;
}
}
return MixAlignment::AlignNone;
}
void TimelineModel::requestResizeMix(int cid, int duration, MixAlignment align)
{
Q_ASSERT(isClip(cid));
......@@ -5352,12 +5370,12 @@ void TimelineModel::requestResizeMix(int cid, int duration, MixAlignment align)
return true;
};
if (align == MixAlignment::AlignLeft) {
int updatedDuration = m_allClips.at(cid)->getPosition() + m_allClips.at(cid)->getPlaytime() - cutPos + duration;
int result = requestItemResize(cid, updatedDuration, false, true, undo, redo);
updatedDuration = cutPos - m_allClips.at(clipToResize)->getPosition();
result = requestItemResize(clipToResize, updatedDuration, true, true, undo, redo);
int updatedDuration = cutPos + duration - m_allClips.at(clipToResize)->getPosition();
int result = requestItemResize(clipToResize, updatedDuration, true, true, undo, redo);
updatedDuration = m_allClips.at(cid)->getPosition() + m_allClips.at(cid)->getPlaytime() - cutPos;
result = requestItemResize(cid, updatedDuration, false, true, undo, redo);
Fun adjust_mix = [this, tid, cid, duration]() {
getTrackById_const(tid)->setMixDuration(cid, duration, 0);
getTrackById_const(tid)->setMixDuration(cid, duration, duration);
QModelIndex ix = makeClipIndexFromID(cid);
emit dataChanged(ix, ix, {TimelineModel::MixRole,TimelineModel::MixCutRole});
return true;
......@@ -5365,12 +5383,12 @@ void TimelineModel::requestResizeMix(int cid, int duration, MixAlignment align)
adjust_mix();
UPDATE_UNDO_REDO(adjust_mix, adjust_mix_undo, undo, redo);
} else if (align == MixAlignment::AlignRight) {
int updatedDuration = cutPos + duration - m_allClips.at(clipToResize)->getPosition();
int result = requestItemResize(clipToResize, updatedDuration, true, true, undo, redo);
updatedDuration = m_allClips.at(cid)->getPosition() + m_allClips.at(cid)->getPlaytime() - cutPos;
result = requestItemResize(cid, updatedDuration, false, true, undo, redo);
int updatedDuration = m_allClips.at(cid)->getPosition() + m_allClips.at(cid)->getPlaytime() - cutPos + duration;
int result = requestItemResize(cid, updatedDuration, false, true, undo, redo);
updatedDuration = cutPos - m_allClips.at(clipToResize)->getPosition();
result = requestItemResize(clipToResize, updatedDuration, true, true, undo, redo);
Fun adjust_mix = [this, tid, cid, duration]() {
getTrackById_const(tid)->setMixDuration(cid, duration, duration);
getTrackById_const(tid)->setMixDuration(cid, duration, 0);
QModelIndex ix = makeClipIndexFromID(cid);
emit dataChanged(ix, ix, {TimelineModel::MixRole,TimelineModel::MixCutRole});
return true;
......
......@@ -742,6 +742,7 @@ public:
bool mixClip(int idToMove = -1, int delta = 0);
Q_INVOKABLE bool resizeStartMix(int cid, int duration, bool singleResize);
void requestResizeMix(int cid, int duration, MixAlignment align);
MixAlignment getMixAlign(int cid) const;
std::shared_ptr<SubtitleModel> getSubtitleModel();
protected:
......
......@@ -4369,9 +4369,14 @@ int TimelineController::clipMaxDuration(int cid)
return m_model->m_allClips[cid]->getMaxDuration();
}
void TimelineController::resizeMix(int duration, MixAlignment align)
void TimelineController::resizeMix(int cid, int duration, MixAlignment align)
{
if (m_model->m_selectedMix > -1) {
m_model->requestResizeMix(m_model->m_selectedMix, duration, align);
if (cid > -1) {
m_model->requestResizeMix(cid, duration, align);
}
}
MixAlignment TimelineController::getMixAlign(int cid) const
{
return m_model->getMixAlign(cid);
}
......@@ -666,7 +666,9 @@ public slots:
/** @brief Restore timeline scroll pos on open. */
void setScrollPos(int pos);
/** @brief Request resizing currently selected mix. */
void resizeMix(int duration, MixAlignment align);
void resizeMix(int cid, int duration, MixAlignment align);
/** @brief Get align info for a mix. */
MixAlignment getMixAlign(int cid) const;
/** @brief change zone info with undo. */
Q_INVOKABLE void updateZone(const QPoint oldZone, const QPoint newZone, bool withUndo = true);
Q_INVOKABLE void updateEffectZone(const QPoint oldZone, const QPoint newZone, bool withUndo = true);
......
......@@ -45,21 +45,24 @@ MixStackView::MixStackView(QWidget *parent)
m_alignLeft->setIcon(QIcon::fromTheme(QStringLiteral("align-horizontal-left")));
m_alignLeft->setToolTip(i18n("Align left"));
m_alignLeft->setAutoRaise(true);
m_alignLeft->setCheckable(true);
connect(m_alignLeft, &QToolButton::clicked, this, &MixStackView::slotAlignLeft);
m_alignRight = new QToolButton(this);
m_alignRight->setIcon(QIcon::fromTheme(QStringLiteral("align-horizontal-right")));
m_alignRight->setToolTip(i18n("Align right"));
m_alignRight->setAutoRaise(true);
m_alignRight->setCheckable(true);
connect(m_alignRight, &QToolButton::clicked, this, &MixStackView::slotAlignRight);
m_alignCenter = new QToolButton(this);
m_alignCenter->setIcon(QIcon::fromTheme(QStringLiteral("align-horizontal-center")));
m_alignCenter->setToolTip(i18n("Center"));
m_alignCenter->setAutoRaise(true);
m_alignCenter->setCheckable(true);
connect(m_alignCenter, &QToolButton::clicked, this, &MixStackView::slotAlignCenter);
m_durationLayout->addStretch();
m_durationLayout->addWidget(m_alignLeft);
m_durationLayout->addWidget(m_alignCenter);
m_durationLayout->addWidget(m_alignRight);
m_durationLayout->addWidget(m_alignCenter);
m_durationLayout->addWidget(m_alignLeft);
}
void MixStackView::setModel(const std::shared_ptr<AssetParameterModel> &model, QSize frameSize, bool addSpacer)
......@@ -82,6 +85,26 @@ void MixStackView::setModel(const std::shared_ptr<AssetParameterModel> &model, Q
m_duration->setValue(m_model->data(m_model->index(0, 0), AssetParameterModel::ParentDurationRole).toInt());
connect(m_model.get(), &AssetParameterModel::dataChanged, this, &MixStackView::durationChanged);
}
int mainClipId = stackOwner().second;
MixAlignment align = pCore->getMixAlign(mainClipId);
m_alignLeft->setChecked(false);
m_alignRight->setChecked(false);
m_alignCenter->setChecked(false);
switch (align) {
case MixAlignment::AlignLeft:
m_alignLeft->setChecked(true);
break;
case MixAlignment::AlignRight:
m_alignRight->setChecked(true);
break;
case MixAlignment::AlignCenter:
m_alignCenter->setChecked(true);
break;
default:
// No alignment
break;
}
m_model->data(m_model->index(0, 0), AssetParameterModel::ParentDurationRole).toInt();
connect(m_duration, &TimecodeDisplay::timeCodeUpdated, this, &MixStackView::updateDuration);
m_lay->addLayout(m_durationLayout);
m_lay->addStretch(10);
......@@ -96,28 +119,56 @@ void MixStackView::durationChanged(const QModelIndex &, const QModelIndex &, con
}
}
MixAlignment MixStackView::alignment() const
{
if (m_alignRight->isChecked()) {
return MixAlignment::AlignRight;
}
if (m_alignLeft->isChecked()) {
return MixAlignment::AlignLeft;
}
if (m_alignCenter->isChecked()) {
return MixAlignment::AlignCenter;
}
return MixAlignment::AlignNone;
}
void MixStackView::updateDuration()
{
int newDuration = m_duration->getValue();
pCore->resizeMix(newDuration, MixAlignment::AlignNone);
pCore->resizeMix(stackOwner().second, m_duration->getValue(), alignment());
}
void MixStackView::slotAlignLeft()
{
if (!m_alignLeft->isChecked()) {
return;
}
m_alignRight->setChecked(false);
m_alignCenter->setChecked(false);
int newDuration = m_duration->getValue();
pCore->resizeMix(newDuration, MixAlignment::AlignLeft);
pCore->resizeMix(stackOwner().second, newDuration, MixAlignment::AlignLeft);
}
void MixStackView::slotAlignRight()
{
if (!m_alignRight->isChecked()) {
return;
}
m_alignLeft->setChecked(false);
m_alignCenter->setChecked(false);
int newDuration = m_duration->getValue();
pCore->resizeMix(newDuration, MixAlignment::AlignRight);
pCore->resizeMix(stackOwner().second, newDuration, MixAlignment::AlignRight);
}
void MixStackView::slotAlignCenter()
{
if (!m_alignCenter->isChecked()) {
return;
}
m_alignLeft->setChecked(false);
m_alignRight->setChecked(false);
int newDuration = m_duration->getValue();
pCore->resizeMix(newDuration, MixAlignment::AlignCenter);
pCore->resizeMix(stackOwner().second, newDuration, MixAlignment::AlignCenter);
}
void MixStackView::unsetModel()
......
......@@ -56,7 +56,7 @@ private:
QToolButton *m_alignLeft;
QToolButton *m_alignCenter;
QToolButton *m_alignRight;
MixAlignment alignment() const;
};
#endif
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