]> git.sesse.net Git - kdenlive/blob - src/effectslistwidget.cpp
Comment out names of unused parameters [PATCH by Ray Lehtiniemi]
[kdenlive] / src / effectslistwidget.cpp
1 /***************************************************************************
2  *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
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.                                   *
8  *                                                                         *
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.                          *
13  *                                                                         *
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  ***************************************************************************/
19
20
21 #include "effectslistwidget.h"
22 #include "effectslist.h"
23 #include "mainwindow.h"
24
25 #include "KDebug"
26
27 #include "QApplication"
28 #include "QMouseEvent"
29 #include <QMenu>
30
31
32 static const int EFFECT_VIDEO = 1;
33 static const int EFFECT_AUDIO = 2;
34 static const int EFFECT_CUSTOM = 3;
35
36 const int TypeRole = Qt::UserRole;
37 const int IdRole = TypeRole + 1;
38
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);
46     setDragEnabled(true);
47     setAcceptDrops(true);
48     initList();
49 }
50
51 EffectsListWidget::~EffectsListWidget() {
52 }
53
54 void EffectsListWidget::initList() {
55     clear();
56     QListWidgetItem *item;
57     QString effectName;
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);
68         }
69     }
70
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);
78         }
79     }
80
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);
88         }
89     }
90 }
91
92 QDomElement EffectsListWidget::currentEffect() {
93     return itemEffect(currentItem());
94 }
95
96 QDomElement EffectsListWidget::itemEffect(QListWidgetItem *item) {
97     QDomElement effect;
98     if (!item) return effect;
99     QStringList effectInfo = item->data(IdRole).toStringList();
100     kDebug() << "// EFFECT SELECTED: " << effectInfo;
101     switch (item->data(TypeRole).toInt()) {
102     case 1:
103         effect =  MainWindow::videoEffects.getEffectByTag(effectInfo.at(0), effectInfo.at(1));
104         break;
105     case 2:
106         effect = MainWindow::audioEffects.getEffectByTag(effectInfo.at(0), effectInfo.at(1));
107         break;
108     default:
109         effect = MainWindow::customEffects.getEffectByTag(effectInfo.at(0), effectInfo.at(1));
110         break;
111     }
112     return effect;
113 }
114
115
116 QString EffectsListWidget::currentInfo() {
117     QListWidgetItem *item = currentItem();
118     if (!item) return QString();
119     QString info;
120     QStringList effectInfo = item->data(IdRole).toStringList();
121     switch (item->data(TypeRole).toInt()) {
122     case 1:
123         info = MainWindow::videoEffects.getInfo(effectInfo.at(0), effectInfo.at(1));
124         break;
125     case 2:
126         info = MainWindow::audioEffects.getInfo(effectInfo.at(0), effectInfo.at(1));
127         break;
128     default:
129         info = MainWindow::customEffects.getInfo(effectInfo.at(0), effectInfo.at(1));
130         break;
131     }
132     return info;
133 }
134
135 // virtual
136 void EffectsListWidget::mousePressEvent(QMouseEvent *event) {
137     if (event->button() == Qt::LeftButton) {
138         this->m_DragStartPosition = event->pos();
139         m_dragStarted = true;
140     }
141     KListWidget::mousePressEvent(event);
142 }
143
144 // virtual
145 void EffectsListWidget::mouseMoveEvent(QMouseEvent *event) {
146     if (!m_dragStarted) return;
147     if ((event->pos() - m_DragStartPosition).manhattanLength()
148             < QApplication::startDragDistance())
149         return;
150
151     {
152         QListWidgetItem *clickItem = itemAt(event->pos());
153         if (clickItem) {
154             QDrag *drag = new QDrag(this);
155             QMimeData *mimeData = new QMimeData;
156             const QList <QListWidgetItem *>list = selectedItems();
157             QDomDocument doc;
158             foreach(QListWidgetItem *item, list) {
159                 QDomElement e = itemEffect(item);
160                 if (!e.isNull()) doc.appendChild(doc.importNode(e, true));
161             }
162             QByteArray data;
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);
170         }
171         //event->accept();
172     }
173 }
174
175 void EffectsListWidget::dragMoveEvent(QDragMoveEvent * event) {
176     event->setDropAction(Qt::IgnoreAction);
177     //if (item) {
178     event->setDropAction(Qt::MoveAction);
179     if (event->mimeData()->hasText()) {
180         event->acceptProposedAction();
181     }
182     //}
183 }
184
185 //virtual
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());
189 }
190
191 #include "effectslistwidget.moc"