]> git.sesse.net Git - kdenlive/blob - src/headertrack.cpp
Krazy fixes: cleanup all headers
[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
21 #include "headertrack.h"
22 #include "kdenlivesettings.h"
23
24 #include <KIcon>
25 #include <KLocale>
26 #include <KDebug>
27
28 #include <QMouseEvent>
29 #include <QWidget>
30 #include <QPainter>
31 #include <QAction>
32
33 HeaderTrack::HeaderTrack(int index, TrackInfo info, QWidget *parent)
34         : QWidget(parent), m_index(index), m_type(info.type) {
35     setFixedHeight(KdenliveSettings::trackheight());
36     view.setupUi(this);
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"));
44
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"));
50     } else {
51         view.buttonVideo->setHidden(true);
52     }
53     if (!info.isMute) view.buttonAudio->setIcon(KIcon("kdenlive-show-audio"));
54     else view.buttonAudio->setIcon(KIcon("kdenlive-hide-audio"));
55
56     if (!info.isLocked) view.buttonLock->setIcon(KIcon("kdenlive-unlock"));
57     else view.buttonLock->setIcon(KIcon("kdenlive-lock"));
58
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()));
62
63     m_contextMenu = new QMenu(this);
64
65     QAction *insertAction = new QAction(i18n("Insert Track"), this);
66     m_contextMenu->addAction(insertAction);
67     connect(insertAction, SIGNAL(triggered()), this, SLOT(slotAddTrack()));
68
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()));
72
73     QAction *changeAction = new QAction(i18n("Change Track Type"), this);
74     m_contextMenu->addAction(changeAction);
75     connect(changeAction, SIGNAL(triggered()), this, SLOT(slotChangeTrack()));
76 }
77
78 HeaderTrack::~HeaderTrack() {
79     if (m_contextMenu) delete m_contextMenu;
80 }
81
82 void HeaderTrack::switchVideo() {
83     if (view.buttonVideo->isChecked()) {
84         view.buttonVideo->setIcon(KIcon("kdenlive-show-video"));
85     } else {
86         view.buttonVideo->setIcon(KIcon("kdenlive-hide-video"));
87     }
88     emit switchTrackVideo(m_index);
89 }
90
91 void HeaderTrack::switchAudio() {
92     if (view.buttonAudio->isChecked()) {
93         view.buttonAudio->setIcon(KIcon("kdenlive-show-audio"));
94     } else {
95         view.buttonAudio->setIcon(KIcon("kdenlive-hide-audio"));
96     }
97     emit switchTrackAudio(m_index);
98 }
99
100 void HeaderTrack::switchLock(bool emitSignal) {
101     if (view.buttonLock->isChecked()) {
102         view.buttonLock->setIcon(KIcon("kdenlive-lock"));
103     } else {
104         view.buttonLock->setIcon(KIcon("kdenlive-unlock"));
105     }
106     if (emitSignal) emit switchTrackLock(m_index);
107 }
108
109
110 void HeaderTrack::setLock(bool lock) {
111     view.buttonLock->setChecked(lock);
112     switchLock(false);
113 }
114
115 void HeaderTrack::slotDeleteTrack() {
116     emit deleteTrack(m_index);
117 }
118
119 void HeaderTrack::slotAddTrack() {
120     emit insertTrack(m_index);
121 }
122
123 void HeaderTrack::slotChangeTrack() {
124     emit changeTrack(m_index);
125 }
126
127 // virtual
128 void HeaderTrack::contextMenuEvent(QContextMenuEvent * event) {
129     m_contextMenu->popup(event->globalPos());
130 }
131
132 // virtual
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);
141 }*/
142
143
144 #include "headertrack.moc"