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