]> git.sesse.net Git - kdenlive/blob - src/effectslistwidget.cpp
made effectLists static
[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 #include "QApplication"
21 #include "QMouseEvent"
22
23 #include "KDebug"
24
25 #include "effectslistwidget.h"
26 #include "effectslist.h"
27 #include "mainwindow.h"
28
29 #define EFFECT_VIDEO 1
30 #define EFFECT_AUDIO 2
31 #define EFFECT_CUSTOM 3
32
33 EffectsListWidget::EffectsListWidget(QWidget *parent)
34         : KListWidget(parent) {
35     //setSelectionMode(QAbstractItemView::ExtendedSelection);
36     //setDragDropMode(QAbstractItemView::DragDrop);
37     setDropIndicatorShown(true);
38     setAlternatingRowColors(true);
39     setSortingEnabled(true);
40     setDragEnabled(true);
41     setAcceptDrops(true);
42     initList();
43 }
44
45 EffectsListWidget::~EffectsListWidget() {
46 }
47
48 void EffectsListWidget::initList() {
49     clear();
50     QStringList names = MainWindow::videoEffects.effectNames();
51     QListWidgetItem *item;
52     foreach(QString str, names) {
53         item = new QListWidgetItem(str, this);
54         item->setData(Qt::UserRole, QString::number((int) EFFECT_VIDEO));
55     }
56
57     names = MainWindow::audioEffects.effectNames();
58     foreach(QString str, names) {
59         item = new QListWidgetItem(str, this);
60         item->setData(Qt::UserRole, QString::number((int) EFFECT_AUDIO));
61     }
62
63     names = MainWindow::customEffects.effectNames();
64     foreach(QString str, names) {
65         item = new QListWidgetItem(str, this);
66         item->setData(Qt::UserRole, QString::number((int) EFFECT_CUSTOM));
67     }
68 }
69
70 QDomElement EffectsListWidget::currentEffect() {
71     return itemEffect(currentItem());
72 }
73
74 QDomElement EffectsListWidget::itemEffect(QListWidgetItem *item) {
75     QDomElement effect;
76     if (!item) return effect;
77     switch (item->data(Qt::UserRole).toInt()) {
78     case 1:
79         effect =  MainWindow::videoEffects.getEffectByName(item->text());
80         break;
81     case 2:
82         effect = MainWindow::audioEffects.getEffectByName(item->text());
83         break;
84     default:
85         effect = MainWindow::customEffects.getEffectByName(item->text());
86         break;
87     }
88     return effect;
89 }
90
91
92 QString EffectsListWidget::currentInfo() {
93     QListWidgetItem *item = currentItem();
94     if (!item) return QString();
95     QString info;
96     switch (item->data(Qt::UserRole).toInt()) {
97     case 1:
98         info = MainWindow::videoEffects.getInfo(item->text());
99         break;
100     case 2:
101         info = MainWindow::audioEffects.getInfo(item->text());
102         break;
103     default:
104         info = MainWindow::customEffects.getInfo(item->text());
105         break;
106     }
107     return info;
108 }
109
110 // virtual
111 void EffectsListWidget::mousePressEvent(QMouseEvent *event) {
112     if (event->button() == Qt::LeftButton) {
113         this->m_DragStartPosition = event->pos();
114         m_dragStarted = true;
115     }
116     KListWidget::mousePressEvent(event);
117 }
118
119 // virtual
120 void EffectsListWidget::mouseMoveEvent(QMouseEvent *event) {
121     if (!m_dragStarted) return;
122     if ((event->pos() - m_DragStartPosition).manhattanLength()
123             < QApplication::startDragDistance())
124         return;
125
126     {
127         QListWidgetItem *clickItem = itemAt(event->pos());
128         if (clickItem) {
129             QDrag *drag = new QDrag(this);
130             QMimeData *mimeData = new QMimeData;
131             QList <QListWidgetItem *> list;
132             list = selectedItems();
133             QDomDocument doc;
134             foreach(QListWidgetItem *item, list) {
135                 doc.appendChild(doc.importNode(itemEffect(item), true));
136             }
137             QByteArray data;
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);
145         }
146         //event->accept();
147     }
148 }
149
150 void EffectsListWidget::dragMoveEvent(QDragMoveEvent * event) {
151     event->setDropAction(Qt::IgnoreAction);
152     //if (item) {
153     event->setDropAction(Qt::MoveAction);
154     if (event->mimeData()->hasText()) {
155         event->acceptProposedAction();
156     }
157     //}
158 }
159
160
161
162 #include "effectslistwidget.moc"