]> git.sesse.net Git - kdenlive/blob - src/effectslistview.cpp
better management of effects in list
[kdenlive] / src / effectslistview.cpp
1 /***************************************************************************
2  *   Copyright (C) 2007 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 <KDebug>
22 #include <KLocale>
23
24 #include "effectslistview.h"
25
26 #define EFFECT_VIDEO 1
27 #define EFFECT_AUDIO 2
28 #define EFFECT_CUSTOM 3
29
30 EffectsListView::EffectsListView(EffectsList *audioEffectList, EffectsList *videoEffectList, EffectsList *customEffectList, QWidget *parent)
31     : QWidget(parent), m_audioList(audioEffectList), m_videoList(videoEffectList), m_customList(customEffectList)
32 {
33   ui.setupUi(this);
34   ui.effectlist->setSortingEnabled(true);
35   ui.search_effect->setListWidget(ui.effectlist);
36   ui.buttonInfo->setIcon(KIcon("help-about"));
37   ui.infopanel->hide();
38
39   initList();
40
41   connect(ui.type_combo, SIGNAL(currentIndexChanged(int)), this, SLOT(filterList(int)));
42   connect (ui.buttonInfo, SIGNAL (clicked()), this, SLOT (showInfoPanel()));
43   connect(ui.effectlist, SIGNAL(itemSelectionChanged()), this, SLOT(slotUpdateInfo()));
44   connect(ui.effectlist, SIGNAL(doubleClicked(QListWidgetItem *,const QPoint &)), this, SLOT(slotEffectSelected()));
45
46   ui.effectlist->setCurrentRow(0); 
47 }
48
49 void EffectsListView::initList()
50 {
51   ui.effectlist->clear();
52   QStringList names = m_videoList->effectNames();
53   QListWidgetItem *item;
54   foreach (QString str, names) {
55     item = new QListWidgetItem(str, ui.effectlist);
56     item->setData(Qt::UserRole, QString::number((int) EFFECT_VIDEO));
57   }
58
59   names = m_audioList->effectNames();
60   foreach (QString str, names) {
61     item = new QListWidgetItem(str, ui.effectlist);
62     item->setData(Qt::UserRole, QString::number((int) EFFECT_AUDIO));
63   }
64
65   names = m_customList->effectNames();
66   foreach (QString str, names) {
67     item = new QListWidgetItem(str, ui.effectlist);
68     item->setData(Qt::UserRole, QString::number((int) EFFECT_CUSTOM));
69   }
70 }
71
72 void EffectsListView::filterList(int pos)
73 {
74   QListWidgetItem *item;
75   for (int i = 0; i < ui.effectlist->count(); i++)
76   {
77     item = ui.effectlist->item(i);
78     if (pos == 0) item->setHidden(false);
79     else if (item->data(Qt::UserRole).toInt() == pos) item->setHidden(false);
80     else item->setHidden(true);
81   }
82   item = ui.effectlist->currentItem();
83   if (item) {
84     if (item->isHidden()) {
85       int i;
86       for (i = 0; i < ui.effectlist->count() && ui.effectlist->item(i)->isHidden(); i++);
87       ui.effectlist->setCurrentRow(i);
88     }
89     else ui.effectlist->scrollToItem(item);
90   }
91 }
92
93 void EffectsListView::showInfoPanel()
94 {
95   if (ui.infopanel->isVisible()) {
96     ui.infopanel->hide();
97     ui.buttonInfo->setDown(false);
98   }
99   else {
100     ui.infopanel->show();
101     ui.buttonInfo->setDown(true);
102   }
103 }
104
105 void EffectsListView::slotEffectSelected()
106 {
107   QListWidgetItem *item = ui.effectlist->currentItem();
108   if (!item) return;
109   QDomElement effect;
110   switch (item->data(Qt::UserRole).toInt())
111   {
112     case 1:
113       effect = m_videoList->getEffectByName(ui.effectlist->currentItem()->text());
114       break;
115     case 2:
116       effect = m_audioList->getEffectByName(ui.effectlist->currentItem()->text());
117       break;
118     default:
119       effect = m_customList->getEffectByName(ui.effectlist->currentItem()->text());
120       break;
121   }
122   emit addEffect(effect);
123 }
124
125 void EffectsListView::slotUpdateInfo()
126 {
127   QListWidgetItem *item = ui.effectlist->currentItem();
128   if (!item) return;
129   QString info; 
130   switch (item->data(Qt::UserRole).toInt())
131   {
132   case 1:
133     info = m_videoList->getInfo(ui.effectlist->currentItem()->text());
134     break;
135   case 2:
136     info = m_audioList->getInfo(ui.effectlist->currentItem()->text());
137     break;
138   default:
139     info = m_customList->getInfo(ui.effectlist->currentItem()->text());
140     break;
141   }
142   ui.infopanel->setText(info);
143 }
144
145 KListWidget *EffectsListView::listView()
146 {
147   return ui.effectlist;
148 }
149
150 #include "effectslistview.moc"