Commit 9b0aa198 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Hidden tracks should not be considered when calculating project duration

Related to #1439
parent a33735ea
......@@ -520,24 +520,6 @@ void TimelineItemModel::setTrackName(int trackId, const QString &text)
PUSH_UNDO(undo_lambda, redo_lambda, i18n("Rename Track"));
}
void TimelineItemModel::hideTrack(int trackId, bool hide)
{
QWriteLocker locker(&m_lock);
bool isAudio = isAudioTrack(trackId);
QString state = hide ? (isAudio ? "1" : "2") : "3";
QString previousState = getTrackProperty(trackId, QStringLiteral("hide")).toString();
Fun undo_lambda = [this, trackId, previousState]() {
setTrackProperty(trackId, QStringLiteral("hide"), previousState);
return true;
};
Fun redo_lambda = [this, trackId, state]() {
setTrackProperty(trackId, QStringLiteral("hide"), state);
return true;
};
redo_lambda();
PUSH_UNDO(undo_lambda, redo_lambda, state == QLatin1String("3") ? i18n("Hide Track") : i18n("Enable Track"));
}
void TimelineItemModel::setTrackProperty(int trackId, const QString &name, const QString &value)
{
std::shared_ptr<TrackModel> track = getTrackById(trackId);
......
......@@ -76,7 +76,6 @@ public:
@param text is the new track name.
*/
Q_INVOKABLE void setTrackName(int trackId, const QString &text);
Q_INVOKABLE void hideTrack(int trackId, bool hide);
/** @brief returns the lower video track index in timeline.
**/
int getFirstVideoTrackIndex() const;
......
......@@ -4576,7 +4576,16 @@ void TimelineModel::updateDuration()
int TimelineModel::duration() const
{
return m_tractor->get_playtime() - TimelineModel::seekDuration;
int duration = 0;
auto it = m_allTracks.cbegin();
while (it != m_allTracks.cend()) {
if (!(*it)->isHidden()) {
int trackDuration = (*it)->getTrackService()->get_playtime();
duration = qMax(duration, trackDuration);
}
++it;
}
return duration;
}
std::unordered_set<int> TimelineModel::getGroupElements(int clipId)
......
......@@ -452,7 +452,7 @@ Rectangle {
}
width: root.collapsedHeight
height: root.collapsedHeight
onClicked: controller.hideTrack(trackId, isDisabled)
onClicked: timeline.hideTrack(trackId, isDisabled)
ToolTip {
visible: muteButton.hovered
font: miniFont
......
......@@ -277,6 +277,25 @@ void TimelineController::checkDuration()
}
}
void TimelineController::hideTrack(int trackId, bool hide)
{
bool isAudio = m_model->isAudioTrack(trackId);
QString state = hide ? (isAudio ? "1" : "2") : "3";
QString previousState = m_model->getTrackProperty(trackId, QStringLiteral("hide")).toString();
Fun undo_lambda = [this, trackId, previousState]() {
m_model->setTrackProperty(trackId, QStringLiteral("hide"), previousState);
checkDuration();
return true;
};
Fun redo_lambda = [this, trackId, state]() {
m_model->setTrackProperty(trackId, QStringLiteral("hide"), state);
checkDuration();
return true;
};
redo_lambda();
pCore->pushUndo(undo_lambda, redo_lambda, state == QLatin1String("3") ? i18n("Hide Track") : i18n("Enable Track"));
}
int TimelineController::selectedTrack() const
{
std::unordered_set<int> sel = m_model->getCurrentSelection();
......@@ -3314,7 +3333,7 @@ void TimelineController::switchTrackDisabled()
} else {
bool isAudio = m_model->getTrackById_const(m_activeTrack)->isAudioTrack();
bool enabled = isAudio ? m_model->getTrackById_const(m_activeTrack)->isMute() : m_model->getTrackById_const(m_activeTrack)->isHidden();
m_model->hideTrack(m_activeTrack, enabled);
hideTrack(m_activeTrack, enabled);
}
}
......
......@@ -349,6 +349,9 @@ public:
Q_INVOKABLE int headerWidth() const;
Q_INVOKABLE void setHeaderWidth(int width);
/** @brief Hide / show a timeline track
*/
Q_INVOKABLE void hideTrack(int trackId, bool hide);
/** @brief Seek to next snap point
*/
......
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