From 41681e71850d9efde66182b552a28fb9dfff6873 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Mon, 10 Dec 2007 13:05:00 +0000 Subject: [PATCH] Add common session handling infrastructure for dialogs. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22061 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/Dialog.cpp | 26 ++++++++++++++++++++++++++ src/frontends/qt4/Dialog.h | 21 +++++++++++++++++++++ src/frontends/qt4/DialogView.cpp | 19 ------------------- src/frontends/qt4/DialogView.h | 7 +------ src/frontends/qt4/DockView.h | 9 +++++---- src/frontends/qt4/GuiProgress.cpp | 4 +++- src/frontends/qt4/GuiView.cpp | 11 +++++++++-- 7 files changed, 65 insertions(+), 32 deletions(-) diff --git a/src/frontends/qt4/Dialog.cpp b/src/frontends/qt4/Dialog.cpp index 15e96136a4..04e09a95fe 100644 --- a/src/frontends/qt4/Dialog.cpp +++ b/src/frontends/qt4/Dialog.cpp @@ -13,6 +13,7 @@ #include "Dialog.h" #include "GuiView.h" +#include "qt_helpers.h" #include "Buffer.h" #include "FuncRequest.h" @@ -21,6 +22,9 @@ #include "support/debug.h" +#include +#include + #include using namespace std; @@ -241,5 +245,27 @@ void Dialog::checkStatus() enableView(false); } + +QString Dialog::sessionKey() const +{ + return "view-" + QString::number(lyxview_->id()) + + "/" + toqstr(name()); +} + + +void Dialog::saveSession() const +{ + QSettings settings; + settings.setValue(sessionKey() + "/geometry", asQWidget()->saveGeometry()); +} + + +void Dialog::restoreSession() +{ + QSettings settings; + asQWidget()->restoreGeometry( + settings.value(sessionKey() + "/geometry").toByteArray()); +} + } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/Dialog.h b/src/frontends/qt4/Dialog.h index 64dd730086..987211d91f 100644 --- a/src/frontends/qt4/Dialog.h +++ b/src/frontends/qt4/Dialog.h @@ -16,6 +16,7 @@ #include +class QString; class QWidget; namespace lyx { @@ -56,6 +57,26 @@ public: virtual QWidget * asQWidget() = 0; virtual QWidget const * asQWidget() const = 0; + /// Session key. + /** + * This key must be used for any session setting. + **/ + QString sessionKey() const; + + /// Save session settings. + /** + * This default implementation saves the geometry state. + * Reimplement to save more settings. + **/ + virtual void saveSession() const; + + /// Restore session settings. + /** + * This default implementation restores the geometry state. + * Reimplement to restore more settings. + **/ + virtual void restoreSession(); + /** \name Container Access * These methods are publicly accessible because they are invoked * by the parent container acting on commands from the LyX kernel. diff --git a/src/frontends/qt4/DialogView.cpp b/src/frontends/qt4/DialogView.cpp index b193bca2ae..c120ea391d 100644 --- a/src/frontends/qt4/DialogView.cpp +++ b/src/frontends/qt4/DialogView.cpp @@ -16,7 +16,6 @@ #include "qt_helpers.h" #include -#include #include @@ -33,24 +32,6 @@ void DialogView::setViewTitle(docstring const & title) setWindowTitle("LyX: " + toqstr(title)); } - -void DialogView::showEvent(QShowEvent * e) -{ - QSettings settings; - QString key = toqstr(name()) + "/geometry"; - restoreGeometry(settings.value(key).toByteArray()); - QDialog::showEvent(e); -} - - -void DialogView::closeEvent(QCloseEvent * e) -{ - QSettings settings; - QString key = toqstr(name()) + "/geometry"; - settings.setValue(key, saveGeometry()); - QDialog::closeEvent(e); -} - } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/DialogView.h b/src/frontends/qt4/DialogView.h index 36f3ef2f08..959423281f 100644 --- a/src/frontends/qt4/DialogView.h +++ b/src/frontends/qt4/DialogView.h @@ -39,14 +39,9 @@ public: virtual QWidget * asQWidget() { return this; } virtual QWidget const * asQWidget() const { return this; } -public: +protected: /// void setViewTitle(docstring const & title); - - /// - void closeEvent(QCloseEvent *); - /// - void showEvent(QShowEvent *); }; } // namespace frontend diff --git a/src/frontends/qt4/DockView.h b/src/frontends/qt4/DockView.h index 3f0bd2347a..4b056789c4 100644 --- a/src/frontends/qt4/DockView.h +++ b/src/frontends/qt4/DockView.h @@ -14,8 +14,6 @@ #include "Dialog.h" #include "GuiView.h" -#include "qt_helpers.h" -#include "support/debug.h" #include @@ -23,8 +21,11 @@ namespace lyx { namespace frontend { /// Dock Widget container for LyX dialogs. -/// This template class that encapsulates a given Widget inside a -/// QDockWidget and presents a Dialog interface +/** + * This template class that encapsulates a given Widget inside a + * QDockWidget and presents a Dialog interface + * FIXME: create a DockView.cpp file + **/ class DockView : public QDockWidget, public Dialog { public: diff --git a/src/frontends/qt4/GuiProgress.cpp b/src/frontends/qt4/GuiProgress.cpp index 694a45ef8e..d9109b1c50 100644 --- a/src/frontends/qt4/GuiProgress.cpp +++ b/src/frontends/qt4/GuiProgress.cpp @@ -13,6 +13,8 @@ #include "GuiProgress.h" +#include "qt_helpers.h" + #include "support/Systemcall.h" #include @@ -27,7 +29,7 @@ GuiProgress::GuiProgress(GuiView & parent, Qt::DockWidgetArea area, { setWindowTitle(qt_("LaTeX Progress")); setWidget(&text_edit); - lyx::support::Systemcall::registerProgressInterface(this); + support::Systemcall::registerProgressInterface(this); } diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index f2c7ced203..5c537fa810 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -421,6 +421,10 @@ void GuiView::closeEvent(QCloseEvent * close_event) #endif settings.setValue(key + "/icon_size", iconSize()); d.toolbars_->saveToolbarInfo(); + // Now take care of all other dialogs: + std::map::const_iterator it = d.dialogs_.begin(); + for (; it!= d.dialogs_.end(); ++it) + it->second->saveSession(); } guiApp->unregisterView(id_); @@ -1619,8 +1623,11 @@ Dialog * GuiView::find_or_build(string const & name) if (it != d.dialogs_.end()) return it->second.get(); - d.dialogs_[name].reset(build(name)); - return d.dialogs_[name].get(); + Dialog * dialog = build(name); + d.dialogs_[name].reset(dialog); + if (lyxrc.allow_geometry_session) + dialog->restoreSession(); + return dialog; }