1 /***************************************************************************
2 * Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
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. *
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. *
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 ***************************************************************************/
21 #include "headertrack.h"
22 #include "kdenlivesettings.h"
28 #include <QMouseEvent>
33 HeaderTrack::HeaderTrack(int index, TrackInfo info, QWidget *parent) :
38 setFixedHeight(KdenliveSettings::trackheight());
40 m_view.track_number->setText(QString::number(m_index));
42 m_view.buttonVideo->setChecked(!info.isBlind);
43 m_view.buttonVideo->setToolTip(i18n("Hide track"));
44 m_view.buttonAudio->setChecked(!info.isMute);
45 m_view.buttonAudio->setToolTip(i18n("Mute track"));
46 m_view.buttonLock->setChecked(info.isLocked);
47 m_view.buttonLock->setToolTip(i18n("Lock track"));
49 if (m_type == VIDEOTRACK) {
50 m_view.frame->setBackgroundRole(QPalette::AlternateBase);
51 m_view.frame->setAutoFillBackground(true);
52 if (!info.isBlind) m_view.buttonVideo->setIcon(KIcon("kdenlive-show-video"));
53 else m_view.buttonVideo->setIcon(KIcon("kdenlive-hide-video"));
55 m_view.buttonVideo->setHidden(true);
57 if (!info.isMute) m_view.buttonAudio->setIcon(KIcon("kdenlive-show-audio"));
58 else m_view.buttonAudio->setIcon(KIcon("kdenlive-hide-audio"));
60 if (!info.isLocked) m_view.buttonLock->setIcon(KIcon("kdenlive-unlock"));
61 else m_view.buttonLock->setIcon(KIcon("kdenlive-lock"));
63 connect(m_view.buttonVideo, SIGNAL(clicked()), this, SLOT(switchVideo()));
64 connect(m_view.buttonAudio, SIGNAL(clicked()), this, SLOT(switchAudio()));
65 connect(m_view.buttonLock, SIGNAL(clicked()), this, SLOT(switchLock()));
67 // Don't show track buttons if size is too small
68 if (KdenliveSettings::trackheight() < 40) {
69 m_view.buttonVideo->setHidden(true);
70 m_view.buttonAudio->setHidden(true);
71 m_view.buttonLock->setHidden(true);
72 //m_view.horizontalSpacer;
75 setContextMenuPolicy(Qt::ActionsContextMenu);
76 QAction *insertAction = new QAction(i18n("Insert Track"), this);
77 addAction(insertAction);
78 connect(insertAction, SIGNAL(triggered()), this, SLOT(slotAddTrack()));
80 QAction *removeAction = new QAction(KIcon("edit-delete"), i18n("Delete Track"), this);
81 addAction(removeAction);
82 connect(removeAction, SIGNAL(triggered()), this, SLOT(slotDeleteTrack()));
84 QAction *changeAction = new QAction(i18n("Change Track Type"), this);
85 addAction(changeAction);
86 connect(changeAction, SIGNAL(triggered()), this, SLOT(slotChangeTrack()));
89 HeaderTrack::~HeaderTrack()
93 void HeaderTrack::switchVideo()
95 if (m_view.buttonVideo->isChecked()) {
96 m_view.buttonVideo->setIcon(KIcon("kdenlive-show-video"));
98 m_view.buttonVideo->setIcon(KIcon("kdenlive-hide-video"));
100 emit switchTrackVideo(m_index);
103 void HeaderTrack::switchAudio()
105 if (m_view.buttonAudio->isChecked()) {
106 m_view.buttonAudio->setIcon(KIcon("kdenlive-show-audio"));
108 m_view.buttonAudio->setIcon(KIcon("kdenlive-hide-audio"));
110 emit switchTrackAudio(m_index);
113 void HeaderTrack::switchLock(bool emitSignal)
115 if (m_view.buttonLock->isChecked()) {
116 m_view.buttonLock->setIcon(KIcon("kdenlive-lock"));
118 m_view.buttonLock->setIcon(KIcon("kdenlive-unlock"));
120 if (emitSignal) emit switchTrackLock(m_index);
124 void HeaderTrack::setLock(bool lock)
126 m_view.buttonLock->setChecked(lock);
130 void HeaderTrack::slotDeleteTrack()
132 emit deleteTrack(m_index);
135 void HeaderTrack::slotAddTrack()
137 emit insertTrack(m_index);
140 void HeaderTrack::slotChangeTrack()
142 emit changeTrack(m_index);
147 /*void HeaderTrack::paintEvent(QPaintEvent *e) {
148 QRect region = e->rect();
149 region.setTopLeft(QPoint(region.left() + 1, region.top() + 1));
150 region.setBottomRight(QPoint(region.right() - 1, region.bottom() - 1));
151 QPainter painter(this);
152 if (m_type == AUDIOTRACK) painter.fillRect(region, QBrush(QColor(240, 240, 255)));
153 else painter.fillRect(region, QBrush(QColor(255, 255, 255)));
154 painter.drawText(region, Qt::AlignCenter, m_label);
158 #include "headertrack.moc"