kwave  18.07.70
Drag.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  KwaveDrag.cpp - Drag&Drop container for Kwave's audio data
3  -------------------
4  begin : Jan 24 2002
5  copyright : (C) 2002 by Thomas Eschenbacher
6  email : Thomas Eschenbacher <thomas.eschenbacher@gmx.de>
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "config.h"
19 
20 #include <new>
21 
22 #include <QMimeData>
23 #include <QWidget>
24 
25 #include "libkwave/CodecManager.h"
26 #include "libkwave/Drag.h"
27 #include "libkwave/MimeData.h"
29 
30 //***************************************************************************
31 Kwave::Drag::Drag(QWidget *dragSource)
32  :QDrag(dragSource)
33 {
34 }
35 
36 //***************************************************************************
38 {
39 }
40 
41 //***************************************************************************
42 bool Kwave::Drag::canDecode(const QMimeData *data)
43 {
44  if (!data) return false;
45  foreach (const QString &format, data->formats())
46  if (Kwave::CodecManager::canDecode(format)) return true;
47  return false;
48 }
49 
50 //***************************************************************************
51 bool Kwave::Drag::encode(QWidget *widget, Kwave::MultiTrackReader &src,
52  const Kwave::MetaDataList &meta_data)
53 {
54  Q_ASSERT(src.tracks());
55  if (!src.tracks()) return false;
56  Q_ASSERT(src[0]);
57  if (!src[0]) return false;
58 
59  // create a mime data container
60  Kwave::MimeData *mime_data = new(std::nothrow) Kwave::MimeData;
61  Q_ASSERT(mime_data);
62  if (!mime_data) return false;
63 
64  // encode into the mime data
65  if (!mime_data->encode(widget, src, meta_data)) {
66  delete mime_data;
67  return false;
68  }
69 
70  // use it for the drag container
71  setMimeData(mime_data);
72  return true;
73 }
74 
75 //***************************************************************************
76 sample_index_t Kwave::Drag::decode(QWidget *widget, const QMimeData *e,
78  sample_index_t pos)
79 {
80  return Kwave::MimeData::decode(widget, e, sig, pos);
81 }
82 
83 //***************************************************************************
84 //***************************************************************************
static sample_index_t decode(QWidget *widget, const QMimeData *e, Kwave::SignalManager &sig, sample_index_t pos)
Definition: Drag.cpp:76
virtual unsigned int tracks() const Q_DECL_OVERRIDE
quint64 sample_index_t
Definition: Sample.h:28
static bool canDecode(const QMimeData *data)
Definition: Drag.cpp:42
virtual ~Drag()
Definition: Drag.cpp:37
static sample_index_t decode(QWidget *widget, const QMimeData *e, Kwave::SignalManager &sig, sample_index_t pos)
Definition: MimeData.cpp:237
bool encode(QWidget *widget, Kwave::MultiTrackReader &src, const Kwave::MetaDataList &meta_data)
Definition: Drag.cpp:51
Drag(QWidget *dragSource=Q_NULLPTR)
Definition: Drag.cpp:31
virtual bool encode(QWidget *widget, Kwave::MultiTrackReader &src, const Kwave::MetaDataList &meta_data)
Definition: MimeData.cpp:184
static bool canDecode(const QString &mimetype_name)