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