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 static const int EFFECT_VIDEO = 1;
31 static const int EFFECT_AUDIO = 2;
32 static const int EFFECT_CUSTOM = 3;
34 const int TypeRole = Qt::UserRole;
35 const int IdRole = TypeRole + 1;
37 EffectsListWidget::EffectsListWidget(QMenu *menu, QWidget *parent)
38 : KListWidget(parent), m_menu(menu) {
39 //setSelectionMode(QAbstractItemView::ExtendedSelection);
40 //setDragDropMode(QAbstractItemView::DragDrop);
41 setDropIndicatorShown(true);
42 setAlternatingRowColors(true);
43 setSortingEnabled(true);
49 EffectsListWidget::~EffectsListWidget() {
52 void EffectsListWidget::initList() {
54 QListWidgetItem *item;
56 QStringList effectInfo;
57 KIcon videoIcon("kdenlive-show-video");
58 KIcon audioIcon("kdenlive-show-audio");
59 int ct = MainWindow::videoEffects.count();
60 for (int ix = 0; ix < ct; ix ++) {
61 effectInfo = MainWindow::videoEffects.effectIdInfo(ix);
62 if (!effectInfo.isEmpty()) {
63 item = new QListWidgetItem(videoIcon, effectInfo.takeFirst(), this);
64 item->setData(TypeRole, QString::number((int) EFFECT_VIDEO));
65 item->setData(IdRole, effectInfo);
69 ct = MainWindow::audioEffects.count();
70 for (int ix = 0; ix < ct; ix ++) {
71 effectInfo = MainWindow::audioEffects.effectIdInfo(ix);
72 if (!effectInfo.isEmpty()) {
73 item = new QListWidgetItem(audioIcon, effectInfo.takeFirst(), this);
74 item->setData(TypeRole, QString::number((int) EFFECT_AUDIO));
75 item->setData(IdRole, effectInfo);
79 ct = MainWindow::customEffects.count();
80 for (int ix = 0; ix < ct; ix ++) {
81 effectInfo = MainWindow::customEffects.effectIdInfo(ix);
82 if (!effectInfo.isEmpty()) {
83 item = new QListWidgetItem(effectInfo.takeFirst(), this);
84 item->setData(TypeRole, QString::number((int) EFFECT_CUSTOM));
85 item->setData(IdRole, effectInfo);
90 QDomElement EffectsListWidget::currentEffect() {
91 return itemEffect(currentItem());
94 QDomElement EffectsListWidget::itemEffect(QListWidgetItem *item) {
96 if (!item) return effect;
97 QStringList effectInfo = item->data(IdRole).toStringList();
98 kDebug() << "// EFFECT SELECTED: " << effectInfo;
99 switch (item->data(TypeRole).toInt()) {
101 effect = MainWindow::videoEffects.getEffectByTag(effectInfo.at(0), effectInfo.at(1));
104 effect = MainWindow::audioEffects.getEffectByTag(effectInfo.at(0), effectInfo.at(1));
107 effect = MainWindow::customEffects.getEffectByTag(effectInfo.at(0), effectInfo.at(1));
114 QString EffectsListWidget::currentInfo() {
115 QListWidgetItem *item = currentItem();
116 if (!item) return QString();
118 QStringList effectInfo = item->data(IdRole).toStringList();
119 switch (item->data(TypeRole).toInt()) {
121 info = MainWindow::videoEffects.getInfo(effectInfo.at(0), effectInfo.at(1));
124 info = MainWindow::audioEffects.getInfo(effectInfo.at(0), effectInfo.at(1));
127 info = MainWindow::customEffects.getInfo(effectInfo.at(0), effectInfo.at(1));
134 void EffectsListWidget::mousePressEvent(QMouseEvent *event) {
135 if (event->button() == Qt::LeftButton) {
136 this->m_DragStartPosition = event->pos();
137 m_dragStarted = true;
139 KListWidget::mousePressEvent(event);
143 void EffectsListWidget::mouseMoveEvent(QMouseEvent *event) {
144 if (!m_dragStarted) return;
145 if ((event->pos() - m_DragStartPosition).manhattanLength()
146 < QApplication::startDragDistance())
150 QListWidgetItem *clickItem = itemAt(event->pos());
152 QDrag *drag = new QDrag(this);
153 QMimeData *mimeData = new QMimeData;
154 const QList <QListWidgetItem *>list = selectedItems();
156 foreach(QListWidgetItem *item, list) {
157 QDomElement e = itemEffect(item);
158 if (!e.isNull()) doc.appendChild(doc.importNode(e, true));
161 data.append(doc.toString().toUtf8());
162 mimeData->setData("kdenlive/effectslist", data);
163 drag->setMimeData(mimeData);
164 //QPixmap pix = qVariantValue<QPixmap>(clickItem->data(Qt::DecorationRole));
165 //drag->setPixmap(pix);
166 //drag->setHotSpot(QPoint(0, 50));
167 drag->start(Qt::MoveAction);
173 void EffectsListWidget::dragMoveEvent(QDragMoveEvent * event) {
174 event->setDropAction(Qt::IgnoreAction);
176 event->setDropAction(Qt::MoveAction);
177 if (event->mimeData()->hasText()) {
178 event->acceptProposedAction();
184 void EffectsListWidget::contextMenuEvent(QContextMenuEvent * event) {
185 QListWidgetItem *item = itemAt(event->pos());
186 if (item && item->data(TypeRole).toInt() == EFFECT_CUSTOM) m_menu->popup(event->globalPos());
189 #include "effectslistwidget.moc"