]> git.sesse.net Git - kdenlive/blob - src/headertrack.cpp
Fix a couple of compile warnings because of unused and uninitialized variables.
[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 "effectslist.h"
23 #include "kdenlivesettings.h"
24
25 #include <KIcon>
26 #include <KLocale>
27 #include <KDebug>
28 #include <KColorScheme>
29
30 #include <QMouseEvent>
31 #include <QWidget>
32 #include <QPainter>
33 #include <QAction>
34 #include <QTimer>
35 #include <QColor>
36 #include <QDomDocument>
37
38 HeaderTrack::HeaderTrack(int index, TrackInfo info, int height, QWidget *parent) :
39         QWidget(parent),
40         m_index(index),
41         m_type(info.type),
42         m_isSelected(false)
43 {
44     setFixedHeight(height);
45     setupUi(this);
46
47     QPalette p = palette();
48     KColorScheme scheme(p.currentColorGroup(), KColorScheme::View, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
49     QColor norm = scheme.shade(scheme.background(KColorScheme::ActiveBackground).color(), KColorScheme::MidShade);
50     p.setColor(QPalette::Button, norm);
51     setPalette(p);
52
53     QColor col = scheme.background().color();
54     QColor col2 = scheme.foreground().color();
55     track_number->setStyleSheet(QString("QLineEdit { background-color: transparent;color: rgb(%4, %5, %6);} QLineEdit:hover{ background-color: rgb(%1, %2, %3);} QLineEdit:focus { background-color: rgb(%1, %2, %3);}").arg(col.red()).arg(col.green()).arg(col.blue()).arg(col2.red()).arg(col2.green()).arg(col2.blue()));
56
57     m_name = info.trackName.isEmpty() ? QString::number(m_index) : info.trackName;
58     track_number->setText(m_name);
59     connect(track_number, SIGNAL(editingFinished()), this, SLOT(slotRenameTrack()));
60
61     buttonVideo->setChecked(info.isBlind);
62     buttonVideo->setToolTip(i18n("Hide track"));
63     buttonAudio->setChecked(info.isMute);
64     buttonAudio->setToolTip(i18n("Mute track"));
65     buttonLock->setChecked(info.isLocked);
66     buttonLock->setToolTip(i18n("Lock track"));
67     effect_label->setPixmap(KIcon("kdenlive-track_has_effect").pixmap(16, 16));
68     updateEffectLabel(info.effectsList.effectNames());
69     setAcceptDrops(true);
70
71     if (m_type == VIDEOTRACK) {
72         setBackgroundRole(QPalette::AlternateBase);
73         setAutoFillBackground(true);
74         if (!info.isBlind)
75             buttonVideo->setIcon(KIcon("kdenlive-show-video"));
76         else
77             buttonVideo->setIcon(KIcon("kdenlive-hide-video"));
78     } else {
79         buttonVideo->setHidden(true);
80     }
81     if (!info.isMute)
82         buttonAudio->setIcon(KIcon("kdenlive-show-audio"));
83     else
84         buttonAudio->setIcon(KIcon("kdenlive-hide-audio"));
85
86     if (!info.isLocked)
87         buttonLock->setIcon(KIcon("kdenlive-unlock"));
88     else
89         buttonLock->setIcon(KIcon("kdenlive-lock"));
90
91     connect(buttonVideo, SIGNAL(clicked()), this, SLOT(switchVideo()));
92     connect(buttonAudio, SIGNAL(clicked()), this, SLOT(switchAudio()));
93     connect(buttonLock, SIGNAL(clicked()), this, SLOT(switchLock()));
94
95     // Don't show track buttons if size is too small
96     if (height < 40) {
97         buttonVideo->setHidden(true);
98         buttonAudio->setHidden(true);
99         buttonLock->setHidden(true);
100         //horizontalSpacer;
101     }
102
103     setContextMenuPolicy(Qt::DefaultContextMenu); //Qt::ActionsContextMenu);
104     QAction *insertAction = new QAction(i18n("Insert Track"), this);
105     m_menu.addAction(insertAction);
106     connect(insertAction, SIGNAL(triggered()), this, SLOT(slotAddTrack()));
107
108     QAction *removeAction = new QAction(KIcon("edit-delete"), i18n("Delete Track"), this);
109     m_menu.addAction(removeAction);
110     connect(removeAction, SIGNAL(triggered()), this, SLOT(slotDeleteTrack()));
111
112     QAction *configAction = new QAction(KIcon("configure"), i18n("Configure Track"), this);
113     m_menu.addAction(configAction);
114     connect(configAction, SIGNAL(triggered()), this, SLOT(slotConfigTrack()));
115 }
116
117 /*HeaderTrack::~HeaderTrack()
118 {
119 }*/
120
121 void HeaderTrack::updateEffectLabel(QStringList effects)
122 {
123     if (!effects.isEmpty()) {
124         effect_label->setHidden(false);
125         effect_label->setToolTip(effects.join("/"));
126     } else {
127         effect_label->setHidden(true);
128         effect_label->setToolTip(QString());
129     }
130 }
131
132 // virtual
133 void HeaderTrack::mousePressEvent(QMouseEvent * event)
134 {
135     if (track_number->hasFocus()) {
136         track_number->clearFocus();
137         return;
138     }
139     if (!m_isSelected) emit selectTrack(m_index);
140     emit showTrackEffects(m_index);
141     QWidget::mousePressEvent(event);
142 }
143
144 // virtual
145 void HeaderTrack::contextMenuEvent(QContextMenuEvent * event)
146 {
147     if (track_number->hasFocus()) {
148         track_number->clearFocus();
149         return;
150     }
151     m_menu.popup(event->globalPos());
152 }
153
154 void HeaderTrack::mouseDoubleClickEvent(QMouseEvent* event)
155 {
156     if (track_number->hasFocus()) {
157         track_number->clearFocus();
158         return;
159     }
160     slotConfigTrack();
161     QWidget::mouseDoubleClickEvent(event);
162 }
163
164 //virtual
165 void HeaderTrack::dropEvent(QDropEvent * event)
166 {
167     const QString effects = QString::fromUtf8(event->mimeData()->data("kdenlive/effectslist"));
168     QDomDocument doc;
169     doc.setContent(effects, true);
170     const QDomElement e = doc.documentElement();
171     emit selectTrack(m_index);
172     emit addTrackInfo(e, m_index);
173     /*if (scene() && !scene()->views().isEmpty()) {
174         event->accept();
175         CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
176         if (view) view->slotAddEffect(e, m_info.startPos, track());
177     }*/
178 }
179
180 //virtual
181 void HeaderTrack::dragEnterEvent(QDragEnterEvent *event)
182 {
183     if (buttonLock->isChecked()) event->setAccepted(false);
184     else event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist"));
185 }
186
187 void HeaderTrack::setSelectedIndex(int ix)
188 {
189     if (m_index == ix) {
190         m_isSelected = true;
191         setBackgroundRole(QPalette::Button);
192         setAutoFillBackground(true);
193     } else if (m_type != VIDEOTRACK) {
194         m_isSelected = false;
195         setAutoFillBackground(false);
196     } else {
197         m_isSelected = false;
198         setBackgroundRole(QPalette::AlternateBase);
199     }
200     update();
201 }
202
203 void HeaderTrack::adjustSize(int height)
204 {
205     // Don't show track buttons if size is too small
206     bool smallTracks = height < 40;
207     if (m_type == VIDEOTRACK)
208         buttonVideo->setHidden(smallTracks);
209     buttonAudio->setHidden(smallTracks);
210     buttonLock->setHidden(smallTracks);
211     setFixedHeight(height);
212 }
213
214 void HeaderTrack::switchVideo()
215 {
216     if (buttonVideo->isChecked())
217         buttonVideo->setIcon(KIcon("kdenlive-hide-video"));
218     else
219         buttonVideo->setIcon(KIcon("kdenlive-show-video"));
220     emit switchTrackVideo(m_index);
221 }
222
223 void HeaderTrack::switchAudio()
224 {
225     if (buttonAudio->isChecked())
226         buttonAudio->setIcon(KIcon("kdenlive-hide-audio"));
227     else
228         buttonAudio->setIcon(KIcon("kdenlive-show-audio"));
229     emit switchTrackAudio(m_index);
230 }
231
232 void HeaderTrack::switchLock(bool emitSignal)
233 {
234     if (buttonLock->isChecked())
235         buttonLock->setIcon(KIcon("kdenlive-lock"));
236     else
237         buttonLock->setIcon(KIcon("kdenlive-unlock"));
238     if (emitSignal)
239         emit switchTrackLock(m_index);
240 }
241
242 void HeaderTrack::setLock(bool lock)
243 {
244     buttonLock->setChecked(lock);
245     switchLock(false);
246 }
247
248 void HeaderTrack::slotDeleteTrack()
249 {
250     QTimer::singleShot(500, this, SLOT(deleteTrack()));
251 }
252
253 void HeaderTrack::deleteTrack()
254 {
255     emit deleteTrack(m_index);
256 }
257
258 void HeaderTrack::slotAddTrack()
259 {
260     emit insertTrack(m_index);
261 }
262
263 void HeaderTrack::slotRenameTrack()
264 {
265     if (m_name != track_number->text()) emit renameTrack(m_index, track_number->text());
266 }
267
268 void HeaderTrack::slotConfigTrack()
269 {
270     emit configTrack(m_index);
271 }
272
273
274 #include "headertrack.moc"