]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiView.cpp
Some improvements to the graphics dialog
[lyx.git] / src / frontends / qt4 / GuiView.cpp
index 1c2c09c4c5cd48299a373be66fe34409cf2b4251..56a2e73d53220895d5f3b927d54e769abd24f263 100644 (file)
@@ -741,7 +741,7 @@ void GuiView::autoSaveThreadFinished()
 void GuiView::saveLayout() const
 {
        QSettings settings;
-       settings.setValue("zoom", lyxrc.currentZoom);
+       settings.setValue("zoom_ratio", zoom_ratio_);
        settings.setValue("devel_mode", devel_mode_);
        settings.beginGroup("views");
        settings.beginGroup(QString::number(id_));
@@ -758,22 +758,28 @@ void GuiView::saveLayout() const
 
 void GuiView::saveUISettings() const
 {
+       QSettings settings;
+
        // Save the toolbar private states
        ToolbarMap::iterator end = d.toolbars_.end();
        for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
-               it->second->saveSession();
+               it->second->saveSession(settings);
        // Now take care of all other dialogs
        map<string, DialogPtr>::const_iterator it = d.dialogs_.begin();
        for (; it!= d.dialogs_.end(); ++it)
-               it->second->saveSession();
+               it->second->saveSession(settings);
 }
 
 
 bool GuiView::restoreLayout()
 {
        QSettings settings;
-       lyxrc.currentZoom = settings.value("zoom", lyxrc.zoom).toInt();
-       lyx::dispatch(FuncRequest(LFUN_BUFFER_ZOOM, convert<docstring>(lyxrc.currentZoom)));
+       zoom_ratio_ = settings.value("zoom_ratio", 1.0).toDouble();
+       // Actual zoom value: default zoom + fractional offset
+       int zoom = lyxrc.defaultZoom * zoom_ratio_;
+       if (zoom < static_cast<int>(zoom_min_))
+               zoom = zoom_min_;
+       lyxrc.currentZoom = zoom;
        devel_mode_ = settings.value("devel_mode", devel_mode_).toBool();
        settings.beginGroup("views");
        settings.beginGroup(QString::number(id_));
@@ -1873,7 +1879,8 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
 
        case LFUN_BUFFER_RELOAD:
                enable = doc_buffer && !doc_buffer->isUnnamed()
-                       && doc_buffer->fileName().exists() && !doc_buffer->isClean();
+                       && doc_buffer->fileName().exists()
+                       && (!doc_buffer->isClean() || doc_buffer->notifiesExternalModification());
                break;
 
        case LFUN_BUFFER_CHILD_OPEN:
@@ -2222,8 +2229,10 @@ Buffer * GuiView::loadDocument(FileName const & filename, bool tolastfiles)
        setBuffer(newBuffer);
        newBuffer->errors("Parse");
 
-       if (tolastfiles)
+       if (tolastfiles) {
                theSession().lastFiles().add(filename);
+               theSession().writeFile();
+  }
 
        return newBuffer;
 }
@@ -2762,6 +2771,7 @@ bool GuiView::saveBuffer(Buffer & b, FileName const & fn)
        bool const success = (fn.empty() ? b.save() : b.saveAs(fn));
        if (success) {
                theSession().lastFiles().add(b.fileName());
+               theSession().writeFile();
                return true;
        }
 
@@ -3169,6 +3179,7 @@ static bool ensureBufferClean(Buffer * buffer)
 
 bool GuiView::reloadBuffer(Buffer & buf)
 {
+       currentBufferView()->cursor().reset();
        Buffer::ReadStatus status = buf.reload();
        return status == Buffer::ReadSuccess;
 }
@@ -4115,36 +4126,37 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                case LFUN_BUFFER_ZOOM_IN:
                case LFUN_BUFFER_ZOOM_OUT:
                case LFUN_BUFFER_ZOOM: {
-                       // use a signed temp to avoid overflow
-                       int zoom = lyxrc.currentZoom;
                        if (cmd.argument().empty()) {
                                if (cmd.action() == LFUN_BUFFER_ZOOM)
-                                       zoom = lyxrc.zoom;
+                                       zoom_ratio_ = 1.0;
                                else if (cmd.action() == LFUN_BUFFER_ZOOM_IN)
-                                       zoom += 20;
+                                       zoom_ratio_ += 0.1;
                                else
-                                       zoom -= 20;
+                                       zoom_ratio_ -= 0.1;
                        } else {
                                if (cmd.action() == LFUN_BUFFER_ZOOM)
-                                       zoom = convert<int>(cmd.argument());
+                                       zoom_ratio_ = convert<int>(cmd.argument()) / double(lyxrc.defaultZoom);
                                else if (cmd.action() == LFUN_BUFFER_ZOOM_IN)
-                                       zoom += convert<int>(cmd.argument());
+                                       zoom_ratio_ += convert<int>(cmd.argument()) / 100.0;
                                else
-                                       zoom -= convert<int>(cmd.argument());
+                                       zoom_ratio_ -= convert<int>(cmd.argument()) / 100.0;
                        }
 
+                       // Actual zoom value: default zoom + fractional extra value
+                       int zoom = lyxrc.defaultZoom * zoom_ratio_;
                        if (zoom < static_cast<int>(zoom_min_))
                                zoom = zoom_min_;
 
                        lyxrc.currentZoom = zoom;
 
-                       dr.setMessage(bformat(_("Zoom level is now %1$d%"), lyxrc.currentZoom));
+                       dr.setMessage(bformat(_("Zoom level is now %1$d% (default value: %2$d%)"),
+                                             lyxrc.currentZoom, lyxrc.defaultZoom));
 
                        // The global QPixmapCache is used in GuiPainter to cache text
                        // painting so we must reset it.
                        QPixmapCache::clear();
                        guiApp->fontLoader().update();
-                       lyx::dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
+                       dr.screenUpdate(Update::Force | Update::FitCursor);
                        break;
                }
 
@@ -4340,19 +4352,19 @@ Buffer const * GuiView::updateInset(Inset const * inset)
                        continue;
                Buffer const * buffer = &(wa->bufferView().buffer());
                if (inset_buffer == buffer)
-                       wa->scheduleRedraw();
+                       wa->scheduleRedraw(true);
        }
        return inset_buffer;
 }
 
 
-void GuiView::restartCursor()
+void GuiView::restartCaret()
 {
        /* When we move around, or type, it's nice to be able to see
-        * the cursor immediately after the keypress.
+        * the caret immediately after the keypress.
         */
        if (d.current_work_area_)
-               d.current_work_area_->startBlinkingCursor();
+               d.current_work_area_->startBlinkingCaret();
 
        // Take this occasion to update the other GUI elements.
        updateDialogs();
@@ -4421,7 +4433,7 @@ void GuiView::resetDialogs()
        // Now update controls with current buffer.
        guiApp->setCurrentView(this);
        restoreLayout();
-       restartCursor();
+       restartCaret();
 }