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)
40 : KListWidget(parent), m_menu(menu)
42 //setSelectionMode(QAbstractItemView::ExtendedSelection);
43 //setDragDropMode(QAbstractItemView::DragDrop);
44 setDropIndicatorShown(true);
45 setAlternatingRowColors(true);
46 setSortingEnabled(true);
52 EffectsListWidget::~EffectsListWidget()
56 void EffectsListWidget::initList()
59 QListWidgetItem *item;
61 QStringList effectInfo;
62 KIcon videoIcon("kdenlive-show-video");
63 KIcon audioIcon("kdenlive-show-audio");
64 int ct = MainWindow::videoEffects.count();
65 for (int ix = 0; ix < ct; ix ++) {
66 effectInfo = MainWindow::videoEffects.effectIdInfo(ix);
67 if (!effectInfo.isEmpty()) {
68 item = new QListWidgetItem(videoIcon, effectInfo.takeFirst(), this);
69 item->setData(TypeRole, QString::number((int) EFFECT_VIDEO));
70 item->setData(IdRole, effectInfo);
74 ct = MainWindow::audioEffects.count();
75 for (int ix = 0; ix < ct; ix ++) {
76 effectInfo = MainWindow::audioEffects.effectIdInfo(ix);
77 if (!effectInfo.isEmpty()) {
78 item = new QListWidgetItem(audioIcon, effectInfo.takeFirst(), this);
79 item->setData(TypeRole, QString::number((int) EFFECT_AUDIO));
80 item->setData(IdRole, effectInfo);
84 ct = MainWindow::customEffects.count();
85 for (int ix = 0; ix < ct; ix ++) {
86 effectInfo = MainWindow::customEffects.effectIdInfo(ix);
87 if (!effectInfo.isEmpty()) {
88 item = new QListWidgetItem(effectInfo.takeFirst(), this);
89 item->setData(TypeRole, QString::number((int) EFFECT_CUSTOM));
90 item->setData(IdRole, effectInfo);
95 QDomElement EffectsListWidget::currentEffect()
97 return itemEffect(currentItem());
100 QDomElement EffectsListWidget::itemEffect(QListWidgetItem *item)
103 if (!item) return effect;
104 QStringList effectInfo = item->data(IdRole).toStringList();
105 kDebug() << "// EFFECT SELECTED: " << effectInfo;
106 switch (item->data(TypeRole).toInt()) {
108 effect = MainWindow::videoEffects.getEffectByTag(effectInfo.at(0), effectInfo.at(1));
111 effect = MainWindow::audioEffects.getEffectByTag(effectInfo.at(0), effectInfo.at(1));
114 effect = MainWindow::customEffects.getEffectByTag(effectInfo.at(0), effectInfo.at(1));
121 QString EffectsListWidget::currentInfo()
123 QListWidgetItem *item = currentItem();
124 if (!item) return QString();
126 QStringList effectInfo = item->data(IdRole).toStringList();
127 switch (item->data(TypeRole).toInt()) {
129 info = MainWindow::videoEffects.getInfo(effectInfo.at(0), effectInfo.at(1));
132 info = MainWindow::audioEffects.getInfo(effectInfo.at(0), effectInfo.at(1));
135 info = MainWindow::customEffects.getInfo(effectInfo.at(0), effectInfo.at(1));
142 void EffectsListWidget::mousePressEvent(QMouseEvent *event)
144 if (event->button() == Qt::LeftButton) {
145 m_DragStartPosition = event->pos();
146 m_dragStarted = true;
148 KListWidget::mousePressEvent(event);
152 void EffectsListWidget::mouseMoveEvent(QMouseEvent *event)
154 if (!m_dragStarted) return;
155 if ((event->pos() - m_DragStartPosition).manhattanLength()
156 < QApplication::startDragDistance())
160 QListWidgetItem *clickItem = itemAt(event->pos());
162 QDrag *drag = new QDrag(this);
163 QMimeData *mimeData = new QMimeData;
164 const QList <QListWidgetItem *>list = selectedItems();
166 foreach(QListWidgetItem *item, list) {
167 QDomElement e = itemEffect(item);
168 if (!e.isNull()) doc.appendChild(doc.importNode(e, true));
171 data.append(doc.toString().toUtf8());
172 mimeData->setData("kdenlive/effectslist", data);
173 drag->setMimeData(mimeData);
174 //QPixmap pix = qVariantValue<QPixmap>(clickItem->data(Qt::DecorationRole));
175 //drag->setPixmap(pix);
176 //drag->setHotSpot(QPoint(0, 50));
177 drag->start(Qt::MoveAction);
183 void EffectsListWidget::dragMoveEvent(QDragMoveEvent * event)
185 event->setDropAction(Qt::IgnoreAction);
187 event->setDropAction(Qt::MoveAction);
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"