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 HeaderTrack::HeaderTrack(int index, TrackInfo info, int height, QWidget *parent) :
39 setFixedHeight(height);
41 track_number->setText(info.trackName.isEmpty() ? QString::number(m_index) : info.trackName);
43 buttonVideo->setChecked(info.isBlind);
44 buttonVideo->setToolTip(i18n("Hide track"));
45 buttonAudio->setChecked(info.isMute);
46 buttonAudio->setToolTip(i18n("Mute track"));
47 buttonLock->setChecked(info.isLocked);
48 buttonLock->setToolTip(i18n("Lock track"));
50 QPalette p = palette();
51 KColorScheme scheme(p.currentColorGroup(), KColorScheme::Window);
52 p.setColor(QPalette::Button, scheme.background(KColorScheme::ActiveBackground).color().darker(120));
55 if (m_type == VIDEOTRACK) {
56 setBackgroundRole(QPalette::AlternateBase);
57 setAutoFillBackground(true);
58 if (!info.isBlind) buttonVideo->setIcon(KIcon("kdenlive-show-video"));
59 else buttonVideo->setIcon(KIcon("kdenlive-hide-video"));
61 buttonVideo->setHidden(true);
63 if (!info.isMute) buttonAudio->setIcon(KIcon("kdenlive-show-audio"));
64 else buttonAudio->setIcon(KIcon("kdenlive-hide-audio"));
66 if (!info.isLocked) buttonLock->setIcon(KIcon("kdenlive-unlock"));
67 else buttonLock->setIcon(KIcon("kdenlive-lock"));
69 connect(buttonVideo, SIGNAL(clicked()), this, SLOT(switchVideo()));
70 connect(buttonAudio, SIGNAL(clicked()), this, SLOT(switchAudio()));
71 connect(buttonLock, SIGNAL(clicked()), this, SLOT(switchLock()));
73 // Don't show track buttons if size is too small
75 buttonVideo->setHidden(true);
76 buttonAudio->setHidden(true);
77 buttonLock->setHidden(true);
81 setContextMenuPolicy(Qt::ActionsContextMenu);
82 QAction *insertAction = new QAction(i18n("Insert Track"), this);
83 addAction(insertAction);
84 connect(insertAction, SIGNAL(triggered()), this, SLOT(slotAddTrack()));
86 QAction *removeAction = new QAction(KIcon("edit-delete"), i18n("Delete Track"), this);
87 addAction(removeAction);
88 connect(removeAction, SIGNAL(triggered()), this, SLOT(slotDeleteTrack()));
90 QAction *changeAction = new QAction(i18n("Change Track Type"), this);
91 addAction(changeAction);
92 connect(changeAction, SIGNAL(triggered()), this, SLOT(slotChangeTrack()));
94 QAction *renameAction = new QAction(i18n("Rename Track"), this);
95 addAction(renameAction);
96 connect(renameAction, SIGNAL(triggered()), this, SLOT(slotRenameTrack()));
100 /*HeaderTrack::~HeaderTrack()
105 void HeaderTrack::mousePressEvent(QMouseEvent * event)
107 emit selectTrack(m_index);
108 QWidget::mousePressEvent(event);
111 void HeaderTrack::mouseDoubleClickEvent(QMouseEvent* event)
113 emit configTrack(m_index);
114 QWidget::mouseDoubleClickEvent(event);
117 void HeaderTrack::setSelectedIndex(int ix)
120 setBackgroundRole(QPalette::Button);
121 setAutoFillBackground(true);
122 } else if (m_type != VIDEOTRACK) setAutoFillBackground(false);
123 else setBackgroundRole(QPalette::AlternateBase);
127 void HeaderTrack::adjustSize(int height)
129 // Don't show track buttons if size is too small
130 bool smallTracks = height < 40;
131 if (m_type == VIDEOTRACK) buttonVideo->setHidden(smallTracks);
132 buttonAudio->setHidden(smallTracks);
133 buttonLock->setHidden(smallTracks);
134 setFixedHeight(height);
137 void HeaderTrack::switchVideo()
139 if (buttonVideo->isChecked()) {
140 buttonVideo->setIcon(KIcon("kdenlive-hide-video"));
142 buttonVideo->setIcon(KIcon("kdenlive-show-video"));
144 emit switchTrackVideo(m_index);
147 void HeaderTrack::switchAudio()
149 if (buttonAudio->isChecked()) {
150 buttonAudio->setIcon(KIcon("kdenlive-hide-audio"));
152 buttonAudio->setIcon(KIcon("kdenlive-show-audio"));
154 emit switchTrackAudio(m_index);
157 void HeaderTrack::switchLock(bool emitSignal)
159 if (buttonLock->isChecked()) {
160 buttonLock->setIcon(KIcon("kdenlive-lock"));
162 buttonLock->setIcon(KIcon("kdenlive-unlock"));
164 if (emitSignal) emit switchTrackLock(m_index);
168 void HeaderTrack::setLock(bool lock)
170 buttonLock->setChecked(lock);
174 void HeaderTrack::slotDeleteTrack()
176 QTimer::singleShot(500, this, SLOT(deleteTrack()));
179 void HeaderTrack::deleteTrack()
181 emit deleteTrack(m_index);
184 void HeaderTrack::slotAddTrack()
186 emit insertTrack(m_index);
189 void HeaderTrack::slotChangeTrack()
191 emit changeTrack(m_index);
194 void HeaderTrack::slotRenameTrack()
196 emit renameTrack(m_index);
200 #include "headertrack.moc"