]> git.lyx.org Git - lyx.git/commitdiff
switch mouse to busy symbol every 3 seconds and then back to show the
authorPeter Kümmel <syntheticpp@gmx.net>
Sat, 23 Oct 2010 10:49:45 +0000 (10:49 +0000)
committerPeter Kümmel <syntheticpp@gmx.net>
Sat, 23 Oct 2010 10:49:45 +0000 (10:49 +0000)
user something is done in the background

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35795 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/GuiClipboard.cpp
src/frontends/qt4/GuiView.cpp
src/frontends/qt4/GuiView.h
src/frontends/qt4/GuiWorkArea.cpp
src/frontends/qt4/GuiWorkArea.h
src/support/bind.h

index 76fcd2d8841d5e466731e1b4b1ecd1db98fa5902..297b828948e45612d0a50456fcfe8ddfe70f4526 100644 (file)
@@ -47,6 +47,7 @@
 
 #include <memory>
 #include <map>
+#include <iostream>
 
 using namespace std;
 using namespace lyx::support;
index efcbdd86b03bf9806c37d51f07f3bab4da9bb925..99962e2a3685ba1e36d448352b2991ecfa287d73 100644 (file)
@@ -26,6 +26,7 @@
 #include "GuiToc.h"
 #include "GuiToolbar.h"
 #include "GuiWorkArea.h"
+#include "GuiProgress.h"
 #include "LayoutBox.h"
 #include "Menus.h"
 #include "TocModel.h"
@@ -79,7 +80,6 @@
 #include "support/Systemcall.h"
 #include "support/Timeout.h"
 #include "support/ProgressInterface.h"
-#include "GuiProgress.h"
 
 #include <QAction>
 #include <QApplication>
@@ -283,6 +283,11 @@ struct GuiView::GuiViewPrivate
                bg_widget_->setFocus();
        }
 
