]> git.sesse.net Git - kdenlive/blobdiff - src/effectslistwidget.cpp
Make render NTSC/PAL standard more strict.
[kdenlive] / src / effectslistwidget.cpp
index dae8c12a33e45ab5a591261c55dcc553581521f0..cdeb00b74f882b3a6c69dd5cc3d86e8f61c67f16 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <KDebug>
 #include <KStandardDirs>
+#include <KAction>
 
 #include <QApplication>
 #include <QMouseEvent>
@@ -39,9 +40,9 @@ const int TypeRole = Qt::UserRole;
 const int IdRole = TypeRole + 1;
 
 
-EffectsListWidget::EffectsListWidget(QMenu *menu, QWidget *parent) :
+EffectsListWidget::EffectsListWidget(QMenu *contextMenu, QWidget *parent) :
         QTreeWidget(parent),
-        m_menu(menu)
+        m_menu(contextMenu)
 {
     setColumnCount(1);
     setDragEnabled(true);
@@ -55,7 +56,6 @@ EffectsListWidget::EffectsListWidget(QMenu *menu, QWidget *parent) :
     QPalette p = palette();
     p.setBrush(QPalette::Base, Qt::NoBrush);
     setPalette(p);
-    initList();
     connect(this, SIGNAL(activated(const QModelIndex &)), this, SLOT(slotExpandItem(const QModelIndex &)));
 }
 
@@ -68,25 +68,22 @@ void EffectsListWidget::slotExpandItem(const QModelIndex & index)
     setExpanded(index, !isExpanded(index));
 }
 
