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 int ct = MainWindow::videoEffects.count();
58 for (int ix = 0; ix < ct; ix ++) {
59 effectInfo = MainWindow::videoEffects.effectIdInfo(ix);
60 if (!effectInfo.isEmpty()) {
61 item = new QListWidgetItem(effectInfo.takeFirst(), this);
62 item->setData(TypeRole, QString::number((int) EFFECT_VIDEO));
63 item->setData(IdRole, effectInfo);
67 ct = MainWindow::audioEffects.count();
68 for (int ix = 0; ix < ct; ix ++) {
69 effectInfo = MainWindow::audioEffects.effectIdInfo(ix);
70 if (!effectInfo.isEmpty()) {
71 item = new QListWidgetItem(effectInfo.takeFirst(), this);
72 item->setData(TypeRole, QString::number((int) EFFECT_AUDIO));
73 item->setData(IdRole, effectInfo);
77 ct = MainWindow::customEffects.count();
78 for (int ix = 0; ix < ct; ix ++) {
79 effectInfo = MainWindow::customEffects.effectIdInfo(ix);
80 if (!effectInfo.isEmpty()) {
81 item = new QListWidgetItem(effectInfo.takeFirst(), this);
82 item->setData(TypeRole, QString::number((int) EFFECT_CUSTOM));
83 item->setData(IdRole, effectInfo);
88 QDomElement EffectsListWidget::currentEffect() {
89 return itemEffect(currentItem());
92 QDomElement EffectsListWidget::itemEffect(QListWidgetItem *item) {
94 if (!item) return effect;
95 QStringList effectInfo = item->data(IdRole).toStringList();
96 kDebug() << "// EFFECT SELECTED: " << effectInfo;
97 switch (item->data(TypeRole).toInt()) {
99 effect = MainWindow::videoEffects.getEffectByTag(effectInfo.at(0), effectInfo.at(1));
102 effect = MainWindow::audioEffects.getEffectByTag(effectInfo.at(0), effectInfo.at(1));
105 effect = MainWindow::customEffects.getEffectByTag(effectInfo.at(0), effectInfo.at(1));
112 QString EffectsListWidget::currentInfo() {
113 QListWidgetItem *item = currentItem();
114 if (!item) return QString();
116 QStringList effectInfo = item->data(IdRole).toStringList();
117 switch (item->data(TypeRole).toInt()) {
119 info = MainWindow::videoEffects.getInfo(effectInfo.at(0), effectInfo.at(1));
122 info = MainWindow::audioEffects.getInfo(effectInfo.at(0), effectInfo.at(1));
125 info = MainWindow::customEffects.getInfo(effectInfo.at(0), effectInfo.at(1));
132 void EffectsListWidget::mousePressEvent(QMouseEvent *event) {
133 if (event->button() == Qt::LeftButton) {
134 this->m_DragStartPosition = event->pos();
135 m_dragStarted = true;
137 KListWidget::mousePressEvent(event);
141 void EffectsListWidget::mouseMoveEvent(QMouseEvent *event) {
142 if (!m_dragStarted) return;
143 if ((event->pos() - m_DragStartPosition).manhattanLength()
144 < QApplication::startDragDistance())
148 QListWidgetItem *clickItem = itemAt(event->pos());
150 QDrag *drag = new QDrag(this);
151 QMimeData *mimeData = new QMimeData;
152 const QList <QListWidgetItem *>list = selectedItems();
154 foreach(QListWidgetItem *item, list) {
155 QDomElement e = itemEffect(item);
156 if (!e.isNull()) doc.appendChild(doc.importNode(e, true));
159 data.append(doc.toString().toUtf8());
160 mimeData->setData("kdenlive/effectslist", data);
161 drag->setMimeData(mimeData);
162 //QPixmap pix = qVariantValue<QPixmap>(clickItem->data(Qt::DecorationRole));
163 //drag->setPixmap(pix);
164 //drag->setHotSpot(QPoint(0, 50));
165 drag->start(Qt::MoveAction);
171 void EffectsListWidget::dragMoveEvent(QDragMoveEvent * event) {
172 event->setDropAction(Qt::IgnoreAction);
174 event->setDropAction(Qt::MoveAction);
175 if (event->mimeData()->hasText()) {
176 event->acceptProposedAction();
182 void EffectsListWidget::contextMenuEvent(QContextMenuEvent * event) {
183 QListWidgetItem *item = itemAt(event->pos());
184 if (item && item->data(TypeRole).toInt() == EFFECT_CUSTOM) m_menu->popup(event->globalPos());
187 #include "effectslistwidget.moc"