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 "kdenlivesettings.h"
28 #include <QMouseEvent>
33 HeaderTrack::HeaderTrack(int index, TrackInfo info, QWidget *parent)
34 : QWidget(parent), m_index(index), m_type(info.type) {
35 setFixedHeight(KdenliveSettings::trackheight());
37 view.track_number->setText(QString::number(m_index));
38 view.buttonVideo->setChecked(!info.isBlind);
39 view.buttonVideo->setToolTip(i18n("Hide track"));
40 view.buttonAudio->setChecked(!info.isMute);
41 view.buttonAudio->setToolTip(i18n("Mute track"));
42 view.buttonLock->setChecked(info.isLocked);
43 view.buttonLock->setToolTip(i18n("Lock track"));
45 if (m_type == VIDEOTRACK) {
46 view.frame->setBackgroundRole(QPalette::AlternateBase);
47 view.frame->setAutoFillBackground(true);
48 if (!info.isBlind) view.buttonVideo->setIcon(KIcon("kdenlive-show-video"));
49 else view.buttonVideo->setIcon(KIcon("kdenlive-hide-video"));
51 view.buttonVideo->setHidden(true);
53 if (!info.isMute) view.buttonAudio->setIcon(KIcon("kdenlive-show-audio"));
54 else view.buttonAudio->setIcon(KIcon("kdenlive-hide-audio"));
56 if (!info.isLocked) view.buttonLock->setIcon(KIcon("kdenlive-unlock"));
57 else view.buttonLock->setIcon(KIcon("kdenlive-lock"));
59 connect(view.buttonVideo, SIGNAL(clicked()), this, SLOT(switchVideo()));
60 connect(view.buttonAudio, SIGNAL(clicked()), this, SLOT(switchAudio()));
61 connect(view.buttonLock, SIGNAL(clicked()), this, SLOT(switchLock()));
63 m_contextMenu = new QMenu(this);
65 QAction *insertAction = new QAction(i18n("Insert Track"), this);
66 m_contextMenu->addAction(insertAction);
67 connect(insertAction, SIGNAL(triggered()), this, SLOT(slotAddTrack()));
69 QAction *removeAction = new QAction(KIcon("edit-delete"), i18n("Delete Track"), this);
70 m_contextMenu->addAction(removeAction);
71 connect(removeAction, SIGNAL(triggered()), this, SLOT(slotDeleteTrack()));
73 QAction *changeAction = new QAction(i18n("Change Track Type"), this);
74 m_contextMenu->addAction(changeAction);
75 connect(changeAction, SIGNAL(triggered()), this, SLOT(slotChangeTrack()));
78 HeaderTrack::~HeaderTrack() {
79 if (m_contextMenu) delete m_contextMenu;
82 void HeaderTrack::switchVideo() {
83 if (view.buttonVideo->isChecked()) {
84 view.buttonVideo->setIcon(KIcon("kdenlive-show-video"));
86 view.buttonVideo->setIcon(KIcon("kdenlive-hide-video"));
88 emit switchTrackVideo(m_index);
91 void HeaderTrack::switchAudio() {
92 if (view.buttonAudio->isChecked()) {
93 view.buttonAudio->setIcon(KIcon("kdenlive-show-audio"));
95 view.buttonAudio->setIcon(KIcon("kdenlive-hide-audio"));
97 emit switchTrackAudio(m_index);
100 void HeaderTrack::switchLock(bool emitSignal) {
101 if (view.buttonLock->isChecked()) {
102 view.buttonLock->setIcon(KIcon("kdenlive-lock"));
104 view.buttonLock->setIcon(KIcon("kdenlive-unlock"));
106 if (emitSignal) emit switchTrackLock(m_index);
110 void HeaderTrack::setLock(bool lock) {
111 view.buttonLock->setChecked(lock);
115 void HeaderTrack::slotDeleteTrack() {
116 emit deleteTrack(m_index);
119 void HeaderTrack::slotAddTrack() {
120 emit insertTrack(m_index);
123 void HeaderTrack::slotChangeTrack() {
124 emit changeTrack(m_index);
128 void HeaderTrack::contextMenuEvent(QContextMenuEvent * event) {
129 m_contextMenu->popup(event->globalPos());
133 /*void HeaderTrack::paintEvent(QPaintEvent *e) {
134 QRect region = e->rect();
135 region.setTopLeft(QPoint(region.left() + 1, region.top() + 1));
136 region.setBottomRight(QPoint(region.right() - 1, region.bottom() - 1));
137 QPainter painter(this);
138 if (m_type == AUDIOTRACK) painter.fillRect(region, QBrush(QColor(240, 240, 255)));
139 else painter.fillRect(region, QBrush(QColor(255, 255, 255)));
140 painter.drawText(region, Qt::AlignCenter, m_label);
144 #include "headertrack.moc"