]> git.lyx.org Git - features.git/commitdiff
Potentially fix slowness issue with Selection. Cache the Selection status when the...
authorAbdelrazak Younes <younes@lyx.org>
Mon, 1 Oct 2007 08:18:14 +0000 (08:18 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Mon, 1 Oct 2007 08:18:14 +0000 (08:18 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20622 a592a061-630c-0410-9148-cb99ea01b6c8

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

index f4d9051148df200950267c73ffed8f25298a3d6a..29cb8951e7acbc5e22a81ba48e9b2217f6af76f9 100644 (file)
@@ -30,6 +30,16 @@ using std::endl;
 namespace lyx {
 namespace frontend {
 
+GuiSelection::GuiSelection()
+       : selection_supported_(qApp->clipboard()->supportsSelection())
+{
+       connect(qApp->clipboard(), SIGNAL(dataChanged()),
+               this, SLOT(on_dataChanged()));
+       // initialize clipboard status.
+       on_dataChanged();
+}
+
+
 void GuiSelection::haveSelection(bool own)
 {
        if (!qApp->clipboard()->supportsSelection())
@@ -78,13 +88,22 @@ void GuiSelection::put(docstring const & str)
 }
 
 
+void GuiSelection::on_dataChanged()
+{
+       text_selection_empty_ = qApp->clipboard()->
+               text(QClipboard::Selection).isEmpty();
+}
+
+
 bool GuiSelection::empty() const
 {
-       if (!qApp->clipboard()->supportsSelection())
+       if (!selection_supported_)
                return true;
 
-       return qApp->clipboard()->text(QClipboard::Selection).isEmpty();
+       return text_selection_empty_;
 }
 
 } // namespace frontend
 } // namespace lyx
+
+#include "GuiSelection_moc.cpp"
index d1fa749a8d9d529b40a0b3c4814a19d2f2920a9a..7e77da715a85a9bc728b08fb22e1de2c760e184a 100644 (file)
 
 #include "frontends/Selection.h"
 
+#include <QObject>
+
 namespace lyx {
 namespace frontend {
 
 /**
  * The Qt4 version of the Selection.
  */
-class GuiSelection : public Selection
+class GuiSelection : public QObject, public Selection
 {
+       Q_OBJECT
 public:
+       GuiSelection();
        virtual ~GuiSelection() {}
 
        /** Selection overloaded methods
@@ -35,6 +39,13 @@ public:
        void put(docstring const & str);
        bool empty() const;
        //@}
+
+private Q_SLOTS:
+       void on_dataChanged();
+
+private:
+       bool text_selection_empty_;
+       bool const selection_supported_;
 };
 
 } // namespace frontend
index 26f410cacdd835e7f5765dda0bbc195bf7e34d57..4f9ebf6b1d7ec92a046f0ef7da1e75a40ec09c3e 100644 (file)
@@ -119,7 +119,6 @@ NOMOCHEADER = \
        ButtonController.h \
        GuiFontLoader.h \
        GuiFontMetrics.h \
-       GuiSelection.h \
        GuiImage.h \
        GuiPainter.h \
        qt_helpers.h
@@ -171,6 +170,7 @@ MOCHEADER = \
        GuiPrint.h \
        GuiRef.h \
        GuiSearch.h \
+       GuiSelection.h \
        GuiSelectionManager.h \
        GuiSendto.h \
        GuiSetBorder.h \