1 /***************************************************************************
2 * Copyright (C) 2007 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 ***************************************************************************/
24 #include "effectslistview.h"
26 #define EFFECT_VIDEO 1
27 #define EFFECT_AUDIO 2
28 #define EFFECT_CUSTOM 3
30 EffectsListView::EffectsListView(EffectsList *audioEffectList, EffectsList *videoEffectList, EffectsList *customEffectList, QWidget *parent)
31 : QWidget(parent), m_audioList(audioEffectList), m_videoList(videoEffectList), m_customList(customEffectList)
34 ui.effectlist->setSortingEnabled(true);
35 ui.search_effect->setListWidget(ui.effectlist);
36 ui.buttonInfo->setIcon(KIcon("help-about"));
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()));
46 ui.effectlist->setCurrentRow(0);
49 void EffectsListView::initList()
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));
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));
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));
72 void EffectsListView::filterList(int pos)
74 QListWidgetItem *item;
75 for (int i = 0; i < ui.effectlist->count(); i++)
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);
82 item = ui.effectlist->currentItem();
84 if (item->isHidden()) {
86 for (i = 0; i < ui.effectlist->count() && ui.effectlist->item(i)->isHidden(); i++);
87 ui.effectlist->setCurrentRow(i);
89 else ui.effectlist->scrollToItem(item);
93 void EffectsListView::showInfoPanel()
95 if (ui.infopanel->isVisible()) {
97 ui.buttonInfo->setDown(false);
100 ui.infopanel->show();
101 ui.buttonInfo->setDown(true);
105 void EffectsListView::slotEffectSelected()
107 QListWidgetItem *item = ui.effectlist->currentItem();
110 switch (item->data(Qt::UserRole).toInt())
113 effect = m_videoList->getEffectByName(ui.effectlist->currentItem()->text());
116 effect = m_audioList->getEffectByName(ui.effectlist->currentItem()->text());
119 effect = m_customList->getEffectByName(ui.effectlist->currentItem()->text());
122 emit addEffect(effect);
125 void EffectsListView::slotUpdateInfo()
127 QListWidgetItem *item = ui.effectlist->currentItem();
130 switch (item->data(Qt::UserRole).toInt())
133 info = m_videoList->getInfo(ui.effectlist->currentItem()->text());
136 info = m_audioList->getInfo(ui.effectlist->currentItem()->text());
139 info = m_customList->getInfo(ui.effectlist->currentItem()->text());
142 ui.infopanel->setText(info);
145 KListWidget *EffectsListView::listView()
147 return ui.effectlist;
150 #include "effectslistview.moc"