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"
27 #include "mainwindow.h"
29 #define EFFECT_VIDEO 1
30 #define EFFECT_AUDIO 2
31 #define EFFECT_CUSTOM 3
33 EffectsListWidget::EffectsListWidget(QWidget *parent)
34 : KListWidget(parent) {
35 //setSelectionMode(QAbstractItemView::ExtendedSelection);
36 //setDragDropMode(QAbstractItemView::DragDrop);
37 setDropIndicatorShown(true);
38 setAlternatingRowColors(true);
39 setSortingEnabled(true);
45 EffectsListWidget::~EffectsListWidget() {
48 void EffectsListWidget::initList() {
50 QStringList names = MainWindow::videoEffects.effectNames();
51 QListWidgetItem *item;
52 foreach(const QString &str, names) {
53 item = new QListWidgetItem(str, this);
54 item->setData(Qt::UserRole, QString::number((int) EFFECT_VIDEO));
57 names = MainWindow::audioEffects.effectNames();
58 foreach(const QString &str, names) {
59 item = new QListWidgetItem(str, this);
60 item->setData(Qt::UserRole, QString::number((int) EFFECT_AUDIO));
63 names = MainWindow::customEffects.effectNames();
64 foreach(const QString &str, names) {
65 item = new QListWidgetItem(str, this);
66 item->setData(Qt::UserRole, QString::number((int) EFFECT_CUSTOM));
70 QDomElement EffectsListWidget::currentEffect() {
71 return itemEffect(currentItem());
74 QDomElement EffectsListWidget::itemEffect(QListWidgetItem *item) {
76 if (!item) return effect;
77 switch (item->data(Qt::UserRole).toInt()) {
79 effect = MainWindow::videoEffects.getEffectByName(item->text());
82 effect = MainWindow::audioEffects.getEffectByName(item->text());
85 effect = MainWindow::customEffects.getEffectByName(item->text());
92 QString EffectsListWidget::currentInfo() {
93 QListWidgetItem *item = currentItem();
94 if (!item) return QString();
96 switch (item->data(Qt::UserRole).toInt()) {
98 info = MainWindow::videoEffects.getInfo(item->text());
101 info = MainWindow::audioEffects.getInfo(item->text());
104 info = MainWindow::customEffects.getInfo(item->text());
111 void EffectsListWidget::mousePressEvent(QMouseEvent *event) {
112 if (event->button() == Qt::LeftButton) {
113 this->m_DragStartPosition = event->pos();
114 m_dragStarted = true;
116 KListWidget::mousePressEvent(event);
120 void EffectsListWidget::mouseMoveEvent(QMouseEvent *event) {
121 if (!m_dragStarted) return;
122 if ((event->pos() - m_DragStartPosition).manhattanLength()
123 < QApplication::startDragDistance())
127 QListWidgetItem *clickItem = itemAt(event->pos());
129 QDrag *drag = new QDrag(this);
130 QMimeData *mimeData = new QMimeData;
131 QList <QListWidgetItem *> list;
132 list = selectedItems();
134 foreach(QListWidgetItem *item, list) {
135 doc.appendChild(doc.importNode(itemEffect(item), true));
138 data.append(doc.toString().toUtf8());
139 mimeData->setData("kdenlive/effectslist", data);
140 drag->setMimeData(mimeData);
141 //QPixmap pix = qVariantValue<QPixmap>(clickItem->data(Qt::DecorationRole));
142 //drag->setPixmap(pix);
143 //drag->setHotSpot(QPoint(0, 50));
144 drag->start(Qt::MoveAction);
150 void EffectsListWidget::dragMoveEvent(QDragMoveEvent * event) {
151 event->setDropAction(Qt::IgnoreAction);
153 event->setDropAction(Qt::MoveAction);
154 if (event->mimeData()->hasText()) {
155 event->acceptProposedAction();
162 #include "effectslistwidget.moc"