]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiWorkArea.cpp
The View->Source pane resets the format every time you click into
[lyx.git] / src / frontends / qt4 / GuiWorkArea.cpp
index 12b7bda1170a5e03bf53599948ea8b28f1764639..563d00b7388da3ab58d253fe1d6ca0fa9a973b12 100644 (file)
@@ -237,14 +237,14 @@ SyntheticMouseEvent::SyntheticMouseEvent()
 
 
 GuiWorkArea::Private::Private(GuiWorkArea * parent)
-: p(parent), buffer_view_(0), read_only_(false), lyx_view_(0), cursor_visible_(false),
+: p(parent), buffer_view_(0), lyx_view_(0), cursor_visible_(false),
 need_resize_(false), schedule_redraw_(false), preedit_lines_(1),
 completer_(new GuiCompleter(p, p))
 {
 }
 
 
-GuiWorkArea::GuiWorkArea(QWidget * w)
+GuiWorkArea::GuiWorkArea(QWidget * /* w */)
 : d(new Private(this)) 
 {
 }
@@ -253,7 +253,6 @@ GuiWorkArea::GuiWorkArea(QWidget * w)
 GuiWorkArea::GuiWorkArea(Buffer & buffer, GuiView & gv)
 : d(new Private(this))
 {
-       d->read_only_ = buffer.isReadonly();
        setGuiView(gv);
        setBuffer(buffer);
        init();
@@ -275,7 +274,7 @@ void GuiWorkArea::init()
                d->cursor_timeout_.setInterval(500);
        }
 
-       d->screen_ = QPixmap(viewport()->width(), viewport()->height());
+       d->resetScreen();
        // With Qt4.5 a mouse event will happen before the first paint event
        // so make sure that the buffer view has an up to date metrics.
        d->buffer_view_->resize(viewport()->width(), viewport()->height());
@@ -476,7 +475,7 @@ void GuiWorkArea::redraw(bool update_metrics)
        if (lyxerr.debugging(Debug::WORKAREA))
                d->buffer_view_->coordCache().dump();
 
-       d->setReadOnly(d->buffer_view_->buffer().isReadonly());
+       updateWindowTitle();
 
        d->updateCursorShape();
 }
@@ -532,6 +531,7 @@ void GuiWorkArea::Private::dispatch(FuncRequest const & cmd0, KeyModifier mod)
        buffer_view_->mouseEventDispatch(cmd);
 
        // Skip these when selecting
+       // FIXME: let GuiView take care of those.
        if (cmd.action() != LFUN_MOUSE_MOTION) {
                completer_->updateVisibility(false, false);
                lyx_view_->updateDialogs();
@@ -543,6 +543,7 @@ void GuiWorkArea::Private::dispatch(FuncRequest const & cmd0, KeyModifier mod)
                // Slight hack: this is only called currently when we
                // clicked somewhere, so we force through the display
                // of the new status here.
+               // FIXME: let GuiView take care of those.
                lyx_view_->clearMessage();
 
                // Show the cursor immediately after any operation
@@ -557,7 +558,10 @@ void GuiWorkArea::Private::resizeBufferView()
 {
        // WARNING: Please don't put any code that will trigger a repaint here!
        // We are already inside a paint event.
-       lyx_view_->setBusy(true);
+       p->stopBlinkingCursor();
+       // Warn our container (GuiView).
+       p->busy(true);
+
        Point point;
        int h = 0;
        buffer_view_->cursorPosAndHeight(point, h);
@@ -573,9 +577,13 @@ void GuiWorkArea::Private::resizeBufferView()
        // as the scrollbar paramters are then set for the first time.
        updateScrollbar();
 
-       lyx_view_->updateLayoutList();
-       lyx_view_->setBusy(false);
        need_resize_ = false;
+       p->busy(false);
+       // Eventually, restart the cursor after the resize event.
+       // We might be resizing even if the focus is on another widget so we only
+       // restart the cursor if we have the focus.
+       if (p->hasFocus())
+               QTimer::singleShot(50, p, SLOT(startBlinkingCursor()));
 }
 
 
@@ -656,6 +664,7 @@ void GuiWorkArea::scrollTo(int value)
 
        if (lyxrc.cursor_follows_scrollbar) {
                d->buffer_view_->setCursorFromScrollbar();
+               // FIXME: let GuiView take care of those.
                d->lyx_view_->updateLayoutList();
        }
        // Show the cursor immediately after any operation.
@@ -707,7 +716,7 @@ bool GuiWorkArea::event(QEvent * e)
 
 void GuiWorkArea::contextMenuEvent(QContextMenuEvent * e)
 {
-       docstring name;
+       string name;
        if (e->reason() == QContextMenuEvent::Mouse)
                // the menu name is set on mouse press
                name = d->context_menu_name_;
@@ -1102,7 +1111,7 @@ void GuiWorkArea::paintEvent(QPaintEvent * ev)
        //      << " y: " << rc.y() << " w: " << rc.width() << " h: " << rc.height());
 
        if (d->need_resize_) {
-               d->screen_ = QPixmap(viewport()->width(), viewport()->height());
+               d->resetScreen();
                d->resizeBufferView();
                if (d->cursor_visible_) {
                        d->hideCursor();
@@ -1111,7 +1120,11 @@ void GuiWorkArea::paintEvent(QPaintEvent * ev)
        }
 
        QPainter pain(viewport());
+#ifdef USE_QIMAGE
+       pain.drawImage(rc, d->screen_, rc);
+#else
        pain.drawPixmap(rc, d->screen_, rc);
+#endif
        d->cursor_->draw(pain);
        ev->accept();
 }
@@ -1349,17 +1362,6 @@ void GuiWorkArea::updateWindowTitle()
 }
 
 
-void GuiWorkArea::Private::setReadOnly(bool read_only)
-{
-       if (read_only_ == read_only)
-               return;
-       read_only_ = read_only;
-       p->updateWindowTitle();
-       if (p == lyx_view_->currentWorkArea())
-               lyx_view_->updateDialogs();
-}
-
-
 bool GuiWorkArea::isFullScreen() const
 {
        return d->lyx_view_ && d->lyx_view_->isFullScreen();