]> git.sesse.net Git - kdenlive/blob - src/headertrack.cpp
Reformat initializer lists in all constructors.
[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     view.setupUi(this);
40     view.track_number->setText(QString::number(m_index));
41     view.buttonVideo->setChecked(!info.isBlind);
42     view.buttonVideo->setToolTip(i18n("Hide track"));
43     view.buttonAudio->setChecked(!info.isMute);
44     view.buttonAudio->setToolTip(i18n("Mute track"));
45     view.buttonLock->setChecked(info.isLocked);
46     view.buttonLock->setToolTip(i18n("Lock track"));
47
48     if (m_type == VIDEOTRACK) {
49         view.frame->setBackgroundRole(QPalette::AlternateBase);
50         view.frame->setAutoFillBackground(true);
51         if (!info.isBlind) view.buttonVideo->setIcon(KIcon("kdenlive-show-video"));
52         else view.buttonVideo->setIcon(KIcon("kdenlive-hide-video"));
53     } else {
54         view.buttonVideo->setHidden(true);
55     }
56     if (!info.isMute) view.buttonAudio->setIcon(KIcon("kdenlive-show-audio"));
57     else view.buttonAudio->setIcon(KIcon("kdenlive-hide-audio"));
58
59     if (!info.isLocked) view.buttonLock->setIcon(KIcon("kdenlive-unlock"));
60     else view.buttonLock->setIcon(KIcon("kdenlive-lock"));
61
62     connect(view.buttonVideo, SIGNAL(clicked()), this, SLOT(switchVideo()));
63     connect(view.buttonAudio, SIGNAL(clicked()), this, SLOT(switchAudio()));
64     connect(view.buttonLock, SIGNAL(clicked()), this, SLOT(switchLock()));
65
66     m_contextMenu = new QMenu(this);
67
68     QAction *insertAction = new QAction(i18n("Insert Track"), this);
69     m_contextMenu->addAction(insertAction);
70     connect(insertAction, SIGNAL(triggered()), this, SLOT(slotAddTrack()));
71
72     QAction *removeAction = new QAction(KIcon("edit-delete"), i18n("Delete Track"), this);
73     m_contextMenu->addAction(removeAction);
74     connect(removeAction, SIGNAL(triggered()), this, SLOT(slotDeleteTrack()));
75
76     QAction *changeAction = new QAction(i18n("Change Track Type"), this);
77     m_contextMenu->addAction(changeAction);
78     connect(changeAction, SIGNAL(triggered()), this, SLOT(slotChangeTrack()));
79 }
80
81 HeaderTrack::~HeaderTrack()
82 {
83     if (m_contextMenu) delete m_contextMenu;
84 }
85
86 void HeaderTrack::switchVideo()
87 {
88     if (view.buttonVideo->isChecked()) {
89         view.buttonVideo->setIcon(KIcon("kdenlive-show-video"));
90     } else {
91         view.buttonVideo->setIcon(KIcon("kdenlive-hide-video"));
92     }
93     emit switchTrackVideo(m_index);
94 }
95
96 void HeaderTrack::switchAudio()
97 {
98     if (view.buttonAudio->isChecked()) {
99         view.buttonAudio->setIcon(KIcon("kdenlive-show-audio"));
100     } else {
101         view.buttonAudio->setIcon(KIcon("kdenlive-hide-audio"));
102     }
103     emit switchTrackAudio(m_index);
104 }
105
106 void HeaderTrack::switchLock(bool emitSignal)
107 {
108     if (view.buttonLock->isChecked()) {
109         view.buttonLock->setIcon(KIcon("kdenlive-lock"));
110     } else {
111         view.buttonLock->setIcon(KIcon("kdenlive-unlock"));
112     }
113     if (emitSignal) emit switchTrackLock(m_index);
114 }
115
116
117 void HeaderTrack::setLock(bool lock)
118 {
119     view.buttonLock->setChecked(lock);
120     switchLock(false);
121 }
122
123 void HeaderTrack::slotDeleteTrack()
124 {
125     emit deleteTrack(m_index);
126 }
127
128 void HeaderTrack::slotAddTrack()
129 {
130     emit insertTrack(m_index);
131 }
132
133 void HeaderTrack::slotChangeTrack()
134 {
135     emit changeTrack(m_index);
136 }
137
138 // virtual
139 void HeaderTrack::contextMenuEvent(QContextMenuEvent * event)
140 {
141     m_contextMenu->popup(event->globalPos());
142 }
143
144 // virtual
145 /*void HeaderTrack::paintEvent(QPaintEvent *e) {
146     QRect region = e->rect();
147     region.setTopLeft(QPoint(region.left() + 1, region.top() + 1));
148     region.setBottomRight(QPoint(region.right() - 1, region.bottom() - 1));
149     QPainter painter(this);
150     if (m_type == AUDIOTRACK) painter.fillRect(region, QBrush(QColor(240, 240, 255)));
151     else painter.fillRect(region, QBrush(QColor(255, 255, 255)));
152     painter.drawText(region, Qt::AlignCenter, m_label);
153 }*/
154
155
156 #include "headertrack.moc"