Abdelrazak Younes wrote:
> > Not if you do that _before_ showing the contents, will it?
Don't know. Couldn't figure that out.
> For that you need to catch the showEvent of the preamble module. Maybe
> using an even filter in QDocumentDialog... This eventFilter thing looks
> quite useful.
>
> Anyway, maybe the simplest solution for now is to do as you've done.
Maybe. FWIW, here's the solution where the map is put into the controller
(although I'm a bit reluctant at putting things in the controller where
there's obviously qt4 to blame).
Jürgen
Index: src/frontends/qt4/QDocument.cpp
===================================================================
--- src/frontends/qt4/QDocument.cpp (Revision 18151)
+++ src/frontends/qt4/QDocument.cpp (Arbeitskopie)
@@ -746,6 +746,10 @@
// preamble
params.preamble =
fromqstr(preambleModule->preambleTE->document()->toPlainText());
+ // store cursor and scrollbar position
+ form_->controller().savePreambleCoords(
+ preambleModule->preambleTE->textCursor().position(),
+ preambleModule->preambleTE->verticalScrollBar()->value());
// biblio
params.setCiteEngine(biblio::ENGINE_BASIC);
@@ -1023,6 +1027,13 @@
// preamble
QString preamble = toqstr(params.preamble);
preambleModule->preambleTE->document()->setPlainText(preamble);
+ // restore cursor and scrollbar position, if possible
+ QTextCursor cur = preambleModule->preambleTE->textCursor();
+ cur.setPosition(form_->controller().getPreambleCoords().first);
+ preambleModule->preambleTE->setTextCursor(cur);
+ preambleModule->preambleTE->verticalScrollBar()->setValue(
+ form_->controller().getPreambleCoords().second);
+ preambleModule->preambleTE->setFocus();
// biblio
biblioModule->citeDefaultRB->setChecked(
Index: src/frontends/qt4/QDocument.h
===================================================================
--- src/frontends/qt4/QDocument.h (Revision 18151)
+++ src/frontends/qt4/QDocument.h (Arbeitskopie)
@@ -29,6 +29,7 @@
#include <QCloseEvent>
#include <QDialog>
+#include <QScrollBar>
#include <vector>
#include <string>
Index: src/frontends/controllers/ControlDocument.cpp
===================================================================
--- src/frontends/controllers/ControlDocument.cpp (Revision 18151)
+++ src/frontends/controllers/ControlDocument.cpp (Arbeitskopie)
@@ -230,5 +230,22 @@
}
+void ControlDocument::savePreambleCoords(int x, int y)
+{
+ preamble_coords_[&kernel().buffer()].first = x;
+ preamble_coords_[&kernel().buffer()].second = y;
+}
+
+
+std::pair<int, int> ControlDocument::getPreambleCoords()
+{
+ Buffer const & buffer = kernel().buffer();
+ if (preamble_coords_.find(&buffer) != preamble_coords_.end())
+ return preamble_coords_[&buffer];
+ else
+ return std::pair<int, int>(0, 0);
+}
+
+
} // namespace frontend
} // namespace lyx
Index: src/frontends/controllers/ControlDocument.h
===================================================================
--- src/frontends/controllers/ControlDocument.h (Revision 18151)
+++ src/frontends/controllers/ControlDocument.h (Arbeitskopie)
@@ -15,6 +15,7 @@
#include "Dialog.h"
#include "support/types.h"
#include <boost/scoped_ptr.hpp>
+#include <map>
namespace lyx {
@@ -63,9 +64,17 @@
bool const providesSC(std::string const & font) const;
/// does this font provide size adjustment?
bool const providesScale(std::string const & font) const;
+ ///
+ void savePreambleCoords(int y, int y);
+ ///
+ std::pair<int, int> getPreambleCoords();
private:
///
boost::scoped_ptr<BufferParams> bp_;
+ ///
+ typedef std::pair<int, int> CoordPair;
+ ///
+ std::map<Buffer const *, CoordPair> preamble_coords_;
};
} // namespace frontend