]> git.sesse.net Git - kdenlive/blob - src/headertrack.cpp
0ad355487438d30ab74cb4a57628857176effa15
[kdenlive] / src / headertrack.cpp
1 /***************************************************************************
2  *   Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
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.                                   *
8  *                                                                         *
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.                          *
13  *                                                                         *
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  ***************************************************************************/
19
20 #include <QMouseEvent>
21 #include <QStylePainter>
22 #include <QFrame>
23 #include <QWidget>
24 #include <QPainter>
25 #include <QAction>
26
27 #include <KIcon>
28 #include <KLocale>
29 #include <KDebug>
30
31 #include "kdenlivesettings.h"
32 #include "headertrack.h"
33
34 HeaderTrack::HeaderTrack(int index, TrackInfo info, QWidget *parent)
35         : QWidget(parent), m_index(index), m_type(info.type) {
36     setFixedHeight(KdenliveSettings::trackheight());
37     view.setupUi(this);
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"));
46     } else {
47         view.buttonVideo->setHidden(true);
48     }
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()));
53
54     m_contextMenu = new QMenu(this);
55
56     //TODO: implement add/remove track
57     /*QAction *insertAction = new QAction(i18n("Insert track"), this);
58     m_contextMenu->addAction(insertAction);
59     connect(insertAction, SIGNAL(triggered()), this, SLOT(slotAddTrack()));
60
61     QAction *removeAction = new QAction(KIcon("edit-delete"), i18n("Delete track"), this);
62     m_contextMenu->addAction(removeAction);
63     connect(removeAction, SIGNAL(triggered()), this, SLOT(slotDeleteTrack()));*/
64 }
65
66 void HeaderTrack::switchVideo() {
67     if (view.buttonVideo->isChecked()) {
68         view.buttonVideo->setIcon(KIcon("kdenlive-show-video"));
69     } else {
70         view.buttonVideo->setIcon(KIcon("kdenlive-hide-video"));
71     }
72     emit switchTrackVideo(m_index);
73 }
74
75 void HeaderTrack::switchAudio() {
76     if (view.buttonAudio->isChecked()) {
77         view.buttonAudio->setIcon(KIcon("kdenlive-show-audio"));
78     } else {
79         view.buttonAudio->setIcon(KIcon("kdenlive-hide-audio"));
80     }
81     emit switchTrackAudio(m_index);
82 }
83
84 void HeaderTrack::slotDeleteTrack() {
85     emit deleteTrack(m_index);
86 }
87
88 void HeaderTrack::slotAddTrack() {
89     emit insertTrack(m_index);
90 }
91
92 // virtual
93 void HeaderTrack::contextMenuEvent(QContextMenuEvent * event) {
94     m_contextMenu->popup(event->globalPos());
95 }
96
97 // virtual
98 /*void HeaderTrack::paintEvent(QPaintEvent *e) {
99     QRect region = e->rect();
100     region.setTopLeft(QPoint(region.left() + 1, region.top() + 1));
101     region.setBottomRight(QPoint(region.right() - 1, region.bottom() - 1));
102     QPainter painter(this);
103     if (m_type == AUDIOTRACK) painter.fillRect(region, QBrush(QColor(240, 240, 255)));
104     else painter.fillRect(region, QBrush(QColor(255, 255, 255)));
105     painter.drawText(region, Qt::AlignCenter, m_label);
106 }*/
107
108
109 #include "headertrack.moc"