trackdialog.cpp 6.16 KB
Newer Older
1
/***************************************************************************
2
 *   Copyright (C) 2017 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
 ***************************************************************************/

#include "trackdialog.h"

#include "kdenlivesettings.h"

#include <QIcon>

26
TrackDialog::TrackDialog(const std::shared_ptr<TimelineItemModel> &model, int trackIndex, QWidget *parent, bool deleteMode, int activeTrackId)
Nicolas Carion's avatar
Nicolas Carion committed
27
    : QDialog(parent)
28
29
30
    , m_trackIndex(trackIndex)
    , m_model(model)
    , m_deleteMode(deleteMode)
31
    , m_activeTrack(activeTrackId)
32
{
33
    setWindowTitle(deleteMode ? i18n("Delete Track(s)") : i18n("Add Track"));
Nicolas Carion's avatar
Nicolas Carion committed
34
    // setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont));
35
    setupUi(this);
36
    if (m_trackIndex > -1 && m_model->isAudioTrack(m_trackIndex)) {
37
38
        audio_track->setChecked(true);
        before_select->setCurrentIndex(1);
39
    }
40
    if (deleteMode) {
41
        tracks_count->setVisible(false);
42
43
44
        track_name->setVisible(false);
        video_track->setVisible(false);
        audio_track->setVisible(false);
45
46
        av_track->setVisible(false);
        arec_track->setVisible(false);
47
48
        name_label->setVisible(false);
        before_select->setVisible(false);
49
50
51
52
53
54
        comboTracks->setVisible(false);
        label->setText(i18n("Select tracks to be deleted :"));
        this->adjustSize();
    }
    else {
        deleteTracks->setVisible(false);
55
    }
56
57
58
59
60
61
62
    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);
    });
63
64
65
66
67
68
69
70
}

void TrackDialog::buildCombo()
{
    QIcon videoIcon = QIcon::fromTheme(QStringLiteral("kdenlive-show-video"));
    QIcon audioIcon = QIcon::fromTheme(QStringLiteral("kdenlive-show-audio"));
    m_positionByIndex.clear();
    comboTracks->clear();
71
    deleteTracks->clear();
72
73
74
75
76
77
    bool audioMode = audio_track->isChecked() || arec_track->isChecked();
    for (int i = m_model->getTracksCount() - 1; i >= 0; i--) {
        int tid = m_model->getTrackIndexFromPosition(i);
        bool audioTrack = m_model->isAudioTrack(tid);
        if (!m_deleteMode && audioMode != audioTrack) {
            continue;
78
        }
79
        const QString trackName = m_model->getTrackFullName(tid);
Pushkar Kukde's avatar
Pushkar Kukde committed
80
        if (m_deleteMode) {
81
82
83
84
85
86
87
88
89
90
91
92
            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);
        }
93
94
        // Track index in in MLT, so add + 1 to compensate black track
        m_positionByIndex.insert(tid, i + 1);
95
    }
96
97
98
99
    if (m_trackIndex > -1) {
        int ix = qMax(0, comboTracks->findData(m_trackIndex));
        comboTracks->setCurrentIndex(ix);
    }
Pushkar Kukde's avatar
Pushkar Kukde committed
100
    if (m_deleteMode) {
101
102
        deleteTracks->setMinimumWidth(deleteTracks->sizeHintForColumn(0));
    }
103
104
}

105
int TrackDialog::selectedTrackPosition() const
106
{
107
    bool audioMode = audio_track->isChecked() || arec_track->isChecked();
108
109
    if (comboTracks->count() > 0) {
        int position = m_positionByIndex.value(comboTracks->currentData().toInt());
110
111
112
113
114
115
        if (audioMode && KdenliveSettings::audiotracksbelow() == 0) {
            // In mixed track modes, indexes are sorted differently so above/under have different meaning
            if (before_select->currentIndex() == 0) {
                position--;
            }
        } else if (before_select->currentIndex() == 1) {
116
117
118
119
            position--;
        }
        return position;
    }
120
    return audioMode ? 0 : -1;
121
122
}

123
int TrackDialog::selectedTrackId() const
124
125
{
    if (comboTracks->count() > 0) {
126
        return comboTracks->currentData().toInt();
127
128
    }
    return -1;
129
130
}

131
132
133
QList<int> TrackDialog::toDeleteTrackIds()
{
    QList<int> todeleteIds;
Pushkar Kukde's avatar
Pushkar Kukde committed
134
    for (int i = deleteTracks->count() - 1; i >= 0; i--)
135
136
    {
        QListWidgetItem *listitem = deleteTracks->item(i);
Pushkar Kukde's avatar
Pushkar Kukde committed
137
        if (listitem->checkState() == Qt::Checked) {
138
139
140
141
142
143
144
            todeleteIds.append(m_idByTrackname[listitem->text()]);
        }
    }
    m_idByTrackname.clear();
    return todeleteIds;
}

145
146
147
148
149
150
151
152
153
154
bool TrackDialog::addAVTrack() const
{
    return av_track->isChecked();
}

bool TrackDialog::addRecTrack() const
{
    return arec_track->isChecked();
}

155
156
bool TrackDialog::addAudioTrack() const
{
157
    return audio_track->isChecked() || arec_track->isChecked();
158
159
160
161
162
}
const QString TrackDialog::trackName() const
{
    return track_name->text();
}
163
164
165
166
167

int TrackDialog::tracksCount() const
{
    return tracks_count->value();
}