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.buttonAudio->setChecked(!info.isMute);
41 if (m_type == VIDEOTRACK) {
42 view.frame->setBackgroundRole(QPalette::AlternateBase);
43 view.frame->setAutoFillBackground(true);
44 if (!info.isBlind) view.buttonVideo->setIcon(KIcon("kdenlive-show-video"));
45 else view.buttonVideo->setIcon(KIcon("kdenlive-hide-video"));
47 view.buttonVideo->setHidden(true);
49 if (!info.isMute) view.buttonAudio->setIcon(KIcon("kdenlive-show-audio"));
50 else view.buttonAudio->setIcon(KIcon("kdenlive-hide-audio"));
51 connect(view.buttonVideo, SIGNAL(clicked()), this, SLOT(switchVideo()));
52 connect(view.buttonAudio, SIGNAL(clicked()), this, SLOT(switchAudio()));
54 m_contextMenu = new QMenu(this);
56 QAction *insertAction = new QAction(i18n("Insert Track"), this);
57 m_contextMenu->addAction(insertAction);
58 connect(insertAction, SIGNAL(triggered()), this, SLOT(slotAddTrack()));
60 QAction *removeAction = new QAction(KIcon("edit-delete"), i18n("Delete Track"), this);
61 m_contextMenu->addAction(removeAction);
62 connect(removeAction, SIGNAL(triggered()), this, SLOT(slotDeleteTrack()));
64 QAction *changeAction = new QAction(i18n("Change Track Type"), this);
65 m_contextMenu->addAction(changeAction);
66 connect(changeAction, SIGNAL(triggered()), this, SLOT(slotChangeTrack()));
69 void HeaderTrack::switchVideo() {
70 if (view.buttonVideo->isChecked()) {
71 view.buttonVideo->setIcon(KIcon("kdenlive-show-video"));
73 view.buttonVideo->setIcon(KIcon("kdenlive-hide-video"));
75 emit switchTrackVideo(m_index);
78 void HeaderTrack::switchAudio() {
79 if (view.buttonAudio->isChecked()) {
80 view.buttonAudio->setIcon(KIcon("kdenlive-show-audio"));
82 view.buttonAudio->setIcon(KIcon("kdenlive-hide-audio"));
84 emit switchTrackAudio(m_index);
87 void HeaderTrack::slotDeleteTrack() {
88 emit deleteTrack(m_index);
91 void HeaderTrack::slotAddTrack() {
92 emit insertTrack(m_index);
95 void HeaderTrack::slotChangeTrack() {
96 emit changeTrack(m_index);
100 void HeaderTrack::contextMenuEvent(QContextMenuEvent * event) {
101 m_contextMenu->popup(event->globalPos());
105 /*void HeaderTrack::paintEvent(QPaintEvent *e) {
106 QRect region = e->rect();
107 region.setTopLeft(QPoint(region.left() + 1, region.top() + 1));
108 region.setBottomRight(QPoint(region.right() - 1, region.bottom() - 1));
109 QPainter painter(this);
110 if (m_type == AUDIOTRACK) painter.fillRect(region, QBrush(QColor(240, 240, 255)));
111 else painter.fillRect(region, QBrush(QColor(255, 255, 255)));
112 painter.drawText(region, Qt::AlignCenter, m_label);
116 #include "headertrack.moc"