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"
26 #include <KColorScheme>
28 #include <QMouseEvent>
34 #include <QDomDocument>
36 HeaderTrack::HeaderTrack(int index, TrackInfo info, int height, QWidget *parent) :
42 setFixedHeight(height);
44 QColor col = track_number->palette().color(QPalette::Base);
45 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()));
47 m_name = info.trackName.isEmpty() ? QString::number(m_index) : info.trackName;
48 track_number->setText(m_name);
49 connect(track_number, SIGNAL(editingFinished()), this, SLOT(slotRenameTrack()));
51 buttonVideo->setChecked(info.isBlind);
52 buttonVideo->setToolTip(i18n("Hide track"));
53 buttonAudio->setChecked(info.isMute);
54 buttonAudio->setToolTip(i18n("Mute track"));
55 buttonLock->setChecked(info.isLocked);
56 buttonLock->setToolTip(i18n("Lock track"));
60 QPalette p = palette();
61 KColorScheme scheme(p.currentColorGroup(), KColorScheme::Window);
62 p.setColor(QPalette::Button, scheme.background(KColorScheme::ActiveBackground).color().darker(120));
65 if (m_type == VIDEOTRACK) {
66 setBackgroundRole(QPalette::AlternateBase);
67 setAutoFillBackground(true);
69 buttonVideo->setIcon(KIcon("kdenlive-show-video"));
71 buttonVideo->setIcon(KIcon("kdenlive-hide-video"));
73 buttonVideo->setHidden(true);
76 buttonAudio->setIcon(KIcon("kdenlive-show-audio"));
78 buttonAudio->setIcon(KIcon("kdenlive-hide-audio"));
81 buttonLock->setIcon(KIcon("kdenlive-unlock"));
83 buttonLock->setIcon(KIcon("kdenlive-lock"));
85 connect(buttonVideo, SIGNAL(clicked()), this, SLOT(switchVideo()));
86 connect(buttonAudio, SIGNAL(clicked()), this, SLOT(switchAudio()));
87 connect(buttonLock, SIGNAL(clicked()), this, SLOT(switchLock()));
89 // Don't show track buttons if size is too small
91 buttonVideo->setHidden(true);
92 buttonAudio->setHidden(true);
93 buttonLock->setHidden(true);
97 setContextMenuPolicy(Qt::DefaultContextMenu); //Qt::ActionsContextMenu);
98 QAction *insertAction = new QAction(i18n("Insert Track"), this);
99 m_menu.addAction(insertAction);
100 connect(insertAction, SIGNAL(triggered()), this, SLOT(slotAddTrack()));
102 QAction *removeAction = new QAction(KIcon("edit-delete"), i18n("Delete Track"), this);
103 m_menu.addAction(removeAction);
104 connect(removeAction, SIGNAL(triggered()), this, SLOT(slotDeleteTrack()));
106 QAction *configAction = new QAction(KIcon("configure"), i18n("Configure Track"), this);
107 m_menu.addAction(configAction);
108 connect(configAction, SIGNAL(triggered()), this, SLOT(slotConfigTrack()));
111 /*HeaderTrack::~HeaderTrack()
116 void HeaderTrack::mousePressEvent(QMouseEvent * event)
118 if (track_number->hasFocus()) {
119 track_number->clearFocus();
122 if (!m_isSelected) emit selectTrack(m_index);
123 emit showTrackEffects(m_index);
124 QWidget::mousePressEvent(event);
128 void HeaderTrack::contextMenuEvent(QContextMenuEvent * event)
130 if (track_number->hasFocus()) {
131 track_number->clearFocus();
134 m_menu.popup(event->globalPos());
137 void HeaderTrack::mouseDoubleClickEvent(QMouseEvent* event)
139 if (track_number->hasFocus()) {
140 track_number->clearFocus();
144 QWidget::mouseDoubleClickEvent(event);
148 void HeaderTrack::dropEvent(QDropEvent * event)
150 const QString effects = QString(event->mimeData()->data("kdenlive/effectslist"));
152 doc.setContent(effects, true);
153 const QDomElement e = doc.documentElement();
154 emit addTrackInfo(e, m_index);
155 /*if (scene() && !scene()->views().isEmpty()) {
157 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
158 if (view) view->slotAddEffect(e, m_info.startPos, track());
163 void HeaderTrack::dragEnterEvent(QDragEnterEvent *event)
165 if (buttonLock->isChecked()) event->setAccepted(false);
166 else event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist"));
169 void HeaderTrack::setSelectedIndex(int ix)
173 setBackgroundRole(QPalette::Button);
174 setAutoFillBackground(true);
175 } else if (m_type != VIDEOTRACK) {
176 m_isSelected = false;
177 setAutoFillBackground(false);
179 m_isSelected = false;
180 setBackgroundRole(QPalette::AlternateBase);
185 void HeaderTrack::adjustSize(int height)
187 // Don't show track buttons if size is too small
188 bool smallTracks = height < 40;
189 if (m_type == VIDEOTRACK)
190 buttonVideo->setHidden(smallTracks);
191 buttonAudio->setHidden(smallTracks);
192 buttonLock->setHidden(smallTracks);
193 setFixedHeight(height);
196 void HeaderTrack::switchVideo()
198 if (buttonVideo->isChecked())
199 buttonVideo->setIcon(KIcon("kdenlive-hide-video"));
201 buttonVideo->setIcon(KIcon("kdenlive-show-video"));
202 emit switchTrackVideo(m_index);
205 void HeaderTrack::switchAudio()
207 if (buttonAudio->isChecked())
208 buttonAudio->setIcon(KIcon("kdenlive-hide-audio"));
210 buttonAudio->setIcon(KIcon("kdenlive-show-audio"));
211 emit switchTrackAudio(m_index);
214 void HeaderTrack::switchLock(bool emitSignal)
216 if (buttonLock->isChecked())
217 buttonLock->setIcon(KIcon("kdenlive-lock"));
219 buttonLock->setIcon(KIcon("kdenlive-unlock"));
221 emit switchTrackLock(m_index);
224 void HeaderTrack::setLock(bool lock)
226 buttonLock->setChecked(lock);
230 void HeaderTrack::slotDeleteTrack()
232 QTimer::singleShot(500, this, SLOT(deleteTrack()));
235 void HeaderTrack::deleteTrack()
237 emit deleteTrack(m_index);
240 void HeaderTrack::slotAddTrack()
242 emit insertTrack(m_index);
245 void HeaderTrack::slotRenameTrack()
247 if (m_name != track_number->text()) emit renameTrack(m_index, track_number->text());
250 void HeaderTrack::slotConfigTrack()
252 emit configTrack(m_index);
256 #include "headertrack.moc"