3 * \file qt4/GuiClipboard.C
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
8 * \author Abdelrazak Younes
10 * Full author contact details are available in file CREDITS.
15 #include "GuiClipboard.h"
16 #include "qt_helpers.h"
20 #include <QApplication>
25 #include "support/lstrings.h"
26 using lyx::support::internalLineEnding;
27 using lyx::support::externalLineEnding;
35 char const * const mime_type = "application/x-lyx";
43 string const GuiClipboard::getAsLyX() const
45 lyxerr[Debug::ACTION] << "GuiClipboard::getAsLyX(): `";
46 // We don't convert encodings here since the encoding of the
47 // clipboard contents is specified in the data itself
48 QMimeData const * source =
49 qApp->clipboard()->mimeData(QClipboard::Clipboard);
51 lyxerr[Debug::ACTION] << "' (no QMimeData)" << endl;
54 if (source->hasFormat(mime_type)) {
55 // data from ourself or some other LyX instance
56 QByteArray const ar = source->data(mime_type);
57 string const s(ar.data(), ar.count());
58 if (lyxerr.debugging(Debug::ACTION))
59 lyxerr[Debug::ACTION] << s << "'" << endl;
62 lyxerr[Debug::ACTION] << "'" << endl;
67 docstring const GuiClipboard::getAsText() const
69 // text data from other applications
70 QString const str = qApp->clipboard()->text(QClipboard::Clipboard);
71 if (lyxerr.debugging(Debug::ACTION))
72 lyxerr[Debug::ACTION] << "GuiClipboard::getAsText(): `"
73 << fromqstr(str) << "'" << endl;
77 return internalLineEnding(qstring_to_ucs4(str));
81 void GuiClipboard::put(string const & lyx, docstring const & text)
83 if (lyxerr.debugging(Debug::ACTION))
84 lyxerr[Debug::ACTION] << "GuiClipboard::put(`" << lyx << "' `"
85 << to_utf8(text) << "')" << endl;
86 // We don't convert the encoding of lyx since the encoding of the
87 // clipboard contents is specified in the data itself
88 QMimeData * data = new QMimeData;
90 QByteArray const qlyx(lyx.c_str(), lyx.size());
91 data->setData(mime_type, qlyx);
93 // Don't test for text.empty() since we want to be able to clear the
95 QString const qtext = toqstr(text);
97 qApp->clipboard()->setMimeData(data, QClipboard::Clipboard);
101 bool GuiClipboard::hasLyXContents() const
103 QMimeData const * const source =
104 qApp->clipboard()->mimeData(QClipboard::Clipboard);
105 return source && source->hasFormat(mime_type);
109 bool GuiClipboard::isInternal() const
111 return qApp->clipboard()->ownsClipboard();
115 bool GuiClipboard::empty() const
117 return qApp->clipboard()->text(QClipboard::Clipboard).isEmpty();
120 } // namespace frontend