+       int tabWorkAreaCount()
+       {
+               return splitter_->count();
+       }
+       
        TabWorkArea * tabWorkArea(int i)
        {
                return dynamic_cast<TabWorkArea *>(splitter_->widget(i));
@@ -290,11 +295,12 @@ struct GuiView::GuiViewPrivate
 
        TabWorkArea * currentTabWorkArea()
        {
-               if (splitter_->count() == 1)
+               int areas = tabWorkAreaCount();
+               if (areas == 1)
                        // The first TabWorkArea is always the first one, if any.
                        return tabWorkArea(0);
 
-               for (int i = 0; i != splitter_->count(); ++i) {
+               for (int i = 0; i != areas;  ++i) {
                        TabWorkArea * twa = tabWorkArea(i);
                        if (current_main_work_area_ == twa->currentWorkArea())
                                return twa;
@@ -307,12 +313,12 @@ struct GuiView::GuiViewPrivate
 #if (QT_VERSION >= 0x040400)
        void setPreviewFuture(QFuture<docstring> const & f)
        {
-               if (preview_watcher_.isRunning()) {
+               if (processing_thread_watcher_.isRunning()) {
                        // we prefer to cancel this preview in order to keep a snappy
                        // interface.
                        return;
                }
-               preview_watcher_.setFuture(f);
+               processing_thread_watcher_.setFuture(f);
        }
 #endif
 
@@ -356,12 +362,12 @@ public:
 #if (QT_VERSION >= 0x040400)
        ///
        QFutureWatcher<docstring> autosave_watcher_;
-       QFutureWatcher<docstring> preview_watcher_;
+       QFutureWatcher<docstring> processing_thread_watcher_;
        ///
        string last_export_format;
 #else
        struct DummyWatcher { bool isRunning(){return false;} };
-       DummyWatcher preview_watcher_;
+       DummyWatcher processing_thread_watcher_;
 #endif
 
        static QSet<Buffer const *> busyBuffers;
@@ -381,7 +387,10 @@ public:
                                   bool (Buffer::*syncFunc)(string const &, bool, bool) const,
                                   bool (Buffer::*previewFunc)(string const &, bool) const);
 
-       
+       QTimer processing_cursor_timer_;
+       bool indicates_processing_;
+       QMap<GuiWorkArea*, Qt::CursorShape> orig_cursors_;
+       QVector<GuiWorkArea*> guiWorkAreas();
 };
 
 QSet<Buffer const *> GuiView::GuiViewPrivate::busyBuffers;
@@ -436,9 +445,13 @@ GuiView::GuiView(int id)
 
 #if (QT_VERSION >= 0x040400)
        connect(&d.autosave_watcher_, SIGNAL(finished()), this,
-               SLOT(threadFinished()));
-       connect(&d.preview_watcher_, SIGNAL(finished()), this,
-               SLOT(threadFinished()));
+               SLOT(processingThreadFinished()));
+       connect(&d.processing_thread_watcher_, SIGNAL(finished()), this,
+               SLOT(processingThreadFinished()));
+
+       d.processing_cursor_timer_.setInterval(1000 * 3);
+       connect(&d.processing_cursor_timer_, SIGNAL(timeout()), this,
+               SLOT(indicateProcessing()));
 #endif
 
        connect(this, SIGNAL(triggerShowDialog(QString const &, QString const &, Inset *)),
@@ -470,7 +483,64 @@ GuiView::~GuiView()
 }
 
 
-void GuiView::threadFinished()
+QVector<GuiWorkArea*> GuiView::GuiViewPrivate::guiWorkAreas()
+{
+       QVector<GuiWorkArea*> areas;
+       for (int i = 0; i < tabWorkAreaCount(); i++) {
+               TabWorkArea* ta = tabWorkArea(i);
+               for (int u = 0; u < ta->count(); u++) {
+                       areas << ta->workArea(u);
+               }
+       }
+       return areas;
+}
+
+void GuiView::setCursorShapes(Qt::CursorShape shape)
+{
+       QVector<GuiWorkArea*> areas = d.guiWorkAreas();
+       Q_FOREACH(GuiWorkArea* wa, areas) {
+               wa->setCursorShape(shape);
+       }
+}
+
+void GuiView::restoreCursorShapes()
+{
+       QVector<GuiWorkArea*> areas = d.guiWorkAreas();
+       Q_FOREACH(GuiWorkArea* wa, areas) {
+               if (d.orig_cursors_.contains(wa)) {
+                       wa->setCursorShape(d.orig_cursors_[wa]);
+               }
+       }
+}
+
+void GuiView::saveCursorShapes()
+{
+       d.orig_cursors_.clear();
+       QVector<GuiWorkArea*> areas = d.guiWorkAreas();
+       Q_FOREACH(GuiWorkArea* wa, areas) {
+               d.orig_cursors_[wa] = wa->cursorShape();
+       }
+}
+
+void GuiView::indicateProcessing()
+{
+       if (d.indicates_processing_) {
+               restoreCursorShapes();
+       } else {
+               setCursorShapes(Qt::BusyCursor);
+       }
+       d.indicates_processing_ = !d.indicates_processing_;
+}
+
+void GuiView::processingThreadStarted()
+{
+       saveCursorShapes();
+       d.indicates_processing_ = false;
+       indicateProcessing();
+       d.processing_cursor_timer_.start();
+}
+
+void GuiView::processingThreadFinished()
 {
 #if (QT_VERSION >= 0x040400)
        QFutureWatcher<docstring> const * watcher =
@@ -478,6 +548,9 @@ void GuiView::threadFinished()
        message(watcher->result());
        updateToolbars();
        errors(d.last_export_format);
+       d.processing_cursor_timer_.stop();
+       restoreCursorShapes();
+       d.indicates_processing_ = false;
 #endif
 }
 
@@ -1444,12 +1517,12 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
        case LFUN_MASTER_BUFFER_UPDATE:
        case LFUN_MASTER_BUFFER_VIEW:
                enable = doc_buffer && doc_buffer->parent() != 0
-                       && !d.preview_watcher_.isRunning();
+                       && !d.processing_thread_watcher_.isRunning();
                break;
 
        case LFUN_BUFFER_UPDATE:
        case LFUN_BUFFER_VIEW: {
-               if (!doc_buffer || d.preview_watcher_.isRunning()) {
+               if (!doc_buffer || d.processing_thread_watcher_.isRunning()) {
                        enable = false;
                        break;
                }
@@ -2865,6 +2938,7 @@ bool GuiView::GuiViewPrivate::asyncBufferProcessing(
        if (!used_buffer) {
                return false;
        }
+       gv_->processingThreadStarted();
        string format = argument;
        if (format.empty()) {
                format = used_buffer->getDefaultOutputFormat();
index deb1e24a72ae4335b5bd85e9b6a0cd20ce59ecf7..80bfc6d05780b01b69b90fd6be2f229c3fac65b8 100644 (file)
@@ -82,6 +82,10 @@ public:
        /// are we busy ?
        bool busy() const;
 
+       void saveCursorShapes();
+       void restoreCursorShapes();
+       void setCursorShapes(Qt::CursorShape shape);
+
        /// \name Generic accessor functions
        //@{
        /// The current BufferView refers to the BufferView that has the focus,
@@ -224,8 +228,10 @@ private Q_SLOTS:
        void normalSizedIcons();
        void bigSizedIcons();
 
-       /// For completion of autosave or exporrt threads.
-       void threadFinished();
+       /// For completion of autosave or export threads.
+       void processingThreadStarted();
+       void processingThreadFinished();
+       void indicateProcessing();
 
        /// must be called in GUI thread
        void doShowDialog(QString const & qname, QString const & qdata,
@@ -411,6 +417,7 @@ private:
        bool closing_;
        /// if the view is busy the cursor shouldn't blink for instance.
        bool busy_;
+
 };
 
 } // namespace frontend
index cc1c8091dcb93394fb1fb170c2248df494cb791d..0c1eeed670db8e63f50cd20fdabc0100da47ca3d 100644 (file)
@@ -288,7 +288,7 @@ void GuiWorkArea::init()
 
        setFocusPolicy(Qt::StrongFocus);
 
-       viewport()->setCursor(Qt::IBeamCursor);
+       setCursorShape(Qt::IBeamCursor);
 
        synthetic_mouse_event_.timeout.timeout.connect(
                bind(&GuiWorkArea::generateSyntheticMouseEvent,
@@ -320,6 +320,16 @@ GuiWorkArea::~GuiWorkArea()
 }
 
 
+Qt::CursorShape GuiWorkArea::cursorShape() const
+{
+       return viewport()->cursor().shape();
+}
+
+void GuiWorkArea::setCursorShape(Qt::CursorShape shape)
+{
+       viewport()->setCursor(shape);
+}
+
 void GuiWorkArea::setGuiView(GuiView & gv)
 {
        lyx_view_ = &gv;
@@ -1465,7 +1475,7 @@ void TabWorkArea::mouseDoubleClickEvent(QMouseEvent * event)
 void TabWorkArea::setFullScreen(bool full_screen)
 {
        for (int i = 0; i != count(); ++i) {
-               if (GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(widget(i)))
+               if (GuiWorkArea * wa = workArea(i))
                        wa->setFullScreen(full_screen);
        }
 
@@ -1496,12 +1506,18 @@ GuiWorkArea * TabWorkArea::currentWorkArea()
 }
 
 
+GuiWorkArea * TabWorkArea::workArea(int index)
+{
+       return dynamic_cast<GuiWorkArea *>(widget(index));
+}
+
+
 GuiWorkArea * TabWorkArea::workArea(Buffer & buffer)
 {
        // FIXME: this method doesn't work if we have more than work area
        // showing the same buffer.
        for (int i = 0; i != count(); ++i) {
-               GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(widget(i));
+               GuiWorkArea * wa = workArea(i);
                LASSERT(wa, return 0);
                if (&wa->bufferView().buffer() == &buffer)
                        return wa;
@@ -1513,7 +1529,7 @@ GuiWorkArea * TabWorkArea::workArea(Buffer & buffer)
 void TabWorkArea::closeAll()
 {
        while (count()) {
-               GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(widget(0));
+               GuiWorkArea * wa = workArea(0);
                LASSERT(wa, /**/);
                removeTab(0);
                delete wa;
@@ -1596,7 +1612,7 @@ void TabWorkArea::on_currentTabChanged(int i)
        // returns e.g. on application destruction
        if (i == -1)
                return;
-       GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(widget(i));
+       GuiWorkArea * wa = workArea(i);
        LASSERT(wa, return);
        wa->setUpdatesEnabled(true);
        wa->redraw(true);
@@ -1615,7 +1631,7 @@ void TabWorkArea::closeCurrentBuffer()
        if (clicked_tab_ == -1)
                wa = currentWorkArea();
        else {
-               wa = dynamic_cast<GuiWorkArea *>(widget(clicked_tab_));
+               wa = workArea(clicked_tab_);
                LASSERT(wa, /**/);
        }
        wa->view().closeWorkArea(wa);
@@ -1628,7 +1644,7 @@ void TabWorkArea::hideCurrentTab()
        if (clicked_tab_ == -1)
                wa = currentWorkArea();
        else {
-               wa = dynamic_cast<GuiWorkArea *>(widget(clicked_tab_));
+               wa = workArea(clicked_tab_);
                LASSERT(wa, /**/);
        }
        wa->view().hideWorkArea(wa);
@@ -1642,7 +1658,7 @@ void TabWorkArea::closeTab(int index)
        if (index == -1)
                wa = currentWorkArea();
        else {
-               wa = dynamic_cast<GuiWorkArea *>(widget(index));
+               wa = workArea(index);
                LASSERT(wa, /**/);
        }
        wa->view().closeWorkArea(wa);
@@ -1753,7 +1769,7 @@ void TabWorkArea::updateTabTexts()
        // collect full names first: path into postfix, empty prefix and
        // filename without extension
        for (size_t i = 0; i < n; ++i) {
-               GuiWorkArea * i_wa = dynamic_cast<GuiWorkArea *>(widget(i));
+               GuiWorkArea * i_wa = workArea(i);
                FileName const fn = i_wa->bufferView().buffer().fileName();
                paths.push_back(DisplayPath(i, fn));
        }
@@ -1837,7 +1853,7 @@ void TabWorkArea::updateTabTexts()
 
        // set new tab titles
        for (It it = paths.begin(); it != paths.end(); ++it) {
-               GuiWorkArea * i_wa = dynamic_cast<GuiWorkArea *>(widget(it->tab()));
+               GuiWorkArea * i_wa = workArea(it->tab());
                Buffer & buf = i_wa->bufferView().buffer();
                if (!buf.fileName().empty() && !buf.isClean())
                        setTabText(it->tab(), it->displayString() + "*");
index 0858521a9a5bf0f98d36553dc9e39b51fa76a156..a0fcf737860106bf8d3930b241a8605462968df1 100644 (file)
@@ -139,6 +139,9 @@ public:
        ///
        GuiCompleter & completer() { return *completer_; }
 
+       Qt::CursorShape cursorShape() const;
+       void setCursorShape(Qt::CursorShape shape);
+
 
        /// Return the GuiView this workArea belongs to
        GuiView const & view() const { return *lyx_view_; }
@@ -309,6 +312,7 @@ public:
        bool removeWorkArea(GuiWorkArea *);
        GuiWorkArea * currentWorkArea();
        GuiWorkArea * workArea(Buffer & buffer);
+       GuiWorkArea * workArea(int index);
 
 Q_SIGNALS:
        ///
index 4d2968048d087760de846fd03c6bfbc62da35dfe..efd3267de5ceb17667e94ed351b114d447ebf368 100644 (file)
 #ifndef LYX_BIND_H
 #define LYX_BIND_H
 
-#ifdef LYX_USE_TR1
-
-#include <functional>
+#include "support/functional.h"
 
-#ifdef __GNUC__
-#include <tr1/functional>
-#endif
+#ifdef LYX_USE_TR1
 
 namespace lyx
 {