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"
29 #include <QMouseEvent>
34 #include <QDomDocument>
36 HeaderTrack::HeaderTrack(int index, TrackInfo info, int height, 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(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 const QDomElement e = doc.documentElement();
139 emit selectTrack(m_index);
140 emit addTrackInfo(e, m_index);
141 /*if (scene() && !scene()->views().isEmpty()) {
143 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
144 if (view) view->slotAddEffect(e, m_info.startPos, track());
149 void HeaderTrack::dragEnterEvent(QDragEnterEvent *event)
151 if (buttonLock->isChecked()) {
152 event->setAccepted(false);
154 if (event->mimeData()->hasFormat("kdenlive/effectslist")) {
155 const QString effects = QString::fromUtf8(event->mimeData()->data("kdenlive/effectslist"));
157 doc.setContent(effects, true);
158 if (doc.documentElement().attribute("id") != "speed") {
159 event->setAccepted(true);
165 void HeaderTrack::setSelectedIndex(int ix)
169 setBackgroundRole(QPalette::Button);
170 setAutoFillBackground(true);
171 } else if (m_type != VIDEOTRACK) {
172 m_isSelected = false;
173 setAutoFillBackground(false);
175 m_isSelected = false;
176 setBackgroundRole(QPalette::AlternateBase);
181 void HeaderTrack::adjustSize(int height)
183 // Don't show track buttons if size is too small
184 bool smallTracks = height < 40;
185 if (m_type == VIDEOTRACK)
186 buttonVideo->setHidden(smallTracks);
187 buttonAudio->setHidden(smallTracks);
188 buttonLock->setHidden(smallTracks);
189 setFixedHeight(height);
192 void HeaderTrack::switchVideo()
194 if (buttonVideo->isChecked())
195 buttonVideo->setIcon(KIcon("kdenlive-hide-video"));
197 buttonVideo->setIcon(KIcon("kdenlive-show-video"));
198 emit switchTrackVideo(m_index);
201 void HeaderTrack::switchAudio()
203 if (buttonAudio->isChecked())
204 buttonAudio->setIcon(KIcon("kdenlive-hide-audio"));
206 buttonAudio->setIcon(KIcon("kdenlive-show-audio"));
207 emit switchTrackAudio(m_index);
210 void HeaderTrack::switchLock(bool emitSignal)
212 if (buttonLock->isChecked())
213 buttonLock->setIcon(KIcon("kdenlive-lock"));
215 buttonLock->setIcon(KIcon("kdenlive-unlock"));
217 emit switchTrackLock(m_index);
220 void HeaderTrack::setLock(bool lock)
222 buttonLock->setChecked(lock);
226 void HeaderTrack::slotDeleteTrack()
228 QTimer::singleShot(500, this, SLOT(deleteTrack()));
231 void HeaderTrack::slotRenameTrack()
233 if (m_name != track_number->text()) emit renameTrack(m_index, track_number->text());
238 #include "headertrack.moc"