From e5eabfe0676eb728d160d3e65d3ba794df24400d Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Wed, 14 Nov 2007 13:56:13 +0000 Subject: [PATCH] Transfer geometry related session code from LyX::newLyXView() to GuiView::setGeometry(). git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21606 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/LyX.cpp | 53 +--------------------- src/frontends/Application.h | 4 +- src/frontends/qt4/GuiApplication.cpp | 11 +---- src/frontends/qt4/GuiApplication.h | 5 +- src/frontends/qt4/GuiView.cpp | 68 +++++++++++++++++++++++++--- src/frontends/qt4/GuiView.h | 8 +--- 6 files changed, 68 insertions(+), 81 deletions(-) diff --git a/src/LyX.cpp b/src/LyX.cpp index 47c048cbf8..786b2cae1c 100644 --- a/src/LyX.cpp +++ b/src/LyX.cpp @@ -56,7 +56,6 @@ #include "support/filetools.h" #include "support/lstrings.h" #include "support/lyxlib.h" -#include "support/convert.h" #include "support/ExceptionMessage.h" #include "support/os.h" #include "support/Package.h" @@ -712,58 +711,8 @@ LyXView * LyX::newLyXView() if (!lyx::use_gui) return 0; - // FIXME: transfer all this geometry stuff to the frontend. - - // determine windows size and position, from lyxrc and/or session - // initial geometry - unsigned int width = 690; - unsigned int height = 510; - // default icon size, will be overwritten by stored session value - unsigned int iconSizeXY = 0; - // FIXME: 0 means GuiView::NotMaximized by default! - int maximized = 0; - // first try lyxrc - if (lyxrc.geometry_width != 0 && lyxrc.geometry_height != 0 ) { - width = lyxrc.geometry_width; - height = lyxrc.geometry_height; - } - // if lyxrc returns (0,0), then use session info - else { - string val = session().sessionInfo().load("WindowWidth"); - if (!val.empty()) - width = convert(val); - val = session().sessionInfo().load("WindowHeight"); - if (!val.empty()) - height = convert(val); - val = session().sessionInfo().load("WindowMaximized"); - if (!val.empty()) - maximized = convert(val); - val = session().sessionInfo().load("IconSizeXY"); - if (!val.empty()) - iconSizeXY = convert(val); - } - - // if user wants to restore window position - int posx = -1; - int posy = -1; - if (lyxrc.geometry_xysaved) { - string val = session().sessionInfo().load("WindowPosX"); - if (!val.empty()) - posx = convert(val); - val = session().sessionInfo().load("WindowPosY"); - if (!val.empty()) - posy = convert(val); - } - - if (!geometryArg.empty()) - { - width = 0; - height = 0; - } - // create the main window - LyXView * view = &pimpl_->application_->createView(width, height, - posx, posy, maximized, iconSizeXY, geometryArg); + LyXView * view = &pimpl_->application_->createView(geometryArg); return view; } diff --git a/src/frontends/Application.h b/src/frontends/Application.h index f341358ddb..87293abbfb 100644 --- a/src/frontends/Application.h +++ b/src/frontends/Application.h @@ -214,9 +214,7 @@ public: virtual void unregisterSocketCallback(int fd) = 0; /// Create the main window with given geometry settings. - virtual LyXView & createView(unsigned int width, unsigned int height, - int posx, int posy, int maximized, - unsigned int iconSizeXY, const std::string & geometryArg) = 0; + virtual LyXView & createView(std::string const & geometryArg) = 0; /// LyXView const * currentView() const { return current_view_; } diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp index a61b2a8080..de70c6a457 100644 --- a/src/frontends/qt4/GuiApplication.cpp +++ b/src/frontends/qt4/GuiApplication.cpp @@ -194,21 +194,14 @@ GuiApplication::~GuiApplication() } -LyXView & GuiApplication::createView(unsigned int width, - unsigned int height, - int posx, int posy, - int maximized, - unsigned int iconSizeXY, - const std::string & geometryArg) +LyXView & GuiApplication::createView(string const & geometryArg) { int const id = gui_.createRegisteredView(); GuiView & view = static_cast(gui_.view(id)); theLyXFunc().setLyXView(&view); view.init(); - view.setGeometry(width, height, posx, posy, GuiView::Maximized(maximized), - iconSizeXY, geometryArg); - + view.setGeometry(geometryArg); view.setFocus(); setCurrentView(view); diff --git a/src/frontends/qt4/GuiApplication.h b/src/frontends/qt4/GuiApplication.h index 8768d4b7be..6d8f8cb502 100644 --- a/src/frontends/qt4/GuiApplication.h +++ b/src/frontends/qt4/GuiApplication.h @@ -70,10 +70,7 @@ public: virtual void updateColor(ColorCode col); virtual void registerSocketCallback(int fd, SocketCallback func); void unregisterSocketCallback(int fd); - /// Create the main window with given geometry settings. - LyXView & createView(unsigned int width, unsigned int height, - int posx, int posy, int maximized, - unsigned int iconSizeXY, const std::string & geometryArg); + LyXView & createView(std::string const & geometryArg); //@} /// Methods inherited from \c QApplication class diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 35fe6b49c8..906ca11d8a 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -494,13 +494,69 @@ void GuiView::saveGeometry() } -void GuiView::setGeometry(unsigned int width, - unsigned int height, - int posx, int posy, - GuiView::Maximized maximized, - unsigned int iconSizeXY, - const string & geometryArg) +void GuiView::setGeometry(string const & geometryArg) { + // ******************************************* + // Beginning of the session handling stuff + + //FIXME: Instead of the stuff below, we should use QSettings: + /* + QSettings settings; + QString key = "view " + QString::number(id) + "/geometry"; + view.restoreGeometry(settings.value(key).toByteArray()); + */ + + // determine windows size and position, from lyxrc and/or session + // initial geometry + unsigned int width = 690; + unsigned int height = 510; + // default icon size, will be overwritten by stored session value + unsigned int iconSizeXY = 0; + Maximized maximized = NotMaximized; + SessionInfoSection & session = LyX::ref().session().sessionInfo(); + + // first try lyxrc + if (lyxrc.geometry_width != 0 && lyxrc.geometry_height != 0 ) { + width = lyxrc.geometry_width; + height = lyxrc.geometry_height; + } + // if lyxrc returns (0,0), then use session info + else { + string val = session.load("WindowWidth"); + if (!val.empty()) + width = convert(val); + val = session.load("WindowHeight"); + if (!val.empty()) + height = convert(val); + val = session.load("WindowMaximized"); + if (!val.empty()) + maximized = GuiView::Maximized(convert(val)); + val = session.load("IconSizeXY"); + if (!val.empty()) + iconSizeXY = convert(val); + } + + // if user wants to restore window position + int posx = -1; + int posy = -1; + if (lyxrc.geometry_xysaved) { + string val = session.load("WindowPosX"); + if (!val.empty()) + posx = convert(val); + val = session.load("WindowPosY"); + if (!val.empty()) + posy = convert(val); + } + + if (!geometryArg.empty()) + { + width = 0; + height = 0; + } + + // End of the sesssion handling stuff + // ******************************************* + // use last value (not at startup) if (d.lastIconSize != 0) setIconSize(d.lastIconSize); diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h index d3868a74a2..32c1f6064e 100644 --- a/src/frontends/qt4/GuiView.h +++ b/src/frontends/qt4/GuiView.h @@ -67,13 +67,7 @@ public: CompletelyMaximized }; /// - virtual void setGeometry( - unsigned int width, - unsigned int height, - int posx, int posy, - Maximized maximized, - unsigned int iconSizeXY, - const std::string & geometryArg); + virtual void setGeometry(std::string const & geometryArg); /// save the geometry state in the session manager. virtual void saveGeometry(); virtual void setBusy(bool);