#include "GuiToc.h"
#include "GuiToolbar.h"
#include "GuiWorkArea.h"
+#include "GuiProgress.h"
#include "LayoutBox.h"
#include "Menus.h"
#include "TocModel.h"
#include "support/Systemcall.h"
#include "support/Timeout.h"
#include "support/ProgressInterface.h"
-#include "GuiProgress.h"
#include <QAction>
#include <QApplication>
bg_widget_->setFocus();
}
+ int tabWorkAreaCount()
+ {
+ return splitter_->count();
+ }
+
TabWorkArea * tabWorkArea(int i)
{
return dynamic_cast<TabWorkArea *>(splitter_->widget(i));
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;
#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
#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;
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;
#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 *)),
}
-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 =
message(watcher->result());
updateToolbars();
errors(d.last_export_format);
+ d.processing_cursor_timer_.stop();
+ restoreCursorShapes();
+ d.indicates_processing_ = false;
#endif
}
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;
}
if (!used_buffer) {
return false;
}
+ gv_->processingThreadStarted();
string format = argument;
if (format.empty()) {
format = used_buffer->getDefaultOutputFormat();
setFocusPolicy(Qt::StrongFocus);
- viewport()->setCursor(Qt::IBeamCursor);
+ setCursorShape(Qt::IBeamCursor);
synthetic_mouse_event_.timeout.timeout.connect(
bind(&GuiWorkArea::generateSyntheticMouseEvent,
}
+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;
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);
}
}
+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;
void TabWorkArea::closeAll()
{
while (count()) {
- GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(widget(0));
+ GuiWorkArea * wa = workArea(0);
LASSERT(wa, /**/);
removeTab(0);
delete wa;
// 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);
if (clicked_tab_ == -1)
wa = currentWorkArea();
else {
- wa = dynamic_cast<GuiWorkArea *>(widget(clicked_tab_));
+ wa = workArea(clicked_tab_);
LASSERT(wa, /**/);
}
wa->view().closeWorkArea(wa);
if (clicked_tab_ == -1)
wa = currentWorkArea();
else {
- wa = dynamic_cast<GuiWorkArea *>(widget(clicked_tab_));
+ wa = workArea(clicked_tab_);
LASSERT(wa, /**/);
}
wa->view().hideWorkArea(wa);
if (index == -1)
wa = currentWorkArea();
else {
- wa = dynamic_cast<GuiWorkArea *>(widget(index));
+ wa = workArea(index);
LASSERT(wa, /**/);
}
wa->view().closeWorkArea(wa);
// 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));
}
// 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() + "*");