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);
42 QString name = info.trackName.isEmpty() ? QString::number(m_index) : info.trackName;
43 track_number->setText(name);
44 inputName->setText(name);
45 inputName->setHidden(true);
46 connect(inputName, SIGNAL(editingFinished()), this, SLOT(slotRenameTrack()));
48 buttonVideo->setChecked(info.isBlind);
49 buttonVideo->setToolTip(i18n("Hide track"));
50 buttonAudio->setChecked(info.isMute);
51 buttonAudio->setToolTip(i18n("Mute track"));
52 buttonLock->setChecked(info.isLocked);
53 buttonLock->setToolTip(i18n("Lock track"));
55 QPalette p = palette();
56 KColorScheme scheme(p.currentColorGroup(), KColorScheme::Window);
57 p.setColor(QPalette::Button, scheme.background(KColorScheme::ActiveBackground).color().darker(120));
60 if (m_type == VIDEOTRACK) {
61 setBackgroundRole(QPalette::AlternateBase);
62 setAutoFillBackground(true);
64 buttonVideo->setIcon(KIcon("kdenlive-show-video"));
66 buttonVideo->setIcon(KIcon("kdenlive-hide-video"));
68 buttonVideo->setHidden(true);
71 buttonAudio->setIcon(KIcon("kdenlive-show-audio"));
73 buttonAudio->setIcon(KIcon("kdenlive-hide-audio"));
76 buttonLock->setIcon(KIcon("kdenlive-unlock"));
78 buttonLock->setIcon(KIcon("kdenlive-lock"));
80 connect(buttonVideo, SIGNAL(clicked()), this, SLOT(switchVideo()));
81 connect(buttonAudio, SIGNAL(clicked()), this, SLOT(switchAudio()));
82 connect(buttonLock, SIGNAL(clicked()), this, SLOT(switchLock()));
84 // Don't show track buttons if size is too small
86 buttonVideo->setHidden(true);
87 buttonAudio->setHidden(true);
88 buttonLock->setHidden(true);
92 setContextMenuPolicy(Qt::ActionsContextMenu);
93 QAction *insertAction = new QAction(i18n("Insert Track"), this);
94 addAction(insertAction);
95 connect(insertAction, SIGNAL(triggered()), this, SLOT(slotAddTrack()));
97 QAction *removeAction = new QAction(KIcon("edit-delete"), i18n("Delete Track"), this);
98 addAction(removeAction);
99 connect(removeAction, SIGNAL(triggered()), this, SLOT(slotDeleteTrack()));
101 QAction *configAction = new QAction(KIcon("configure"), i18n("Configure Track"), this);
102 addAction(configAction);
103 connect(configAction, SIGNAL(triggered()), this, SLOT(slotConfigTrack()));
106 /*HeaderTrack::~HeaderTrack()
111 void HeaderTrack::mousePressEvent(QMouseEvent * event)
113 emit selectTrack(m_index);
114 QWidget::mousePressEvent(event);
117 void HeaderTrack::mouseDoubleClickEvent(QMouseEvent* event)
120 QWidget::mouseDoubleClickEvent(event);
123 void HeaderTrack::setSelectedIndex(int ix)
125 track_number->setHidden(false);
126 inputName->setHidden(true);
128 setBackgroundRole(QPalette::Button);
129 setAutoFillBackground(true);
130 track_number->setHidden(true);
131 inputName->setHidden(false);
132 } else if (m_type != VIDEOTRACK) {
133 setAutoFillBackground(false);
135 setBackgroundRole(QPalette::AlternateBase);
140 void HeaderTrack::adjustSize(int height)
142 // Don't show track buttons if size is too small
143 bool smallTracks = height < 40;
144 if (m_type == VIDEOTRACK)
145 buttonVideo->setHidden(smallTracks);
146 buttonAudio->setHidden(smallTracks);
147 buttonLock->setHidden(smallTracks);
148 setFixedHeight(height);
151 void HeaderTrack::switchVideo()
153 if (buttonVideo->isChecked())
154 buttonVideo->setIcon(KIcon("kdenlive-hide-video"));
156 buttonVideo->setIcon(KIcon("kdenlive-show-video"));
157 emit switchTrackVideo(m_index);
160 void HeaderTrack::switchAudio()
162 if (buttonAudio->isChecked())
163 buttonAudio->setIcon(KIcon("kdenlive-hide-audio"));
165 buttonAudio->setIcon(KIcon("kdenlive-show-audio"));
166 emit switchTrackAudio(m_index);
169 void HeaderTrack::switchLock(bool emitSignal)
171 if (buttonLock->isChecked())
172 buttonLock->setIcon(KIcon("kdenlive-lock"));
174 buttonLock->setIcon(KIcon("kdenlive-unlock"));
176 emit switchTrackLock(m_index);
179 void HeaderTrack::setLock(bool lock)
181 buttonLock->setChecked(lock);
185 void HeaderTrack::slotDeleteTrack()
187 QTimer::singleShot(500, this, SLOT(deleteTrack()));
190 void HeaderTrack::deleteTrack()
192 emit deleteTrack(m_index);
195 void HeaderTrack::slotAddTrack()
197 emit insertTrack(m_index);
200 void HeaderTrack::slotRenameTrack()
202 emit renameTrack(m_index, inputName->text());
205 void HeaderTrack::slotConfigTrack()
207 emit configTrack(m_index);
211 #include "headertrack.moc"