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"
27 #include <KColorScheme>
29 #include <QMouseEvent>
35 #include <QDomDocument>
37 HeaderTrack::HeaderTrack(int index, TrackInfo info, int height, QWidget *parent) :
43 setFixedHeight(height);
45 QColor col = track_number->palette().color(QPalette::Base);
46 track_number->setStyleSheet(QString("QLineEdit { background-color: transparent;} QLineEdit:hover{ background-color: rgb(%1, %2, %3);} QLineEdit:focus { background-color: rgb(%1, %2, %3);}").arg(col.red()).arg(col.green()).arg(col.blue()));
48 m_name = info.trackName.isEmpty() ? QString::number(m_index) : info.trackName;
49 track_number->setText(m_name);
50 connect(track_number, SIGNAL(editingFinished()), this, SLOT(slotRenameTrack()));
52 buttonVideo->setChecked(info.isBlind);
53 buttonVideo->setToolTip(i18n("Hide track"));
54 buttonAudio->setChecked(info.isMute);
55 buttonAudio->setToolTip(i18n("Mute track"));
56 buttonLock->setChecked(info.isLocked);
57 buttonLock->setToolTip(i18n("Lock track"));
58 effect_label->setPixmap(KIcon("kdenlive-track_has_effect").pixmap(16, 16));
59 updateEffectLabel(info.effectsList.effectNames());
62 QPalette p = palette();
63 KColorScheme scheme(p.currentColorGroup(), KColorScheme::Window);
64 p.setColor(QPalette::Button, scheme.background(KColorScheme::ActiveBackground).color().darker(120));
67 if (m_type == VIDEOTRACK) {
68 setBackgroundRole(QPalette::AlternateBase);
69 setAutoFillBackground(true);
71 buttonVideo->setIcon(KIcon("kdenlive-show-video"));
73 buttonVideo->setIcon(KIcon("kdenlive-hide-video"));
75 buttonVideo->setHidden(true);
78 buttonAudio->setIcon(KIcon("kdenlive-show-audio"));
80 buttonAudio->setIcon(KIcon("kdenlive-hide-audio"));
83 buttonLock->setIcon(KIcon("kdenlive-unlock"));
85 buttonLock->setIcon(KIcon("kdenlive-lock"));
87 connect(buttonVideo, SIGNAL(clicked()), this, SLOT(switchVideo()));
88 connect(buttonAudio, SIGNAL(clicked()), this, SLOT(switchAudio()));
89 connect(buttonLock, SIGNAL(clicked()), this, SLOT(switchLock()));
91 // Don't show track buttons if size is too small
93 buttonVideo->setHidden(true);
94 buttonAudio->setHidden(true);
95 buttonLock->setHidden(true);
99 setContextMenuPolicy(Qt::DefaultContextMenu); //Qt::ActionsContextMenu);
100 QAction *insertAction = new QAction(i18n("Insert Track"), this);
101 m_menu.addAction(insertAction);
102 connect(insertAction, SIGNAL(triggered()), this, SLOT(slotAddTrack()));
104 QAction *removeAction = new QAction(KIcon("edit-delete"), i18n("Delete Track"), this);
105 m_menu.addAction(removeAction);
106 connect(removeAction, SIGNAL(triggered()), this, SLOT(slotDeleteTrack()));
108 QAction *configAction = new QAction(KIcon("configure"), i18n("Configure Track"), this);
109 m_menu.addAction(configAction);
110 connect(configAction, SIGNAL(triggered()), this, SLOT(slotConfigTrack()));
113 /*HeaderTrack::~HeaderTrack()
117 void HeaderTrack::updateEffectLabel(QStringList effects)
119 QColor col = track_number->palette().color(QPalette::Base);
120 if (!effects.isEmpty()) {
121 effect_label->setHidden(false);
122 effect_label->setToolTip(effects.join("/"));
124 effect_label->setHidden(true);
125 effect_label->setToolTip(QString());
130 void HeaderTrack::mousePressEvent(QMouseEvent * event)
132 if (track_number->hasFocus()) {
133 track_number->clearFocus();
136 if (!m_isSelected) emit selectTrack(m_index);
137 emit showTrackEffects(m_index);
138 QWidget::mousePressEvent(event);
142 void HeaderTrack::contextMenuEvent(QContextMenuEvent * event)
144 if (track_number->hasFocus()) {
145 track_number->clearFocus();
148 m_menu.popup(event->globalPos());
151 void HeaderTrack::mouseDoubleClickEvent(QMouseEvent* event)
153 if (track_number->hasFocus()) {
154 track_number->clearFocus();
158 QWidget::mouseDoubleClickEvent(event);
162 void HeaderTrack::dropEvent(QDropEvent * event)
164 const QString effects = QString(event->mimeData()->data("kdenlive/effectslist"));
166 doc.setContent(effects, true);
167 const QDomElement e = doc.documentElement();
168 emit selectTrack(m_index);
169 emit addTrackInfo(e, m_index);
170 /*if (scene() && !scene()->views().isEmpty()) {
172 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
173 if (view) view->slotAddEffect(e, m_info.startPos, track());
178 void HeaderTrack::dragEnterEvent(QDragEnterEvent *event)
180 if (buttonLock->isChecked()) event->setAccepted(false);
181 else event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist"));
184 void HeaderTrack::setSelectedIndex(int ix)
188 setBackgroundRole(QPalette::Button);
189 setAutoFillBackground(true);
190 } else if (m_type != VIDEOTRACK) {
191 m_isSelected = false;
192 setAutoFillBackground(false);
194 m_isSelected = false;
195 setBackgroundRole(QPalette::AlternateBase);
200 void HeaderTrack::adjustSize(int height)
202 // Don't show track buttons if size is too small
203 bool smallTracks = height < 40;
204 if (m_type == VIDEOTRACK)
205 buttonVideo->setHidden(smallTracks);
206 buttonAudio->setHidden(smallTracks);
207 buttonLock->setHidden(smallTracks);
208 setFixedHeight(height);
211 void HeaderTrack::switchVideo()
213 if (buttonVideo->isChecked())
214 buttonVideo->setIcon(KIcon("kdenlive-hide-video"));
216 buttonVideo->setIcon(KIcon("kdenlive-show-video"));
217 emit switchTrackVideo(m_index);
220 void HeaderTrack::switchAudio()
222 if (buttonAudio->isChecked())
223 buttonAudio->setIcon(KIcon("kdenlive-hide-audio"));
225 buttonAudio->setIcon(KIcon("kdenlive-show-audio"));
226 emit switchTrackAudio(m_index);
229 void HeaderTrack::switchLock(bool emitSignal)
231 if (buttonLock->isChecked())
232 buttonLock->setIcon(KIcon("kdenlive-lock"));
234 buttonLock->setIcon(KIcon("kdenlive-unlock"));
236 emit switchTrackLock(m_index);
239 void HeaderTrack::setLock(bool lock)
241 buttonLock->setChecked(lock);
245 void HeaderTrack::slotDeleteTrack()
247 QTimer::singleShot(500, this, SLOT(deleteTrack()));
250 void HeaderTrack::deleteTrack()
252 emit deleteTrack(m_index);
255 void HeaderTrack::slotAddTrack()
257 emit insertTrack(m_index);
260 void HeaderTrack::slotRenameTrack()
262 if (m_name != track_number->text()) emit renameTrack(m_index, track_number->text());
265 void HeaderTrack::slotConfigTrack()
267 emit configTrack(m_index);
271 #include "headertrack.moc"