void CollapsibleGroup::slotSaveGroup() { QString name = QInputDialog::getText(this, i18n("Save Group"), i18n("Name for saved group: "), QLineEdit::Normal, m_title->text()); if (name.isEmpty()) return; QDir dir(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/effects/"); if (!dir.exists()) { dir.mkpath(QStringLiteral(".")); } if (dir.exists(name + ".xml")) if (KMessageBox::questionYesNo(this, i18n("File %1 already exists.\nDo you want to overwrite it?", name + ".xml")) == KMessageBox::No) return; QDomDocument doc = effectsData(); QDomElement base = doc.documentElement(); QDomNodeList effects = base.elementsByTagName(QStringLiteral("effect")); for (int i = 0; i < effects.count(); ++i) { QDomElement eff = effects.at(i).toElement(); eff.removeAttribute(QStringLiteral("kdenlive_ix")); EffectInfo info; info.fromString(eff.attribute(QStringLiteral("kdenlive_info"))); // Make sure all effects have the correct new group name info.groupName = name; // Saved effect group should have a group index of -1 info.groupIndex = -1; eff.setAttribute(QStringLiteral("kdenlive_info"), info.toString()); } base.setAttribute(QStringLiteral("name"), name); base.setAttribute(QStringLiteral("id"), name); base.setAttribute(QStringLiteral("type"), QStringLiteral("custom")); QFile file(dir.absoluteFilePath(name + ".xml")); if (file.open(QFile::WriteOnly | QFile::Truncate)) { QTextStream out(&file); out << doc.toString(); } file.close(); emit reloadEffects(); }
void CollapsibleGroup::dropEvent(QDropEvent *event) { frame->setProperty("target", false); frame->setStyleSheet(frame->styleSheet()); const QString effects = QString::fromUtf8(event->mimeData()->data("kdenlive/effectslist")); //event->acceptProposedAction(); QDomDocument doc; doc.setContent(effects, true); QDomElement e = doc.documentElement(); int ix = e.attribute("kdenlive_ix").toInt(); if (ix == 0 || e.tagName() == "effectgroup") { if (e.tagName() == "effectgroup") { // dropped a group on another group QDomNodeList pastedEffects = e.elementsByTagName("effect"); if (pastedEffects.isEmpty() || m_subWidgets.isEmpty()) { // Buggy groups, should not happen event->ignore(); return; } QList <int> pastedEffectIndexes; QList <int> currentEffectIndexes; EffectInfo pasteInfo; pasteInfo.fromString(pastedEffects.at(0).toElement().attribute("kdenlive_info")); if (pasteInfo.groupIndex == -1) { // Group dropped from effects list, add effect e.setAttribute("kdenlive_ix", m_subWidgets.last()->effectIndex()); emit addEffect(e); event->setDropAction(Qt::CopyAction); event->accept(); return; } // Moving group for (int i = 0; i < pastedEffects.count(); i++) { pastedEffectIndexes << pastedEffects.at(i).toElement().attribute("kdenlive_ix").toInt(); } for (int i = 0; i < m_subWidgets.count(); i++) { currentEffectIndexes << m_subWidgets.at(i)->effectIndex(); } kDebug()<<"PASTING: "<<pastedEffectIndexes<<" TO "<<currentEffectIndexes; if (pastedEffectIndexes.at(0) < currentEffectIndexes.at(0)) { // Pasting group after current one: emit moveEffect(pastedEffectIndexes, currentEffectIndexes.last(), pasteInfo.groupIndex, pasteInfo.groupName); } else { // Group moved before current one emit moveEffect(pastedEffectIndexes, currentEffectIndexes.first(), pasteInfo.groupIndex, pasteInfo.groupName); } event->setDropAction(Qt::MoveAction); event->accept(); return; } // effect dropped from effects list, add it e.setAttribute("kdenlive_info", m_info.toString()); if (!m_subWidgets.isEmpty()) { e.setAttribute("kdenlive_ix", m_subWidgets.at(0)->effectIndex()); } emit addEffect(e); event->setDropAction(Qt::CopyAction); event->accept(); return; } if (m_subWidgets.isEmpty()) return; int new_index = m_subWidgets.last()->effectIndex(); emit moveEffect(QList <int> () <<ix, new_index, m_info.groupIndex, m_title->text()); event->setDropAction(Qt::MoveAction); event->accept(); }