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 QString style = "QTreeView::branch:has-siblings:!adjoins-item{border-image: none 0;} \
39 QTreeView::branch:has-siblings:adjoins-item {border-image: none 0;} \
40 QTreeView::branch:!has-children:!has-siblings:adjoins-item {border-image: none 0;} \
41 QTreeView::branch:has-children:!has-siblings:closed,QTreeView::branch:closed:has-children:has-siblings { \
42 border-image: none;image: url(:/images/stylesheet-branch-closed.png);} \
43 QTreeView::branch:open:has-children:!has-siblings,QTreeView::branch:open:has-children:has-siblings { \
44 border-image: none;image: url(:/images/stylesheet-branch-open.png);}";
46 QMenu *contextMenu = new QMenu(this);
47 m_effectsList = new EffectsListWidget(contextMenu);
48 m_effectsList->setStyleSheet(style);
49 QVBoxLayout *lyr = new QVBoxLayout(effectlistframe);
50 lyr->addWidget(m_effectsList);
51 lyr->setContentsMargins(0, 0, 0, 0);
52 search_effect->setTreeWidget(m_effectsList);
53 search_effect->setToolTip(i18n("Search in the effect list"));
54 buttonInfo->setIcon(KIcon("help-about"));
55 buttonInfo->setToolTip(i18n("Show/Hide the effect description"));
56 setFocusPolicy(Qt::StrongFocus);
57 setFocusProxy(search_effect);
58 m_effectsList->setFocusProxy(search_effect);
60 if (KdenliveSettings::showeffectinfo())
61 buttonInfo->setDown(true);
65 contextMenu->addAction(KIcon("edit-delete"), i18n("Delete effect"), this, SLOT(slotRemoveEffect()));
67 connect(type_combo, SIGNAL(currentIndexChanged(int)), this, SLOT(filterList(int)));
68 connect(buttonInfo, SIGNAL(clicked()), this, SLOT(showInfoPanel()));
69 connect(m_effectsList, SIGNAL(itemSelectionChanged()), this, SLOT(slotUpdateInfo()));
70 connect(m_effectsList, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(slotEffectSelected()));
71 connect(search_effect, SIGNAL(hiddenChanged(QTreeWidgetItem *, bool)), this, SLOT(slotUpdateSearch(QTreeWidgetItem *, bool)));
72 connect(search_effect, SIGNAL(textChanged(QString)), this, SLOT(slotAutoExpand(QString)));
73 //m_effectsList->setCurrentRow(0);
76 void EffectsListView::filterList(int pos)
78 for (int i = 0; i < m_effectsList->topLevelItemCount(); i++) {
79 QTreeWidgetItem *folder = m_effectsList->topLevelItem(i);
80 bool hideFolder = true;
81 for (int j = 0; j < folder->childCount(); j++) {
82 QTreeWidgetItem *item = folder->child(j);
83 if (pos == 0 || pos == item->data(0, Qt::UserRole).toInt()) {
84 item->setHidden(false);
87 item->setHidden(true);
90 // do not hide the folder if it's empty but "All" is selected
93 folder->setHidden(hideFolder);
95 // make sure we don't show anything not matching the search expression
96 search_effect->updateSearch();
99 /*item = m_effectsList->currentItem();
101 if (item->isHidden()) {
103 for (i = 0; i < m_effectsList->count() && m_effectsList->item(i)->isHidden(); i++); //do nothing
104 m_effectsList->setCurrentRow(i);
105 } else m_effectsList->scrollToItem(item);
109 void EffectsListView::showInfoPanel()
111 bool show = !infopanel->isVisible();
112 infopanel->setVisible(show);
113 buttonInfo->setDown(show);
114 KdenliveSettings::setShoweffectinfo(show);
117 void EffectsListView::slotEffectSelected()
119 QDomElement effect = m_effectsList->currentEffect();
120 QTreeWidgetItem* item=m_effectsList->currentItem();
121 if (item && m_effectsList->indexOfTopLevelItem(item)!=-1){
122 item->setExpanded(!item->isExpanded());
124 if (!effect.isNull())
125 emit addEffect(effect);
128 void EffectsListView::slotUpdateInfo()
130 infopanel->setText(m_effectsList->currentInfo());
133 void EffectsListView::reloadEffectList(QMenu *effectsMenu, KActionCategory *effectActions)
135 m_effectsList->initList(effectsMenu, effectActions);
138 void EffectsListView::slotRemoveEffect()
140 QTreeWidgetItem *item = m_effectsList->currentItem();
141 QString effectId = item->text(0);
142 QString path = KStandardDirs::locateLocal("appdata", "effects/", true);
144 QDir directory = QDir(path);
147 const QStringList fileList = directory.entryList(filter, QDir::Files);
149 foreach(const QString &filename, fileList) {
150 itemName = KUrl(path + filename).path();
152 QFile file(itemName);
153 doc.setContent(&file, false);
155 QDomNodeList effects = doc.elementsByTagName("effect");
156 if (effects.count() != 1) {
157 kDebug() << "More than one effect in file " << itemName << ", NOT SUPPORTED YET";
159 QDomElement e = effects.item(0).toElement();
160 if (e.attribute("id") == effectId) {
161 QFile::remove(itemName);
166 emit reloadEffects();
169 void EffectsListView::slotUpdateSearch(QTreeWidgetItem *item, bool hidden)
172 if (item->data(0, Qt::UserRole).toInt() == type_combo->currentIndex()) {
174 item->parent()->setHidden(false);
176 if (type_combo->currentIndex() != 0)
177 item->setHidden(true);
182 void EffectsListView::slotAutoExpand(QString text)
184 search_effect->updateSearch();
186 for (int i = 0; i < m_effectsList->topLevelItemCount(); ++i) {
187 QTreeWidgetItem *folder = m_effectsList->topLevelItem(i);
188 bool expandFolder = false;
189 /*if (folder->isHidden())
191 if (!text.isEmpty()) {
192 for (int j = 0; j < folder->childCount(); j++) {
193 QTreeWidgetItem *item = folder->child(j);
194 if (!item->isHidden())
198 folder->setExpanded(expandFolder);
202 #include "effectslistview.moc"