integrate track hide/mute to undo system

Ref: T1949
parent 07b44df2
......@@ -3679,11 +3679,6 @@ void CustomTrackView::configTracks(const QList < TrackInfo > &trackInfos)
viewport()->update();
}
void CustomTrackView::slotSwitchTrackAudio(int ix, bool enable)
{
m_timeline->switchTrackAudio(ix, enable);
}
void CustomTrackView::slotSwitchTrackLock(int ix, bool enable, bool applyToAll)
{
QUndoCommand *command = NULL;
......@@ -3776,14 +3771,6 @@ void CustomTrackView::lockTrack(int ix, bool lock, bool requestUpdate)
viewport()->update();
}
void CustomTrackView::slotSwitchTrackVideo(int ix, bool enable)
{
m_timeline->switchTrackVideo(ix, enable);
m_document->renderer()->doRefresh();
//TODO: create undo/redo command for this
setDocumentModified();
}
QList<QGraphicsItem *> CustomTrackView::checkForGroups(const QRectF &rect, bool *ok)
{
// Check there is no group going over several tracks there, or that would result in timeline corruption
......
......@@ -278,8 +278,6 @@ public slots:
void slotAddTransition(ClipItem* clip, ItemInfo transitionInfo, int endTrack, QDomElement transition = QDomElement());
void slotAddTransitionToSelectedClips(QDomElement transition, QList<QGraphicsItem *> itemList = QList<QGraphicsItem *>());
void slotTransitionUpdated(Transition *, QDomElement);
void slotSwitchTrackAudio(int ix, bool enable);
void slotSwitchTrackVideo(int ix, bool enable);
void slotSwitchTrackLock(int ix, bool enable, bool applyToAll = false);
void slotUpdateClip(const QString &clipId, bool reload = true);
......
......@@ -271,6 +271,22 @@ void HeaderTrack::switchLock(bool enable)
emit switchTrackLock(m_parentTrack->index(), enable);
}
void HeaderTrack::setVideoMute(bool mute)
{
m_switchVideo->blockSignals(true);
m_switchVideo->setActive(mute);
m_switchVideo->blockSignals(false);
updateLed();
}
void HeaderTrack::setAudioMute(bool mute)
{
m_switchVideo->blockSignals(true);
m_switchVideo->setActive(mute);
m_switchVideo->blockSignals(false);
updateLed();
}
void HeaderTrack::setLock(bool lock)
{
m_switchLock->blockSignals(true);
......
......@@ -53,6 +53,8 @@ public:
void refreshPalette();
void switchTarget(bool enable);
void updateLed();
void setVideoMute(bool mute);
void setAudioMute(bool mute);
protected:
void mousePressEvent(QMouseEvent * event);
......
......@@ -316,8 +316,8 @@ int Timeline::getTracks() {
if (trackduration > duration) duration = trackduration;
tk->trackHeader->setSelectedIndex(m_trackview->selectedTrack());
connect(tk->trackHeader, &HeaderTrack::switchTrackComposite, this, &Timeline::slotSwitchTrackComposite);
connect(tk->trackHeader, SIGNAL(switchTrackVideo(int,bool)), m_trackview, SLOT(slotSwitchTrackVideo(int,bool)));
connect(tk->trackHeader, SIGNAL(switchTrackAudio(int,bool)), m_trackview, SLOT(slotSwitchTrackAudio(int,bool)));
connect(tk->trackHeader, SIGNAL(switchTrackVideo(int,bool)), this, SLOT(switchTrackVideo(int,bool)));
connect(tk->trackHeader, SIGNAL(switchTrackAudio(int,bool)), this, SLOT(switchTrackAudio(int,bool)));
connect(tk->trackHeader, SIGNAL(switchTrackLock(int,bool)), m_trackview, SLOT(slotSwitchTrackLock(int,bool)));
connect(tk->trackHeader, SIGNAL(selectTrack(int,bool)), m_trackview, SLOT(slotSelectTrack(int,bool)));
connect(tk->trackHeader, SIGNAL(renameTrack(int,QString)), this, SLOT(slotRenameTrack(int,QString)));
......@@ -698,36 +698,52 @@ void Timeline::updateTrackState(int ix, int state)
QScopedPointer<Mlt::Producer> track(m_tractor->track(ix));
currentState = track->get_int("hide");
if (state == currentState) return;
bool processAudio = false;
bool hideAudio = false;
bool processVideo = false;
bool hideVideo = false;
if (state == 0) {
// Show all
if (currentState & 1) {
switchTrackVideo(ix, false);
doSwitchTrackVideo(ix, false);
}
if (currentState & 2) {
switchTrackAudio(ix, false);
doSwitchTrackAudio(ix, false);
}
}
else if (state == 1) {
// Mute video
if (currentState & 2) {
switchTrackAudio(ix, false);
doSwitchTrackAudio(ix, false);
}
switchTrackVideo(ix, true);
doSwitchTrackVideo(ix, true);
}
else if (state == 2) {
// Mute audio
if (currentState & 1) {
switchTrackVideo(ix, false);
doSwitchTrackVideo(ix, false);
}
switchTrackAudio(ix, true);
doSwitchTrackAudio(ix, true);
}
else {
switchTrackVideo(ix, true);
switchTrackAudio(ix, true);
doSwitchTrackVideo(ix, true);
doSwitchTrackAudio(ix, true);
}
}
void Timeline::switchTrackVideo(int ix, bool hide)
{
QUndoCommand *trackState = new ChangeTrackStateCommand(this, ix, false, true, false, hide);
m_doc->commandStack()->push(trackState);
}
void Timeline::switchTrackAudio(int ix, bool hide)
{
QUndoCommand *trackState = new ChangeTrackStateCommand(this, ix, true, false, hide, false);
m_doc->commandStack()->push(trackState);
}
void Timeline::doSwitchTrackVideo(int ix, bool hide)
{
Track* tk = track(ix);
if (tk == NULL) {
......@@ -739,6 +755,7 @@ void Timeline::switchTrackVideo(int ix, bool hide)
// Video is already muted
return;
}
tk->trackHeader->setVideoMute(hide);
int newstate = 0;
if (hide) {
if (state & 2) {
......@@ -759,6 +776,7 @@ void Timeline::switchTrackVideo(int ix, bool hide)
tk->setState(newstate);
invalidateTrack(ix);
refreshTractor();
m_doc->renderer()->doRefresh();
}
void Timeline::slotSwitchTrackComposite(int trackIndex, bool enable)
......@@ -793,7 +811,7 @@ void Timeline::refreshTractor()
m_tractor->refresh();
}
void Timeline::switchTrackAudio(int ix, bool mute)
void Timeline::doSwitchTrackAudio(int ix, bool mute)
{
Track* tk = track(ix);
if (tk == NULL) {
......@@ -805,6 +823,7 @@ void Timeline::switchTrackAudio(int ix, bool mute)
// audio is already muted
return;
}
tk->trackHeader->setAudioMute(mute);
if (mute && state < 2 ) {
// We mute a track with sound
/*if (ix == getLowestNonMutedAudioTrack())*/
......@@ -1822,7 +1841,6 @@ void Timeline::updatePreviewSettings(const QString &profile)
if (profile.isEmpty()) return;
QString params = profile.section(";", 0, 0);
QString ext = profile.section(";", 1, 1);
qDebug()<<" / / /NEW TP: "<<params<<"\nEXR: "<<ext;
if (params != m_doc->getDocumentProperty(QStringLiteral("previewparameters")) || ext != m_doc->getDocumentProperty(QStringLiteral("previewextension"))) {
// Timeline preview params changed, delete all existing previews.
invalidateRange(ItemInfo());
......
......@@ -79,9 +79,9 @@ public:
void lockTrack(int ix, bool lock);
bool isTrackLocked(int ix);
/** @brief Dis / enable video for a track. */
void switchTrackVideo(int ix, bool hide);
void doSwitchTrackVideo(int ix, bool hide);
/** @brief Dis / enable audio for a track. */
void switchTrackAudio(int ix, bool mute);
void doSwitchTrackAudio(int ix, bool mute);
/** @brief Adjust audio transitions depending on tracks muted state. */
void fixAudioMixing();
......@@ -255,6 +255,11 @@ private slots:
void slotUpdateTrackEffectState(int);
/** @brief Toggle use of timeline zone for editing.*/
void slotEnableZone(bool enable);
/** @brief Dis / enable video for a track. */
void switchTrackVideo(int ix, bool hide);
/** @brief Dis / enable audio for a track. */
void switchTrackAudio(int ix, bool mute);
signals:
void mousePosition(int);
......
......@@ -804,3 +804,31 @@ void SplitAudioCommand::redo()
m_view->doSplitAudio(m_pos, m_track, m_destTrack, true);
}
ChangeTrackStateCommand::ChangeTrackStateCommand(Timeline *timeline, const int track, bool changeAudio, bool changeVideo, bool hideAudio, bool hideVideo, QUndoCommand * parent) :
QUndoCommand(parent)
, m_timeline(timeline)
, m_track(track)
, m_audio(changeAudio)
, m_video(changeVideo)
, m_hideAudio(hideAudio)
, m_hideVideo(hideVideo)
{
setText(i18n("Change track state"));
}
// virtual
void ChangeTrackStateCommand::undo()
{
if (m_audio)
m_timeline->doSwitchTrackAudio(m_track, !m_hideAudio);
if (m_video)
m_timeline->doSwitchTrackVideo(m_track, !m_hideVideo);
}
// virtual
void ChangeTrackStateCommand::redo()
{
if (m_audio)
m_timeline->doSwitchTrackAudio(m_track, m_hideAudio);
if (m_video)
m_timeline->doSwitchTrackVideo(m_track, m_hideVideo);
}
......@@ -438,5 +438,20 @@ private:
const int m_destTrack;
};
class ChangeTrackStateCommand : public QUndoCommand
{
public:
ChangeTrackStateCommand(Timeline *timeline, const int track, bool changeAudio, bool changeVideo, bool hideAudio, bool hideVideo, QUndoCommand * parent = 0);
void undo();
void redo();
private:
Timeline *m_timeline;
const int m_track;
bool m_audio;
bool m_video;
bool m_hideAudio;
bool m_hideVideo;
};
#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