kwave  18.07.70
Kwave::ClipBoard Class Reference

#include <ClipBoard.h>

Inheritance diagram for Kwave::ClipBoard:
Inheritance graph
Collaboration diagram for Kwave::ClipBoard:
Collaboration graph

Public Slots

void slotChanged (QClipboard::Mode mode)
 

Signals

void clipboardChanged (bool data_available)
 

Public Member Functions

 ClipBoard ()
 
virtual ~ClipBoard ()
 
void copy (QWidget *widget, Kwave::SignalManager &signal_manager, const QList< unsigned int > &track_list, sample_index_t offset, sample_index_t length)
 
bool paste (QWidget *widget, Kwave::SignalManager &signal_manager, sample_index_t offset, sample_index_t length)
 
void clear ()
 
bool isEmpty ()
 

Static Public Member Functions

static ClipBoardinstance ()
 

Private Attributes

unsigned int m_tracks
 

Detailed Description

Implements a global clipboard for Kwave. It supports only the three simple operations put, get and clear.

Definition at line 41 of file ClipBoard.h.

Constructor & Destructor Documentation

◆ ClipBoard()

Kwave::ClipBoard::ClipBoard ( )

Constructor.

Definition at line 45 of file ClipBoard.cpp.

46  :m_tracks(0)
47 {
48 }
unsigned int m_tracks
Definition: ClipBoard.h:115

◆ ~ClipBoard()

Kwave::ClipBoard::~ClipBoard ( )
virtual

Destructor

Definition at line 51 of file ClipBoard.cpp.

52 {
53  // clear() must have been before, e.g. in the application's destructor !
54 }

Member Function Documentation

◆ clear()

void Kwave::ClipBoard::clear ( )

Clears the internal buffers. The clipboard will be empty after this function returns and the sample rate will be set to zero.

Definition at line 124 of file ClipBoard.cpp.

Referenced by Kwave::SignalManager::executeCommand().

125 {
126  QApplication::clipboard()->clear();
127 }
Here is the caller graph for this function:

◆ clipboardChanged

void Kwave::ClipBoard::clipboardChanged ( bool  data_available)
signal

Emitted whenever the clipboard has changed from empty to non-empty (with decodeable data) or vice versa.

Parameters
data_availableif true: contains decodeable data, if false: nothing decodeable or empty

Referenced by slotChanged().

Here is the caller graph for this function:

◆ copy()

void Kwave::ClipBoard::copy ( QWidget *  widget,
Kwave::SignalManager signal_manager,
const QList< unsigned int > &  track_list,
sample_index_t  offset,
sample_index_t  length 
)

Discards the current content of the clipboard and fills it with a selected range of samples from a set of tracks.

Parameters
widgetthe widget used as parent for displaying error messages
signal_managerthe SignalManager with the tracks to read from
track_lista list of indices of tracks for reading
offsetfirst sample to copy
lengthnumber of samples

Definition at line 69 of file ClipBoard.cpp.

References Kwave::MimeData::clear(), Kwave::MimeData::encode(), Kwave::SignalManager::metaData(), and Kwave::SinglePassForward.

Referenced by Kwave::SignalManager::executeCommand().

73 {
74  // break if nothing to do
75  if (!length || !track_list.count()) return;
76 
77  // get a buffer, implemented as a KwaveMimeData container
78  Kwave::MimeData *buffer = new(std::nothrow) Kwave::MimeData();
79  Q_ASSERT(buffer);
80  if (!buffer) return;
81 
82  // encode into the mime data container
84  track_list, offset, offset + length - 1);
85 
86  if (!buffer->encode(widget, src, signal_manager.metaData())) {
87  // encoding failed, reset to empty
88  buffer->clear();
89  delete buffer;
90  return;
91  }
92 
93  // give the buffer to the KDE clipboard
94  qApp->processEvents();
95  QApplication::clipboard()->setMimeData(buffer, QClipboard::Clipboard);
96 }
virtual void clear()
Definition: MimeData.cpp:434
Kwave::MetaDataList & metaData()
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:

