X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Ffrontends%2Fqt4%2FGuiClipboard.cpp;h=7798228a21c878ac87c885cf82a2ad06c4cb6d1d;hb=42015a8ebd17092c9b55c9519015119d04f52218;hp=463bad4913e6fa38b0c11c742b8a4dbe91324b34;hpb=897436efbb9bd641b61467d185a2dfae9839e575;p=lyx.git diff --git a/src/frontends/qt4/GuiClipboard.cpp b/src/frontends/qt4/GuiClipboard.cpp index 463bad4913..7798228a21 100644 --- a/src/frontends/qt4/GuiClipboard.cpp +++ b/src/frontends/qt4/GuiClipboard.cpp @@ -23,6 +23,7 @@ #include #include "support/lstrings.h" + using lyx::support::internalLineEnding; using lyx::support::externalLineEnding; @@ -35,25 +36,34 @@ static char const * const mime_type = "application/x-lyx"; namespace lyx { namespace frontend { +GuiClipboard::GuiClipboard() +{ + connect(qApp->clipboard(), SIGNAL(dataChanged()), + this, SLOT(on_dataChanged())); + // initialize clipboard status. + on_dataChanged(); +} + + string const GuiClipboard::getAsLyX() const { - LYXERR(Debug::ACTION) << "GuiClipboard::getAsLyX(): `"; + LYXERR(Debug::ACTION, "GuiClipboard::getAsLyX(): `"); // We don't convert encodings here since the encoding of the // clipboard contents is specified in the data itself QMimeData const * source = qApp->clipboard()->mimeData(QClipboard::Clipboard); if (!source) { - LYXERR(Debug::ACTION) << "' (no QMimeData)" << endl; + LYXERR(Debug::ACTION, "' (no QMimeData)"); return string(); } if (source->hasFormat(mime_type)) { // data from ourself or some other LyX instance QByteArray const ar = source->data(mime_type); string const s(ar.data(), ar.count()); - LYXERR(Debug::ACTION) << s << "'" << endl; + LYXERR(Debug::ACTION, s << "'"); return s; } - LYXERR(Debug::ACTION) << "'" << endl; + LYXERR(Debug::ACTION, "'"); return string(); } @@ -62,9 +72,8 @@ docstring const GuiClipboard::getAsText() const { // text data from other applications QString const str = qApp->clipboard()->text(QClipboard::Clipboard) - .normalized(QString::NormalizationForm_KC); - LYXERR(Debug::ACTION) << "GuiClipboard::getAsText(): `" - << fromqstr(str) << "'" << endl; + .normalized(QString::NormalizationForm_C); + LYXERR(Debug::ACTION, "GuiClipboard::getAsText(): `" << fromqstr(str) << "'"); if (str.isNull()) return docstring(); @@ -74,8 +83,8 @@ docstring const GuiClipboard::getAsText() const void GuiClipboard::put(string const & lyx, docstring const & text) { - LYXERR(Debug::ACTION) << "GuiClipboard::put(`" << lyx << "' `" - << to_utf8(text) << "')" << endl; + LYXERR(Debug::ACTION, "GuiClipboard::put(`" << lyx << "' `" + << to_utf8(text) << "')"); // We don't convert the encoding of lyx since the encoding of the // clipboard contents is specified in the data itself QMimeData * data = new QMimeData; @@ -109,16 +118,27 @@ bool GuiClipboard::isInternal() const } +void GuiClipboard::on_dataChanged() +{ + text_clipboard_empty_ = qApp->clipboard()-> + text(QClipboard::Clipboard).isEmpty(); + + has_lyx_contents_ = hasLyXContents(); +} + + bool GuiClipboard::empty() const { // We need to check both the plaintext and the LyX version of the // clipboard. The plaintext version is empty if the LyX version - // contains only one inset, and the LyX version is empry if the + // contains only one inset, and the LyX version is empty if the // clipboard does not come from LyX. - if (!qApp->clipboard()->text(QClipboard::Clipboard).isEmpty()) + if (!text_clipboard_empty_) return false; - return !hasLyXContents(); + return !has_lyx_contents_; } } // namespace frontend } // namespace lyx + +#include "GuiClipboard_moc.cpp"