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 ***************************************************************************/
21 #include "effectslistview.h"
22 #include "effectslistwidget.h"
23 #include "effectslist.h"
24 #include "kdenlivesettings.h"
28 #include <KStandardDirs>
33 EffectsListView::EffectsListView(QWidget *parent) :
38 QMenu *menu = new QMenu(this);
39 m_effectsList = new EffectsListWidget(menu);
40 QVBoxLayout *lyr = new QVBoxLayout(effectlistframe);
41 lyr->addWidget(m_effectsList);
42 lyr->setContentsMargins(0, 0, 0, 0);
43 search_effect->setTreeWidget(m_effectsList);
44 buttonInfo->setIcon(KIcon("help-about"));
45 setFocusPolicy(Qt::StrongFocus);
46 setFocusProxy(search_effect);
48 if (KdenliveSettings::showeffectinfo()) {
49 buttonInfo->setDown(true);
50 } else infopanel->hide();
51 menu->addAction(KIcon("edit-delete"), i18n("Delete effect"), this, SLOT(slotRemoveEffect()));
53 connect(type_combo, SIGNAL(currentIndexChanged(int)), this, SLOT(filterList(int)));
54 connect(buttonInfo, SIGNAL(clicked()), this, SLOT(showInfoPanel()));
55 connect(m_effectsList, SIGNAL(itemSelectionChanged()), this, SLOT(slotUpdateInfo()));
56 connect(m_effectsList, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(slotEffectSelected()));
57 connect(search_effect, SIGNAL(hiddenChanged(QTreeWidgetItem *, bool)), this, SLOT(slotUpdateSearch(QTreeWidgetItem *, bool)));
58 connect(search_effect, SIGNAL(textChanged(QString)), this, SLOT(slotAutoExpand(QString)));
59 //m_effectsList->setCurrentRow(0);
62 void EffectsListView::filterList(int pos)
64 for (int i = 0; i < m_effectsList->topLevelItemCount(); i++) {
65 QTreeWidgetItem *folder = m_effectsList->topLevelItem(i);
66 bool hideFolder = true;
67 for (int j = 0; j < folder->childCount(); j++) {
68 QTreeWidgetItem *item = folder->child(j);
69 if (pos == 0 || pos == item->data(0, Qt::UserRole).toInt()) {
70 item->setHidden(false);
73 item->setHidden(true);
76 // do not hide the folder if it's empty but "All" is selected
79 folder->setHidden(hideFolder);
81 // make sure we don't show anything not matching the search expression
82 search_effect->updateSearch();
85 /*item = m_effectsList->currentItem();
87 if (item->isHidden()) {
89 for (i = 0; i < m_effectsList->count() && m_effectsList->item(i)->isHidden(); i++); //do nothing
90 m_effectsList->setCurrentRow(i);
91 } else m_effectsList->scrollToItem(item);
95 void EffectsListView::showInfoPanel()
97 bool show = !infopanel->isVisible();
98 infopanel->setVisible(show);
99 buttonInfo->setDown(show);
100 KdenliveSettings::setShoweffectinfo(show);
103 void EffectsListView::slotEffectSelected()
105 QDomElement effect = m_effectsList->currentEffect();
106 if (!effect.isNull()) emit addEffect(effect);
109 void EffectsListView::slotUpdateInfo()
111 infopanel->setText(m_effectsList->currentInfo());
114 void EffectsListView::reloadEffectList()
116 m_effectsList->initList();
119 void EffectsListView::slotRemoveEffect()
121 QTreeWidgetItem *item = m_effectsList->currentItem();
122 QString effectId = item->text(0);
123 QString path = KStandardDirs::locateLocal("appdata", "effects/", true);
125 QDir directory = QDir(path);
128 const QStringList fileList = directory.entryList(filter, QDir::Files);
130 foreach(const QString &filename, fileList) {
131 itemName = KUrl(path + filename).path();
133 QFile file(itemName);
134 doc.setContent(&file, false);
136 QDomNodeList effects = doc.elementsByTagName("effect");
137 if (effects.count() != 1) {
138 kDebug() << "More than one effect in file " << itemName << ", NOT SUPPORTED YET";
140 QDomElement e = effects.item(0).toElement();
141 if (e.attribute("id") == effectId) {
142 QFile::remove(itemName);
147 emit reloadEffects();
150 void EffectsListView::slotUpdateSearch(QTreeWidgetItem *item, bool hidden)
153 if (item->data(0, Qt::UserRole).toInt() == type_combo->currentIndex()) {
155 item->parent()->setHidden(false);
157 if (type_combo->currentIndex() != 0)
158 item->setHidden(true);
163 void EffectsListView::slotAutoExpand(QString text)
165 for (int i = 0; i < m_effectsList->topLevelItemCount(); ++i) {
166 QTreeWidgetItem *folder = m_effectsList->topLevelItem(i);
167 bool expandFolder = false;
168 /*if (folder->isHidden())
170 if (!text.isEmpty()) {
171 for (int j = 0; j < folder->childCount(); j++) {
172 QTreeWidgetItem *item = folder->child(j);
173 if (!item->isHidden())
177 folder->setExpanded(expandFolder);
181 #include "effectslistview.moc"