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 ***************************************************************************/
21 #include "effectslistwidget.h"
22 #include "effectslist.h"
23 #include "mainwindow.h"
27 #include "QApplication"
28 #include "QMouseEvent"
32 static const int EFFECT_VIDEO = 1;
33 static const int EFFECT_AUDIO = 2;
34 static const int EFFECT_CUSTOM = 3;
36 const int TypeRole = Qt::UserRole;
37 const int IdRole = TypeRole + 1;
39 EffectsListWidget::EffectsListWidget(QMenu *menu, QWidget *parent)
40 : KListWidget(parent), m_menu(menu) {
41 //setSelectionMode(QAbstractItemView::ExtendedSelection);
42 //setDragDropMode(QAbstractItemView::DragDrop);
43 setDropIndicatorShown(true);
44 setAlternatingRowColors(true);
45 setSortingEnabled(true);
51 EffectsListWidget::~EffectsListWidget() {
54 void EffectsListWidget::initList() {
56 QListWidgetItem *item;
58 QStringList effectInfo;
59 KIcon videoIcon("kdenlive-show-video");
60 KIcon audioIcon("kdenlive-show-audio");
61 int ct = MainWindow::videoEffects.count();
62 for (int ix = 0; ix < ct; ix ++) {
63 effectInfo = MainWindow::videoEffects.effectIdInfo(ix);
64 if (!effectInfo.isEmpty()) {
65 item = new QListWidgetItem(videoIcon, effectInfo.takeFirst(), this);
66 item->setData(TypeRole, QString::number((int) EFFECT_VIDEO));
67 item->setData(IdRole, effectInfo);
71 ct = MainWindow::audioEffects.count();
72 for (int ix = 0; ix < ct; ix ++) {
73 effectInfo = MainWindow::audioEffects.effectIdInfo(ix);
74 if (!effectInfo.isEmpty()) {
75 item = new QListWidgetItem(audioIcon, effectInfo.takeFirst(), this);
76 item->setData(TypeRole, QString::number((int) EFFECT_AUDIO));
77 item->setData(IdRole, effectInfo);
81 ct = MainWindow::customEffects.count();
82 for (int ix = 0; ix < ct; ix ++) {
83 effectInfo = MainWindow::customEffects.effectIdInfo(ix);
84 if (!effectInfo.isEmpty()) {
85 item = new QListWidgetItem(effectInfo.takeFirst(), this);
86 item->setData(TypeRole, QString::number((int) EFFECT_CUSTOM));
87 item->setData(IdRole, effectInfo);
92 QDomElement EffectsListWidget::currentEffect() {
93 return itemEffect(currentItem());
96 QDomElement EffectsListWidget::itemEffect(QListWidgetItem *item) {
98 if (!item) return effect;
99 QStringList effectInfo = item->data(IdRole).toStringList();
100 kDebug() << "// EFFECT SELECTED: " << effectInfo;
101 switch (item->data(TypeRole).toInt()) {
103 effect = MainWindow::videoEffects.getEffectByTag(effectInfo.at(0), effectInfo.at(1));
106 effect = MainWindow::audioEffects.getEffectByTag(effectInfo.at(0), effectInfo.at(1));
109 effect = MainWindow::customEffects.getEffectByTag(effectInfo.at(0), effectInfo.at(1));
116 QString EffectsListWidget::currentInfo() {
117 QListWidgetItem *item = currentItem();
118 if (!item) return QString();
120 QStringList effectInfo = item->data(IdRole).toStringList();
121 switch (item->data(TypeRole).toInt()) {
123 info = MainWindow::videoEffects.getInfo(effectInfo.at(0), effectInfo.at(1));
126 info = MainWindow::audioEffects.getInfo(effectInfo.at(0), effectInfo.at(1));
129 info = MainWindow::customEffects.getInfo(effectInfo.at(0), effectInfo.at(1));
136 void EffectsListWidget::mousePressEvent(QMouseEvent *event) {
137 if (event->button() == Qt::LeftButton) {
138 m_DragStartPosition = event->pos();
139 m_dragStarted = true;
141 KListWidget::mousePressEvent(event);
145 void EffectsListWidget::mouseMoveEvent(QMouseEvent *event) {
146 if (!m_dragStarted) return;
147 if ((event->pos() - m_DragStartPosition).manhattanLength()
148 < QApplication::startDragDistance())
152 QListWidgetItem *clickItem = itemAt(event->pos());
154 QDrag *drag = new QDrag(this);
155 QMimeData *mimeData = new QMimeData;
156 const QList <QListWidgetItem *>list = selectedItems();
158 foreach(QListWidgetItem *item, list) {
159 QDomElement e = itemEffect(item);
160 if (!e.isNull()) doc.appendChild(doc.importNode(e, true));
163 data.append(doc.toString().toUtf8());
164 mimeData->setData("kdenlive/effectslist", data);
165 drag->setMimeData(mimeData);
166 //QPixmap pix = qVariantValue<QPixmap>(clickItem->data(Qt::DecorationRole));
167 //drag->setPixmap(pix);
168 //drag->setHotSpot(QPoint(0, 50));
169 drag->start(Qt::MoveAction);
175 void EffectsListWidget::dragMoveEvent(QDragMoveEvent * event) {
176 event->setDropAction(Qt::IgnoreAction);
178 event->setDropAction(Qt::MoveAction);
179 if (event->mimeData()->hasText()) {
180 event->acceptProposedAction();
186 void EffectsListWidget::contextMenuEvent(QContextMenuEvent * event) {
187 QListWidgetItem *item = itemAt(event->pos());
188 if (item && item->data(TypeRole).toInt() == EFFECT_CUSTOM) m_menu->popup(event->globalPos());
191 #include "effectslistwidget.moc"