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