]> git.sesse.net Git - kdenlive/blobdiff - src/effectstackview.cpp
fix crash when starting under macOSX
[kdenlive] / src / effectstackview.cpp
index 1812e6f44761d31052daa92762f55bab768c8e8e..939a58f93dcf73dd9cf25b246bcd23ab9713487e 100644 (file)
 #include "effectslist.h"
 #include "clipitem.h"
 #include "mainwindow.h"
-
+#include "kdenlivesettings.h"
 
 EffectStackView::EffectStackView(QWidget *parent)
         : QWidget(parent) {
     ui.setupUi(this);
-    effectedit = new EffectStackEdit(ui.frame, this);
+    effectedit = new EffectStackEdit(ui.frame);
     //ui.effectlist->horizontalHeader()->setVisible(false);
     //ui.effectlist->verticalHeader()->setVisible(false);
     clipref = NULL;
@@ -58,7 +58,6 @@ EffectStackView::EffectStackView(QWidget *parent)
 
     connect(ui.effectlist, SIGNAL(itemSelectionChanged()), this , SLOT(slotItemSelectionChanged()));
     connect(ui.effectlist, SIGNAL(itemChanged(QListWidgetItem *)), this , SLOT(slotItemChanged(QListWidgetItem *)));
-    connect(ui.buttonNew, SIGNAL(clicked()), this, SLOT(slotNewEffect()));
     connect(ui.buttonUp, SIGNAL(clicked()), this, SLOT(slotItemUp()));
     connect(ui.buttonDown, SIGNAL(clicked()), this, SLOT(slotItemDown()));
     connect(ui.buttonDel, SIGNAL(clicked()), this, SLOT(slotItemDel()));
@@ -69,11 +68,19 @@ EffectStackView::EffectStackView(QWidget *parent)
     effectLists["audio"] = &MainWindow::audioEffects;
     effectLists["video"] = &MainWindow::videoEffects;
     effectLists["custom"] = &MainWindow::customEffects;
-
-    ui.infoBox->hide();
+    ui.splitter->setStretchFactor(1, 10);
+    ui.splitter->setStretchFactor(0, 1);
     setEnabled(false);
 }
 
