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 int ct = MainWindow::videoEffects.count();
66 for (int ix = 0; ix < ct; ix ++) {
67 effectInfo = MainWindow::videoEffects.effectIdInfo(ix);
68 if (!effectInfo.isEmpty()) {
69 item = new QListWidgetItem(videoIcon, effectInfo.takeFirst(), this);
70 item->setData(TypeRole, QString::number((int) EFFECT_VIDEO));
71 item->setData(IdRole, effectInfo);
75 ct = MainWindow::audioEffects.count();
76 for (int ix = 0; ix < ct; ix ++) {
77 effectInfo = MainWindow::audioEffects.effectIdInfo(ix);
78 if (!effectInfo.isEmpty()) {
79 item = new QListWidgetItem(audioIcon, effectInfo.takeFirst(), this);
80 item->setData(TypeRole, QString::number((int) EFFECT_AUDIO));
81 item->setData(IdRole, effectInfo);
85 ct = MainWindow::customEffects.count();
86 for (int ix = 0; ix < ct; ix ++) {
87 effectInfo = MainWindow::customEffects.effectIdInfo(ix);
88 if (!effectInfo.isEmpty()) {
89 item = new QListWidgetItem(effectInfo.takeFirst(), this);
90 item->setData(TypeRole, QString::number((int) EFFECT_CUSTOM));
91 item->setData(IdRole, effectInfo);
96 QDomElement EffectsListWidget::currentEffect()
98 return itemEffect(currentItem());
101 QDomElement EffectsListWidget::itemEffect(QListWidgetItem *item)
104 if (!item) return effect;
105 QStringList effectInfo = item->data(IdRole).toStringList();
106 kDebug() << "// EFFECT SELECTED: " << effectInfo;
107 switch (item->data(TypeRole).toInt()) {
109 effect = MainWindow::videoEffects.getEffectByTag(effectInfo.at(0), effectInfo.at(1));
112 effect = MainWindow::audioEffects.getEffectByTag(effectInfo.at(0), effectInfo.at(1));
115 effect = MainWindow::customEffects.getEffectByTag(effectInfo.at(0), effectInfo.at(1));
122 QString EffectsListWidget::currentInfo()
124 QListWidgetItem *item = currentItem();
125 if (!item) return QString();
127 QStringList effectInfo = item->data(IdRole).toStringList();
128 switch (item->data(TypeRole).toInt()) {
130 info = MainWindow::videoEffects.getInfo(effectInfo.at(0), effectInfo.at(1));
133 info = MainWindow::audioEffects.getInfo(effectInfo.at(0), effectInfo.at(1));
136 info = MainWindow::customEffects.getInfo(effectInfo.at(0), effectInfo.at(1));
143 void EffectsListWidget::mousePressEvent(QMouseEvent *event)
145 if (event->button() == Qt::LeftButton) {
146 m_DragStartPosition = event->pos();
147 m_dragStarted = true;
149 KListWidget::mousePressEvent(event);
153 void EffectsListWidget::mouseMoveEvent(QMouseEvent *event)
155 if (!m_dragStarted) return;
156 if ((event->pos() - m_DragStartPosition).manhattanLength()
157 < QApplication::startDragDistance())
161 QListWidgetItem *clickItem = itemAt(event->pos());
163 QDrag *drag = new QDrag(this);
164 QMimeData *mimeData = new QMimeData;
165 const QList <QListWidgetItem *>list = selectedItems();
167 foreach(QListWidgetItem *item, list) {
168 QDomElement e = itemEffect(item);
169 if (!e.isNull()) doc.appendChild(doc.importNode(e, true));
172 data.append(doc.toString().toUtf8());
173 mimeData->setData("kdenlive/effectslist", data);
174 drag->setMimeData(mimeData);
175 //QPixmap pix = qVariantValue<QPixmap>(clickItem->data(Qt::DecorationRole));
176 //drag->setPixmap(pix);
177 //drag->setHotSpot(QPoint(0, 50));
178 drag->start(Qt::MoveAction);
184 void EffectsListWidget::dragMoveEvent(QDragMoveEvent * event)
186 event->setDropAction(Qt::IgnoreAction);
188 event->setDropAction(Qt::MoveAction);
189 if (event->mimeData()->hasText()) {
190 event->acceptProposedAction();
196 void EffectsListWidget::contextMenuEvent(QContextMenuEvent * event)
198 QListWidgetItem *item = itemAt(event->pos());
199 if (item && item->data(TypeRole).toInt() == EFFECT_CUSTOM) m_menu->popup(event->globalPos());
202 #include "effectslistwidget.moc"