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