From 04cfa65a96b89e51a0c5f8077a0eec732490b2ce Mon Sep 17 00:00:00 2001 From: =?utf8?q?Peter=20K=C3=BCmmel?= Date: Wed, 21 Jun 2006 10:30:32 +0000 Subject: [PATCH] fix: qt3/qt4 save/restore of the window geometry and maximize status git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14166 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt3/QtView.C | 49 +++++++++++++++++++++++++++++++------ src/frontends/qt3/QtView.h | 21 ++++++++++++++-- src/frontends/qt3/lyx_gui.C | 19 +++++++++----- src/frontends/qt4/GuiView.C | 43 ++++++++++++++++++++++++++++---- src/frontends/qt4/GuiView.h | 16 ++++++++++-- src/frontends/qt4/lyx_gui.C | 24 +++++++++++++++--- src/lyx_main.C | 13 +++++++++- src/lyx_main.h | 4 +++ 8 files changed, 161 insertions(+), 28 deletions(-) diff --git a/src/frontends/qt3/QtView.C b/src/frontends/qt3/QtView.C index 1e1bab5540..ca7953d52e 100644 --- a/src/frontends/qt3/QtView.C +++ b/src/frontends/qt3/QtView.C @@ -37,6 +37,8 @@ #include #include +#include + using std::string; FontLoader fontloader; @@ -55,14 +57,12 @@ int const statusbar_timer_value = 3000; -QtView::QtView(unsigned int width, unsigned int height) +QtView::QtView() : QMainWindow(), LyXView(), commandbuffer_(0), frontend_(*this) { - resize(width, height); - qApp->setMainWidget(this); - bufferview_.reset(new BufferView(this, width, height)); + bufferview_.reset(new BufferView(this, width(), height())); menubar_.reset(new QLMenubar(this, menubackend)); getToolbars().init(); @@ -157,17 +157,49 @@ bool QtView::hasFocus() const return qApp->activeWindow() == this; } +void QtView::initFloatingGeometry(QRect const & g) +{ + floatingGeometry_ = g; + maxWidth = QApplication::desktop()->width() - 20; +} + +void QtView::updateFloatingGeometry() +{ + if (width() < maxWidth && frameGeometry().x() > 0) + { + // setX/Y changes the size! + floatingGeometry_.setX(x()); + floatingGeometry_.setY(y()); + floatingGeometry_.setWidth(width()); + floatingGeometry_.setHeight(height()); + } +} + +void QtView::resizeEvent(QResizeEvent *) +{ + maxWidth = std::max(width(), maxWidth); + + updateFloatingGeometry(); +} + +void QtView::moveEvent(QMoveEvent *) +{ + updateFloatingGeometry(); +} void QtView::closeEvent(QCloseEvent *) { + updateFloatingGeometry(); + QRect geometry = floatingGeometry_; + Session & session = LyX::ref().session(); session.saveSessionInfo("WindowIsMaximized", (isMaximized() ? "yes" : "no")); // save windows size and position - session.saveSessionInfo("WindowWidth", convert(width())); - session.saveSessionInfo("WindowHeight", convert(height())); + session.saveSessionInfo("WindowWidth", convert(geometry.width())); + session.saveSessionInfo("WindowHeight", convert(geometry.height())); if (lyxrc.geometry_xysaved) { - session.saveSessionInfo("WindowPosX", convert(x())); - session.saveSessionInfo("WindowPosY", convert(y())); + session.saveSessionInfo("WindowPosX", convert(geometry.x())); + session.saveSessionInfo("WindowPosY", convert(geometry.y())); } // trigger LFUN_LYX_QUIT instead of quit directly // since LFUN_LYX_QUIT may have more cleanup stuff @@ -179,6 +211,7 @@ void QtView::show() { setCaption(qt_("LyX")); QMainWindow::show(); + updateFloatingGeometry(); } diff --git a/src/frontends/qt3/QtView.h b/src/frontends/qt3/QtView.h index 29cf568f5d..75286f8d06 100644 --- a/src/frontends/qt3/QtView.h +++ b/src/frontends/qt3/QtView.h @@ -38,8 +38,8 @@ class QCommandBuffer; class QtView : public QMainWindow, public LyXView { Q_OBJECT public: - /// create a main window of the given dimensions - QtView(unsigned int w, unsigned int h); + /// create a main window + QtView(); ~QtView(); @@ -67,9 +67,19 @@ public: // lyx::frontend::Gui & gui() { return frontend_; } + /// + void initFloatingGeometry(QRect const &); + public slots: /// idle timeout void update_view_state_qt(); + + /// + virtual void resizeEvent(QResizeEvent * e); + + /// + virtual void moveEvent(QMoveEvent * e); + protected: /// make sure we quit cleanly virtual void closeEvent(QCloseEvent * e); @@ -94,6 +104,13 @@ private: /// GuiImplementation frontend_; + + /// + void updateFloatingGeometry(); + /// + QRect floatingGeometry_; + /// + int maxWidth; }; } // namespace frontend diff --git a/src/frontends/qt3/lyx_gui.C b/src/frontends/qt3/lyx_gui.C index f58f5cf564..7336f7f616 100644 --- a/src/frontends/qt3/lyx_gui.C +++ b/src/frontends/qt3/lyx_gui.C @@ -222,22 +222,29 @@ void parse_lyxrc() void start(string const & batch, vector const & files, - unsigned int width, unsigned int height, int posx, int posy, bool) + unsigned int width, unsigned int height, int posx, int posy, bool maximize) { // this can't be done before because it needs the Languages object initEncodings(); - boost::shared_ptr view_ptr(new QtView(width, height)); + boost::shared_ptr view_ptr(new QtView); LyX::ref().addLyXView(view_ptr); QtView & view = *view_ptr.get(); - if (posx != -1 && posy != -1) - view.move(QPoint(posx, posy)); - - view.show(); view.init(); + if (width != -1 && height != -1) { + view.initFloatingGeometry(QRect(posx, posy, width, height)); + view.resize(width, height); + if (posx != -1 && posy != -1) + view.move(posx, posy); + view.show(); + if (maximize) + view.setWindowState(Qt::WindowMaximized); + } else + view.show(); + // FIXME: some code below needs moving lyxserver = new LyXServer(&view.getLyXFunc(), lyxrc.lyxpipes); diff --git a/src/frontends/qt4/GuiView.C b/src/frontends/qt4/GuiView.C index 013526306d..840c406b10 100644 --- a/src/frontends/qt4/GuiView.C +++ b/src/frontends/qt4/GuiView.C @@ -45,8 +45,6 @@ #include #include #include -//#include -//#include #include "support/lstrings.h" @@ -70,7 +68,7 @@ int const statusbar_timer_value = 3000; } // namespace anon -GuiView::GuiView(unsigned int width, unsigned int height) +GuiView::GuiView() : QMainWindow(), LyXView(), commandbuffer_(0), frontend_(*this) { mainWidget_ = this; @@ -78,7 +76,8 @@ GuiView::GuiView(unsigned int width, unsigned int height) // setToolButtonStyle(Qt::ToolButtonIconOnly); // setIconSize(QSize(12,12)); - bufferview_.reset(new BufferView(this, width, height)); + // -geometry could set the width and hight + bufferview_.reset(new BufferView(this, geometry().width(), geometry().height())); menubar_.reset(new QLMenubar(this, menubackend)); connect(menuBar(), SIGNAL(triggered(QAction *)), this, SLOT(updateMenu(QAction *))); @@ -176,12 +175,45 @@ bool GuiView::hasFocus() const return qApp->activeWindow() == this; } +void GuiView::updateFloatingGeometry() +{ + if (!isMaximized()) { + // setX/Y changes the size! + floatingGeometry_.setX(x()); + floatingGeometry_.setY(y()); + floatingGeometry_.setWidth(width()); + floatingGeometry_.setHeight(height()); + } +} + +void GuiView::resizeEvent(QResizeEvent *) +{ + updateFloatingGeometry(); +} + +void GuiView::moveEvent(QMoveEvent *) +{ + updateFloatingGeometry(); +} + void GuiView::closeEvent(QCloseEvent *) { + // FIXME: + // change the ifdef to 'geometry = normalGeometry();' only + // when Trolltech has fixed the broken normalGeometry on X11. + // Then also the moveEvent, resizeEvent, and the + // code for floatingGeometry_ can be removed; + // adjust lyx_gui::start +#ifdef Q_OS_WIN32 QRect geometry = normalGeometry(); - Session & session = LyX::ref().session(); +#else + updateFloatingGeometry(); + QRect geometry = floatingGeometry_; +#endif + // save windows size and position + Session & session = LyX::ref().session(); session.saveSessionInfo("WindowWidth", convert(geometry.width())); session.saveSessionInfo("WindowHeight", convert(geometry.height())); session.saveSessionInfo("WindowIsMaximized", (isMaximized() ? "yes" : "no")); @@ -199,6 +231,7 @@ void GuiView::show() { QMainWindow::setWindowTitle(qt_("LyX")); QMainWindow::show(); + updateFloatingGeometry(); } diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h index 66a7d5a9f7..f77fbc7989 100644 --- a/src/frontends/qt4/GuiView.h +++ b/src/frontends/qt4/GuiView.h @@ -48,8 +48,8 @@ QWidget* mainWindow(); class GuiView : public QMainWindow, public LyXView { Q_OBJECT public: - /// create a main window of the given dimensions - GuiView(unsigned int w, unsigned int h); + /// create a main window + GuiView(); ~GuiView(); @@ -89,6 +89,13 @@ public slots: protected: /// make sure we quit cleanly virtual void closeEvent(QCloseEvent * e); + + /// + virtual void resizeEvent(QResizeEvent * e); + + /// + virtual void moveEvent(QMoveEvent * e); + private: /// focus the command buffer widget void focus_command_widget(); @@ -112,6 +119,11 @@ private: static QMainWindow* mainWidget_; GuiImplementation frontend_; + + /// + void updateFloatingGeometry(); + /// + QRect floatingGeometry_; }; } // namespace frontend diff --git a/src/frontends/qt4/lyx_gui.C b/src/frontends/qt4/lyx_gui.C index ed9116e3b4..e1d8ce12ed 100644 --- a/src/frontends/qt4/lyx_gui.C +++ b/src/frontends/qt4/lyx_gui.C @@ -194,15 +194,31 @@ void start(string const & batch, vector const & files, // this can't be done before because it needs the Languages object initEncodings(); - boost::shared_ptr view_ptr(new GuiView(width, height)); + boost::shared_ptr view_ptr(new GuiView); + LyX::ref().addLyXView(view_ptr); GuiView & view = *view_ptr.get(); view.init(); - - if (posx != -1 && posy != -1) { - view.setGeometry(posx, posy, width, height); + + // only true when the -geometry option was NOT used + if (width != -1 && height != -1) + { + if (posx != -1 && posy != -1) + { +#ifdef Q_OS_WIN32 + // FIXME: use only setGeoemtry when Trolltech has + // fixed the qt4/X11 bug + view.setGeometry(posx, posy,width, height); +#else + view.resize(width, height); + view.move(posx, posy); +#endif + } else { + view.resize(width, height); + } + if (maximize) view.setWindowState(Qt::WindowMaximized); } diff --git a/src/lyx_main.C b/src/lyx_main.C index 7443434b3b..226bbb998f 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -170,7 +170,7 @@ LyX const & LyX::cref() LyX::LyX() - : first_start(false) + : first_start(false), geometryOption_(false) {} @@ -335,7 +335,14 @@ void LyX::exec2(int & argc, char * argv[]) if (!val.empty()) posy = convert(val); } + + if (geometryOption_) { + width = -1; + height = -1; + } + lyx_gui::start(batch_command, files, width, height, posx, posy, maximize); + } else { // Something went wrong above quitLyX(false); @@ -995,6 +1002,10 @@ bool LyX::easyParse(int & argc, char * argv[]) std::map::const_iterator it = cmdmap.find(argv[i]); + // check for X11 -geometry option + if (lyx::support::compare(argv[i], "-geometry") == 0) + geometryOption_ = true; + // don't complain if not found - may be parsed later if (it == cmdmap.end()) continue; diff --git a/src/lyx_main.h b/src/lyx_main.h index 15bb2ef636..550619784a 100644 --- a/src/lyx_main.h +++ b/src/lyx_main.h @@ -107,6 +107,10 @@ private: /// typedef std::list > ViewList; ViewList views_; + + /// + bool geometryOption_; + }; #endif // LYX_MAIN_H -- 2.39.2