kwave  18.07.70
Kwave::Drag Class Reference

#include <Drag.h>

Inheritance diagram for Kwave::Drag:
Inheritance graph
Collaboration diagram for Kwave::Drag:
Collaboration graph

Public Member Functions

 Drag (QWidget *dragSource=Q_NULLPTR)
 
virtual ~Drag ()
 
bool encode (QWidget *widget, Kwave::MultiTrackReader &src, const Kwave::MetaDataList &meta_data)
 

Static Public Member Functions

static bool canDecode (const QMimeData *data)
 
static sample_index_t decode (QWidget *widget, const QMimeData *e, Kwave::SignalManager &sig, sample_index_t pos)
 

Detailed Description

Simple class for drag & drop of wav data.

Todo:
the current storage mechanism is straight-forward and stupid, it should be extended to use virtual memory

Definition at line 46 of file Drag.h.

Constructor & Destructor Documentation

◆ Drag()

Kwave::Drag::Drag ( QWidget *  dragSource = Q_NULLPTR)
explicit

Constructor

See also
QDragObject

Definition at line 31 of file Drag.cpp.

32  :QDrag(dragSource)
33 {
34 }

◆ ~Drag()

Kwave::Drag::~Drag ( )
virtual

Destructor

Definition at line 37 of file Drag.cpp.

38 {
39 }

Member Function Documentation

◆ canDecode()

bool Kwave::Drag::canDecode ( const QMimeData *  data)
static

Returns true if the mime type of the given source can be decoded

Definition at line 42 of file Drag.cpp.

References Kwave::CodecManager::canDecode().

Referenced by Kwave::SignalView::dragMoveEvent(), Kwave::MainWidget::dropEvent(), and Kwave::SignalView::dropEvent().

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 }
static bool canDecode(const QString &mimetype_name)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ decode()

sample_index_t Kwave::Drag::decode ( QWidget *  widget,
const QMimeData *  e,
Kwave::SignalManager sig,
sample_index_t  pos 
)
static

Decodes the encoded byte data of the given mime source and initializes a MultiTrackReader.

Parameters
widgetthe widget used for displaying error messages
emime source
sigsignal that receives the mime data
posposition within the signal where to insert the data
Returns
number of decoded samples if successful, zero if failed

Definition at line 76 of file Drag.cpp.

References Kwave::MimeData::decode().

Referenced by Kwave::MainWidget::dropEvent(), and Kwave::SignalView::dropEvent().

79 {
80  return Kwave::MimeData::decode(widget, e, sig, pos);
81 }
static sample_index_t decode(QWidget *widget, const QMimeData *e, Kwave::SignalManager &sig, sample_index_t pos)
Definition: MimeData.cpp:237
Here is the call graph for this function:
Here is the caller graph for this function:

◆ encode()

bool Kwave::Drag::encode ( QWidget *  widget,
Kwave::MultiTrackReader src,
const Kwave::MetaDataList meta_data 
)

Encodes wave data received from a MultiTrackReader into a byte array that is compatible with the format of a wav file.

Parameters
widgetthe widget used for displaying error messages
srcsource of the samples
meta_datainformation about the signal, sample rate, resolution and other meta data
Returns
true if successful

Definition at line 51 of file Drag.cpp.

References Kwave::MimeData::encode(), and Kwave::MultiTrackSource< SOURCE, INITIALIZE >::tracks().

Referenced by Kwave::SelectionItem::startDragging().

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 }
virtual unsigned int tracks() const Q_DECL_OVERRIDE
virtual bool encode(QWidget *widget, Kwave::MultiTrackReader &src, const Kwave::MetaDataList &meta_data)
Definition: MimeData.cpp:184
Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following files: