]> git.sesse.net Git - kdenlive/blob - src/headertrack.cpp
cleanup
[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
23 #include <KIcon>
24 #include <KLocale>
25 #include <KDebug>
26
27 #include <QMouseEvent>
28 #include <QWidget>
29 #include <QPainter>
30 #include <QAction>
31 #include <QTimer>
32
33 HeaderTrack::HeaderTrack(int index, TrackInfo info, int height, QWidget *parent) :
34         QWidget(parent),
35         m_index(index),
36         m_type(info.type)
37 {
38     setFixedHeight(height);
39     setupUi(this);
40     track_number->setText(info.trackName.isEmpty() ? QString::number(m_index) : info.trackName);
41
42     buttonVideo->setChecked(info.isBlind);
43     buttonVideo->setToolTip(i18n("Hide track"));
44     buttonAudio->setChecked(info.isMute);
45     buttonAudio->setToolTip(i18n("Mute track"));
46     buttonLock->setChecked(info.isLocked);
47     buttonLock->setToolTip(i18n("Lock track"));
48
49     if (m_type == VIDEOTRACK) {
50         setBackgroundRole(QPalette::AlternateBase);
51         setAutoFillBackground(true);
52         if (!info.isBlind) buttonVideo->setIcon(KIcon("kdenlive-show-video"));
53         else buttonVideo->setIcon(KIcon("kdenlive-hide-video"));
54     } else {
55         buttonVideo->setHidden(true);
56     }
57     if (!info.isMute) buttonAudio->setIcon(KIcon("kdenlive-show-audio"));
58     else buttonAudio->setIcon(KIcon("kdenlive-hide-audio"));
59
60     if (!info.isLocked) buttonLock->setIcon(KIcon("kdenlive-unlock"));
61     else buttonLock->setIcon(KIcon("kdenlive-lock"));
62
63     connect(buttonVideo, SIGNAL(clicked()), this, SLOT(switchVideo()));
64     connect(buttonAudio, SIGNAL(clicked()), this, SLOT(switchAudio()));
65     connect(buttonLock, SIGNAL(clicked()), this, SLOT(switchLock()));
66
67     // Don't show track buttons if size is too small
68     if (height < 40) {
69         buttonVideo->setHidden(true);
70         buttonAudio->setHidden(true);
71         buttonLock->setHidden(true);
72         //horizontalSpacer;
73     }
74
75     setContextMenuPolicy(Qt::ActionsContextMenu);
76     QAction *insertAction = new QAction(i18n("Insert Track"), this);
77     addAction(insertAction);
78     connect(insertAction, SIGNAL(triggered()), this, SLOT(slotAddTrack()));
79
80     QAction *removeAction = new QAction(KIcon("edit-delete"), i18n("Delete Track"), this);
81     addAction(removeAction);
82     connect(removeAction, SIGNAL(triggered()), this, SLOT(slotDeleteTrack()));
83
84     QAction *changeAction = new QAction(i18n("Change Track Type"), this);
85     addAction(changeAction);
86     connect(changeAction, SIGNAL(triggered()), this, SLOT(slotChangeTrack()));
87
88     QAction *renameAction = new QAction(i18n("Rename Track"), this);
89     addAction(renameAction);
90     connect(renameAction, SIGNAL(triggered()), this, SLOT(slotRenameTrack()));
91
92 }
93
94 /*HeaderTrack::~HeaderTrack()
95 {
96 }*/
97
98 void HeaderTrack::adjustSize(int height)
99 {
100     // Don't show track buttons if size is too small
101     bool smallTracks = height < 40;
102     if (m_type == VIDEOTRACK) buttonVideo->setHidden(smallTracks);
103     buttonAudio->setHidden(smallTracks);
104     buttonLock->setHidden(smallTracks);
105     setFixedHeight(height);
106 }
107
108 void HeaderTrack::switchVideo()
109 {
110     if (buttonVideo->isChecked()) {
111         buttonVideo->setIcon(KIcon("kdenlive-hide-video"));
112     } else {
113         buttonVideo->setIcon(KIcon("kdenlive-show-video"));
114     }
115     emit switchTrackVideo(m_index);
116 }
117
118 void HeaderTrack::switchAudio()
119 {
120     if (buttonAudio->isChecked()) {
121         buttonAudio->setIcon(KIcon("kdenlive-hide-audio"));
122     } else {
123         buttonAudio->setIcon(KIcon("kdenlive-show-audio"));
124     }
125     emit switchTrackAudio(m_index);
126 }
127
128 void HeaderTrack::switchLock(bool emitSignal)
129 {
130     if (buttonLock->isChecked()) {
131         buttonLock->setIcon(KIcon("kdenlive-lock"));
132     } else {
133         buttonLock->setIcon(KIcon("kdenlive-unlock"));
134     }
135     if (emitSignal) emit switchTrackLock(m_index);
136 }
137
138
139 void HeaderTrack::setLock(bool lock)
140 {
141     buttonLock->setChecked(lock);
142     switchLock(false);
143 }
144
145 void HeaderTrack::slotDeleteTrack()
146 {
147     QTimer::singleShot(500, this, SLOT(deleteTrack()));
148 }
149
150 void HeaderTrack::deleteTrack()
151 {
152     emit deleteTrack(m_index);
153 }
154
155 void HeaderTrack::slotAddTrack()
156 {
157     emit insertTrack(m_index);
158 }
159
160 void HeaderTrack::slotChangeTrack()
161 {
162     emit changeTrack(m_index);
163 }
164
165 void HeaderTrack::slotRenameTrack()
166 {
167     emit renameTrack(m_index);
168 }
169
170
171 #include "headertrack.moc"