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"
26 #include "effectslistwidget.h"
27 #include "effectslist.h"
28 #include "mainwindow.h"
30 #define EFFECT_VIDEO 1
31 #define EFFECT_AUDIO 2
32 #define EFFECT_CUSTOM 3
34 EffectsListWidget::EffectsListWidget(QMenu *menu, QWidget *parent)
35 : KListWidget(parent), m_menu(menu) {
36 //setSelectionMode(QAbstractItemView::ExtendedSelection);
37 //setDragDropMode(QAbstractItemView::DragDrop);
38 setDropIndicatorShown(true);
39 setAlternatingRowColors(true);
40 setSortingEnabled(true);
46 EffectsListWidget::~EffectsListWidget() {
49 void EffectsListWidget::initList() {
51 QStringList names = MainWindow::videoEffects.effectNames();
52 QListWidgetItem *item;
53 foreach(const QString &str, names) {
54 item = new QListWidgetItem(str, this);
55 item->setData(Qt::UserRole, QString::number((int) EFFECT_VIDEO));
58 names = MainWindow::audioEffects.effectNames();
59 foreach(const QString &str, names) {
60 item = new QListWidgetItem(str, this);
61 item->setData(Qt::UserRole, QString::number((int) EFFECT_AUDIO));
64 names = MainWindow::customEffects.effectNames();
65 foreach(const QString &str, names) {
66 item = new QListWidgetItem(str, this);
67 item->setData(Qt::UserRole, QString::number((int) EFFECT_CUSTOM));
71 QDomElement EffectsListWidget::currentEffect() {
72 return itemEffect(currentItem());
75 QDomElement EffectsListWidget::itemEffect(QListWidgetItem *item) {
77 if (!item) return effect;
78 switch (item->data(Qt::UserRole).toInt()) {
80 effect = MainWindow::videoEffects.getEffectByName(item->text());
83 effect = MainWindow::audioEffects.getEffectByName(item->text());
86 effect = MainWindow::customEffects.getEffectByName(item->text());
93 QString EffectsListWidget::currentInfo() {
94 QListWidgetItem *item = currentItem();
95 if (!item) return QString();
97 switch (item->data(Qt::UserRole).toInt()) {
99 info = MainWindow::videoEffects.getInfo(item->text());
102 info = MainWindow::audioEffects.getInfo(item->text());
105 info = MainWindow::customEffects.getInfo(item->text());
112 void EffectsListWidget::mousePressEvent(QMouseEvent *event) {
113 if (event->button() == Qt::LeftButton) {
114 this->m_DragStartPosition = event->pos();
115 m_dragStarted = true;
117 KListWidget::mousePressEvent(event);
121 void EffectsListWidget::mouseMoveEvent(QMouseEvent *event) {
122 if (!m_dragStarted) return;
123 if ((event->pos() - m_DragStartPosition).manhattanLength()
124 < QApplication::startDragDistance())
128 QListWidgetItem *clickItem = itemAt(event->pos());
130 QDrag *drag = new QDrag(this);
131 QMimeData *mimeData = new QMimeData;
132 const QList <QListWidgetItem *>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();
161 void EffectsListWidget::contextMenuEvent(QContextMenuEvent * event) {
162 QListWidgetItem *item = itemAt(event->pos());
163 if (item && item->data(Qt::UserRole).toInt() == EFFECT_CUSTOM) m_menu->popup(event->globalPos());
166 #include "effectslistwidget.moc"