Make track names optional (now that we have tags: A1,A2,V1,...) and fix

confusion between track position and id in track delete operation
parent bd38a175
......@@ -310,7 +310,7 @@ QDomDocument KdenliveDoc::createEmptyDocument(int videotracks, int audiotracks)
audioTrack.isMute = false;
audioTrack.isBlind = true;
audioTrack.isLocked = false;
audioTrack.trackName = i18n("Audio %1", audiotracks - i);
//audioTrack.trackName = i18n("Audio %1", audiotracks - i);
audioTrack.duration = 0;
audioTrack.effectsList = EffectsList(true);
tracks.append(audioTrack);
......@@ -321,7 +321,7 @@ QDomDocument KdenliveDoc::createEmptyDocument(int videotracks, int audiotracks)
videoTrack.isMute = false;
videoTrack.isBlind = false;
videoTrack.isLocked = false;
videoTrack.trackName = i18n("Video %1", i + 1);
//videoTrack.trackName = i18n("Video %1", i + 1);
videoTrack.duration = 0;
videoTrack.effectsList = EffectsList(true);
tracks.append(videoTrack);
......
......@@ -297,8 +297,7 @@ QVariant TimelineItemModel::data(const QModelIndex &index, int role) const
switch (role) {
case NameRole:
case Qt::DisplayRole: {
QString tName = getTrackById_const(id)->getProperty("kdenlive:track_name").toString();
return tName;
return getTrackById_const(id)->getProperty("kdenlive:track_name").toString();
}
case DurationRole:
// qDebug() << "DATA yielding duration" << m_tractor->get_playtime();
......@@ -390,9 +389,16 @@ void TimelineItemModel::setTrackProperty(int trackId, const QString &name, const
}
}
QVariant TimelineItemModel::getTrackProperty(int tid, const QString &name)
QVariant TimelineItemModel::getTrackProperty(int tid, const QString &name) const
{
return getTrackById(tid)->getProperty(name);
return getTrackById_const(tid)->getProperty(name);
}
const QString TimelineItemModel::getTrackFullName(int tid) const
{
QString tag = getTrackTagById(tid);
QString trackName = getTrackById_const(tid)->getProperty(QStringLiteral("kdenlive:track_name")).toString();
return trackName.isEmpty() ? tag : tag + QStringLiteral(" - ") + trackName;
}
void TimelineItemModel::buildTrackCompositing()
......
......@@ -80,7 +80,8 @@ public:
QModelIndex makeTrackIndexFromID(int trackId) const override;
QModelIndex parent(const QModelIndex &index) const override;
Q_INVOKABLE void setTrackProperty(int tid, const QString &name, const QString &value);
Q_INVOKABLE QVariant getTrackProperty(int tid, const QString &name);
Q_INVOKABLE QVariant getTrackProperty(int tid, const QString &name) const;
const QString getTrackFullName(int tid) const;
void notifyChange(const QModelIndex &topleft, const QModelIndex &bottomright, bool start, bool duration, bool updateThumb) override;
void notifyChange(const QModelIndex &topleft, const QModelIndex &bottomright, const QVector<int> &roles) override;
void buildTrackCompositing();
......
......@@ -41,10 +41,11 @@ TrackDialog::TrackDialog(std::shared_ptr<TimelineItemModel> model, int trackInde
} else {
m_videoCount++;
}
const QString trackName = model->getTrackProperty(tid, QStringLiteral("kdenlive:track_name")).toString();
const QString trackName = model->getTrackFullName(tid);
existingTrackNames << trackName;
comboTracks->addItem(audioTrack ? audioIcon : videoIcon, trackName.isEmpty() ? QString::number(i) : trackName, tid);
// Track index in in MLT, so add + 1 to compensate black track
comboTracks->addItem(audioTrack ? audioIcon : videoIcon, trackName.isEmpty() ? QString::number(i) : trackName, i + 1);
m_positionByIndex.insert(tid, i+1);
}
if (trackIndex > -1) {
int ix = comboTracks->findData(trackIndex);
......@@ -59,29 +60,31 @@ TrackDialog::TrackDialog(std::shared_ptr<TimelineItemModel> model, int trackInde
before_select->setVisible(false);
label->setText(i18n("Delete Track"));
} else {
QString proposedName = i18n("Video %1", trackIndex);
// No default name since we now use tags
/*QString proposedName = i18n("Video %1", trackIndex);
while (existingTrackNames.contains(proposedName)) {
proposedName = i18n("Video %1", ++trackIndex);
}
track_name->setText(proposedName);
track_name->setText(proposedName);*/
}
connect(audio_track, &QRadioButton::toggled, this, &TrackDialog::updateName);
}
void TrackDialog::updateName(bool audioTrack)
int TrackDialog::selectedTrackPosition() const
{
QString proposedName = i18n(audioTrack ? "Audio %1" : "Video %1", audioTrack ? m_audioCount : m_videoCount);
track_name->setText(proposedName);
if (comboTracks->count() > 0) {
int position = m_positionByIndex.value(comboTracks->currentData().toInt());
if (before_select->currentIndex() == 1) {
position--;
}
return position;
}
return -1;
}
int TrackDialog::selectedTrack() const
int TrackDialog::selectedTrackId() const
{
if (comboTracks->count() > 0) {
int ix = comboTracks->currentData().toInt();
if (before_select->currentIndex() == 1) {
ix--;
}
return ix;
return comboTracks->currentData().toInt();
}
return -1;
}
......
......@@ -29,9 +29,13 @@ class TrackDialog : public QDialog, public Ui::AddTrack_UI
public:
explicit TrackDialog(std::shared_ptr<TimelineItemModel> model, int trackIndex = -1, QWidget *parent = nullptr, bool deleteMode = false);
/** @brief: returns the selected position in MLT
*/
int selectedTrackPosition() const;
/** @brief: returns the selected track's trackId
*/
int selectedTrack() const;
int selectedTrackId() const;
/** @brief: returns true if we want to insert an audio track
*/
bool addAudioTrack() const;
......@@ -39,12 +43,10 @@ public:
*/
const QString trackName() const;
private slots:
void updateName(bool audioTrack);
private:
int m_audioCount;
int m_videoCount;
QMap<int, int>m_positionByIndex;
};
#endif
......@@ -223,6 +223,18 @@ Rectangle {
onClicked: {
mouse.accepted = false
}
onEntered: {
if (nameEdit.visible == false && trackName == '') {
console.log('entered, making edit visible')
placeHolder.visible = true
}
}
onExited: {
if (placeHolder.visible == true) {
console.log('entered, making edit INvisible')
placeHolder.visible = false
}
}
}
Label {
text: trackName
......@@ -231,6 +243,16 @@ Rectangle {
anchors.leftMargin: 4
elide: Qt.ElideRight
}
Label {
id: placeHolder
visible: false
enabled: false
text: i18n('Edit track name')
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.leftMargin: 4
elide: Qt.ElideRight
}
TextField {
id: nameEdit
visible: false
......
......@@ -172,12 +172,13 @@ const QString TimelineController::getTrackNameFromMltIndex(int trackPos)
if (trackPos == 0) {
return i18n("Black");
}
return m_model->getTrackById(m_model->getTrackIndexFromPosition(trackPos - 1))->getProperty(QStringLiteral("kdenlive:track_name")).toString();
return m_model->getTrackTagById(m_model->getTrackIndexFromPosition(trackPos - 1));
}
const QString TimelineController::getTrackNameFromIndex(int trackIndex)
{
return m_model->getTrackById(trackIndex)->getProperty(QStringLiteral("kdenlive:track_name")).toString();
QString trackName = m_model->getTrackById(trackIndex)->getProperty(QStringLiteral("kdenlive:track_name")).toString();
return trackName.isEmpty() ? m_model->getTrackTagById(trackIndex) : trackName;
}
QMap<int, QString> TimelineController::getTrackNames(bool videoOnly)
......@@ -187,7 +188,13 @@ QMap<int, QString> TimelineController::getTrackNames(bool videoOnly)
if (videoOnly && m_model->getTrackById(track.first)->getProperty(QStringLiteral("kdenlive:audio_track")).toInt() == 1) {
continue;
}
names[m_model->getTrackMltIndex(track.first)] = m_model->getTrackById(track.first)->getProperty("kdenlive:track_name").toString();
QString trackName = m_model->getTrackById_const(track.first)->getProperty("kdenlive:track_name").toString();
if (trackName.isEmpty()) {
trackName = m_model->getTrackTagById(track.first);
} else {
trackName.prepend(m_model->getTrackTagById(track.first) + QStringLiteral(" - "));
}
names[m_model->getTrackMltIndex(track.first)] = trackName;
}
return names;
}
......@@ -518,11 +525,10 @@ void TimelineController::addTrack(int tid)
if (tid == -1) {
tid = m_activeTrack;
}
QPointer<TrackDialog> d = new TrackDialog(m_model, m_model->getTrackMltIndex(tid), qApp->activeWindow());
QPointer<TrackDialog> d = new TrackDialog(m_model, tid, qApp->activeWindow());
if (d->exec() == QDialog::Accepted) {
int mltIndex = d->selectedTrack();
int newTid;
m_model->requestTrackInsertion(mltIndex, newTid, d->trackName(), d->addAudioTrack());
m_model->requestTrackInsertion(d->selectedTrackPosition(), newTid, d->trackName(), d->addAudioTrack());
}
}
......@@ -531,10 +537,9 @@ void TimelineController::deleteTrack(int tid)
if (tid == -1) {
tid = m_activeTrack;
}
QPointer<TrackDialog> d = new TrackDialog(m_model, m_model->getTrackMltIndex(tid), qApp->activeWindow(), true);
QPointer<TrackDialog> d = new TrackDialog(m_model, tid, qApp->activeWindow(), true);
if (d->exec() == QDialog::Accepted) {
int mltIndex = d->selectedTrack();
m_model->requestTrackDeletion(mltIndex);
m_model->requestTrackDeletion(d->selectedTrackId());
}
}
......
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