1 /***************************************************************************
2 * Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
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 ***************************************************************************/
21 #include "headertrack.h"
22 #include "effectslist.h"
23 #include "kdenlivesettings.h"
26 #include <KLocalizedString>
29 #include <QMouseEvent>
34 #include <QDomDocument>
36 HeaderTrack::HeaderTrack(int index, TrackInfo info, int height, const QList <QAction *> &actions, QWidget *parent) :
42 setFixedHeight(height);
45 m_name = info.trackName.isEmpty() ? QString::number(m_index) : info.trackName;
46 track_number->setText(m_name);
47 connect(track_number, SIGNAL(editingFinished()), this, SLOT(slotRenameTrack()));
49 buttonVideo->setChecked(info.isBlind);
50 buttonVideo->setToolTip(i18n("Hide track"));
51 buttonAudio->setChecked(info.isMute);
52 buttonAudio->setToolTip(i18n("Mute track"));
53 buttonLock->setChecked(info.isLocked);
54 buttonLock->setToolTip(i18n("Lock track"));
55 effect_label->setPixmap(KIcon("kdenlive-track_has_effect").pixmap(16, 16));
56 updateEffectLabel(info.effectsList.effectNames());
59 if (m_type == VIDEOTRACK) {
60 setBackgroundRole(QPalette::AlternateBase);
61 setAutoFillBackground(true);
63 buttonVideo->setIcon(KIcon("kdenlive-show-video"));
65 buttonVideo->setIcon(KIcon("kdenlive-hide-video"));
67 buttonVideo->setHidden(true);
70 buttonAudio->setIcon(KIcon("kdenlive-show-audio"));
72 buttonAudio->setIcon(KIcon("kdenlive-hide-audio"));
75 buttonLock->setIcon(KIcon("kdenlive-unlock"));
77 buttonLock->setIcon(KIcon("kdenlive-lock"));
79 connect(buttonVideo, SIGNAL(clicked()), this, SLOT(switchVideo()));
80 connect(buttonAudio, SIGNAL(clicked()), this, SLOT(switchAudio()));
81 connect(buttonLock, SIGNAL(clicked()), this, SLOT(switchLock()));
83 // Don't show track buttons if size is too small
85 buttonVideo->setHidden(true);
86 buttonAudio->setHidden(true);
87 buttonLock->setHidden(true);
91 setContextMenuPolicy(Qt::ActionsContextMenu);
95 /*HeaderTrack::~HeaderTrack()
99 void HeaderTrack::updateEffectLabel(const QStringList &effects)
101 if (!effects.isEmpty()) {
102 effect_label->setHidden(false);
103 effect_label->setToolTip(effects.join("/"));
105 effect_label->setHidden(true);
106 effect_label->setToolTip(QString());
111 void HeaderTrack::mousePressEvent(QMouseEvent * event)
113 if (track_number->hasFocus()) {
114 track_number->clearFocus();
117 if (!m_isSelected) emit selectTrack(m_index);
118 emit showTrackEffects(m_index);
119 QWidget::mousePressEvent(event);
122 void HeaderTrack::mouseDoubleClickEvent(QMouseEvent* event)
124 if (track_number->hasFocus()) {
125 track_number->clearFocus();
128 emit configTrack(m_index);
129 QWidget::mouseDoubleClickEvent(event);
133 void HeaderTrack::dropEvent(QDropEvent * event)
135 const QString effects = QString::fromUtf8(event->mimeData()->data("kdenlive/effectslist"));
137 doc.setContent(effects, true);
138 QDomElement e = doc.documentElement();
139 if (e.tagName() == "effectgroup") {
140 // dropped an effect group
141 QDomNodeList effectlist = e.elementsByTagName("effect");
142 for (int i = 0; i < effectlist.count(); ++i) {
143 effectlist.at(i).toElement().removeAttribute("kdenlive_ix");
146 // single effect dropped
147 e.removeAttribute("kdenlive_ix");
149 emit selectTrack(m_index);
150 emit addTrackEffect(e, m_index);
151 /*if (scene() && !scene()->views().isEmpty()) {
153 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
154 if (view) view->slotAddEffect(e, m_info.startPos, track());
159 void HeaderTrack::dragEnterEvent(QDragEnterEvent *event)
161 if (buttonLock->isChecked()) {
162 event->setAccepted(false);
164 if (event->mimeData()->hasFormat("kdenlive/effectslist")) {
165 const QString effects = QString::fromUtf8(event->mimeData()->data("kdenlive/effectslist"));
167 doc.setContent(effects, true);
168 if (doc.documentElement().attribute("id") != "speed") {
169 event->setAccepted(true);
175 void HeaderTrack::setSelectedIndex(int ix)
179 setBackgroundRole(QPalette::Button);
180 setAutoFillBackground(true);
181 } else if (m_type != VIDEOTRACK) {
182 m_isSelected = false;
183 setAutoFillBackground(false);
185 m_isSelected = false;
186 setBackgroundRole(QPalette::AlternateBase);
191 void HeaderTrack::adjustSize(int height)
193 // Don't show track buttons if size is too small
194 bool smallTracks = height < 40;
195 if (m_type == VIDEOTRACK)
196 buttonVideo->setHidden(smallTracks);
197 buttonAudio->setHidden(smallTracks);
198 buttonLock->setHidden(smallTracks);
199 setFixedHeight(height);
202 void HeaderTrack::switchVideo()
204 if (buttonVideo->isChecked())
205 buttonVideo->setIcon(KIcon("kdenlive-hide-video"));
207 buttonVideo->setIcon(KIcon("kdenlive-show-video"));
208 emit switchTrackVideo(m_index);
211 void HeaderTrack::switchAudio()
213 if (buttonAudio->isChecked())
214 buttonAudio->setIcon(KIcon("kdenlive-hide-audio"));
216 buttonAudio->setIcon(KIcon("kdenlive-show-audio"));
217 emit switchTrackAudio(m_index);
220 void HeaderTrack::switchLock(bool emitSignal)
222 if (buttonLock->isChecked())
223 buttonLock->setIcon(KIcon("kdenlive-lock"));
225 buttonLock->setIcon(KIcon("kdenlive-unlock"));
227 emit switchTrackLock(m_index);
230 void HeaderTrack::setLock(bool lock)
232 buttonLock->setChecked(lock);
236 void HeaderTrack::slotDeleteTrack()
238 QTimer::singleShot(500, this, SLOT(deleteTrack()));
241 void HeaderTrack::slotRenameTrack()
243 if (m_name != track_number->text()) emit renameTrack(m_index, track_number->text());
248 #include "headertrack.moc"