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 ***************************************************************************/
20 #include <QMouseEvent>
21 #include <QStylePainter>
31 #include "kdenlivesettings.h"
32 #include "headertrack.h"
34 HeaderTrack::HeaderTrack(int index, TrackInfo info, QWidget *parent)
35 : QWidget(parent), m_index(index), m_type(info.type) {
36 setFixedHeight(KdenliveSettings::trackheight());
38 view.track_number->setText(QString::number(m_index));
39 view.buttonVideo->setChecked(!info.isBlind);
40 view.buttonVideo->setToolTip(i18n("Hide track"));
41 view.buttonAudio->setChecked(!info.isMute);
42 view.buttonAudio->setToolTip(i18n("Mute track"));
43 view.buttonLock->setChecked(info.isLocked);
44 view.buttonLock->setToolTip(i18n("Lock track"));
46 if (m_type == VIDEOTRACK) {
47 view.frame->setBackgroundRole(QPalette::AlternateBase);
48 view.frame->setAutoFillBackground(true);
49 if (!info.isBlind) view.buttonVideo->setIcon(KIcon("kdenlive-show-video"));
50 else view.buttonVideo->setIcon(KIcon("kdenlive-hide-video"));
52 view.buttonVideo->setHidden(true);
54 if (!info.isMute) view.buttonAudio->setIcon(KIcon("kdenlive-show-audio"));
55 else view.buttonAudio->setIcon(KIcon("kdenlive-hide-audio"));
57 if (!info.isLocked) view.buttonLock->setIcon(KIcon("kdenlive-unlock"));
58 else view.buttonLock->setIcon(KIcon("kdenlive-lock"));
60 connect(view.buttonVideo, SIGNAL(clicked()), this, SLOT(switchVideo()));
61 connect(view.buttonAudio, SIGNAL(clicked()), this, SLOT(switchAudio()));
62 connect(view.buttonLock, SIGNAL(clicked()), this, SLOT(switchLock()));
64 m_contextMenu = new QMenu(this);
66 QAction *insertAction = new QAction(i18n("Insert Track"), this);
67 m_contextMenu->addAction(insertAction);
68 connect(insertAction, SIGNAL(triggered()), this, SLOT(slotAddTrack()));
70 QAction *removeAction = new QAction(KIcon("edit-delete"), i18n("Delete Track"), this);
71 m_contextMenu->addAction(removeAction);
72 connect(removeAction, SIGNAL(triggered()), this, SLOT(slotDeleteTrack()));
74 QAction *changeAction = new QAction(i18n("Change Track Type"), this);
75 m_contextMenu->addAction(changeAction);
76 connect(changeAction, SIGNAL(triggered()), this, SLOT(slotChangeTrack()));
79 HeaderTrack::~HeaderTrack() {
80 if (m_contextMenu) delete m_contextMenu;
83 void HeaderTrack::switchVideo() {
84 if (view.buttonVideo->isChecked()) {
85 view.buttonVideo->setIcon(KIcon("kdenlive-show-video"));
87 view.buttonVideo->setIcon(KIcon("kdenlive-hide-video"));
89 emit switchTrackVideo(m_index);
92 void HeaderTrack::switchAudio() {
93 if (view.buttonAudio->isChecked()) {
94 view.buttonAudio->setIcon(KIcon("kdenlive-show-audio"));
96 view.buttonAudio->setIcon(KIcon("kdenlive-hide-audio"));
98 emit switchTrackAudio(m_index);
101 void HeaderTrack::switchLock(bool emitSignal) {
102 if (view.buttonLock->isChecked()) {
103 view.buttonLock->setIcon(KIcon("kdenlive-lock"));
105 view.buttonLock->setIcon(KIcon("kdenlive-unlock"));
107 if (emitSignal) emit switchTrackLock(m_index);
111 void HeaderTrack::setLock(bool lock) {
112 view.buttonLock->setChecked(lock);
116 void HeaderTrack::slotDeleteTrack() {
117 emit deleteTrack(m_index);
120 void HeaderTrack::slotAddTrack() {
121 emit insertTrack(m_index);
124 void HeaderTrack::slotChangeTrack() {
125 emit changeTrack(m_index);
129 void HeaderTrack::contextMenuEvent(QContextMenuEvent * event) {
130 m_contextMenu->popup(event->globalPos());
134 /*void HeaderTrack::paintEvent(QPaintEvent *e) {
135 QRect region = e->rect();
136 region.setTopLeft(QPoint(region.left() + 1, region.top() + 1));
137 region.setBottomRight(QPoint(region.right() - 1, region.bottom() - 1));
138 QPainter painter(this);
139 if (m_type == AUDIOTRACK) painter.fillRect(region, QBrush(QColor(240, 240, 255)));
140 else painter.fillRect(region, QBrush(QColor(255, 255, 255)));
141 painter.drawText(region, Qt::AlignCenter, m_label);
145 #include "headertrack.moc"