]> git.sesse.net Git - kdenlive/blob - src/headertrack.cpp
cleanup + fix crash on track insert
[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 "kdenlivesettings.h"
23
24 #include <KIcon>
25 #include <KLocale>
26 #include <KDebug>
27
28 #include <QMouseEvent>
29 #include <QWidget>
30 #include <QPainter>
31 #include <QAction>
32
33 HeaderTrack::HeaderTrack(int index, TrackInfo info, QWidget *parent) :
34         QWidget(parent),
35         m_index(index),
36         m_type(info.type)
37 {
38     setFixedHeight(KdenliveSettings::trackheight());
39     m_view.setupUi(this);
40     m_view.track_number->setText(QString::number(m_index));
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     setContextMenuPolicy(Qt::ActionsContextMenu);
67     QAction *insertAction = new QAction(i18n("Insert Track"), this);
68     addAction(insertAction);
69     connect(insertAction, SIGNAL(triggered()), this, SLOT(slotAddTrack()));
70
71     QAction *removeAction = new QAction(KIcon("edit-delete"), i18n("Delete Track"), this);
72     addAction(removeAction);
73     connect(removeAction, SIGNAL(triggered()), this, SLOT(slotDeleteTrack()));
74
75     QAction *changeAction = new QAction(i18n("Change Track Type"), this);
76     addAction(changeAction);
77     connect(changeAction, SIGNAL(triggered()), this, SLOT(slotChangeTrack()));
78 }
79
80 HeaderTrack::~HeaderTrack()
81 {
82 }
83
84 void HeaderTrack::switchVideo()
85 {
86     if (m_view.buttonVideo->isChecked()) {
87         m_view.buttonVideo->setIcon(KIcon("kdenlive-show-video"));
88     } else {
89         m_view.buttonVideo->setIcon(KIcon("kdenlive-hide-video"));
90     }
91     emit switchTrackVideo(m_index);
92 }
93
94 void HeaderTrack::switchAudio()
95 {
96     if (m_view.buttonAudio->isChecked()) {
97         m_view.buttonAudio->setIcon(KIcon("kdenlive-show-audio"));
98     } else {
99         m_view.buttonAudio->setIcon(KIcon("kdenlive-hide-audio"));
100     }
101     emit switchTrackAudio(m_index);
102 }
103
104 void HeaderTrack::switchLock(bool emitSignal)
105 {
106     if (m_view.buttonLock->isChecked()) {
107         m_view.buttonLock->setIcon(KIcon("kdenlive-lock"));
108     } else {
109         m_view.buttonLock->setIcon(KIcon("kdenlive-unlock"));
110     }
111     if (emitSignal) emit switchTrackLock(m_index);
112 }
113
114
115 void HeaderTrack::setLock(bool lock)
116 {
117     m_view.buttonLock->setChecked(lock);
118     switchLock(false);
119 }
120
121 void HeaderTrack::slotDeleteTrack()
122 {
123     emit deleteTrack(m_index);
124 }
125
126 void HeaderTrack::slotAddTrack()
127 {
128     emit insertTrack(m_index);
129 }
130
131 void HeaderTrack::slotChangeTrack()
132 {
133     emit changeTrack(m_index);
134 }
135
136
137 // virtual
138 /*void HeaderTrack::paintEvent(QPaintEvent *e) {
139     QRect region = e->rect();
140     region.setTopLeft(QPoint(region.left() + 1, region.top() + 1));
141     region.setBottomRight(QPoint(region.right() - 1, region.bottom() - 1));
142     QPainter painter(this);
143     if (m_type == AUDIOTRACK) painter.fillRect(region, QBrush(QColor(240, 240, 255)));
144     else painter.fillRect(region, QBrush(QColor(255, 255, 255)));
145     painter.drawText(region, Qt::AlignCenter, m_label);
146 }*/
147
148
149 #include "headertrack.moc"