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"
26 #include "effectslist.h"
28 #define EFFECT_VIDEO 1
29 #define EFFECT_AUDIO 2
30 #define EFFECT_CUSTOM 3
32 EffectsListWidget::EffectsListWidget(EffectsList *audioEffectList, EffectsList *videoEffectList, EffectsList *customEffectList, QWidget *parent)
33 : 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() {
47 void EffectsListWidget::initList() {
49 QStringList names = m_videoList->effectNames();
50 QListWidgetItem *item;
51 foreach(QString str, names) {
52 item = new QListWidgetItem(str, this);
53 item->setData(Qt::UserRole, QString::number((int) EFFECT_VIDEO));
56 names = m_audioList->effectNames();
57 foreach(QString str, names) {
58 item = new QListWidgetItem(str, this);
59 item->setData(Qt::UserRole, QString::number((int) EFFECT_AUDIO));
62 names = m_customList->effectNames();
63 foreach(QString str, names) {
64 item = new QListWidgetItem(str, this);
65 item->setData(Qt::UserRole, QString::number((int) EFFECT_CUSTOM));
69 QDomElement EffectsListWidget::currentEffect() {
70 return itemEffect(currentItem());
73 QDomElement EffectsListWidget::itemEffect(QListWidgetItem *item) {
75 if (!item) return effect;
76 switch (item->data(Qt::UserRole).toInt()) {
78 effect = m_videoList->getEffectByName(item->text());
81 effect = m_audioList->getEffectByName(item->text());
84 effect = m_customList->getEffectByName(item->text());
91 QString EffectsListWidget::currentInfo() {
92 QListWidgetItem *item = currentItem();
93 if (!item) return QString();
95 switch (item->data(Qt::UserRole).toInt()) {
97 info = m_videoList->getInfo(item->text());
100 info = m_audioList->getInfo(item->text());
103 info = m_customList->getInfo(item->text());
110 void EffectsListWidget::mousePressEvent(QMouseEvent *event) {
111 if (event->button() == Qt::LeftButton) {
112 this->m_DragStartPosition = event->pos();
113 m_dragStarted = true;
115 KListWidget::mousePressEvent(event);
119 void EffectsListWidget::mouseMoveEvent(QMouseEvent *event) {
120 if (!m_dragStarted) return;
121 if ((event->pos() - m_DragStartPosition).manhattanLength()
122 < QApplication::startDragDistance())
126 QListWidgetItem *clickItem = itemAt(event->pos());
128 QDrag *drag = new QDrag(this);
129 QMimeData *mimeData = new QMimeData;
130 QList <QListWidgetItem *> list;
131 list = selectedItems();
133 foreach(QListWidgetItem *item, list) {
134 doc.appendChild(doc.importNode(itemEffect(item), true));
137 data.append(doc.toString().toUtf8());
138 mimeData->setData("kdenlive/effectslist", data);
139 drag->setMimeData(mimeData);
140 //QPixmap pix = qVariantValue<QPixmap>(clickItem->data(Qt::DecorationRole));
141 //drag->setPixmap(pix);
142 //drag->setHotSpot(QPoint(0, 50));
143 drag->start(Qt::MoveAction);
149 void EffectsListWidget::dragMoveEvent(QDragMoveEvent * event) {
150 event->setDropAction(Qt::IgnoreAction);
152 event->setDropAction(Qt::MoveAction);
153 if (event->mimeData()->hasText()) {
154 event->acceptProposedAction();
161 #include "effectslistwidget.moc"