+void EffectStackView::setMenu(QMenu *menu) {
+    ui.buttonNew->setMenu(menu);
+}
+
+void EffectStackView::updateProjectFormat(MltVideoProfile profile, Timecode t) {
+    effectedit->updateProjectFormat(profile, t);
+}
+
 void EffectStackView::slotSaveEffect() {
     QString name = QInputDialog::getText(this, i18n("Save Effect"), i18n("Name for saved effect: "));
     if (name.isEmpty()) return;
@@ -88,6 +95,7 @@ void EffectStackView::slotSaveEffect() {
     effect = doc.firstChild().toElement();
     effect.removeAttribute("kdenlive_ix");
     effect.setAttribute("id", name);
+    effect.setAttribute("type", "custom");
     QDomElement effectname = effect.firstChildElement("name");
     effect.removeChild(effectname);
     effectname = doc.createElement("name");
@@ -113,16 +121,17 @@ void EffectStackView::slotUpdateEffectParams(const QDomElement& old, const QDomE
         emit updateClipEffect(clipref, old, e, ui.effectlist->currentRow());
 }
 
-void EffectStackView::slotClipItemSelected(ClipItem* c) {
-    int ix = 0;
+void EffectStackView::slotClipItemSelected(ClipItem* c, int ix) {
     if (c && c == clipref) {
-        ix = ui.effectlist->currentRow();
+        if (ix == -1) ix = ui.effectlist->currentRow();
     } else {
         clipref = c;
         if (c) ix = c->selectedEffectIndex();
+        else ix = 0;
     }
     if (clipref == NULL) {
         ui.effectlist->clear();
+        effectedit->transferParamDesc(QDomElement(), 0, 0);
         setEnabled(false);
         return;
     }
@@ -143,18 +152,34 @@ void EffectStackView::slotItemChanged(QListWidgetItem *item) {
 
 void EffectStackView::setupListView(int ix) {
     ui.effectlist->clear();
+
+    // Issue 238: Add icons for effect type in effectstack.
+    KIcon videoIcon("kdenlive-show-video");
+    KIcon audioIcon("kdenlive-show-audio");
+    QListWidgetItem* item;
+
     for (int i = 0;i < clipref->effectsCount();i++) {
         QDomElement d = clipref->effectAt(i);
+
         QDomNode namenode = d.elementsByTagName("name").item(0);
         if (!namenode.isNull()) {
-            QListWidgetItem* item = new QListWidgetItem(namenode.toElement().text(), ui.effectlist);
+            // Issue 238: Add icons for effect type in effectstack.
+            // Logic more or less copied from initeffects.cpp
+            QString type = d.attribute("type", QString::null);
+            if ("audio" == type) {
+                item = new QListWidgetItem(audioIcon, i18n(namenode.toElement().text().toUtf8().data()), ui.effectlist);
+            } else if ("custom" == type) {
+                item = new QListWidgetItem(i18n(namenode.toElement().text().toUtf8().data()), ui.effectlist);
+            } else {
+                item = new QListWidgetItem(videoIcon, i18n(namenode.toElement().text().toUtf8().data()), ui.effectlist);
+            }
             item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
             if (d.attribute("disabled") == "1") item->setCheckState(Qt::Unchecked);
             else item->setCheckState(Qt::Checked);
         }
     }
     if (clipref->effectsCount() == 0) {
-        emit transferParamDesc(QDomElement(), 0, 100);
+        emit transferParamDesc(QDomElement(), 0, 0);
         ui.buttonDel->setEnabled(false);
         ui.buttonSave->setEnabled(false);
         ui.buttonReset->setEnabled(false);
@@ -178,7 +203,7 @@ void EffectStackView::slotItemSelectionChanged() {
     bool isChecked = false;
     if (hasItem && ui.effectlist->currentItem()->checkState() == Qt::Checked) isChecked = true;
     if (hasItem && ui.effectlist->currentItem()->isSelected()) {
-        emit transferParamDesc(clipref->effectAt(activeRow), 0, 100);//minx max frame
+        emit transferParamDesc(clipref->effectAt(activeRow), clipref->cropStart().frames(KdenliveSettings::project_fps()), clipref->cropDuration().frames(KdenliveSettings::project_fps()));//minx max frame
     }
     if (clipref) clipref->setSelectedEffect(activeRow);
     ui.buttonDel->setEnabled(hasItem);
@@ -190,29 +215,13 @@ void EffectStackView::slotItemSelectionChanged() {
 
 void EffectStackView::slotItemUp() {
     int activeRow = ui.effectlist->currentRow();
-    if (activeRow > 0) {
-        QDomElement act = clipref->effectAt(activeRow).cloneNode().toElement();
-        QDomElement before = clipref->effectAt(activeRow - 1).cloneNode().toElement();
-        clipref->setEffectAt(activeRow - 1, act);
-        clipref->setEffectAt(activeRow, before);
-    }
-    QListWidgetItem *item = ui.effectlist->takeItem(activeRow);
-    ui.effectlist->insertItem(activeRow - 1, item);
-    ui.effectlist->setCurrentItem(item);
+    if (activeRow <= 0) return;
     emit changeEffectPosition(clipref, activeRow + 1, activeRow);
 }
 
 void EffectStackView::slotItemDown() {
     int activeRow = ui.effectlist->currentRow();
-    if (activeRow < ui.effectlist->count() - 1) {
-        QDomElement act = clipref->effectAt(activeRow).cloneNode().toElement();
-        QDomElement after = clipref->effectAt(activeRow + 1).cloneNode().toElement();
-        clipref->setEffectAt(activeRow + 1, act);
-        clipref->setEffectAt(activeRow, after);
-    }
-    QListWidgetItem *item = ui.effectlist->takeItem(activeRow);
-    ui.effectlist->insertItem(activeRow + 1, item);
-    ui.effectlist->setCurrentItem(item);
+    if (activeRow >= ui.effectlist->count() - 1) return;
     emit changeEffectPosition(clipref, activeRow + 1, activeRow + 2);
 }
 
@@ -238,50 +247,11 @@ void EffectStackView::slotResetEffect() {
     }
     if (!dom.isNull()) {
         dom.setAttribute("kdenlive_ix", old.attribute("kdenlive_ix"));
-        emit transferParamDesc(dom, 0, 100);//minx max frame
+        emit transferParamDesc(dom, clipref->cropStart().frames(KdenliveSettings::project_fps()), clipref->cropDuration().frames(KdenliveSettings::project_fps()));//minx max frame
         emit updateClipEffect(clipref, old, dom, activeRow);
     }
 }
 
-void EffectStackView::slotNewEffect() {
-    int ix = ui.effectlist->currentRow();
-    QMenu *displayMenu = new QMenu(this);
-    displayMenu->setTitle("Filters");
-    foreach(const QString &type, effectLists.keys()) {
-        QAction *a = new QAction(type, displayMenu);
-        EffectsList *list = effectLists[type];
-
-        QMenu *parts = new QMenu(type, displayMenu);
-        parts->setTitle(type);
-        foreach(const QString &name, list->effectNames()) {
-            QAction *entry = new QAction(name, parts);
-            entry->setData(name);
-            entry->setToolTip(list->getInfo(name));
-            entry->setStatusTip(list->getInfo(name));
-            parts->addAction(entry);
-            //QAction
-        }
-        displayMenu->addMenu(parts);
-
-    }
-
-    QAction *result = displayMenu->exec(mapToGlobal(ui.buttonNew->pos() + ui.buttonNew->rect().bottomRight()));
-
-    if (result) {
-        //TODO effects.append(result->data().toString());
-        foreach(const EffectsList *e, effectLists.values()) {
-            QDomElement dom = e->getEffectByName(result->data().toString());
-            if (clipref)
-                clipref->addEffect(dom);
-            slotClipItemSelected(clipref);
-        }
-
-        setupListView(ix);
-        //kDebug()<< result->data();
-    }
-    delete displayMenu;
-
-}
 
 void EffectStackView::raiseWindow(QWidget* dock) {
     if (clipref && dock)
@@ -295,6 +265,7 @@ void EffectStackView::clear() {
     ui.buttonReset->setEnabled(false);
     ui.buttonUp->setEnabled(false);
     ui.buttonDown->setEnabled(false);
+    effectedit->transferParamDesc(QDomElement(), 0, 0);
 }
 
 #include "effectstackview.moc"