Commit 791e2d06 authored by Pushkar Kukde's avatar Pushkar Kukde Committed by Jean-Baptiste Mardelle

Added multiple track deletion feature

parent 20311cb5
......@@ -2646,7 +2646,8 @@ void MainWindow::slotInsertTrack()
void MainWindow::slotDeleteTrack()
{
pCore->monitorManager()->activateMonitor(Kdenlive::ProjectMonitor);
getCurrentTimeline()->controller()->deleteTrack(-1);
getCurrentTimeline()->controller()->deleteMultipleTracks(-1);
// getCurrentTimeline()->controller()->deleteTrack(-1);
}
void MainWindow::slotSwitchTrackAudioStream()
......
......@@ -23,26 +23,22 @@
#include <QIcon>
TrackDialog::TrackDialog(const std::shared_ptr<TimelineItemModel> &model, int trackIndex, QWidget *parent, bool deleteMode)
#include <QCheckBox>
TrackDialog::TrackDialog(const std::shared_ptr<TimelineItemModel> &model, int trackIndex, QWidget *parent, bool deleteMode, int activeTrackId)
: QDialog(parent)
, m_trackIndex(trackIndex)
, m_model(model)
, m_deleteMode(deleteMode)
, m_activeTrack(activeTrackId)
{
setWindowTitle(deleteMode ? i18n("Delete Track") : i18n("Add Track"));
setWindowTitle(deleteMode ? i18n("Delete Track(s)") : i18n("Add Track"));
// setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont));
setupUi(this);
if (m_trackIndex > -1 && m_model->isAudioTrack(m_trackIndex)) {
audio_track->setChecked(true);
before_select->setCurrentIndex(1);
}
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, [this] (int count) {
tracks_count->setSuffix(i18np(" track", " tracks", count));
track_name->setEnabled(count == 1);
});
if (deleteMode) {
tracks_count->setVisible(false);
track_name->setVisible(false);
......@@ -52,8 +48,20 @@ TrackDialog::TrackDialog(const std::shared_ptr<TimelineItemModel> &model, int tr
arec_track->setVisible(false);
name_label->setVisible(false);
before_select->setVisible(false);
label->setText(i18n("Delete Track"));
comboTracks->setVisible(false);
label->setText(i18n("Select tracks to be deleted :"));
this->adjustSize();
}
else {
deleteTracks->setVisible(false);
}
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, [this] (int count) {
tracks_count->setSuffix(i18np(" track", " tracks", count));
track_name->setEnabled(count == 1);
});
}
void TrackDialog::buildCombo()
......@@ -62,6 +70,7 @@ void TrackDialog::buildCombo()
QIcon audioIcon = QIcon::fromTheme(QStringLiteral("kdenlive-show-audio"));
m_positionByIndex.clear();
comboTracks->clear();
deleteTracks->clear();
bool audioMode = audio_track->isChecked() || arec_track->isChecked();
for (int i = m_model->getTracksCount() - 1; i >= 0; i--) {
int tid = m_model->getTrackIndexFromPosition(i);
......@@ -70,7 +79,19 @@ void TrackDialog::buildCombo()
continue;
}
const QString trackName = m_model->getTrackFullName(tid);
comboTracks->addItem(audioTrack ? audioIcon : videoIcon, trackName.isEmpty() ? QString::number(i) : trackName, tid);
if(m_deleteMode) {
QListWidgetItem *track = new QListWidgetItem(audioTrack ? audioIcon : videoIcon,trackName);
m_idByTrackname.insert(trackName,tid);
track->setFlags(track->flags() | Qt::ItemIsUserCheckable);
track->setCheckState(Qt::Unchecked);
if(m_activeTrack == tid) {
track->setCheckState(Qt::Checked);
}
deleteTracks->addItem(track);
}
else {
comboTracks->addItem(audioTrack ? audioIcon : videoIcon, trackName.isEmpty() ? QString::number(i) : trackName, tid);
}
// Track index in in MLT, so add + 1 to compensate black track
m_positionByIndex.insert(tid, i + 1);
}
......@@ -78,7 +99,9 @@ void TrackDialog::buildCombo()
int ix = qMax(0, comboTracks->findData(m_trackIndex));
comboTracks->setCurrentIndex(ix);
}
if(m_deleteMode) {
deleteTracks->setMinimumWidth(deleteTracks->sizeHintForColumn(0));
}
}
int TrackDialog::selectedTrackPosition() const
......@@ -107,6 +130,20 @@ int TrackDialog::selectedTrackId() const
return -1;
}
QList<int> TrackDialog::toDeleteTrackIds()
{
QList<int> todeleteIds;
for(int i = deleteTracks->count() - 1; i >= 0; i--)
{
QListWidgetItem *listitem = deleteTracks->item(i);
if(listitem->checkState() == Qt::Checked) {
todeleteIds.append(m_idByTrackname[listitem->text()]);
}
}
m_idByTrackname.clear();
return todeleteIds;
}
bool TrackDialog::addAVTrack() const
{
return av_track->isChecked();
......
......@@ -28,7 +28,7 @@ class TrackDialog : public QDialog, public Ui::AddTrack_UI
Q_OBJECT
public:
explicit TrackDialog(const std::shared_ptr<TimelineItemModel> &model, int trackIndex = -1, QWidget *parent = nullptr, bool deleteMode = false);
explicit TrackDialog(const std::shared_ptr<TimelineItemModel> &model, int trackIndex = -1, QWidget *parent = nullptr, bool deleteMode = false, int activeTracks = -1);
/** @brief: returns the selected position in MLT
*/
int selectedTrackPosition() const;
......@@ -48,6 +48,9 @@ public:
/** @brief: returns the newly created track name
*/
const QString trackName() const;
/** @brief: returns all the selected ids
*/
QList<int> toDeleteTrackIds();
/** @brief: returns the number of tracks to be inserted
*/
int tracksCount() const;
......@@ -56,7 +59,9 @@ private:
int m_trackIndex;
std::shared_ptr<TimelineItemModel> m_model;
bool m_deleteMode;
int m_activeTrack;
QMap<int, int> m_positionByIndex;
QMap<QString,int> m_idByTrackname;
private slots:
/** @brief: Fill track list combo
......
......@@ -647,22 +647,23 @@ void TimelineController::addTrack(int tid)
}
}
void TimelineController::deleteTrack(int tid)
void TimelineController::deleteMultipleTracks(int tid)
{
QPointer<TrackDialog> d = new TrackDialog(m_model, tid, qApp->activeWindow(), true,m_activeTrack);
if (tid == -1) {
tid = m_activeTrack;
}
QPointer<TrackDialog> d = new TrackDialog(m_model, tid, qApp->activeWindow(), true);
if (d->exec() == QDialog::Accepted) {
int selectedTrackIx = d->selectedTrackId();
m_model->requestTrackDeletion(selectedTrackIx);
if (m_activeTrack == -1) {
setActiveTrack(m_model->getTrackIndexFromPosition(m_model->getTracksCount() - 1));
QList<int> allIds = d->toDeleteTrackIds();
for(int selectedTrackIx : allIds) {
m_model->requestTrackDeletion(selectedTrackIx);
if (m_activeTrack == -1) {
setActiveTrack(m_model->getTrackIndexFromPosition(m_model->getTracksCount() - 1));
}
}
}
}
void TimelineController::switchTrackRecord(int tid)
{
if (tid == -1) {
......
......@@ -259,9 +259,9 @@ public:
/* @brief Insert a timeline track
*/
Q_INVOKABLE void addTrack(int tid);
/* @brief Remove a timeline track
/* @brief Remove multiple(or single) timeline tracks
*/
Q_INVOKABLE void deleteTrack(int tid);
Q_INVOKABLE void deleteMultipleTracks(int tid);
/* @brief Show / hide audio rec controls in active track
*/
void switchTrackRecord(int tid = -1);
......
......@@ -7,11 +7,38 @@
<x>0</x>
<y>0</y>
<width>611</width>
<height>194</height>
<height>215</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0" colspan="4">
<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>
<item row="4" column="3">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="KComboBox" name="comboTracks"/>
</item>
<item row="3" column="0" colspan="4">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="name_label">
......@@ -25,10 +52,43 @@
</item>
</layout>
</item>
<item row="0" column="3">
<widget class="KComboBox" name="comboTracks"/>
<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="1" column="0" colspan="4">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Insert</string>
</property>
</widget>
</item>
<item row="4" column="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="1" colspan="2" alignment="Qt::AlignVCenter">
<widget class="QListWidget" name="deleteTracks"/>
</item>
<item row="2" column="0" colspan="4">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QRadioButton" name="video_track">
......@@ -76,63 +136,6 @@
</item>
</layout>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Insert</string>
</property>
</widget>
</item>
<item row="3" column="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
<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>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</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