1 /***************************************************************************
2 * Copyright (C) 2010 by Till Theato (root@ttill.de) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include "tracksconfigdialog.h"
21 #include "kdenlivedoc.h"
23 #include <QTableWidget>
28 TracksDelegate::TracksDelegate(QObject *parent) :
33 QWidget *TracksDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem & /* option */, const QModelIndex & /*index*/) const
35 QComboBox *comboBox = new QComboBox(parent);
36 comboBox->addItem(i18n("Video"));
37 comboBox->addItem(i18n("Audio"));
38 connect(comboBox, SIGNAL(activated(int)), this, SLOT(emitCommitData()));
42 void TracksDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
44 QComboBox *comboBox = qobject_cast<QComboBox *>(editor);
47 const int pos = comboBox->findText(index.model()->data(index).toString(), Qt::MatchExactly);
48 comboBox->setCurrentIndex(pos);
51 void TracksDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
53 QComboBox *comboBox = qobject_cast<QComboBox *>(editor);
56 model->setData(index, comboBox->currentText());
59 void TracksDelegate::emitCommitData()
61 emit commitData(qobject_cast<QWidget *>(sender()));
65 TracksConfigDialog::TracksConfigDialog(KdenliveDoc * doc, int selected, QWidget* parent) :
71 table->setColumnCount(5);
72 table->setHorizontalHeaderLabels(QStringList() << i18n("Name") << i18n("Type") << i18n("Hidden") << i18n("Muted") << i18n("Locked"));
73 table->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
74 table->horizontalHeader()->setResizeMode(1, QHeaderView::Fixed);
75 table->horizontalHeader()->setResizeMode(2, QHeaderView::Fixed);
76 table->horizontalHeader()->setResizeMode(3, QHeaderView::Fixed);
77 table->horizontalHeader()->setResizeMode(4, QHeaderView::Fixed);
79 table->setItemDelegateForColumn(1, new TracksDelegate(this));
81 buttonReset->setIcon(KIcon("document-revert"));
82 buttonReset->setToolTip(i18n("Reset"));
83 connect(buttonReset, SIGNAL(clicked()), this, SLOT(setupOriginal()));
85 buttonAdd->setIcon(KIcon("list-add"));
86 buttonAdd->setToolTip(i18n("Add Track"));
87 buttonAdd->setEnabled(false);
89 buttonDelete->setIcon(KIcon("list-remove"));
90 buttonDelete->setToolTip(i18n("Delete Track"));
91 connect(buttonDelete, SIGNAL(clicked()), this, SLOT(slotDelete()));
93 buttonUp->setIcon(KIcon("arrow-up"));
94 buttonUp->setToolTip(i18n("Move Track upwards"));
95 buttonUp->setEnabled(false);
97 buttonDown->setIcon(KIcon("arrow-down"));
98 buttonDown->setToolTip(i18n("Move Track downwards"));
99 buttonDown->setEnabled(false);
101 setupOriginal(selected);
102 connect(table, SIGNAL(itemChanged(QTableWidgetItem*)), this, SLOT(slotUpdateRow(QTableWidgetItem*)));
105 const QList <TrackInfo> TracksConfigDialog::tracksList()
107 QList <TrackInfo> tracks;
109 for (int i = table->rowCount() - 1; i >= 0; --i) {
110 info.trackName = table->item(i, 0)->text();
111 QTableWidgetItem *item = table->item(i, 1);
112 if (item->text() == i18n("Audio")) {
113 info.type = AudioTrack;
116 info.type = VideoTrack;
117 info.isBlind = (table->item(i, 2)->checkState() == Qt::Checked);
119 info.isMute = (table->item(i, 3)->checkState() == Qt::Checked);
120 info.isLocked = (table->item(i, 4)->checkState() == Qt::Checked);
126 QList <int> TracksConfigDialog::deletedTracks() const
128 return m_deletedRows;
131 void TracksConfigDialog::setupOriginal(int selected)
133 table->setRowCount(m_doc->tracksCount());
137 for (int i = m_doc->tracksCount() - 1; i >= 0; --i) {
138 numbers << QString::number(i);
139 info = m_doc->trackInfoAt(m_doc->tracksCount() - i - 1);
140 table->setItem(i, 0, new QTableWidgetItem(info.trackName));
142 QTableWidgetItem *item1 = new QTableWidgetItem(i18n("Video"));
143 if (info.type == AudioTrack)
144 item1->setText(i18n("Audio"));
145 table->setItem(i, 1, item1);
146 table->openPersistentEditor(item1);
148 QTableWidgetItem *item2 = new QTableWidgetItem("");
149 item2->setFlags(item2->flags() & ~Qt::ItemIsEditable);
150 item2->setCheckState(info.isBlind ? Qt::Checked : Qt::Unchecked);
151 if (info.type == AudioTrack)
152 item2->setFlags(item2->flags() & ~Qt::ItemIsEnabled);
153 table->setItem(i, 2, item2);
155 QTableWidgetItem *item3 = new QTableWidgetItem("");
156 item3->setFlags(item3->flags() & ~Qt::ItemIsEditable);
157 item3->setCheckState(info.isMute ? Qt::Checked : Qt::Unchecked);
158 table->setItem(i, 3, item3);
160 QTableWidgetItem *item4 = new QTableWidgetItem("");
161 item4->setFlags(item4->flags() & ~Qt::ItemIsEditable);
162 item4->setCheckState(info.isLocked ? Qt::Checked : Qt::Unchecked);
163 table->setItem(i, 4, item4);
165 table->setVerticalHeaderLabels(numbers);
167 table->resizeColumnsToContents();
169 table->selectRow(selected);
171 m_deletedRows = QList<int>();
174 void TracksConfigDialog::slotUpdateRow(QTableWidgetItem* item)
176 if (table->column(item) == 1) {
177 QTableWidgetItem *item2 = table->item(table->row(item), 2);
178 if (item->text() == i18n("Audio")) {
179 item2->setFlags(item2->flags() & ~Qt::ItemIsEnabled);
180 item2->setCheckState(Qt::Checked);
182 item2->setFlags(item2->flags() | Qt::ItemIsEnabled);
183 item2->setCheckState(Qt::Unchecked);
188 void TracksConfigDialog::slotDelete()
190 int row = table->currentRow();
192 while (i < m_deletedRows.count()) {
193 if (m_deletedRows.at(i) == row)
195 if (m_deletedRows.at(i) > row)
199 m_deletedRows.insert(i, row);
200 for (i = 0; i < table->columnCount(); ++i) {
201 QTableWidgetItem *item = table->item(row, i);
202 item->setFlags(Qt::NoItemFlags);
203 item->setBackground(palette().dark());
207 #include "tracksconfigdialog.moc"