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) {
33 //setSelectionMode(QAbstractItemView::ExtendedSelection);
34 //setDragDropMode(QAbstractItemView::DragDrop);
35 setDropIndicatorShown(true);
36 setAlternatingRowColors(true);
37 setSortingEnabled(true);
43 EffectsListWidget::~EffectsListWidget() {
46 void EffectsListWidget::initList() {
48 QStringList names = m_videoList->effectNames();
49 QListWidgetItem *item;
50 foreach(QString str, names) {
51 item = new QListWidgetItem(str, this);
52 item->setData(Qt::UserRole, QString::number((int) EFFECT_VIDEO));
55 names = m_audioList->effectNames();
56 foreach(QString str, names) {
57 item = new QListWidgetItem(str, this);
58 item->setData(Qt::UserRole, QString::number((int) EFFECT_AUDIO));
61 names = m_customList->effectNames();
62 foreach(QString str, names) {
63 item = new QListWidgetItem(str, this);
64 item->setData(Qt::UserRole, QString::number((int) EFFECT_CUSTOM));
68 QDomElement EffectsListWidget::currentEffect() {
69 return itemEffect(currentItem());
72 QDomElement EffectsListWidget::itemEffect(QListWidgetItem *item) {
74 if (!item) return effect;
75 switch (item->data(Qt::UserRole).toInt()) {
77 effect = m_videoList->getEffectByName(item->text());
80 effect = m_audioList->getEffectByName(item->text());
83 effect = m_customList->getEffectByName(item->text());
90 QString EffectsListWidget::currentInfo() {
91 QListWidgetItem *item = currentItem();
92 if (!item) return QString();
94 switch (item->data(Qt::UserRole).toInt()) {
96 info = m_videoList->getInfo(item->text());
99 info = m_audioList->getInfo(item->text());
102 info = m_customList->getInfo(item->text());
109 void EffectsListWidget::mousePressEvent(QMouseEvent *event) {
110 if (event->button() == Qt::LeftButton) {
111 this->m_DragStartPosition = event->pos();
112 m_dragStarted = true;
114 KListWidget::mousePressEvent(event);
118 void EffectsListWidget::mouseMoveEvent(QMouseEvent *event) {
119 if (!m_dragStarted) return;
120 if ((event->pos() - m_DragStartPosition).manhattanLength()
121 < QApplication::startDragDistance())
125 QListWidgetItem *clickItem = itemAt(event->pos());
127 QDrag *drag = new QDrag(this);
128 QMimeData *mimeData = new QMimeData;
129 QList <QListWidgetItem *> list;
130 list = selectedItems();
132 foreach(QListWidgetItem *item, list) {
133 doc.appendChild(doc.importNode(itemEffect(item), true));
136 data.append(doc.toString().toUtf8());
137 mimeData->setData("kdenlive/effectslist", data);
138 drag->setMimeData(mimeData);
139 //QPixmap pix = qVariantValue<QPixmap>(clickItem->data(Qt::DecorationRole));
140 //drag->setPixmap(pix);
141 //drag->setHotSpot(QPoint(0, 50));
142 drag->start(Qt::MoveAction);
148 void EffectsListWidget::dragMoveEvent(QDragMoveEvent * event) {
149 event->setDropAction(Qt::IgnoreAction);
151 event->setDropAction(Qt::MoveAction);
152 if (event->mimeData()->hasText()) {
153 event->acceptProposedAction();
160 #include "effectslistwidget.moc"