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, 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::DefaultContextMenu); //Qt::ActionsContextMenu);
92 QAction *insertAction = new QAction(i18n("Insert Track"), this);
93 m_menu.addAction(insertAction);
94 connect(insertAction, SIGNAL(triggered()), this, SLOT(slotAddTrack()));
96 QAction *removeAction = new QAction(KIcon("edit-delete"), i18n("Delete Track"), this);
97 m_menu.addAction(removeAction);
98 connect(removeAction, SIGNAL(triggered()), this, SLOT(slotDeleteTrack()));
100 QAction *configAction = new QAction(KIcon("configure"), i18n("Configure Track"), this);
101 m_menu.addAction(configAction);
102 connect(configAction, SIGNAL(triggered()), this, SLOT(slotConfigTrack()));
105 /*HeaderTrack::~HeaderTrack()
109 void HeaderTrack::updateEffectLabel(QStringList effects)
111 if (!effects.isEmpty()) {
112 effect_label->setHidden(false);
113 effect_label->setToolTip(effects.join("/"));
115 effect_label->setHidden(true);
116 effect_label->setToolTip(QString());
121 void HeaderTrack::mousePressEvent(QMouseEvent * event)
123 if (track_number->hasFocus()) {
124 track_number->clearFocus();
127 if (!m_isSelected) emit selectTrack(m_index);
128 emit showTrackEffects(m_index);
129 QWidget::mousePressEvent(event);
133 void HeaderTrack::contextMenuEvent(QContextMenuEvent * event)
135 if (track_number->hasFocus()) {
136 track_number->clearFocus();
139 m_menu.popup(event->globalPos());
142 void HeaderTrack::mouseDoubleClickEvent(QMouseEvent* event)
144 if (track_number->hasFocus()) {
145 track_number->clearFocus();
149 QWidget::mouseDoubleClickEvent(event);
153 void HeaderTrack::dropEvent(QDropEvent * event)
155 const QString effects = QString::fromUtf8(event->mimeData()->data("kdenlive/effectslist"));
157 doc.setContent(effects, true);
158 const QDomElement e = doc.documentElement();
159 emit selectTrack(m_index);
160 emit addTrackInfo(e, m_index);
161 /*if (scene() && !scene()->views().isEmpty()) {
163 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
164 if (view) view->slotAddEffect(e, m_info.startPos, track());
169 void HeaderTrack::dragEnterEvent(QDragEnterEvent *event)
171 if (buttonLock->isChecked()) {
172 event->setAccepted(false);
174 if (event->mimeData()->hasFormat("kdenlive/effectslist")) {
175 const QString effects = QString::fromUtf8(event->mimeData()->data("kdenlive/effectslist"));
177 doc.setContent(effects, true);
178 if (doc.documentElement().attribute("id") != "speed") {
179 event->setAccepted(true);
185 void HeaderTrack::setSelectedIndex(int ix)
189 setBackgroundRole(QPalette::Button);
190 setAutoFillBackground(true);
191 } else if (m_type != VIDEOTRACK) {
192 m_isSelected = false;
193 setAutoFillBackground(false);
195 m_isSelected = false;
196 setBackgroundRole(QPalette::AlternateBase);
201 void HeaderTrack::adjustSize(int height)
203 // Don't show track buttons if size is too small
204 bool smallTracks = height < 40;
205 if (m_type == VIDEOTRACK)
206 buttonVideo->setHidden(smallTracks);
207 buttonAudio->setHidden(smallTracks);
208 buttonLock->setHidden(smallTracks);
209 setFixedHeight(height);
212 void HeaderTrack::switchVideo()
214 if (buttonVideo->isChecked())
215 buttonVideo->setIcon(KIcon("kdenlive-hide-video"));
217 buttonVideo->setIcon(KIcon("kdenlive-show-video"));
218 emit switchTrackVideo(m_index);
221 void HeaderTrack::switchAudio()
223 if (buttonAudio->isChecked())
224 buttonAudio->setIcon(KIcon("kdenlive-hide-audio"));
226 buttonAudio->setIcon(KIcon("kdenlive-show-audio"));
227 emit switchTrackAudio(m_index);
230 void HeaderTrack::switchLock(bool emitSignal)
232 if (buttonLock->isChecked())
233 buttonLock->setIcon(KIcon("kdenlive-lock"));
235 buttonLock->setIcon(KIcon("kdenlive-unlock"));
237 emit switchTrackLock(m_index);
240 void HeaderTrack::setLock(bool lock)
242 buttonLock->setChecked(lock);
246 void HeaderTrack::slotDeleteTrack()
248 QTimer::singleShot(500, this, SLOT(deleteTrack()));
251 void HeaderTrack::deleteTrack()
253 emit deleteTrack(m_index);
256 void HeaderTrack::slotAddTrack()
258 emit insertTrack(m_index);
261 void HeaderTrack::slotRenameTrack()
263 if (m_name != track_number->text()) emit renameTrack(m_index, track_number->text());
266 void HeaderTrack::slotConfigTrack()
268 emit configTrack(m_index);
272 #include "headertrack.moc"