Commit 3aa01a85 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Mixes: switch to slider to adjust mix position in settings

Related to #796
parent c0bd2cc4
......@@ -5605,7 +5605,7 @@ MixAlignment TimelineModel::getMixAlign(int cid) const
return MixAlignment::AlignNone;
}
void TimelineModel::requestResizeMix(int cid, int duration, MixAlignment align, int leftFrames)
void TimelineModel::requestResizeMix(int cid, int duration, MixAlignment align, int rightFrames)
{
Q_ASSERT(isClip(cid));
int tid = m_allClips.at(cid)->getCurrentTrackId();
......@@ -5718,13 +5718,12 @@ void TimelineModel::requestResizeMix(int cid, int duration, MixAlignment align,
}
int deltaLeft = m_allClips.at(clipToResize)->getPosition() + updatedDurationLeft - cutPos;
int deltaRight = cutPos - (m_allClips.at(cid)->getPosition() + m_allClips.at(cid)->getPlaytime() - updatedDurationRight);
if (deltaLeft < 1 || deltaRight < 1) {
pCore->displayMessage(i18n("Cannot align mix"), ErrorMessage, 500);
emit selectedMixChanged(cid, getTrackById_const(tid)->mixModel(cid), true);
return;
if (deltaRight) {
requestItemResize(cid, updatedDurationRight, false, true, undo, redo);
}
if (deltaLeft > 0) {
requestItemResize(clipToResize, updatedDurationLeft, true, true, undo, redo);
}
requestItemResize(cid, updatedDurationRight, false, true, undo, redo);
requestItemResize(clipToResize, updatedDurationLeft, true, true, undo, redo);
int mixCutPos = m_allClips.at(clipToResize)->getPosition() + m_allClips.at(clipToResize)->getPlaytime() - cutPos;
if (mixCutPos > updatedDuration) {
pCore->displayMessage(i18n("Cannot resize mix"), ErrorMessage, 500);
......@@ -5749,10 +5748,10 @@ void TimelineModel::requestResizeMix(int cid, int duration, MixAlignment align,
// No alignment specified
int updatedDurationRight;
int updatedDurationLeft;
if (leftFrames > -1) {
// A left frame offset was specified
updatedDurationLeft = qBound(0, leftFrames, duration);
updatedDurationRight = duration - updatedDurationLeft;
if (rightFrames > -1) {
// A right frame offset was specified
updatedDurationRight = qBound(0, rightFrames, duration);
updatedDurationLeft = duration - updatedDurationRight;
} else {
updatedDurationRight = m_allClips.at(cid)->getMixCutPosition();
updatedDurationLeft = m_allClips.at(cid)->getMixDuration() - updatedDurationRight;
......
......@@ -749,7 +749,7 @@ public:
/** @brief Create a mix selection with currently selected clip. If delta = -1, mix with previous clip, +1 with next clip and 0 will check cursor position*/
bool mixClip(int idToMove = -1, const QString &mixId = QStringLiteral("luma"), int delta = 0);
Q_INVOKABLE bool resizeStartMix(int cid, int duration, bool singleResize);
void requestResizeMix(int cid, int duration, MixAlignment align, int leftFrames = -1);
void requestResizeMix(int cid, int duration, MixAlignment align, int rightFrames = -1);
/** @brief Get Mix cut pos (the duration of the mix on the right clip) */
int getMixCutPos(int cid) const;
MixAlignment getMixAlign(int cid) const;
......
......@@ -4692,10 +4692,10 @@ int TimelineController::clipMaxDuration(int cid)
return m_model->m_allClips[cid]->getMaxDuration();
}
void TimelineController::resizeMix(int cid, int duration, MixAlignment align, int leftFrames)
void TimelineController::resizeMix(int cid, int duration, MixAlignment align, int rightFrames)
{
if (cid > -1) {
m_model->requestResizeMix(cid, duration, align, leftFrames);
m_model->requestResizeMix(cid, duration, align, rightFrames);
}
}
......
......@@ -676,7 +676,7 @@ public slots:
/** @brief Restore timeline scroll pos on open. */
void setScrollPos(int pos);
/** @brief Request resizing currently selected mix. */
void resizeMix(int cid, int duration, MixAlignment align, int leftFrames = -1);
void resizeMix(int cid, int duration, MixAlignment align, int rightFrames = -1);
/** @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);
......
......@@ -8,6 +8,7 @@
#include "assets/model/assetparametermodel.hpp"
#include "core.h"
#include "monitor/monitor.h"
#include "widgets/positionwidget.h"
#include "timecodedisplay.h"
#include <QComboBox>
......@@ -22,12 +23,7 @@ MixStackView::MixStackView(QWidget *parent)
: AssetParameterView(parent)
{
// Position widget
m_positionLayout = new QHBoxLayout;
m_position = new TimecodeDisplay(pCore->timecode(), this);
m_position->setRange(0, -1);
m_positionLayout->addWidget(new QLabel(i18n("Position (left):")));
m_positionLayout->addWidget(m_position);
m_positionLayout->addStretch();
m_position = new PositionWidget(i18n("Position"), 0, 0, 0, pCore->timecode()); // TimecodeDisplay(pCore->timecode(), this);
// Duration widget
m_durationLayout = new QHBoxLayout;
m_duration = new TimecodeDisplay(pCore->timecode(), this);
......@@ -57,7 +53,7 @@ MixStackView::MixStackView(QWidget *parent)
m_durationLayout->addWidget(m_alignCenter);
m_durationLayout->addWidget(m_alignLeft);
connect(m_duration, &TimecodeDisplay::timeCodeUpdated, this, &MixStackView::updateDuration);
connect(m_position, &TimecodeDisplay::timeCodeUpdated, this, &MixStackView::updatePosition);
connect(m_position, &PositionWidget::valueChanged, this, &MixStackView::updatePosition);
connect(this, &AssetParameterView::seekToPos, [this](int pos) {
// at this point, the effects returns a pos relative to the clip. We need to convert it to a global time
int clipIn = pCore->getItemPosition(m_model->getOwnerId());
......@@ -80,12 +76,14 @@ void MixStackView::setModel(const std::shared_ptr<AssetParameterModel> &model, Q
const QSignalBlocker bk1(m_position);
int duration = m_model->data(m_model->index(0, 0), AssetParameterModel::ParentDurationRole).toInt();
m_duration->setValue(duration + 1);
m_position->setValue(duration - pCore->getMixCutPos(stackOwner().second));
m_position->updateTimecodeFormat();
m_position->setRange(0, duration);
m_position->setPosition(duration - pCore->getMixCutPos(stackOwner().second));
connect(m_model.get(), &AssetParameterModel::dataChanged, this, &MixStackView::durationChanged);
// The layout is handled by AssetParameterView, so we can only add our custom stuff later here
m_lay->addLayout(m_durationLayout);
m_lay->addLayout(m_positionLayout);
m_lay->addWidget(m_position);
m_lay->addStretch(10);
checkAlignment();
slotRefresh();
......@@ -119,12 +117,17 @@ void MixStackView::checkAlignment()
void MixStackView::durationChanged(const QModelIndex &, const QModelIndex &, const QVector<int> &roles)
{
if (roles.contains(AssetParameterModel::ParentDurationRole)) {
int duration = m_model->data(m_model->index(0, 0), AssetParameterModel::ParentDurationRole).toInt();
int mixCutPos = pCore->getMixCutPos(stackOwner().second);
if (duration + 1 == m_duration->getValue() && mixCutPos == m_position->getPosition()) {
// No change
return;
}
QSignalBlocker bk1(m_duration);
QSignalBlocker bk2(m_position);
int duration = m_model->data(m_model->index(0, 0), AssetParameterModel::ParentDurationRole).toInt();
m_duration->setValue(duration + 1);
m_position->setRange(0, duration);
m_position->setValue(duration - pCore->getMixCutPos(stackOwner().second));
m_position->setPosition(mixCutPos);
checkAlignment();
}
}
......@@ -150,7 +153,7 @@ void MixStackView::updateDuration()
void MixStackView::updatePosition()
{
pCore->resizeMix(stackOwner().second, m_duration->getValue() - 1, MixAlignment::AlignNone, m_position->getValue());
pCore->resizeMix(stackOwner().second, m_duration->getValue() - 1, MixAlignment::AlignNone, m_position->getPosition());
}
void MixStackView::slotAlignLeft()
......@@ -188,7 +191,7 @@ void MixStackView::unsetModel()
if (m_model) {
m_model->setActive(false);
m_lay->removeItem(m_durationLayout);
m_lay->removeItem(m_positionLayout);
m_lay->removeWidget(m_position);
auto kfr = m_model->getKeyframeModel();
if (kfr) {
disconnect(kfr.get(), &KeyframeModelList::modelChanged, this, &AssetParameterView::slotRefresh);
......
......@@ -12,6 +12,7 @@
class QComboBox;
class QToolButton;
class TimecodeDisplay;
class PositionWidget;
class QHBoxLayout;
class MixStackView : public AssetParameterView
......@@ -36,8 +37,8 @@ private slots:
void slotAlignCenter();
private:
QHBoxLayout *m_positionLayout;
TimecodeDisplay *m_position;
//QHBoxLayout *m_positionLayout;
PositionWidget *m_position;
QHBoxLayout *m_durationLayout;
TimecodeDisplay *m_duration;
QToolButton *m_alignLeft;
......
......@@ -73,6 +73,7 @@ void PositionWidget::setRange(int min, int max, bool absolute)
m_slider->setRange(0, max - min);
m_display->setRange(0, max - min);
}
m_slider->setSingleStep(std::ceil((max - min) / 10.));
}
bool PositionWidget::isValid() const
......
Supports Markdown
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