◆ instance()

Kwave::ClipBoard & Kwave::ClipBoard::instance ( )
static

returns the static instance of the clipboard

Definition at line 39 of file ClipBoard.cpp.

References g_clipboard.

Referenced by Kwave::App::App(), Kwave::SignalWidget::contextMenuEvent(), Kwave::SignalManager::executeCommand(), Kwave::TopWidget::init(), and Kwave::TopWidget::updateMenu().

40 {
41  return g_clipboard;
42 }
static Kwave::ClipBoard g_clipboard
Definition: ClipBoard.cpp:36
Here is the caller graph for this function:

◆ isEmpty()

bool Kwave::ClipBoard::isEmpty ( )

Returns true if the buffer is empty.

Definition at line 130 of file ClipBoard.cpp.

References Kwave::CodecManager::canDecode().

Referenced by Kwave::SignalManager::executeCommand(), paste(), slotChanged(), and Kwave::TopWidget::updateMenu().

131 {
132  const QMimeData *mime_data =
133  QApplication::clipboard()->mimeData(QClipboard::Clipboard);
134 
135  // no mime data -> empty
136  if (!mime_data) return true;
137 
138  // there is a format that we can decode -> not empty
139  foreach (const QString &format, mime_data->formats())
140  if (Kwave::CodecManager::canDecode(format)) return false;
141 
142  // nothing to decode -> empty
143  return true;
144 }
static bool canDecode(const QString &mimetype_name)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ paste()

bool Kwave::ClipBoard::paste ( QWidget *  widget,
Kwave::SignalManager signal_manager,
sample_index_t  offset,
sample_index_t  length 
)

Transfers all stored data from the clipboard into a SignalManager.

Parameters
widgetthe widget used as parent for displaying error messages
signal_managerthe SignalManager with the tracks to write to
offsetsample position where to paste
lengthlength of the current selection in samples
Returns
true if successful, false if failed

Definition at line 99 of file ClipBoard.cpp.

References Kwave::MimeData::decode(), Kwave::SignalManager::deleteRange(), isEmpty(), and Kwave::SignalManager::selectRange().

Referenced by Kwave::SignalManager::executeCommand().

102 {
103  Q_ASSERT(!isEmpty());
104  if (isEmpty()) return false; // clipboard is empty ?
105 
106  // delete the current selection (with undo)
107  if (length <= 1) length = 0; // do not paste single samples !
108  if (length && !signal_manager.deleteRange(offset, length))
109  return false;
110 
111  sample_index_t decoded_samples = Kwave::MimeData::decode(
112  widget,
113  QApplication::clipboard()->mimeData(QClipboard::Clipboard),
114  signal_manager,
115  offset);
116  if (!decoded_samples) return false;
117 
118  // set the selection to the inserted range
119  signal_manager.selectRange(offset, decoded_samples);
120  return true;
121 }
void selectRange(sample_index_t offset, sample_index_t length)
quint64 sample_index_t
Definition: Sample.h:28
bool deleteRange(sample_index_t offset, sample_index_t length, const QList< unsigned int > &track_list)
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:

◆ slotChanged

void Kwave::ClipBoard::slotChanged ( QClipboard::Mode  mode)
slot

emits clipboardChanged() whenever the clipboard has changed from empty to filled (with decodeable data) or vice versa (connected to the Qt clipboard)

Definition at line 57 of file ClipBoard.cpp.

References clipboardChanged(), and isEmpty().

58 {
59  if (mode != QClipboard::Clipboard) return;
60  bool data_available = !isEmpty();
61 
62 // qDebug("=> ClipBoard::clipboardChanged(%s)",
63 // data_available ? "FULL" : "EMPTY");
64 
65  emit clipboardChanged(data_available);
66 }
void clipboardChanged(bool data_available)
Here is the call graph for this function:

Member Data Documentation

◆ m_tracks

unsigned int Kwave::ClipBoard::m_tracks
private

number of tracks of the content

Definition at line 115 of file ClipBoard.h.


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