]> git.sesse.net Git - kdenlive/blob - src/effectslistview.cpp
- Fix drop frame timecode format. [1]
[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 "effectslistview.h"
22 #include "effectslistwidget.h"
23 #include "effectslist.h"
24 #include "kdenlivesettings.h"
25
26 #include <KDebug>
27 #include <KLocale>
28 #include <KStandardDirs>
29
30 #include <QMenu>
31 #include <QDir>
32
33 EffectsListView::EffectsListView(QWidget *parent) :
34         QWidget(parent)
35 {
36     setupUi(this);
37
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
47     if (KdenliveSettings::showeffectinfo()) {
48         buttonInfo->setDown(true);
49     } else infopanel->hide();
50     menu->addAction(KIcon("edit-delete"), i18n("Delete effect"), this, SLOT(slotRemoveEffect()));
51
52     connect(type_combo, SIGNAL(currentIndexChanged(int)), this, SLOT(filterList(int)));
53     connect(buttonInfo, SIGNAL(clicked()), this, SLOT(showInfoPanel()));
54     connect(m_effectsList, SIGNAL(itemSelectionChanged()), this, SLOT(slotUpdateInfo()));
55     connect(m_effectsList, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(slotEffectSelected()));
56     connect(search_effect, SIGNAL(hiddenChanged(QTreeWidgetItem *, bool)), this, SLOT(slotUpdateSearch(QTreeWidgetItem *, bool)));
57     //m_effectsList->setCurrentRow(0);
58 }
59
60
61 void EffectsListView::focusInEvent(QFocusEvent * /*event*/)
62 {
63     search_effect->setFocus();
64 }
65
66 void EffectsListView::filterList(int pos)
67 {
68     for (int i = 0; i < m_effectsList->topLevelItemCount(); i++) {
69         QTreeWidgetItem *folder = m_effectsList->topLevelItem(i);
70         bool hideFolder = true;
71         for (int j = 0; j < folder->childCount(); j++) {
72             QTreeWidgetItem *item = folder->child(j);
73             if (pos == 0 || pos == item->data(0, Qt::UserRole).toInt()) {
74                 item->setHidden(false);
75                 hideFolder = false;
76             } else {
77                 item->setHidden(true);
78             }
79         }
80         // do not hide the folder if it's empty but "All" is selected
81         if (pos == 0)
82             hideFolder = false;
83         folder->setHidden(hideFolder);
84     }
85     // make sure we don't show anything not matching the search expression
86     search_effect->updateSearch();
87
88     /*item = m_effectsList->currentItem();
89     if (item) {
90         if (item->isHidden()) {
91             int i;
92             for (i = 0; i < m_effectsList->count() && m_effectsList->item(i)->isHidden(); i++); //do nothing
93             m_effectsList->setCurrentRow(i);
94         } else m_effectsList->scrollToItem(item);
95     }*/
96 }
97
98 void EffectsListView::showInfoPanel()
99 {
100     if (infopanel->isVisible()) {
101         infopanel->setVisible(false);
102         buttonInfo->setDown(false);
103         KdenliveSettings::setShoweffectinfo(false);
104     } else {
105         infopanel->setVisible(true);
106         buttonInfo->setDown(true);
107         KdenliveSettings::setShoweffectinfo(true);
108     }
109 }
110
111 void EffectsListView::slotEffectSelected()
112 {
113     QDomElement effect = m_effectsList->currentEffect();
114     if (!effect.isNull()) emit addEffect(effect);
115 }
116
117 void EffectsListView::slotUpdateInfo()
118 {
119     infopanel->setText(m_effectsList->currentInfo());
120 }
121
122 void EffectsListView::reloadEffectList()
123 {
124     m_effectsList->initList();
125 }
126
127 void EffectsListView::slotRemoveEffect()
128 {
129     QTreeWidgetItem *item = m_effectsList->currentItem();
130     QString effectId = item->text(0);
131     QString path = KStandardDirs::locateLocal("appdata", "effects/", true);
132
133     QDir directory = QDir(path);
134     QStringList filter;
135     filter << "*.xml";
136     const QStringList fileList = directory.entryList(filter, QDir::Files);
137     QString itemName;
138     foreach(const QString &filename, fileList) {
139         itemName = KUrl(path + filename).path();
140         QDomDocument doc;
141         QFile file(itemName);
142         doc.setContent(&file, false);
143         file.close();
144         QDomNodeList effects = doc.elementsByTagName("effect");
145         if (effects.count() != 1) {
146             kDebug() << "More than one effect in file " << itemName << ", NOT SUPPORTED YET";
147         } else {
148             QDomElement e = effects.item(0).toElement();
149             if (e.attribute("id") == effectId) {
150                 QFile::remove(itemName);
151                 break;
152             }
153         }
154     }
155     emit reloadEffects();
156 }
157
158 void EffectsListView::slotUpdateSearch(QTreeWidgetItem *item, bool hidden)
159 {
160     if (!hidden) {
161         if (item->data(0, Qt::UserRole).toInt() == type_combo->currentIndex()) {
162             item->parent()->setHidden(false);
163         } else {
164             if (type_combo->currentIndex() != 0)
165                 item->setHidden(true);
166         }
167     }
168 }
169
170 #include "effectslistview.moc"