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"
28 #include <KColorScheme>
30 #include <QMouseEvent>
36 #include <QDomDocument>
38 HeaderTrack::HeaderTrack(int index, TrackInfo info, int height, QWidget *parent) :
44 setFixedHeight(height);
47 QPalette p = palette();
48 KColorScheme scheme(p.currentColorGroup(), KColorScheme::View, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
49 QColor norm = scheme.shade(scheme.background(KColorScheme::ActiveBackground).color(), KColorScheme::MidShade);
50 p.setColor(QPalette::Button, norm);
53 QColor col = scheme.background().color();
54 QColor col2 = scheme.foreground().color();
55 track_number->setStyleSheet(QString("QLineEdit { background-color: transparent;color: rgb(%4, %5, %6);} 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()).arg(col2.red()).arg(col2.green()).arg(col2.blue()));
57 m_name = info.trackName.isEmpty() ? QString::number(m_index) : info.trackName;
58 track_number->setText(m_name);
59 connect(track_number, SIGNAL(editingFinished()), this, SLOT(slotRenameTrack()));
61 buttonVideo->setChecked(info.isBlind);
62 buttonVideo->setToolTip(i18n("Hide track"));
63 buttonAudio->setChecked(info.isMute);
64 buttonAudio->setToolTip(i18n("Mute track"));
65 buttonLock->setChecked(info.isLocked);
66 buttonLock->setToolTip(i18n("Lock track"));
67 effect_label->setPixmap(KIcon("kdenlive-track_has_effect").pixmap(16, 16));
68 updateEffectLabel(info.effectsList.effectNames());
71 if (m_type == VIDEOTRACK) {
72 setBackgroundRole(QPalette::AlternateBase);
73 setAutoFillBackground(true);
75 buttonVideo->setIcon(KIcon("kdenlive-show-video"));
77 buttonVideo->setIcon(KIcon("kdenlive-hide-video"));
79 buttonVideo->setHidden(true);
82 buttonAudio->setIcon(KIcon("kdenlive-show-audio"));
84 buttonAudio->setIcon(KIcon("kdenlive-hide-audio"));
87 buttonLock->setIcon(KIcon("kdenlive-unlock"));
89 buttonLock->setIcon(KIcon("kdenlive-lock"));
91 connect(buttonVideo, SIGNAL(clicked()), this, SLOT(switchVideo()));
92 connect(buttonAudio, SIGNAL(clicked()), this, SLOT(switchAudio()));
93 connect(buttonLock, SIGNAL(clicked()), this, SLOT(switchLock()));
95 // Don't show track buttons if size is too small
97 buttonVideo->setHidden(true);
98 buttonAudio->setHidden(true);
99 buttonLock->setHidden(true);
103 setContextMenuPolicy(Qt::DefaultContextMenu); //Qt::ActionsContextMenu);
104 QAction *insertAction = new QAction(i18n("Insert Track"), this);
105 m_menu.addAction(insertAction);
106 connect(insertAction, SIGNAL(triggered()), this, SLOT(slotAddTrack()));
108 QAction *removeAction = new QAction(KIcon("edit-delete"), i18n("Delete Track"), this);
109 m_menu.addAction(removeAction);
110 connect(removeAction, SIGNAL(triggered()), this, SLOT(slotDeleteTrack()));
112 QAction *configAction = new QAction(KIcon("configure"), i18n("Configure Track"), this);
113 m_menu.addAction(configAction);
114 connect(configAction, SIGNAL(triggered()), this, SLOT(slotConfigTrack()));
117 /*HeaderTrack::~HeaderTrack()
121 void HeaderTrack::updateEffectLabel(QStringList effects)
123 QColor col = track_number->palette().color(QPalette::Base);
124 if (!effects.isEmpty()) {
125 effect_label->setHidden(false);
126 effect_label->setToolTip(effects.join("/"));
128 effect_label->setHidden(true);
129 effect_label->setToolTip(QString());
134 void HeaderTrack::mousePressEvent(QMouseEvent * event)
136 if (track_number->hasFocus()) {
137 track_number->clearFocus();
140 if (!m_isSelected) emit selectTrack(m_index);
141 emit showTrackEffects(m_index);
142 QWidget::mousePressEvent(event);
146 void HeaderTrack::contextMenuEvent(QContextMenuEvent * event)
148 if (track_number->hasFocus()) {
149 track_number->clearFocus();
152 m_menu.popup(event->globalPos());
155 void HeaderTrack::mouseDoubleClickEvent(QMouseEvent* event)
157 if (track_number->hasFocus()) {
158 track_number->clearFocus();
162 QWidget::mouseDoubleClickEvent(event);
166 void HeaderTrack::dropEvent(QDropEvent * event)
168 const QString effects = QString(event->mimeData()->data("kdenlive/effectslist"));
170 doc.setContent(effects, true);
171 const QDomElement e = doc.documentElement();
172 emit selectTrack(m_index);
173 emit addTrackInfo(e, m_index);
174 /*if (scene() && !scene()->views().isEmpty()) {
176 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
177 if (view) view->slotAddEffect(e, m_info.startPos, track());
182 void HeaderTrack::dragEnterEvent(QDragEnterEvent *event)
184 if (buttonLock->isChecked()) event->setAccepted(false);
185 else event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist"));
188 void HeaderTrack::setSelectedIndex(int ix)
192 setBackgroundRole(QPalette::Button);
193 setAutoFillBackground(true);
194 } else if (m_type != VIDEOTRACK) {
195 m_isSelected = false;
196 setAutoFillBackground(false);
198 m_isSelected = false;
199 setBackgroundRole(QPalette::AlternateBase);
204 void HeaderTrack::adjustSize(int height)
206 // Don't show track buttons if size is too small
207 bool smallTracks = height < 40;
208 if (m_type == VIDEOTRACK)
209 buttonVideo->setHidden(smallTracks);
210 buttonAudio->setHidden(smallTracks);
211 buttonLock->setHidden(smallTracks);
212 setFixedHeight(height);
215 void HeaderTrack::switchVideo()
217 if (buttonVideo->isChecked())
218 buttonVideo->setIcon(KIcon("kdenlive-hide-video"));
220 buttonVideo->setIcon(KIcon("kdenlive-show-video"));
221 emit switchTrackVideo(m_index);
224 void HeaderTrack::switchAudio()
226 if (buttonAudio->isChecked())
227 buttonAudio->setIcon(KIcon("kdenlive-hide-audio"));
229 buttonAudio->setIcon(KIcon("kdenlive-show-audio"));
230 emit switchTrackAudio(m_index);
233 void HeaderTrack::switchLock(bool emitSignal)
235 if (buttonLock->isChecked())
236 buttonLock->setIcon(KIcon("kdenlive-lock"));
238 buttonLock->setIcon(KIcon("kdenlive-unlock"));
240 emit switchTrackLock(m_index);
243 void HeaderTrack::setLock(bool lock)
245 buttonLock->setChecked(lock);
249 void HeaderTrack::slotDeleteTrack()
251 QTimer::singleShot(500, this, SLOT(deleteTrack()));
254 void HeaderTrack::deleteTrack()
256 emit deleteTrack(m_index);
259 void HeaderTrack::slotAddTrack()
261 emit insertTrack(m_index);
264 void HeaderTrack::slotRenameTrack()
266 if (m_name != track_number->text()) emit renameTrack(m_index, track_number->text());
269 void HeaderTrack::slotConfigTrack()
271 emit configTrack(m_index);
275 #include "headertrack.moc"