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>
35 HeaderTrack::HeaderTrack(int index, TrackInfo info, int height, QWidget *parent) :
41 setFixedHeight(height);
43 QColor col = track_number->palette().color(QPalette::Base);
44 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()));
46 m_name = info.trackName.isEmpty() ? QString::number(m_index) : info.trackName;
47 track_number->setText(m_name);
48 connect(track_number, SIGNAL(editingFinished()), this, SLOT(slotRenameTrack()));
50 buttonVideo->setChecked(info.isBlind);
51 buttonVideo->setToolTip(i18n("Hide track"));
52 buttonAudio->setChecked(info.isMute);
53 buttonAudio->setToolTip(i18n("Mute track"));
54 buttonLock->setChecked(info.isLocked);
55 buttonLock->setToolTip(i18n("Lock track"));
57 QPalette p = palette();
58 KColorScheme scheme(p.currentColorGroup(), KColorScheme::Window);
59 p.setColor(QPalette::Button, scheme.background(KColorScheme::ActiveBackground).color().darker(120));
62 if (m_type == VIDEOTRACK) {
63 setBackgroundRole(QPalette::AlternateBase);
64 setAutoFillBackground(true);
66 buttonVideo->setIcon(KIcon("kdenlive-show-video"));
68 buttonVideo->setIcon(KIcon("kdenlive-hide-video"));
70 buttonVideo->setHidden(true);
73 buttonAudio->setIcon(KIcon("kdenlive-show-audio"));
75 buttonAudio->setIcon(KIcon("kdenlive-hide-audio"));
78 buttonLock->setIcon(KIcon("kdenlive-unlock"));
80 buttonLock->setIcon(KIcon("kdenlive-lock"));
82 connect(buttonVideo, SIGNAL(clicked()), this, SLOT(switchVideo()));
83 connect(buttonAudio, SIGNAL(clicked()), this, SLOT(switchAudio()));
84 connect(buttonLock, SIGNAL(clicked()), this, SLOT(switchLock()));
86 // Don't show track buttons if size is too small
88 buttonVideo->setHidden(true);
89 buttonAudio->setHidden(true);
90 buttonLock->setHidden(true);
94 setContextMenuPolicy(Qt::DefaultContextMenu); //Qt::ActionsContextMenu);
95 QAction *insertAction = new QAction(i18n("Insert Track"), this);
96 m_menu.addAction(insertAction);
97 connect(insertAction, SIGNAL(triggered()), this, SLOT(slotAddTrack()));
99 QAction *removeAction = new QAction(KIcon("edit-delete"), i18n("Delete Track"), this);
100 m_menu.addAction(removeAction);
101 connect(removeAction, SIGNAL(triggered()), this, SLOT(slotDeleteTrack()));
103 QAction *configAction = new QAction(KIcon("configure"), i18n("Configure Track"), this);
104 m_menu.addAction(configAction);
105 connect(configAction, SIGNAL(triggered()), this, SLOT(slotConfigTrack()));
108 /*HeaderTrack::~HeaderTrack()
113 void HeaderTrack::mousePressEvent(QMouseEvent * event)
115 if (track_number->hasFocus()) {
116 track_number->clearFocus();
119 if (!m_isSelected) emit selectTrack(m_index);
120 QWidget::mousePressEvent(event);
124 void HeaderTrack::contextMenuEvent(QContextMenuEvent * event)
126 if (track_number->hasFocus()) {
127 track_number->clearFocus();
130 m_menu.popup(event->globalPos());
133 void HeaderTrack::mouseDoubleClickEvent(QMouseEvent* event)
135 if (track_number->hasFocus()) {
136 track_number->clearFocus();
140 QWidget::mouseDoubleClickEvent(event);
143 void HeaderTrack::setSelectedIndex(int ix)
147 setBackgroundRole(QPalette::Button);
148 setAutoFillBackground(true);
149 } else if (m_type != VIDEOTRACK) {
150 m_isSelected = false;
151 setAutoFillBackground(false);
153 m_isSelected = false;
154 setBackgroundRole(QPalette::AlternateBase);
159 void HeaderTrack::adjustSize(int height)
161 // Don't show track buttons if size is too small
162 bool smallTracks = height < 40;
163 if (m_type == VIDEOTRACK)
164 buttonVideo->setHidden(smallTracks);
165 buttonAudio->setHidden(smallTracks);
166 buttonLock->setHidden(smallTracks);
167 setFixedHeight(height);
170 void HeaderTrack::switchVideo()
172 if (buttonVideo->isChecked())
173 buttonVideo->setIcon(KIcon("kdenlive-hide-video"));
175 buttonVideo->setIcon(KIcon("kdenlive-show-video"));
176 emit switchTrackVideo(m_index);
179 void HeaderTrack::switchAudio()
181 if (buttonAudio->isChecked())
182 buttonAudio->setIcon(KIcon("kdenlive-hide-audio"));
184 buttonAudio->setIcon(KIcon("kdenlive-show-audio"));
185 emit switchTrackAudio(m_index);
188 void HeaderTrack::switchLock(bool emitSignal)
190 if (buttonLock->isChecked())
191 buttonLock->setIcon(KIcon("kdenlive-lock"));
193 buttonLock->setIcon(KIcon("kdenlive-unlock"));
195 emit switchTrackLock(m_index);
198 void HeaderTrack::setLock(bool lock)
200 buttonLock->setChecked(lock);
204 void HeaderTrack::slotDeleteTrack()
206 QTimer::singleShot(500, this, SLOT(deleteTrack()));
209 void HeaderTrack::deleteTrack()
211 emit deleteTrack(m_index);
214 void HeaderTrack::slotAddTrack()
216 emit insertTrack(m_index);
219 void HeaderTrack::slotRenameTrack()
221 if (m_name != track_number->text()) emit renameTrack(m_index, track_number->text());
224 void HeaderTrack::slotConfigTrack()
226 emit configTrack(m_index);
230 #include "headertrack.moc"