]> git.lyx.org Git - features.git/commitdiff
Fix slowness issue with Clipboard. Cache the Clipboard status when the data is changed.
authorAbdelrazak Younes <younes@lyx.org>
Sun, 30 Sep 2007 20:28:15 +0000 (20:28 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Sun, 30 Sep 2007 20:28:15 +0000 (20:28 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20617 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/GuiClipboard.cpp
src/frontends/qt4/GuiClipboard.h
src/frontends/qt4/Makefile.am

index cd9914cde6aca29bf7610da60d7abafe6692c0e8..fa2cf260fdf9bc9812596236b05cb86942d7c1c7 100644 (file)
@@ -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"
index 12a8864a413d580f771ca534c286e1a1cdd1b96c..da98c2b163136c4fb112bc90a36774e3b9922510 100644 (file)
 
 #include "frontends/Clipboard.h"
 
+#include <QObject>
+
 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
index d1709a8e82d4eec45556e65bfea990d5e96f2899..26f410cacdd835e7f5765dda0bbc195bf7e34d57 100644 (file)
@@ -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 \