From: Abdelrazak Younes Date: Sun, 30 Sep 2007 20:28:15 +0000 (+0000) Subject: Fix slowness issue with Clipboard. Cache the Clipboard status when the data is changed. X-Git-Tag: 1.6.10~8104 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=e3e83d1c65237c0bc421454eeffbff1002df28d1;p=features.git Fix slowness issue with Clipboard. Cache the Clipboard status when the data is changed. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20617 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/qt4/GuiClipboard.cpp b/src/frontends/qt4/GuiClipboard.cpp index cd9914cde6..fa2cf260fd 100644 --- a/src/frontends/qt4/GuiClipboard.cpp +++ b/src/frontends/qt4/GuiClipboard.cpp @@ -36,6 +36,15 @@ 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(): `"; @@ -110,16 +119,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" diff --git a/src/frontends/qt4/GuiClipboard.h b/src/frontends/qt4/GuiClipboard.h index 12a8864a41..da98c2b163 100644 --- a/src/frontends/qt4/GuiClipboard.h +++ b/src/frontends/qt4/GuiClipboard.h @@ -16,15 +16,19 @@ #include "frontends/Clipboard.h" +#include + namespace lyx { namespace frontend { /** * The Qt4 version of the Clipboard. */ -class GuiClipboard : public Clipboard +class GuiClipboard: public QObject, public Clipboard { + Q_OBJECT public: + GuiClipboard(); virtual ~GuiClipboard() {} /** Clipboard overloaded methods @@ -37,6 +41,13 @@ public: bool isInternal() const; bool empty() const; //@} + +private Q_SLOTS: + void on_dataChanged(); + +private: + bool text_clipboard_empty_; + bool has_lyx_contents_; }; } // namespace frontend diff --git a/src/frontends/qt4/Makefile.am b/src/frontends/qt4/Makefile.am index d1709a8e82..26f410cacd 100644 --- a/src/frontends/qt4/Makefile.am +++ b/src/frontends/qt4/Makefile.am @@ -117,7 +117,6 @@ SOURCEFILES = \ NOMOCHEADER = \ ButtonController.h \ - GuiClipboard.h \ GuiFontLoader.h \ GuiFontMetrics.h \ GuiSelection.h \ @@ -143,6 +142,7 @@ MOCHEADER = \ GuiChanges.h \ GuiCharacter.h \ GuiCitation.h \ + GuiClipboard.h \ GuiCommandBuffer.h \ GuiCommandEdit.h \ GuiDelimiter.h \