]> 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 #include <KColorScheme>
27
28 #include <QMouseEvent>
29 #include <QWidget>
30 #include <QPainter>
31 #include <QAction>
32 #include <QTimer>
33
34 HeaderTrack::HeaderTrack(int index, TrackInfo info, int height, QWidget *parent) :
35         QWidget(parent),
36         m_index(index),
37         m_type(info.type)
38 {
39     setFixedHeight(height);
40     setupUi(this);
41     track_number->setText(info.trackName.isEmpty() ? QString::number(m_index) : info.trackName);
42
43     buttonVideo->setChecked(info.isBlind);
44     buttonVideo->setToolTip(i18n("Hide track"));
45     buttonAudio->setChecked(info.isMute);
46     buttonAudio->setToolTip(i18n("Mute track"));
47     buttonLock->setChecked(info.isLocked);
48     buttonLock->setToolTip(i18n("Lock track"));
49
50     QPalette p = palette();
51     KColorScheme scheme(p.currentColorGroup(), KColorScheme::Window);
52     p.setColor(QPalette::Button, scheme.background(KColorScheme::ActiveBackground).color().darker(120));
53     setPalette(p);
54
55     if (m_type == VIDEOTRACK) {
56         setBackgroundRole(QPalette::AlternateBase);
57         setAutoFillBackground(true);
58         if (!info.isBlind) buttonVideo->setIcon(KIcon("kdenlive-show-video"));
59         else buttonVideo->setIcon(KIcon("kdenlive-hide-video"));
60     } else {
61         buttonVideo->setHidden(true);
62     }
63     if (!info.isMute) buttonAudio->setIcon(KIcon("kdenlive-show-audio"));
64     else buttonAudio->setIcon(KIcon("kdenlive-hide-audio"));
65
66     if (!info.isLocked) buttonLock->setIcon(KIcon("kdenlive-unlock"));
67     else buttonLock->setIcon(KIcon("kdenlive-lock"));
68
69     connect(buttonVideo, SIGNAL(clicked()), this, SLOT(switchVideo()));
70     connect(buttonAudio, SIGNAL(clicked()), this, SLOT(switchAudio()));
71     connect(buttonLock, SIGNAL(clicked()), this, SLOT(switchLock()));
72
73     // Don't show track buttons if size is too small
74     if (height < 40) {
75         buttonVideo->setHidden(true);
76         buttonAudio->setHidden(true);
77         buttonLock->setHidden(true);
78         //horizontalSpacer;
79     }
80
81     setContextMenuPolicy(Qt::ActionsContextMenu);
82     QAction *insertAction = new QAction(i18n("Insert Track"), this);
83     addAction(insertAction);
84     connect(insertAction, SIGNAL(triggered()), this, SLOT(slotAddTrack()));
85
86     QAction *removeAction = new QAction(KIcon("edit-delete"), i18n("Delete Track"), this);
87     addAction(removeAction);
88     connect(removeAction, SIGNAL(triggered()), this, SLOT(slotDeleteTrack()));
89
90     QAction *configAction = new QAction(KIcon("configure"), i18n("Configure Track"), this);
91     addAction(configAction);
92     connect(configAction, SIGNAL(triggered()), this, SLOT(slotConfigTrack()));
93 }
94
95 /*HeaderTrack::~HeaderTrack()
96 {
97 }*/
98
99 // virtual
100 void HeaderTrack::mousePressEvent(QMouseEvent * event)
101 {
102     emit selectTrack(m_index);
103     QWidget::mousePressEvent(event);
104 }
105
106 void HeaderTrack::mouseDoubleClickEvent(QMouseEvent* event)
107 {
108     slotConfigTrack();
109     QWidget::mouseDoubleClickEvent(event);
110 }
111
112 void HeaderTrack::setSelectedIndex(int ix)
113 {
114     if (m_index == ix) {
115         setBackgroundRole(QPalette::Button);
116         setAutoFillBackground(true);
117     } else if (m_type != VIDEOTRACK) setAutoFillBackground(false);
118     else setBackgroundRole(QPalette::AlternateBase);
119     update();
120 }
121
122 void HeaderTrack::adjustSize(int height)
123 {
124     // Don't show track buttons if size is too small
125     bool smallTracks = height < 40;
126     if (m_type == VIDEOTRACK) buttonVideo->setHidden(smallTracks);
127     buttonAudio->setHidden(smallTracks);
128     buttonLock->setHidden(smallTracks);
129     setFixedHeight(height);
130 }
131
132 void HeaderTrack::switchVideo()
133 {
134     if (buttonVideo->isChecked()) {
135         buttonVideo->setIcon(KIcon("kdenlive-hide-video"));
136     } else {
137         buttonVideo->setIcon(KIcon("kdenlive-show-video"));
138     }
139     emit switchTrackVideo(m_index);
140 }
141
142 void HeaderTrack::switchAudio()
143 {
144     if (buttonAudio->isChecked()) {
145         buttonAudio->setIcon(KIcon("kdenlive-hide-audio"));
146     } else {
147         buttonAudio->setIcon(KIcon("kdenlive-show-audio"));
148     }
149     emit switchTrackAudio(m_index);
150 }
151
152 void HeaderTrack::switchLock(bool emitSignal)
153 {
154     if (buttonLock->isChecked()) {
155         buttonLock->setIcon(KIcon("kdenlive-lock"));
156     } else {
157         buttonLock->setIcon(KIcon("kdenlive-unlock"));
158     }
159     if (emitSignal) emit switchTrackLock(m_index);
160 }
161
162 void HeaderTrack::setLock(bool lock)
163 {
164     buttonLock->setChecked(lock);
165     switchLock(false);
166 }
167
168 void HeaderTrack::slotDeleteTrack()
169 {
170     QTimer::singleShot(500, this, SLOT(deleteTrack()));
171 }
172
173 void HeaderTrack::deleteTrack()
174 {
175     emit deleteTrack(m_index);
176 }
177
178 void HeaderTrack::slotAddTrack()
179 {
180     emit insertTrack(m_index);
181 }
182
183 void HeaderTrack::slotRenameTrack()
184 {
185     emit renameTrack(m_index);
186 }
187
188 void HeaderTrack::slotConfigTrack()
189 {
190     emit configTrack(m_index);
191 }
192
193
194 #include "headertrack.moc"