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 if (!effects.isEmpty()) {
124 effect_label->setHidden(false);
125 effect_label->setToolTip(effects.join("/"));
127 effect_label->setHidden(true);
128 effect_label->setToolTip(QString());
133 void HeaderTrack::mousePressEvent(QMouseEvent * event)
135 if (track_number->hasFocus()) {
136 track_number->clearFocus();
139 if (!m_isSelected) emit selectTrack(m_index);
140 emit showTrackEffects(m_index);
141 QWidget::mousePressEvent(event);
145 void HeaderTrack::contextMenuEvent(QContextMenuEvent * event)
147 if (track_number->hasFocus()) {
148 track_number->clearFocus();
151 m_menu.popup(event->globalPos());
154 void HeaderTrack::mouseDoubleClickEvent(QMouseEvent* event)
156 if (track_number->hasFocus()) {
157 track_number->clearFocus();
161 QWidget::mouseDoubleClickEvent(event);
165 void HeaderTrack::dropEvent(QDropEvent * event)
167 const QString effects = QString::fromUtf8(event->mimeData()->data("kdenlive/effectslist"));
169 doc.setContent(effects, true);
170 const QDomElement e = doc.documentElement();
171 emit selectTrack(m_index);
172 emit addTrackInfo(e, m_index);
173 /*if (scene() && !scene()->views().isEmpty()) {
175 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
176 if (view) view->slotAddEffect(e, m_info.startPos, track());
181 void HeaderTrack::dragEnterEvent(QDragEnterEvent *event)
183 if (buttonLock->isChecked()) event->setAccepted(false);
184 else event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist"));
187 void HeaderTrack::setSelectedIndex(int ix)
191 setBackgroundRole(QPalette::Button);
192 setAutoFillBackground(true);
193 } else if (m_type != VIDEOTRACK) {
194 m_isSelected = false;
195 setAutoFillBackground(false);
197 m_isSelected = false;
198 setBackgroundRole(QPalette::AlternateBase);
203 void HeaderTrack::adjustSize(int height)
205 // Don't show track buttons if size is too small
206 bool smallTracks = height < 40;
207 if (m_type == VIDEOTRACK)
208 buttonVideo->setHidden(smallTracks);
209 buttonAudio->setHidden(smallTracks);
210 buttonLock->setHidden(smallTracks);
211 setFixedHeight(height);
214 void HeaderTrack::switchVideo()
216 if (buttonVideo->isChecked())
217 buttonVideo->setIcon(KIcon("kdenlive-hide-video"));
219 buttonVideo->setIcon(KIcon("kdenlive-show-video"));
220 emit switchTrackVideo(m_index);
223 void HeaderTrack::switchAudio()
225 if (buttonAudio->isChecked())
226 buttonAudio->setIcon(KIcon("kdenlive-hide-audio"));
228 buttonAudio->setIcon(KIcon("kdenlive-show-audio"));
229 emit switchTrackAudio(m_index);
232 void HeaderTrack::switchLock(bool emitSignal)
234 if (buttonLock->isChecked())
235 buttonLock->setIcon(KIcon("kdenlive-lock"));
237 buttonLock->setIcon(KIcon("kdenlive-unlock"));
239 emit switchTrackLock(m_index);
242 void HeaderTrack::setLock(bool lock)
244 buttonLock->setChecked(lock);
248 void HeaderTrack::slotDeleteTrack()
250 QTimer::singleShot(500, this, SLOT(deleteTrack()));
253 void HeaderTrack::deleteTrack()
255 emit deleteTrack(m_index);
258 void HeaderTrack::slotAddTrack()
260 emit insertTrack(m_index);
263 void HeaderTrack::slotRenameTrack()
265 if (m_name != track_number->text()) emit renameTrack(m_index, track_number->text());
268 void HeaderTrack::slotConfigTrack()
270 emit configTrack(m_index);
274 #include "headertrack.moc"