3 * \file qt4/GuiSelection.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 "GuiSelection.h"
16 #include "qt_helpers.h"
20 #include <QApplication>
24 #include "support/lstrings.h"
25 using lyx::support::internalLineEnding;
26 using lyx::support::externalLineEnding;
33 void GuiSelection::haveSelection(bool own)
35 if (!qApp->clipboard()->supportsSelection())
38 // Tell qt that we have a selection by setting a dummy selection.
39 // We don't use the interface provided by Qt for setting the
40 // selection for performance reasons (see documentation of
41 // Selection::put()). Instead we only tell here that we have a
42 // selection by setting the selection to the empty string.
43 // The real selection is set in GuiApplication::x11EventFilter when
44 // an application actually requests it.
45 // This way calling Selection::have() is cheap and we can do it as
48 qApp->clipboard()->setText(QString(), QClipboard::Selection);
49 // We don't need to do anything if own = false, as this case is
54 docstring const GuiSelection::get() const
56 QString const str = qApp->clipboard()->text(QClipboard::Selection);
57 lyxerr[Debug::ACTION] << "GuiSelection::get: " << fromqstr(str)
62 return internalLineEnding(qstring_to_ucs4(str));
66 void GuiSelection::put(docstring const & str)
68 lyxerr[Debug::ACTION] << "GuiSelection::put: " << lyx::to_utf8(str) << endl;
70 qApp->clipboard()->setText(toqstr(externalLineEnding(str)),
71 QClipboard::Selection);
74 } // namespace frontend