X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Feffectslistwidget.cpp;h=6b1a4212c394d17ff7a87a156a514d5c03c16727;hb=c3302003093710ee247ad84c0fe2ef3c579d417f;hp=60277c0d4783eb2b8b3a588b0c20900a00822dec;hpb=6a33521fe12af44ab9abe8e09c6e007f4093b2da;p=kdenlive diff --git a/src/effectslistwidget.cpp b/src/effectslistwidget.cpp index 60277c0d..6b1a4212 100644 --- a/src/effectslistwidget.cpp +++ b/src/effectslistwidget.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -39,9 +40,9 @@ const int TypeRole = Qt::UserRole; const int IdRole = TypeRole + 1; -EffectsListWidget::EffectsListWidget(QMenu *menu, QWidget *parent) : - QTreeWidget(parent), - m_menu(menu) +EffectsListWidget::EffectsListWidget(QMenu *contextMenu, QWidget *parent) : + QTreeWidget(parent), + m_menu(contextMenu) { setColumnCount(1); setDragEnabled(true); @@ -49,14 +50,14 @@ EffectsListWidget::EffectsListWidget(QMenu *menu, QWidget *parent) : setHeaderHidden(true); setFrameShape(QFrame::NoFrame); setAutoFillBackground(false); - setRootIsDecorated(false); + setRootIsDecorated(true); + setIndentation(10); //setSelectionMode(QAbstractItemView::ExtendedSelection); setDragDropMode(QAbstractItemView::DragOnly); QPalette p = palette(); p.setBrush(QPalette::Base, Qt::NoBrush); setPalette(p); - initList(); - connect(this, SIGNAL(activated(const QModelIndex &)), this, SLOT(slotExpandItem(const QModelIndex &))); + connect(this, SIGNAL(activated(QModelIndex)), this, SLOT(slotExpandItem(QModelIndex))); } EffectsListWidget::~EffectsListWidget() @@ -68,27 +69,22 @@ void EffectsListWidget::slotExpandItem(const QModelIndex & index) setExpanded(index, !isExpanded(index)); } -void EffectsListWidget::initList() +void EffectsListWidget::initList(QMenu *effectsMenu, KActionCategory *effectActions) { QString current; QString currentFolder; QTreeWidgetItem *item = NULL; - QTreeWidgetItem *parentItem; bool found = false; - + effectsMenu->clear(); + if (currentItem()) { current = currentItem()->text(0); - if (currentItem()->parent()) currentFolder = currentItem()->parent()->text(0); - else if (currentItem()->data(0, TypeRole) == EFFECT_FOLDER) currentFolder = currentItem()->text(0); + if (currentItem()->parent()) + currentFolder = currentItem()->parent()->text(0); + else if (currentItem()->data(0, TypeRole) == EFFECT_FOLDER) + currentFolder = currentItem()->text(0); } - QString effectName; - QStringList effectInfo; - KIcon videoIcon("kdenlive-show-video"); - KIcon audioIcon("kdenlive-show-audio"); - KIcon customIcon("kdenlive-custom-effect"); - KIcon folderIcon("folder"); - QString effectCategory = KStandardDirs::locate("config", "kdenliveeffectscategory.rc"); QDomDocument doc; QFile file(effectCategory); @@ -97,28 +93,28 @@ void EffectsListWidget::initList() QList folders; QStringList folderNames; QDomNodeList groups = doc.documentElement().elementsByTagName("group"); - for (int i = 0; i < groups.count(); i++) { - folderNames << groups.at(i).firstChild().firstChild().nodeValue(); + for (int i = 0; i < groups.count(); ++i) { + folderNames << i18n(groups.at(i).firstChild().firstChild().nodeValue().toUtf8().constData()); } - for (int i = 0; i < topLevelItemCount(); i++) { + for (int i = 0; i < topLevelItemCount(); ++i) { topLevelItem(i)->takeChildren(); QString currentName = topLevelItem(i)->text(0); if (currentName != i18n("Misc") && currentName != i18n("Audio") && currentName != i18nc("Folder Name", "Custom") && !folderNames.contains(currentName)) { takeTopLevelItem(i); - i--; + --i; } } - for (int i = 0; i < groups.count(); i++) { + for (int i = 0; i < groups.count(); ++i) { item = findFolder(folderNames.at(i)); if (item) { item->setData(0, IdRole, groups.at(i).toElement().attribute("list")); } else { item = new QTreeWidgetItem((QTreeWidget*)0, QStringList(folderNames.at(i))); - item->setIcon(0, folderIcon); item->setData(0, TypeRole, QString::number((int) EFFECT_FOLDER)); item->setData(0, IdRole, groups.at(i).toElement().attribute("list")); item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + item->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicatorWhenChildless); insertTopLevelItem(0, item); } folders.append(item); @@ -127,7 +123,6 @@ void EffectsListWidget::initList() QTreeWidgetItem *misc = findFolder(i18n("Misc")); if (misc == NULL) { misc = new QTreeWidgetItem((QTreeWidget*)0, QStringList(i18n("Misc"))); - misc->setIcon(0, folderIcon); misc->setData(0, TypeRole, QString::number((int) EFFECT_FOLDER)); misc->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); insertTopLevelItem(0, misc); @@ -136,7 +131,6 @@ void EffectsListWidget::initList() QTreeWidgetItem *audio = findFolder(i18n("Audio")); if (audio == NULL) { audio = new QTreeWidgetItem((QTreeWidget*)0, QStringList(i18n("Audio"))); - audio->setIcon(0, folderIcon); audio->setData(0, TypeRole, QString::number((int) EFFECT_FOLDER)); audio->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); insertTopLevelItem(0, audio); @@ -145,7 +139,6 @@ void EffectsListWidget::initList() QTreeWidgetItem *custom = findFolder(i18nc("Folder Name", "Custom")); if (custom == NULL) { custom = new QTreeWidgetItem((QTreeWidget*)0, QStringList(i18nc("Folder Name", "Custom"))); - custom->setIcon(0, folderIcon); custom->setData(0, TypeRole, QString::number((int) EFFECT_FOLDER)); custom->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); insertTopLevelItem(0, custom); @@ -153,90 +146,126 @@ void EffectsListWidget::initList() //insertTopLevelItems(0, folders); + loadEffects(&MainWindow::videoEffects, KIcon("kdenlive-show-video"), misc, &folders, EFFECT_VIDEO, current, &found); + loadEffects(&MainWindow::audioEffects, KIcon("kdenlive-show-audio"), audio, &folders, EFFECT_AUDIO, current, &found); + loadEffects(&MainWindow::customEffects, KIcon("kdenlive-custom-effect"), custom, static_cast *>(0), EFFECT_CUSTOM, current, &found); - int ct = MainWindow::videoEffects.count(); - for (int ix = 0; ix < ct; ix ++) { - effectInfo = MainWindow::videoEffects.effectIdInfo(ix); - parentItem = NULL; - for (int i = 0; i < folders.count(); i++) { - QStringList l = folders.at(i)->data(0, IdRole).toString().split(',', QString::SkipEmptyParts); - if (l.contains(effectInfo.at(2))) { - parentItem = folders.at(i); + if (!found && !currentFolder.isEmpty()) { + // previously selected effect was removed, focus on its parent folder + for (int i = 0; i < topLevelItemCount(); ++i) { + if (topLevelItem(i)->text(0) == currentFolder) { + setCurrentItem(topLevelItem(i)); break; } } - if (parentItem == NULL) parentItem = misc; - if (!effectInfo.isEmpty()) { - item = new QTreeWidgetItem(parentItem, QStringList(effectInfo.takeFirst())); - item->setIcon(0, videoIcon); - item->setData(0, TypeRole, QString::number((int) EFFECT_VIDEO)); - item->setData(0, IdRole, effectInfo); - if (item->text(0) == current) { - setCurrentItem(item); - found = true; + + } + setSortingEnabled(true); + sortByColumn(0, Qt::AscendingOrder); + + // populate effects menu + QMenu *sub1 = NULL; + QMenu *sub2 = NULL; + QMenu *sub3 = NULL; + QMenu *sub4 = NULL; + for (int i = 0; i < topLevelItemCount(); ++i) { + if (!topLevelItem(i)->childCount()) + continue; + QMenu *sub = new QMenu(topLevelItem(i)->text(0), effectsMenu); + effectsMenu->addMenu(sub); + int effectsInCategory = topLevelItem(i)->childCount(); + bool hasSubCategories = false; + if (effectsInCategory > 60) { + // create subcategories if there are too many effects + hasSubCategories = true; + sub1 = new QMenu(i18nc("menu name for effects names between these 2 letters", "0 - F"), sub); + sub->addMenu(sub1); + sub2 = new QMenu(i18nc("menu name for effects names between these 2 letters", "G - L"), sub); + sub->addMenu(sub2); + sub3 = new QMenu(i18nc("menu name for effects names between these 2 letters", "M - R"), sub); + sub->addMenu(sub3); + sub4 = new QMenu(i18nc("menu name for effects names between these 2 letters", "S - Z"), sub); + sub->addMenu(sub4); + } + for (int j = 0; j < effectsInCategory; j++) { + QTreeWidgetItem *item = topLevelItem(i)->child(j); + KAction *a = new KAction(KIcon(item->icon(0)), item->text(0), sub); + QStringList data = item->data(0, IdRole).toStringList(); + QString id = data.at(1); + if (id.isEmpty()) id = data.at(0); + a->setData(data); + a->setIconVisibleInMenu(false); + if (hasSubCategories) { + // put action in sub category + QRegExp rx("^[s-z].+"); + if (rx.exactMatch(item->text(0).toLower())) { + sub4->addAction(a); + } else { + rx.setPattern("^[m-r].+"); + if (rx.exactMatch(item->text(0).toLower())) { + sub3->addAction(a); + } + else { + rx.setPattern("^[g-l].+"); + if (rx.exactMatch(item->text(0).toLower())) { + sub2->addAction(a); + } + else sub1->addAction(a); + } + } } + else sub->addAction(a); + effectActions->addAction("video_effect_" + id, a); } } +} + +void EffectsListWidget::loadEffects(const EffectsList *effectlist, KIcon icon, QTreeWidgetItem *defaultFolder, const QList *folders, int type, const QString ¤t, bool *found) +{ + QStringList effectInfo, l; + QTreeWidgetItem *parentItem; + QTreeWidgetItem *item; + int ct = effectlist->count(); - ct = MainWindow::audioEffects.count(); - for (int ix = 0; ix < ct; ix ++) { - effectInfo = MainWindow::audioEffects.effectIdInfo(ix); + + for (int ix = 0; ix < ct; ++ix) { + effectInfo = effectlist->effectIdInfo(ix); + effectInfo.append(QString::number(type)); parentItem = NULL; - for (int i = 0; i < folders.count(); i++) { - QStringList l = folders.at(i)->data(0, IdRole).toString().split(',', QString::SkipEmptyParts); - if (l.contains(effectInfo.at(2))) { - parentItem = folders.at(i); - break; - } - } - if (parentItem == NULL) parentItem = audio; - if (!effectInfo.isEmpty()) { - item = new QTreeWidgetItem(parentItem, QStringList(effectInfo.takeFirst())); - item->setIcon(0, audioIcon); - item->setData(0, TypeRole, QString::number((int) EFFECT_AUDIO)); - item->setData(0, IdRole, effectInfo); - if (item->text(0) == current) { - setCurrentItem(item); - found = true; + + if (folders) { + for (int i = 0; i < folders->count(); ++i) { + l = folders->at(i)->data(0, IdRole).toString().split(QLatin1Char(','), QString::SkipEmptyParts); + if (l.contains(effectInfo.at(2))) { + parentItem = folders->at(i); + break; + } } } - } + if (parentItem == NULL) + parentItem = defaultFolder; - ct = MainWindow::customEffects.count(); - kDebug() << "--- REBUILDING;: " << ct; - for (int ix = 0; ix < ct; ix ++) { - effectInfo = MainWindow::customEffects.effectIdInfo(ix); if (!effectInfo.isEmpty()) { - item = new QTreeWidgetItem(custom, QStringList(effectInfo.takeFirst())); - item->setIcon(0, customIcon); - item->setData(0, TypeRole, QString::number((int) EFFECT_CUSTOM)); + item = new QTreeWidgetItem(parentItem, QStringList(effectInfo.takeFirst())); + if (effectInfo.count() == 4) item->setIcon(0, KIcon("folder")); + else item->setIcon(0, icon); + item->setData(0, TypeRole, type); item->setData(0, IdRole, effectInfo); + item->setToolTip(0, effectlist->getInfo(effectInfo.at(0), effectInfo.at(1))); if (item->text(0) == current) { setCurrentItem(item); - found = true; + *found = true; } } } - if (!found && !currentFolder.isEmpty()) { - // previously selected effect was removed, focus on its parent folder - for (int i = 0; i < topLevelItemCount(); i++) { - if (topLevelItem(i)->text(0) == currentFolder) { - setCurrentItem(topLevelItem(i)); - break; - } - } - - } - setSortingEnabled(true); - sortByColumn(0, Qt::AscendingOrder); } -QTreeWidgetItem *EffectsListWidget::findFolder(const QString name) +QTreeWidgetItem *EffectsListWidget::findFolder(const QString &name) { QTreeWidgetItem *item = NULL; QList result = findItems(name, Qt::MatchExactly); if (!result.isEmpty()) { - for (int j = 0; j < result.count(); j++) { + for (int j = 0; j < result.count(); ++j) { if (result.at(j)->data(0, TypeRole) == EFFECT_FOLDER) { item = result.at(j); break; @@ -256,7 +285,6 @@ const QDomElement EffectsListWidget::itemEffect(QTreeWidgetItem *item) const QDomElement effect; if (!item || item->data(0, TypeRole).toInt() == (int)EFFECT_FOLDER) return effect; QStringList effectInfo = item->data(0, IdRole).toStringList(); - kDebug() << "// EFFECT SELECTED: " << effectInfo; switch (item->data(0, TypeRole).toInt()) { case 1: effect = MainWindow::videoEffects.getEffectByTag(effectInfo.at(0), effectInfo.at(1)).cloneNode().toElement(); @@ -272,7 +300,7 @@ const QDomElement EffectsListWidget::itemEffect(QTreeWidgetItem *item) const } -QString EffectsListWidget::currentInfo() +QString EffectsListWidget::currentInfo() const { QTreeWidgetItem *item = currentItem(); if (!item || item->data(0, TypeRole).toInt() == (int)EFFECT_FOLDER) return QString(); @@ -292,6 +320,17 @@ QString EffectsListWidget::currentInfo() return info; } +//virtual +void EffectsListWidget::keyPressEvent(QKeyEvent *e) +{ + if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) { + emit applyEffect(currentEffect()); + e->accept(); + return; + } + QTreeWidget::keyPressEvent(e); +} + //virtual QMimeData * EffectsListWidget::mimeData(const QList list) const { @@ -299,7 +338,8 @@ QMimeData * EffectsListWidget::mimeData(const QList list) con foreach(QTreeWidgetItem *item, list) { if (item->flags() & Qt::ItemIsDragEnabled) { const QDomElement e = itemEffect(item); - if (!e.isNull()) doc.appendChild(doc.importNode(e, true)); + if (!e.isNull()) + doc.appendChild(doc.importNode(e, true)); } } QMimeData *mime = new QMimeData; @@ -324,7 +364,8 @@ void EffectsListWidget::dragMoveEvent(QDragMoveEvent *event) void EffectsListWidget::contextMenuEvent(QContextMenuEvent * event) { QTreeWidgetItem *item = itemAt(event->pos()); - if (item && item->data(0, TypeRole).toInt() == EFFECT_CUSTOM) m_menu->popup(event->globalPos()); + if (item && item->data(0, TypeRole).toInt() == EFFECT_CUSTOM) + m_menu->popup(event->globalPos()); } #include "effectslistwidget.moc"