1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
21 #include "effectslistwidget.h"
22 #include "effectslist.h"
23 #include "mainwindow.h"
27 #include "QApplication"
28 #include "QMouseEvent"
32 static const int EFFECT_VIDEO = 1;
33 static const int EFFECT_AUDIO = 2;
34 static const int EFFECT_CUSTOM = 3;
36 const int TypeRole = Qt::UserRole;
37 const int IdRole = TypeRole + 1;
39 EffectsListWidget::EffectsListWidget(QMenu *menu, QWidget *parent) :
43 //setSelectionMode(QAbstractItemView::ExtendedSelection);
44 //setDragDropMode(QAbstractItemView::DragDrop);
45 setDropIndicatorShown(true);
46 setAlternatingRowColors(true);
47 setSortingEnabled(true);
53 EffectsListWidget::~EffectsListWidget()
57 void EffectsListWidget::initList()
60 QListWidgetItem *item;
62 QStringList effectInfo;
63 KIcon videoIcon("kdenlive-show-video");
64 KIcon audioIcon("kdenlive-show-audio");
65 KIcon customIcon("kdenlive-custom-effect");
66 int ct = MainWindow::videoEffects.count();
67 for (int ix = 0; ix < ct; ix ++) {
68 effectInfo = MainWindow::videoEffects.effectIdInfo(ix);
69 if (!effectInfo.isEmpty()) {
70 item = new QListWidgetItem(videoIcon, effectInfo.takeFirst(), this);
71 item->setData(TypeRole, QString::number((int) EFFECT_VIDEO));
72 item->setData(IdRole, effectInfo);
76 ct = MainWindow::audioEffects.count();
77 for (int ix = 0; ix < ct; ix ++) {
78 effectInfo = MainWindow::audioEffects.effectIdInfo(ix);
79 if (!effectInfo.isEmpty()) {
80 item = new QListWidgetItem(audioIcon, effectInfo.takeFirst(), this);
81 item->setData(TypeRole, QString::number((int) EFFECT_AUDIO));
82 item->setData(IdRole, effectInfo);
86 ct = MainWindow::customEffects.count();
87 for (int ix = 0; ix < ct; ix ++) {
88 effectInfo = MainWindow::customEffects.effectIdInfo(ix);
89 if (!effectInfo.isEmpty()) {
90 item = new QListWidgetItem(customIcon, effectInfo.takeFirst(), this);
91 item->setData(TypeRole, QString::number((int) EFFECT_CUSTOM));
92 item->setData(IdRole, effectInfo);
97 const QDomElement EffectsListWidget::currentEffect() const
99 return itemEffect(currentItem());
102 const QDomElement EffectsListWidget::itemEffect(QListWidgetItem *item) const
105 if (!item) return effect;
106 QStringList effectInfo = item->data(IdRole).toStringList();
107 kDebug() << "// EFFECT SELECTED: " << effectInfo;
108 switch (item->data(TypeRole).toInt()) {
110 effect = MainWindow::videoEffects.getEffectByTag(effectInfo.at(0), effectInfo.at(1)).cloneNode().toElement();
113 effect = MainWindow::audioEffects.getEffectByTag(effectInfo.at(0), effectInfo.at(1)).cloneNode().toElement();
116 effect = MainWindow::customEffects.getEffectByTag(effectInfo.at(0), effectInfo.at(1)).cloneNode().toElement();
123 QString EffectsListWidget::currentInfo()
125 QListWidgetItem *item = currentItem();
126 if (!item) return QString();
128 QStringList effectInfo = item->data(IdRole).toStringList();
129 switch (item->data(TypeRole).toInt()) {
131 info = MainWindow::videoEffects.getInfo(effectInfo.at(0), effectInfo.at(1));
134 info = MainWindow::audioEffects.getInfo(effectInfo.at(0), effectInfo.at(1));
137 info = MainWindow::customEffects.getInfo(effectInfo.at(0), effectInfo.at(1));
144 void EffectsListWidget::mousePressEvent(QMouseEvent *event)
146 if (event->button() == Qt::LeftButton) {
147 m_DragStartPosition = event->pos();
148 m_dragStarted = true;
150 KListWidget::mousePressEvent(event);
154 void EffectsListWidget::mouseMoveEvent(QMouseEvent *event)
156 if (!m_dragStarted) return;
157 if ((event->pos() - m_DragStartPosition).manhattanLength()
158 < QApplication::startDragDistance())
162 QListWidgetItem *clickItem = itemAt(event->pos());
164 QDrag *drag = new QDrag(this);
165 QMimeData *mimeData = new QMimeData;
166 const QList <QListWidgetItem *>list = selectedItems();
168 foreach(QListWidgetItem *item, list) {
169 const QDomElement e = itemEffect(item);
170 if (!e.isNull()) doc.appendChild(doc.importNode(e, true));
173 data.append(doc.toString().toUtf8());
174 mimeData->setData("kdenlive/effectslist", data);
175 drag->setMimeData(mimeData);
176 //QPixmap pix = qVariantValue<QPixmap>(clickItem->data(Qt::DecorationRole));
177 //drag->setPixmap(pix);
178 //drag->setHotSpot(QPoint(0, 50));
179 drag->start(Qt::CopyAction);
185 void EffectsListWidget::dragMoveEvent(QDragMoveEvent * event)
187 event->setDropAction(Qt::CopyAction);
188 if (event->mimeData()->hasText()) {
189 event->acceptProposedAction();
195 void EffectsListWidget::contextMenuEvent(QContextMenuEvent * event)
197 QListWidgetItem *item = itemAt(event->pos());
198 if (item && item->data(TypeRole).toInt() == EFFECT_CUSTOM) m_menu->popup(event->globalPos());
201 #include "effectslistwidget.moc"