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 ***************************************************************************/
20 #include "QApplication"
21 #include "QMouseEvent"
25 #include "effectslistwidget.h"
27 #define EFFECT_VIDEO 1
28 #define EFFECT_AUDIO 2
29 #define EFFECT_CUSTOM 3
31 EffectsListWidget::EffectsListWidget(EffectsList *audioEffectList, EffectsList *videoEffectList, EffectsList *customEffectList, QWidget *parent)
32 : KListWidget(parent), m_audioList(audioEffectList), m_videoList(videoEffectList), m_customList(customEffectList)
34 //setSelectionMode(QAbstractItemView::ExtendedSelection);
35 //setDragDropMode(QAbstractItemView::DragDrop);
36 setDropIndicatorShown(true);
37 setAlternatingRowColors(true);
38 setSortingEnabled(true);
44 EffectsListWidget::~EffectsListWidget()
48 void EffectsListWidget::initList()
51 QStringList names = m_videoList->effectNames();
52 QListWidgetItem *item;
53 foreach (QString str, names) {
54 item = new QListWidgetItem(str, this);
55 item->setData(Qt::UserRole, QString::number((int) EFFECT_VIDEO));
58 names = m_audioList->effectNames();
59 foreach (QString str, names) {
60 item = new QListWidgetItem(str, this);
61 item->setData(Qt::UserRole, QString::number((int) EFFECT_AUDIO));
64 names = m_customList->effectNames();
65 foreach (QString str, names) {
66 item = new QListWidgetItem(str, this);
67 item->setData(Qt::UserRole, QString::number((int) EFFECT_CUSTOM));
71 QDomElement EffectsListWidget::currentEffect()
73 return itemEffect(currentItem());
76 QDomElement EffectsListWidget::itemEffect(QListWidgetItem *item)
79 if (!item) return effect;
80 switch (item->data(Qt::UserRole).toInt())
83 effect = m_videoList->getEffectByName(item->text());
86 effect = m_audioList->getEffectByName(item->text());
89 effect = m_customList->getEffectByName(item->text());
96 QString EffectsListWidget::currentInfo()
98 QListWidgetItem *item = currentItem();
99 if (!item) return QString();
101 switch (item->data(Qt::UserRole).toInt())
104 info = m_videoList->getInfo(item->text());
107 info = m_audioList->getInfo(item->text());
110 info = m_customList->getInfo(item->text());
117 void EffectsListWidget::mousePressEvent(QMouseEvent *event)
119 if( event->button() == Qt::LeftButton )
121 this->m_DragStartPosition = event->pos();
122 m_dragStarted = true;
124 KListWidget::mousePressEvent(event);
128 void EffectsListWidget::mouseMoveEvent(QMouseEvent *event)
130 if (!m_dragStarted) return;
131 if ((event->pos() - m_DragStartPosition).manhattanLength()
132 < QApplication::startDragDistance())
136 QListWidgetItem *clickItem = itemAt(event->pos());
138 QDrag *drag = new QDrag(this);
139 QMimeData *mimeData = new QMimeData;
140 QList <QListWidgetItem *> list;
141 list = selectedItems();
143 foreach (QListWidgetItem *item, list) {
144 doc.appendChild(doc.importNode(itemEffect(item), true));
147 data.append(doc.toString().toUtf8());
148 mimeData->setData("kdenlive/effectslist", data );
149 drag->setMimeData(mimeData);
150 //drag->setPixmap(clickItem->icon(0).pixmap(50 *16/9.0, 50));
151 drag->setHotSpot(QPoint(0, 50));
152 drag->start(Qt::MoveAction);
158 void EffectsListWidget::dragMoveEvent(QDragMoveEvent * event) {
159 event->setDropAction(Qt::IgnoreAction);
161 event->setDropAction(Qt::MoveAction);
162 if (event->mimeData()->hasText()) {
163 event->acceptProposedAction();
170 #include "effectslistwidget.moc"