]> git.sesse.net Git - kdenlive/blob - src/effectslistwidget.cpp
0754180e6fe2bbfc38e8ce2eae92141359e4e026
[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 {
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
48 void EffectsListWidget::initList()
49 {
50   clear();
51   QStringList names = m_videoList->effectNames();
52   QListWidgetItem *item;
53   foreach (QString str, names) {
54     item = new QListWidgetItem(str, this);
55     item->setData(Qt::UserRole, QString::number((int) EFFECT_VIDEO));
56   }
57
58   names = m_audioList->effectNames();
59   foreach (QString str, names) {
60     item = new QListWidgetItem(str, this);
61     item->setData(Qt::UserRole, QString::number((int) EFFECT_AUDIO));
62   }
63
64   names = m_customList->effectNames();
65   foreach (QString str, names) {
66     item = new QListWidgetItem(str, this);
67     item->setData(Qt::UserRole, QString::number((int) EFFECT_CUSTOM));
68   }
69 }
70
71 QDomElement EffectsListWidget::currentEffect()
72 {
73   return itemEffect(currentItem());
74 }
75
76 QDomElement EffectsListWidget::itemEffect(QListWidgetItem *item)
77 {
78   QDomElement effect;
79   if (!item) return effect;
80   switch (item->data(Qt::UserRole).toInt())
81   {
82     case 1:
83       effect = m_videoList->getEffectByName(item->text());
84       break;
85     case 2:
86       effect = m_audioList->getEffectByName(item->text());
87       break;
88     default:
89       effect = m_customList->getEffectByName(item->text());
90       break;
91   }
92   return effect;
93 }
94
95
96 QString EffectsListWidget::currentInfo()
97 {
98   QListWidgetItem *item = currentItem();
99   if (!item) return QString();
100   QString info;
101   switch (item->data(Qt::UserRole).toInt())
102   {
103   case 1:
104     info = m_videoList->getInfo(item->text());
105     break;
106   case 2:
107     info = m_audioList->getInfo(item->text());
108     break;
109   default:
110     info = m_customList->getInfo(item->text());
111     break;
112   }
113   return info;
114 }
115
116 // virtual
117 void EffectsListWidget::mousePressEvent(QMouseEvent *event)
118 {
119     if( event->button() == Qt::LeftButton )
120     {
121         this->m_DragStartPosition = event->pos();
122         m_dragStarted = true;
123     }
124     KListWidget::mousePressEvent(event);
125 }
126
127 // virtual
128 void EffectsListWidget::mouseMoveEvent(QMouseEvent *event)
129 {
130   if (!m_dragStarted) return;
131   if ((event->pos() - m_DragStartPosition).manhattanLength()
132             < QApplication::startDragDistance())
133         return;
134  
135   {
136     QListWidgetItem *clickItem = itemAt(event->pos());
137     if (clickItem) {
138       QDrag *drag = new QDrag(this);
139       QMimeData *mimeData = new QMimeData;
140       QList <QListWidgetItem *> list;
141       list = selectedItems();
142       QDomDocument doc;
143       foreach (QListWidgetItem *item, list) {
144           doc.appendChild(doc.importNode(itemEffect(item), true));
145       }
146       QByteArray data;
147       data.append(doc.toString().toUtf8());
148       mimeData->setData("kdenlive/effectslist", data );
149       drag->setMimeData(mimeData);
150       //drag->setPixmap(clickItem->icon(0).pixmap(50 *16/9.0, 50));
151       drag->setHotSpot(QPoint(0, 50));
152       drag->start(Qt::MoveAction);
153     }
154     //event->accept(); 
155   }
156 }
157
158 void EffectsListWidget::dragMoveEvent(QDragMoveEvent * event) {
159         event->setDropAction(Qt::IgnoreAction);
160         //if (item) {
161                 event->setDropAction(Qt::MoveAction);
162                 if (event->mimeData()->hasText()) {
163                         event->acceptProposedAction();
164                 }
165         //}
166 }
167
168
169
170 #include "effectslistwidget.moc"