-EffectStackView::EffectStackView(EffectsList *audioEffectList, EffectsList *videoEffectList, EffectsList *customEffectList, QWidget *parent)
-: QWidget(parent)
-{
- ui.setupUi(this);
- effectedit=new EffectStackEdit(ui.frame,this);
- //ui.effectlist->horizontalHeader()->setVisible(false);
- //ui.effectlist->verticalHeader()->setVisible(false);
- clipref=NULL;
-
- ui.buttonNew->setIcon(KIcon("document-new"));
- ui.buttonNew->setToolTip(i18n("Add new effect"));
- ui.buttonUp->setIcon(KIcon("go-up"));
- ui.buttonUp->setToolTip(i18n("Move effect up"));
- ui.buttonDown->setIcon(KIcon("go-down"));
- ui.buttonDown->setToolTip(i18n("Move effect down"));
- ui.buttonDel->setIcon(KIcon("trash-empty"));
- ui.buttonDel->setToolTip(i18n("Delete effect"));
- ui.buttonReset->setIcon(KIcon("view-refresh"));
- ui.buttonReset->setToolTip(i18n("Reset effect"));
-
-
- ui.effectlist->setDragDropMode(QAbstractItemView::NoDragDrop);//use internal if drop is recognised right
-
- connect (ui.effectlist, SIGNAL ( itemSelectionChanged()), this , SLOT( slotItemSelectionChanged() ));
- 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()) );
- 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& )));
- effectLists["audio"]=audioEffectList;
- effectLists["video"]=videoEffectList;
- effectLists["custom"]=customEffectList;
-
- ui.infoBox->hide();
- setEnabled(false);
- setEnabled(false);
-
-}
-
-void EffectStackView::slotUpdateEffectParams(const QDomElement& old, const QDomElement& e){
- if (clipref)
- emit updateClipEffect(clipref, old, e);
-}
-
-void EffectStackView::slotClipItemSelected(ClipItem* c)
-{
- clipref=c;
- if (clipref==NULL) {
- setEnabled(false);
- return;
- }
- setEnabled(true);
- setupListView();
-
-}
-
-void EffectStackView::setupListView(){
-
- ui.effectlist->clear();
- 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);
- item->setFlags(Qt::ItemIsSelectable|Qt::ItemIsDragEnabled|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
- item->setCheckState(Qt::Checked);
- }
- }
- if (clipref->effectsCount() == 0)
- emit transferParamDesc(QDomElement(), 0, 100);
- ui.effectlist->setCurrentRow(0);
-
-}
-
-void EffectStackView::slotItemSelectionChanged(){
- bool hasItem = ui.effectlist->currentItem();
- int activeRow = ui.effectlist->currentRow();
- if (hasItem && ui.effectlist->currentItem()->isSelected() ){
- emit transferParamDesc(clipref->effectAt(activeRow), 0, 100);//minx max frame
- }
- ui.buttonDel->setEnabled( hasItem );
- ui.buttonReset->setEnabled( hasItem );
- ui.buttonUp->setEnabled( activeRow >0 );
- ui.buttonDown->setEnabled( (activeRow < ui.effectlist->count()-1) && hasItem );
-}
-
-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);
- emit refreshEffectStack(clipref);
-}
-
-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);
- emit refreshEffectStack(clipref);
-}
-
-void EffectStackView::slotItemDel(){
- int activeRow = ui.effectlist->currentRow();
- if ( activeRow>=0 ){
- emit removeEffect(clipref, clipref->effectAt(activeRow));
- }
+void EffectStackView::updateProjectFormat(MltVideoProfile profile, Timecode t)
+{
+ m_effectedit->updateProjectFormat(profile, t);
+}
+
+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 %1 already exists.\nDo you want to overwrite it?", path)) == KMessageBox::No) return;
+
+ int i = m_ui.effectlist->currentRow();
+ QDomDocument doc;
+ QDomElement effect = m_currentEffectList.at(i).cloneNode().toElement();
+ doc.appendChild(doc.importNode(effect, true));
+ 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");
+ 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 (m_trackMode)
+ emit updateEffect(NULL, m_trackindex, old, e, m_ui.effectlist->currentRow());
+ else if (m_clipref)
+ emit updateEffect(m_clipref, -1, old, e, m_ui.effectlist->currentRow());
+}
+
+void EffectStackView::slotClipItemSelected(ClipItem* c, int ix)
+{
+ if (c && !c->isEnabled()) return;
+ if (c && c == m_clipref) {
+ if (ix == -1) ix = m_ui.effectlist->currentRow();
+ //if (ix == -1 || ix == m_ui.effectlist->currentRow()) return;
+ } else {
+ m_clipref = c;
+ if (c) {
+ QString cname = m_clipref->clipName();
+ if (cname.length() > 30) {
+ m_ui.checkAll->setToolTip(i18n("Effects for %1").arg(cname));
+ cname.truncate(27);
+ m_ui.checkAll->setText(i18n("Effects for %1").arg(cname) + "...");
+ } else {
+ m_ui.checkAll->setToolTip(QString());
+ m_ui.checkAll->setText(i18n("Effects for %1").arg(cname));
+ }
+ ix = c->selectedEffectIndex();
+ QString size = c->baseClip()->getProperty("frame_size");
+ double factor = c->baseClip()->getProperty("aspect_ratio").toDouble();
+ QPoint p((int)(size.section('x', 0, 0).toInt() * factor + 0.5), size.section('x', 1, 1).toInt());
+ m_effectedit->setFrameSize(p);
+ } else {
+ ix = 0;
+ }
+ }
+ if (m_clipref == NULL) {
+ m_ui.effectlist->blockSignals(true);
+ m_ui.effectlist->clear();
+ m_effectedit->transferParamDesc(QDomElement(), 0, 0, 0);
+ //m_ui.region_url->clear();
+ m_ui.effectlist->blockSignals(false);
+ m_ui.checkAll->setToolTip(QString());
+ m_ui.checkAll->setText(QString());
+ m_ui.labelComment->setText(QString());
+ setEnabled(false);
+ return;
+ }
+ setEnabled(true);
+ m_trackMode = false;
+ m_currentEffectList = m_clipref->effectList();
+ setupListView(ix);
+}
+
+void EffectStackView::slotTrackItemSelected(int ix, const TrackInfo info)
+{
+ m_clipref = NULL;
+ m_trackMode = true;
+ m_currentEffectList = info.effectsList;
+ m_trackInfo = info;
+ kDebug() << "// TRACK; " << ix << ", EFFECTS: " << m_currentEffectList.count();
+ setEnabled(true);
+ m_ui.checkAll->setToolTip(QString());
+ m_ui.checkAll->setText(i18n("Effects for track %1").arg(info.trackName.isEmpty() ? QString::number(ix) : info.trackName));
+ m_trackindex = ix;
+ setupListView(0);
+}
+
+void EffectStackView::slotItemChanged(QListWidgetItem *item)
+{
+ bool disable = true;
+ if (item->checkState() == Qt::Checked) disable = false;
+ m_ui.frame->setEnabled(!disable);
+ m_ui.buttonReset->setEnabled(!disable);
+ int activeRow = m_ui.effectlist->currentRow();
+ if (activeRow >= 0) {
+ m_effectedit->updateParameter("disable", QString::number((int) disable));
+ if (m_trackMode)
+ emit changeEffectState(NULL, m_trackindex, activeRow, disable);
+ else
+ emit changeEffectState(m_clipref, -1, activeRow, disable);
+ }
+ slotUpdateCheckAllButton();
+}
+
+
+void EffectStackView::setupListView(int ix)
+{
+ m_ui.effectlist->blockSignals(true);
+ m_ui.effectlist->clear();
+
+ // Issue 238: Add icons for effect type in effectstack.
+ KIcon videoIcon("kdenlive-show-video");
+ KIcon audioIcon("kdenlive-show-audio");
+ KIcon customIcon("kdenlive-custom-effect");
+ QListWidgetItem* item;
+
+ for (int i = 0; i < m_currentEffectList.count(); i++) {
+ const QDomElement d = m_currentEffectList.at(i).cloneNode().toElement();
+ if (d.isNull()) {
+ kDebug() << " . . . . WARNING, NULL EFFECT IN STACK!!!!!!!!!";
+ continue;
+ }
+
+ /*QDomDocument doc;
+ doc.appendChild(doc.importNode(d, true));
+ kDebug() << "IMPORTED STK: " << doc.toString();*/
+
+ QDomNode namenode = d.elementsByTagName("name").item(0);
+ if (!namenode.isNull()) {
+ // Issue 238: Add icons for effect type in effectstack.
+ // Logic more or less copied from initeffects.cpp
+ QString type = d.attribute("type", QString());
+ if ("audio" == type) {
+ item = new QListWidgetItem(audioIcon, i18n(namenode.toElement().text().toUtf8().data()), m_ui.effectlist);
+ } else if ("custom" == type) {
+ item = new QListWidgetItem(customIcon, i18n(namenode.toElement().text().toUtf8().data()), m_ui.effectlist);
+ } else {
+ item = new QListWidgetItem(videoIcon, i18n(namenode.toElement().text().toUtf8().data()), m_ui.effectlist);
+ }
+ item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
+ if (d.attribute("disable") == "1")
+ item->setCheckState(Qt::Unchecked);
+ else
+ item->setCheckState(Qt::Checked);
+ }
+ }
+ if (m_ui.effectlist->count() == 0) {
+ m_ui.buttonDel->setEnabled(false);
+ m_ui.buttonSave->setEnabled(false);
+ m_ui.buttonReset->setEnabled(false);
+ m_ui.buttonUp->setEnabled(false);
+ m_ui.buttonDown->setEnabled(false);
+ m_ui.checkAll->setEnabled(false);
+ m_ui.buttonShowComments->setEnabled(false);
+ m_ui.labelComment->setHidden(true);
+ } else {
+ ix = qBound(0, ix, m_ui.effectlist->count() - 1);
+ m_ui.effectlist->setCurrentRow(ix);
+ m_ui.checkAll->setEnabled(true);
+ }
+ m_ui.effectlist->blockSignals(false);
+ if (m_ui.effectlist->count() == 0) {
+ m_effectedit->transferParamDesc(QDomElement(), 0, 0, 0);
+ //m_ui.region_url->clear();
+ } else slotItemSelectionChanged(false);
+ slotUpdateCheckAllButton();
+}
+
+void EffectStackView::slotItemSelectionChanged(bool update)
+{
+ bool hasItem = m_ui.effectlist->currentItem();
+ int activeRow = m_ui.effectlist->currentRow();
+ bool isChecked = false;
+ if (hasItem && m_ui.effectlist->currentItem()->checkState() == Qt::Checked) isChecked = true;
+ QDomElement eff;
+ if (hasItem && m_ui.effectlist->currentItem()->isSelected()) {
+ eff = m_currentEffectList.at(activeRow);
+ if (m_trackMode) {
+ // showing track effects
+ m_effectedit->transferParamDesc(eff, 0, 0, m_trackInfo.duration);
+ } else m_effectedit->transferParamDesc(eff,
+ 0,
+ m_clipref->cropStart().frames(KdenliveSettings::project_fps()),
+ (m_clipref->cropStart() + m_clipref->cropDuration()).frames(KdenliveSettings::project_fps()) - 1); //minx max frame
+ //m_ui.region_url->setUrl(KUrl(eff.attribute("region")));
+ m_ui.labelComment->setText(i18n(eff.firstChildElement("description").firstChildElement("full").text().toUtf8().data()));
+ }
+ if (!m_trackMode && m_clipref && update) m_clipref->setSelectedEffect(activeRow);
+ m_ui.buttonDel->setEnabled(hasItem);
+ m_ui.buttonSave->setEnabled(hasItem);
+ m_ui.buttonReset->setEnabled(hasItem && isChecked);
+ m_ui.buttonUp->setEnabled(activeRow > 0);
+ m_ui.buttonDown->setEnabled((activeRow < m_ui.effectlist->count() - 1) && hasItem);
+ m_ui.frame->setEnabled(isChecked);
+ m_ui.buttonShowComments->setEnabled(hasItem);
+
+ emit showComments(m_ui.buttonShowComments->isChecked());
+ m_ui.labelComment->setVisible(hasItem && m_ui.labelComment->text().count() && (m_ui.buttonShowComments->isChecked() || !eff.elementsByTagName("parameter").count()));
+}
+
+void EffectStackView::slotItemUp()
+{
+ int activeRow = m_ui.effectlist->currentRow();
+ if (activeRow <= 0) return;
+ if (m_trackMode) emit changeEffectPosition(NULL, m_trackindex, activeRow + 1, activeRow);
+ else emit changeEffectPosition(m_clipref, -1, activeRow + 1, activeRow);
+}
+
+void EffectStackView::slotItemDown()
+{
+ int activeRow = m_ui.effectlist->currentRow();
+ if (activeRow >= m_ui.effectlist->count() - 1) return;
+ if (m_trackMode) emit changeEffectPosition(NULL, m_trackindex, activeRow + 1, activeRow + 2);
+ else emit changeEffectPosition(m_clipref, -1, activeRow + 1, activeRow + 2);
+}
+
+void EffectStackView::slotItemDel()
+{
+ int activeRow = m_ui.effectlist->currentRow();
+ if (activeRow >= 0) {
+ if (m_trackMode)
+ emit removeEffect(NULL, m_trackindex, m_currentEffectList.at(activeRow).cloneNode().toElement());
+ else
+ emit removeEffect(m_clipref, -1, m_clipref->effectAt(activeRow));
+ slotUpdateCheckAllButton();
+ }