Allow inserting several tracks in one step.

Related to #382
parent 835ffc33
Pipeline #19881 passed with stage
in 9 minutes and 13 seconds
......@@ -39,7 +39,12 @@ TrackDialog::TrackDialog(const std::shared_ptr<TimelineItemModel> &model, int tr
buildCombo();
connect(audio_track, &QRadioButton::toggled, this, &TrackDialog::buildCombo);
connect(arec_track, &QRadioButton::toggled, this, &TrackDialog::buildCombo);
connect(tracks_count, QOverload<int>::of(&QSpinBox::valueChanged), [this] (int count) {
tracks_count->setSuffix(count > 1 ? i18n(" tracks") : i18n(" track"));
track_name->setEnabled(count == 1);
});
if (deleteMode) {
tracks_count->setVisible(false);
track_name->setVisible(false);
video_track->setVisible(false);
audio_track->setVisible(false);
......@@ -115,3 +120,8 @@ const QString TrackDialog::trackName() const
{
return track_name->text();
}
int TrackDialog::tracksCount() const
{
return tracks_count->value();
}
......@@ -48,6 +48,9 @@ public:
/** @brief: returns the newly created track name
*/
const QString trackName() const;
/** @brief: returns the number of tracks to be inserted
*/
int tracksCount() const;
private:
int m_trackIndex;
......
......@@ -585,32 +585,38 @@ void TimelineController::addTrack(int tid)
}
QPointer<TrackDialog> d = new TrackDialog(m_model, tid, qApp->activeWindow());
if (d->exec() == QDialog::Accepted) {
int newTid;
bool audioRecTrack = d->addRecTrack();
bool addAVTrack = d->addAVTrack();
int tracksCount = d->tracksCount();
Fun undo = []() { return true; };
Fun redo = []() { return true; };
bool result = m_model->requestTrackInsertion(d->selectedTrackPosition(), newTid, d->trackName(), d->addAudioTrack(), undo, redo);
if (result) {
m_model->setTrackProperty(newTid, "kdenlive:timeline_active", QStringLiteral("1"));
if (addAVTrack) {
int newTid2;
int mirrorPos = 0;
int mirrorId = m_model->getMirrorAudioTrackId(newTid);
if (mirrorId > -1) {
mirrorPos = m_model->getTrackMltIndex(mirrorId);
bool result = true;
for (int ix = 0; ix < tracksCount; ++ix) {
int newTid;
result = m_model->requestTrackInsertion(d->selectedTrackPosition(), newTid, d->trackName(), d->addAudioTrack(), undo, redo);
if (result) {
m_model->setTrackProperty(newTid, "kdenlive:timeline_active", QStringLiteral("1"));
if (addAVTrack) {
int newTid2;
int mirrorPos = 0;
int mirrorId = m_model->getMirrorAudioTrackId(newTid);
if (mirrorId > -1) {
mirrorPos = m_model->getTrackMltIndex(mirrorId);
}
result = m_model->requestTrackInsertion(mirrorPos, newTid2, d->trackName(), true, undo, redo);
if (result) {
m_model->setTrackProperty(newTid2, "kdenlive:timeline_active", QStringLiteral("1"));
}
}
result = m_model->requestTrackInsertion(mirrorPos, newTid2, d->trackName(), true, undo, redo);
if (result) {
m_model->setTrackProperty(newTid2, "kdenlive:timeline_active", QStringLiteral("1"));
if (audioRecTrack) {
m_model->setTrackProperty(newTid, "kdenlive:audio_rec", QStringLiteral("1"));
}
}
if (audioRecTrack) {
m_model->setTrackProperty(newTid, "kdenlive:audio_rec", QStringLiteral("1"));
} else {
break;
}
}
if (result) {
pCore->pushUndo(undo, redo, addAVTrack ? i18n("Insert Tracks") : i18n("Insert Track"));
pCore->pushUndo(undo, redo, addAVTrack || tracksCount > 1 ? i18n("Insert Tracks") : i18n("Insert Track"));
} else {
pCore->displayMessage(i18n("Could not insert track"), InformationMessage, 500);
undo();
......
......@@ -6,39 +6,29 @@
<rect>
<x>0</x>
<y>0</y>
<width>496</width>
<height>168</height>
<width>611</width>
<height>194</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Insert track</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="KComboBox" name="before_select">
<item row="2" column="0" colspan="4">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<property name="text">
<string>Above</string>
</property>
<widget class="QLabel" name="name_label">
<property name="text">
<string>Track name</string>
</property>
</widget>
</item>
<item>
<property name="text">
<string>Under</string>
</property>
<widget class="QLineEdit" name="track_name"/>
</item>
</widget>
</layout>
</item>
<item row="0" column="2">
<item row="0" column="3">
<widget class="KComboBox" name="comboTracks"/>
</item>
<item row="1" column="0" colspan="3">
<item row="1" column="0" colspan="4">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QRadioButton" name="video_track">
......@@ -86,17 +76,14 @@
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QLabel" name="name_label">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Track name</string>
<string>Insert</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QLineEdit" name="track_name"/>
</item>
<item row="3" column="1">
<item row="3" column="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
......@@ -109,7 +96,20 @@
</property>
</spacer>
</item>
<item row="3" column="2">
<item row="0" column="1">
<widget class="QSpinBox" name="tracks_count">
<property name="suffix">
<string> track</string>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="value">
<number>1</number>
</property>
</widget>
</item>
<item row="3" column="3">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
......@@ -119,6 +119,20 @@
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="KComboBox" name="before_select">
<item>
<property name="text">
<string>Above</string>
</property>
</item>
<item>
<property name="text">
<string>Under</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
<customwidgets>
......
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