]> git.sesse.net Git - kdenlive/blobdiff - src/effectstack/collapsiblegroup.cpp
Fix ungrouping and track effect drop
[kdenlive] / src / effectstack / collapsiblegroup.cpp
index 11fb7493ed9048a289339588f18bd3499baba973..ac0ab4ec115dd1967caab731e05b3c0f5c9c61fe 100644 (file)
@@ -27,6 +27,7 @@
 #include <QDragEnterEvent>
 #include <QDropEvent>
 
+
 #include <KDebug>
 #include <KGlobalSettings>
 #include <KLocale>
 #include <KUrlRequester>
 #include <KColorScheme>
 
+MyEditableLabel::MyEditableLabel(QWidget * parent):
+    QLineEdit(parent)
+{
+    setFrame(false);
+    setReadOnly(true);
+    setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
+}
+
+void MyEditableLabel::mouseDoubleClickEvent ( QMouseEvent * e )
+{
+    setReadOnly(false);
+    selectAll();
+    e->accept();
+}
+
 
-CollapsibleGroup::CollapsibleGroup(int ix, bool firstGroup, bool lastGroup, QWidget * parent) :
+CollapsibleGroup::CollapsibleGroup(int ix, bool firstGroup, bool lastGroup, QString groupName, QWidget * parent) :
         AbstractCollapsibleWidget(parent),
         m_index(ix)
 {
     setupUi(this);
+    m_subWidgets = QList <CollapsibleEffect *> ();
     setFont(KGlobalSettings::smallestReadableFont());
-   
+    QHBoxLayout *l = static_cast <QHBoxLayout *>(framegroup->layout());
+    m_title = new MyEditableLabel(this);
+    l->insertWidget(4, m_title);
+    m_title->setText(groupName.isEmpty() ? i18n("Effect Group") : groupName);
+    connect(m_title, SIGNAL(editingFinished()), this, SLOT(slotRenameGroup()));
     buttonUp->setIcon(KIcon("kdenlive-up"));
     buttonUp->setToolTip(i18n("Move effect up"));
     buttonDown->setIcon(KIcon("kdenlive-down"));
@@ -57,7 +78,6 @@ CollapsibleGroup::CollapsibleGroup(int ix, bool firstGroup, bool lastGroup, QWid
     m_menu->addAction(KIcon("view-refresh"), i18n("Reset effect"), this, SLOT(slotResetEffect()));
     m_menu->addAction(KIcon("document-save"), i18n("Save effect"), this, SLOT(slotSaveEffect()));
     
-    title->setText(i18n("Effect Group"));
     effecticon->setPixmap(KIcon("folder").pixmap(16,16));
     m_menu->addAction(KIcon("list-remove"), i18n("Ungroup"), this, SLOT(slotUnGroup()));
     setAcceptDrops(true);
@@ -97,14 +117,14 @@ void CollapsibleGroup::setActive(bool activate)
 
 void CollapsibleGroup::mouseDoubleClickEvent ( QMouseEvent * event )
 {
-    if (frame->underMouse() && collapseButton->isEnabled()) slotSwitch();
+    if (framegroup->underMouse() && collapseButton->isEnabled()) slotSwitch();
     QWidget::mouseDoubleClickEvent(event);
 }
 
 
 void CollapsibleGroup::slotEnable(bool enable)
 {
-    title->setEnabled(enable);
+    m_title->setEnabled(enable);
     enabledBox->blockSignals(true);
     enabledBox->setChecked(enable);
     enabledBox->blockSignals(false);
@@ -191,12 +211,9 @@ void CollapsibleGroup::slotShow(bool show)
     //emit parameterChanged(m_original_effect, m_effect, effectIndex());   
 }
 
-void CollapsibleGroup::updateGroupIndex(int groupIndex)
+QWidget *CollapsibleGroup::title() const
 {
-  /*TODO:
-    m_info.groupIndex = groupIndex;
-    m_effect.setAttribute("kdenlive_info", m_info.toString());
-    emit parameterChanged(m_original_effect, m_effect, effectIndex());*/
+    return m_title;
 }
 
 void CollapsibleGroup::addGroupEffect(CollapsibleEffect *effect)
@@ -204,11 +221,13 @@ void CollapsibleGroup::addGroupEffect(CollapsibleEffect *effect)
     QVBoxLayout *vbox = static_cast<QVBoxLayout *>(widgetFrame->layout());
     if (vbox == NULL) {
        vbox = new QVBoxLayout();
-       vbox->setContentsMargins(10, 0, 0, 0);
+       vbox->setContentsMargins(0, 0, 0, 0);
        vbox->setSpacing(2);
        widgetFrame->setLayout(vbox);
     }
     effect->setGroupIndex(groupIndex());
+    effect->setGroupName(m_title->text());
+    m_subWidgets.append(effect);
     vbox->addWidget(effect);
 }
 
@@ -221,14 +240,12 @@ void CollapsibleGroup::removeGroup(int ix, QVBoxLayout *layout)
 {
     QVBoxLayout *vbox = static_cast<QVBoxLayout *>(widgetFrame->layout());
     if (vbox == NULL) return;
-    
-    for (int j = vbox->count() - 1; j >= 0; j--) {
-       QLayoutItem *child = vbox->takeAt(j);
-       CollapsibleGroup *e = static_cast<CollapsibleGroup *>(child->widget());
-       layout->insertWidget(ix, e);
-       e->updateGroupIndex(-1);
-       delete child;
+    for (int i = m_subWidgets.count() - 1; i >= 0 ; i--) {
+       vbox->removeWidget(m_subWidgets.at(i));
+       layout->insertWidget(ix, m_subWidgets.at(i));
+        m_subWidgets.at(i)->removeFromGroup();
     }
+    m_subWidgets.clear();
 }
 
 int CollapsibleGroup::groupIndex() const
@@ -236,8 +253,6 @@ int CollapsibleGroup::groupIndex() const
     return m_index;
 }
 
-
-
 bool CollapsibleGroup::isGroup() const
 {
     return true;
@@ -256,22 +271,22 @@ void CollapsibleGroup::updateTimecodeFormat()
 void CollapsibleGroup::dragEnterEvent(QDragEnterEvent *event)
 {
     if (event->mimeData()->hasFormat("kdenlive/effectslist")) {
-       frame->setProperty("active", true);
-       frame->setStyleSheet(frame->styleSheet());
+       framegroup->setProperty("active", true);
+       framegroup->setStyleSheet(framegroup->styleSheet());
        event->acceptProposedAction();
     }
 }
 
 void CollapsibleGroup::dragLeaveEvent(QDragLeaveEvent */*event*/)
 {
-    frame->setProperty("active", false);
-    frame->setStyleSheet(frame->styleSheet());
+    framegroup->setProperty("active", false);
+    framegroup->setStyleSheet(framegroup->styleSheet());
 }
 
 void CollapsibleGroup::dropEvent(QDropEvent *event)
 {
-    frame->setProperty("active", false);
-    frame->setStyleSheet(frame->styleSheet());
+    framegroup->setProperty("active", false);
+    framegroup->setStyleSheet(framegroup->styleSheet());
     const QString effects = QString::fromUtf8(event->mimeData()->data("kdenlive/effectslist"));
     //event->acceptProposedAction();
     QDomDocument doc;
@@ -286,13 +301,37 @@ void CollapsibleGroup::dropEvent(QDropEvent *event)
        emit addEffect(e);
        return;
     }
-    int new_index = -1;
-    QVBoxLayout *vbox = static_cast<QVBoxLayout *>(widgetFrame->layout());
-    if (vbox == NULL) return;
-    CollapsibleEffect *effect = static_cast<CollapsibleEffect *>(vbox->itemAt(vbox->count() -1)->widget());
-    new_index = effect->effectIndex();
-    emit moveEffect(ix, new_index, m_index);
+    if (m_subWidgets.isEmpty()) return;
+    int new_index = m_subWidgets.at(m_subWidgets.count() - 1)->effectIndex();
+    emit moveEffect(ix, new_index, m_index, m_title->text());
     event->setDropAction(Qt::MoveAction);
     event->accept();
 }
 
+void CollapsibleGroup::slotRenameGroup()
+{
+    m_title->setReadOnly(true);
+    if (m_title->text().isEmpty()) m_title->setText(i18n("Effect Group"));
+    for (int j = 0; j < m_subWidgets.count(); j++) {
+       m_subWidgets.at(j)->setGroupName(m_title->text());
+    }
+    emit groupRenamed(this);
+}
+
+QList <CollapsibleEffect*> CollapsibleGroup::effects()
+{
+    return m_subWidgets;
+}
+
+QDomDocument CollapsibleGroup::effectsData()
+{
+    QDomDocument doc;
+    QDomElement list = doc.createElement("list");
+    list.setAttribute("name", m_title->text());
+    doc.appendChild(list);
+    for (int j = 0; j < m_subWidgets.count(); j++) {
+       list.appendChild(doc.importNode(m_subWidgets.at(j)->effect(), true));
+    }
+    return doc;
+}
+