-void EffectsListWidget::initList()
+void EffectsListWidget::initList(QMenu *effectsMenu, KActionCategory *effectActions)
 {
     QString current;
     QString currentFolder;
     QTreeWidgetItem *item = NULL;
-    QTreeWidgetItem *parentItem;
     bool found = false;
-
+    effectsMenu->clear();
+    
     if (currentItem()) {
         current = currentItem()->text(0);
-        if (currentItem()->parent()) currentFolder = currentItem()->parent()->text(0);
-        else if (currentItem()->data(0, TypeRole) ==  EFFECT_FOLDER)  currentFolder = currentItem()->text(0);
+        if (currentItem()->parent())
+            currentFolder = currentItem()->parent()->text(0);
+        else if (currentItem()->data(0, TypeRole) ==  EFFECT_FOLDER)
+            currentFolder = currentItem()->text(0);
     }
 
-    QString effectName;
-    QStringList effectInfo;
-    KIcon videoIcon("kdenlive-show-video");
-    KIcon audioIcon("kdenlive-show-audio");
-    KIcon customIcon("kdenlive-custom-effect");
     KIcon folderIcon("folder");
 
     QString effectCategory = KStandardDirs::locate("config", "kdenliveeffectscategory.rc");
@@ -98,12 +95,12 @@ void EffectsListWidget::initList()
     QStringList folderNames;
     QDomNodeList groups = doc.documentElement().elementsByTagName("group");
     for (int i = 0; i < groups.count(); i++) {
-        folderNames << groups.at(i).firstChild().firstChild().nodeValue();
+        folderNames << i18n(groups.at(i).firstChild().firstChild().nodeValue().toUtf8().constData());
     }
     for (int i = 0; i < topLevelItemCount(); i++) {
         topLevelItem(i)->takeChildren();
         QString currentName = topLevelItem(i)->text(0);
-        if (currentName != i18n("Misc") && currentName != i18n("Audio") && currentName != i18n("Custom") && !folderNames.contains(currentName)) {
+        if (currentName != i18n("Misc") && currentName != i18n("Audio") && currentName != i18nc("Folder Name", "Custom") && !folderNames.contains(currentName)) {
             takeTopLevelItem(i);
             i--;
         }
@@ -142,9 +139,9 @@ void EffectsListWidget::initList()
         insertTopLevelItem(0, audio);
     }
 
-    QTreeWidgetItem *custom = findFolder(i18n("Custom"));
+    QTreeWidgetItem *custom = findFolder(i18nc("Folder Name", "Custom"));
     if (custom == NULL) {
-        custom = new QTreeWidgetItem((QTreeWidget*)0, QStringList(i18n("Custom")));
+        custom = new QTreeWidgetItem((QTreeWidget*)0, QStringList(i18nc("Folder Name", "Custom")));
         custom->setIcon(0, folderIcon);
         custom->setData(0, TypeRole, QString::number((int) EFFECT_FOLDER));
         custom->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
@@ -153,82 +150,79 @@ void EffectsListWidget::initList()
 
     //insertTopLevelItems(0, folders);
 
+    loadEffects(&MainWindow::videoEffects, KIcon("kdenlive-show-video"), misc, &folders, QString::number((int) EFFECT_VIDEO), current, &found);
+    loadEffects(&MainWindow::audioEffects, KIcon("kdenlive-show-audio"), audio, &folders, QString::number((int) EFFECT_AUDIO), current, &found);
+    loadEffects(&MainWindow::customEffects, KIcon("kdenlive-custom-effect"), custom, static_cast<QList<QTreeWidgetItem *> *>(0), QString::number((int) EFFECT_CUSTOM), current, &found);
 
-    int ct = MainWindow::videoEffects.count();
-    for (int ix = 0; ix < ct; ix ++) {
-        effectInfo = MainWindow::videoEffects.effectIdInfo(ix);
-        parentItem = NULL;
-        for (int i = 0; i < folders.count(); i++) {
-            QStringList l = folders.at(i)->data(0, IdRole).toString().split(',', QString::SkipEmptyParts);
-            if (l.contains(effectInfo.at(2))) {
-                parentItem = folders.at(i);
+    if (!found && !currentFolder.isEmpty()) {
+        // previously selected effect was removed, focus on its parent folder
+        for (int i = 0; i < topLevelItemCount(); i++) {
+            if (topLevelItem(i)->text(0) == currentFolder) {
+                setCurrentItem(topLevelItem(i));
                 break;
             }
         }
-        if (parentItem == NULL) parentItem = misc;
-        if (!effectInfo.isEmpty()) {
-            item = new QTreeWidgetItem(parentItem, QStringList(effectInfo.takeFirst()));
-            item->setIcon(0, videoIcon);
-            item->setData(0, TypeRole, QString::number((int) EFFECT_VIDEO));
-            item->setData(0, IdRole, effectInfo);
-            if (item->text(0) == current) {
-                setCurrentItem(item);
-                found = true;
-            }
+
+    }
+    setSortingEnabled(true);
+    sortByColumn(0, Qt::AscendingOrder);
+
+    // populate effects menu
+    for (int i = 0; i < topLevelItemCount(); i++) {
+        if (!topLevelItem(i)->childCount())
+            continue;
+        QMenu *sub = new QMenu(topLevelItem(i)->text(0), effectsMenu);
+        effectsMenu->addMenu(sub);
+        for (int j = 0; j < topLevelItem(i)->childCount(); j++) {
+                QTreeWidgetItem *item = topLevelItem(i)->child(j);
+                KAction *a = new KAction(KIcon(item->icon(0)), item->text(0), sub);
+                QStringList data = item->data(0, IdRole).toStringList();
+                QString id = data.at(1);
+                if (id.isEmpty()) id = data.at(0);
+                a->setData(data);
+                a->setIconVisibleInMenu(false);
+                sub->addAction(a);
+                effectActions->addAction("video_effect_" + id, a);
         }
     }
+}
+
+void EffectsListWidget::loadEffects(const EffectsList *effectlist, KIcon icon, QTreeWidgetItem *defaultFolder, const QList<QTreeWidgetItem *> *folders, const QString type, const QString current, bool *found)
+{
+    QStringList effectInfo, l;
+    QTreeWidgetItem *parentItem;
+    QTreeWidgetItem *item;
+    int ct = effectlist->count();
 
-    ct = MainWindow::audioEffects.count();
     for (int ix = 0; ix < ct; ix ++) {
-        effectInfo = MainWindow::audioEffects.effectIdInfo(ix);
+        effectInfo = effectlist->effectIdInfo(ix);
+        effectInfo.append(type);
         parentItem = NULL;
-        for (int i = 0; i < folders.count(); i++) {
-            QStringList l = folders.at(i)->data(0, IdRole).toString().split(',', QString::SkipEmptyParts);
-            if (l.contains(effectInfo.at(2))) {
-                parentItem = folders.at(i);
-                break;
-            }
-        }
-        if (parentItem == NULL) parentItem = audio;
-        if (!effectInfo.isEmpty()) {
-            item = new QTreeWidgetItem(parentItem, QStringList(effectInfo.takeFirst()));
-            item->setIcon(0, audioIcon);
-            item->setData(0, TypeRole, QString::number((int) EFFECT_AUDIO));
-            item->setData(0, IdRole, effectInfo);
-            if (item->text(0) == current) {
-                setCurrentItem(item);
-                found = true;
+
+        if (folders) {
+            for (int i = 0; i < folders->count(); i++) {
+                l = folders->at(i)->data(0, IdRole).toString().split(',', QString::SkipEmptyParts);
+                if (l.contains(effectInfo.at(2))) {
+                    parentItem = folders->at(i);
+                    break;
+                }
             }
         }
-    }
+        if (parentItem == NULL)
+            parentItem = defaultFolder;
 
-    ct = MainWindow::customEffects.count();
-    kDebug() << "--- REBUILDING;: " << ct;
-    for (int ix = 0; ix < ct; ix ++) {
-        effectInfo = MainWindow::customEffects.effectIdInfo(ix);
         if (!effectInfo.isEmpty()) {
-            item = new QTreeWidgetItem(custom, QStringList(effectInfo.takeFirst()));
-            item->setIcon(0, customIcon);
-            item->setData(0, TypeRole, QString::number((int) EFFECT_CUSTOM));
+            item = new QTreeWidgetItem(parentItem, QStringList(effectInfo.takeFirst()));
+            item->setIcon(0, icon);
+            item->setData(0, TypeRole, type);
             item->setData(0, IdRole, effectInfo);
+            item->setToolTip(0, effectlist->getInfo(effectInfo.at(0), effectInfo.at(1)));
             if (item->text(0) == current) {
                 setCurrentItem(item);
-                found = true;
+                *found = true;
             }
         }
     }
-    if (!found && !currentFolder.isEmpty()) {
-        // previously selected effect was removed, focus on its parent folder
-        for (int i = 0; i < topLevelItemCount(); i++) {
-            if (topLevelItem(i)->text(0) == currentFolder) {
-                setCurrentItem(topLevelItem(i));
-                break;
-            }
-        }
-
-    }
-    setSortingEnabled(true);
-    sortByColumn(0, Qt::AscendingOrder);
 }
 
 QTreeWidgetItem *EffectsListWidget::findFolder(const QString name)