* *
***************************************************************************/
+#include <QHeaderView>
+#include <QMenu>
+#include <QInputDialog>
+#include <QTextStream>
+#include <QFile>
+
#include <KDebug>
#include <KLocale>
+#include <KMessageBox>
+#include <KStandardDirs>
#include "effectstackview.h"
#include "effectslist.h"
#include "clipitem.h"
#include "mainwindow.h"
-#include <QHeaderView>
-#include <QMenu>
+
EffectStackView::EffectStackView(QWidget *parent)
: QWidget(parent) {
ui.buttonDown->setToolTip(i18n("Move effect down"));
ui.buttonDel->setIcon(KIcon("trash-empty"));
ui.buttonDel->setToolTip(i18n("Delete effect"));
+ ui.buttonSave->setIcon(KIcon("document-save"));
+ ui.buttonSave->setToolTip(i18n("Save effect"));
ui.buttonReset->setIcon(KIcon("view-refresh"));
ui.buttonReset->setToolTip(i18n("Reset effect"));
connect(ui.buttonUp, SIGNAL(clicked()), this, SLOT(slotItemUp()));
connect(ui.buttonDown, SIGNAL(clicked()), this, SLOT(slotItemDown()));
connect(ui.buttonDel, SIGNAL(clicked()), this, SLOT(slotItemDel()));
+ connect(ui.buttonSave, SIGNAL(clicked()), this, SLOT(slotSaveEffect()));
connect(ui.buttonReset, SIGNAL(clicked()), this, SLOT(slotResetEffect()));
connect(this, SIGNAL(transferParamDesc(const QDomElement&, int , int)), effectedit , SLOT(transferParamDesc(const QDomElement&, int , int)));
connect(effectedit, SIGNAL(parameterChanged(const QDomElement&, const QDomElement&)), this , SLOT(slotUpdateEffectParams(const QDomElement&, const QDomElement&)));
setEnabled(false);
}
+void EffectStackView::slotSaveEffect() {
+ QString name = QInputDialog::getText(this, i18n("Save Effect"), i18n("Name for saved effect: "));
+ if (name.isEmpty()) return;
+ QString path = KStandardDirs::locateLocal("appdata", "effects/", true);
+ path = path + name + ".xml";
+ if (QFile::exists(path)) if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it ?")) == KMessageBox::No) return;
+
+ int i = ui.effectlist->currentRow();
+ QDomDocument doc;
+ QDomElement effect = clipref->effectAt(i).cloneNode().toElement();
+ doc.appendChild(doc.importNode(effect, true));
+ effect = doc.firstChild().toElement();
+ effect.removeAttribute("kdenlive_ix");
+ effect.setAttribute("id", name);
+ QDomElement effectname = effect.firstChildElement("name");
+ effect.removeChild(effectname);
+ effectname = doc.createElement("name");
+ QDomText nametext = doc.createTextNode(name);
+ effectname.appendChild(nametext);
+ effect.insertBefore(effectname, QDomNode());
+ QDomElement effectprops = effect.firstChildElement("properties");
+ effectprops.setAttribute("id", name);
+ effectprops.setAttribute("type", "custom");
+
+
+ QFile file(path);
+ if (file.open(QFile::WriteOnly | QFile::Truncate)) {
+ QTextStream out(&file);
+ out << doc.toString();
+ }
+ file.close();
+ emit reloadEffects();
+}
+
void EffectStackView::slotUpdateEffectParams(const QDomElement& old, const QDomElement& e) {
if (clipref)
- emit updateClipEffect(clipref, old, e);
+ emit updateClipEffect(clipref, old, e, ui.effectlist->currentRow());
}
void EffectStackView::slotClipItemSelected(ClipItem* c) {
- clipref = c;
+ int ix = 0;
+ if (c && c == clipref) {
+ ix = ui.effectlist->currentRow();
+ } else {
+ clipref = c;
+ if (c) ix = c->selectedEffectIndex();
+ }
if (clipref == NULL) {
+ ui.effectlist->clear();
setEnabled(false);
return;
}
setEnabled(true);
- setupListView();
-
+ setupListView(ix);
}
void EffectStackView::slotItemChanged(QListWidgetItem *item) {
ui.buttonReset->setEnabled(!disable);
int activeRow = ui.effectlist->currentRow();
if (activeRow >= 0) {
- emit changeEffectState(clipref, clipref->effectAt(activeRow), disable);
+ emit changeEffectState(clipref, activeRow, disable);
}
}
-void EffectStackView::setupListView() {
-
+void EffectStackView::setupListView(int ix) {
ui.effectlist->clear();
for (int i = 0;i < clipref->effectsCount();i++) {
QDomElement d = clipref->effectAt(i);
else item->setCheckState(Qt::Checked);
}
}
- if (clipref->effectsCount() == 0)
+ if (clipref->effectsCount() == 0) {
emit transferParamDesc(QDomElement(), 0, 100);
- ui.effectlist->setCurrentRow(0);
-
+ ui.buttonDel->setEnabled(false);
+ ui.buttonSave->setEnabled(false);
+ ui.buttonReset->setEnabled(false);
+ ui.buttonUp->setEnabled(false);
+ ui.buttonDown->setEnabled(false);
+ } else {
+ if (ix < 0) ix = 0;
+ if (ix > ui.effectlist->count() - 1) ix = ui.effectlist->count() - 1;
+ ui.effectlist->setCurrentRow(ix);
+ ui.buttonDel->setEnabled(true);
+ ui.buttonSave->setEnabled(true);
+ ui.buttonReset->setEnabled(true);
+ ui.buttonUp->setEnabled(ix > 0);
+ ui.buttonDown->setEnabled(ix < clipref->effectsCount() - 1);
+ }
}
void EffectStackView::slotItemSelectionChanged() {
bool hasItem = ui.effectlist->currentItem();
int activeRow = ui.effectlist->currentRow();
- bool isChecked = ui.effectlist->currentItem()->checkState() == Qt::Checked;
+ 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
}
+ if (clipref) clipref->setSelectedEffect(activeRow);
ui.buttonDel->setEnabled(hasItem);
+ ui.buttonSave->setEnabled(hasItem);
ui.buttonReset->setEnabled(hasItem && isChecked);
ui.buttonUp->setEnabled(activeRow > 0);
ui.buttonDown->setEnabled((activeRow < ui.effectlist->count() - 1) && hasItem);
QListWidgetItem *item = ui.effectlist->takeItem(activeRow);
ui.effectlist->insertItem(activeRow - 1, item);
ui.effectlist->setCurrentItem(item);
- emit refreshEffectStack(clipref);
+ emit changeEffectPosition(clipref, activeRow + 1, activeRow);
}
void EffectStackView::slotItemDown() {
QListWidgetItem *item = ui.effectlist->takeItem(activeRow);
ui.effectlist->insertItem(activeRow + 1, item);
ui.effectlist->setCurrentItem(item);
- emit refreshEffectStack(clipref);
+ emit changeEffectPosition(clipref, activeRow + 1, activeRow + 2);
}
void EffectStackView::slotItemDel() {
void EffectStackView::slotResetEffect() {
int activeRow = ui.effectlist->currentRow();
+ if (activeRow < 0) return;
QDomElement old = clipref->effectAt(activeRow).cloneNode().toElement();
QDomElement dom;
QString effectName = ui.effectlist->currentItem()->text();
- foreach(QString type, effectLists.keys()) {
+ foreach(const QString &type, effectLists.keys()) {
EffectsList *list = effectLists[type];
if (list->effectNames().contains(effectName)) {
dom = list->getEffectByName(effectName);
if (!dom.isNull()) {
dom.setAttribute("kdenlive_ix", old.attribute("kdenlive_ix"));
emit transferParamDesc(dom, 0, 100);//minx max frame
- emit updateClipEffect(clipref, old, dom);
+ emit updateClipEffect(clipref, old, dom, activeRow);
}
}
void EffectStackView::slotNewEffect() {
-
-
+ int ix = ui.effectlist->currentRow();
QMenu *displayMenu = new QMenu(this);
displayMenu->setTitle("Filters");
- foreach(QString type, effectLists.keys()) {
+ 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(QString name, list->effectNames()) {
+ foreach(const QString &name, list->effectNames()) {
QAction *entry = new QAction(name, parts);
entry->setData(name);
entry->setToolTip(list->getInfo(name));
if (result) {
//TODO effects.append(result->data().toString());
- foreach(EffectsList* e, effectLists.values()) {
+ foreach(const EffectsList *e, effectLists.values()) {
QDomElement dom = e->getEffectByName(result->data().toString());
if (clipref)
clipref->addEffect(dom);
slotClipItemSelected(clipref);
}
- setupListView();
+ setupListView(ix);
//kDebug()<< result->data();
}
delete displayMenu;
}
+void EffectStackView::raiseWindow(QWidget* dock) {
+ if (clipref && dock)
+ dock->raise();
+}
+
+void EffectStackView::clear() {
+ ui.effectlist->clear();
+ ui.buttonDel->setEnabled(false);
+ ui.buttonSave->setEnabled(false);
+ ui.buttonReset->setEnabled(false);
+ ui.buttonUp->setEnabled(false);
+ ui.buttonDown->setEnabled(false);
+}
+
#include "effectstackview.moc"