Hi Abdel, Bo

here the next version with your embedded suggestions.
I've also simplified the floating code.

Peter
Index: frontends/qt3/lyx_gui.C
===================================================================
--- frontends/qt3/lyx_gui.C     (revision 14157)
+++ frontends/qt3/lyx_gui.C     (working copy)
@@ -222,22 +222,29 @@
 
 
 void start(string const & batch, vector<string> 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<QtView> view_ptr(new QtView(width, height));
+       boost::shared_ptr<QtView> 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);
Index: frontends/qt3/QtView.C
===================================================================
--- frontends/qt3/QtView.C      (revision 14157)
+++ frontends/qt3/QtView.C      (working copy)
@@ -55,14 +55,12 @@
 
 
 
-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 +155,49 @@
        return qApp->activeWindow() == this;
 }
 
+void QtView::initFloatingGeometry(const QRect & 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 *)
+{
+       if (width() > maxWidth)
+               maxWidth = width();
+       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<string>(width()));
-       session.saveSessionInfo("WindowHeight", convert<string>(height()));
+       session.saveSessionInfo("WindowWidth", 
convert<string>(geometry.width()));
+       session.saveSessionInfo("WindowHeight", 
convert<string>(geometry.height()));
        if (lyxrc.geometry_xysaved) {
-               session.saveSessionInfo("WindowPosX", convert<string>(x()));
-               session.saveSessionInfo("WindowPosY", convert<string>(y()));
+               session.saveSessionInfo("WindowPosX", 
convert<string>(geometry.x()));
+               session.saveSessionInfo("WindowPosY", 
convert<string>(geometry.y()));
        }
        // trigger LFUN_LYX_QUIT instead of quit directly
        // since LFUN_LYX_QUIT may have more cleanup stuff
@@ -179,6 +209,7 @@
 {
        setCaption(qt_("LyX"));
        QMainWindow::show();
+       updateFloatingGeometry();
 }
 
 
Index: frontends/qt3/QtView.h
===================================================================
--- frontends/qt3/QtView.h      (revision 14157)
+++ frontends/qt3/QtView.h      (working copy)
@@ -38,8 +38,8 @@
 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 @@
        //
        lyx::frontend::Gui & gui() { return frontend_; }
 
+       ///
+       void initFloatingGeometry(const QRect &);
+
 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 @@
        
        ///
        GuiImplementation frontend_;
+
+       ///
+       void updateFloatingGeometry();
+       ///
+       QRect floatingGeometry_;
+       ///
+       int maxWidth;
 };
 
 } // namespace frontend
Index: frontends/qt4/lyx_gui.C
===================================================================
--- frontends/qt4/lyx_gui.C     (revision 14157)
+++ frontends/qt4/lyx_gui.C     (working copy)
@@ -194,15 +194,31 @@
        // this can't be done before because it needs the Languages object
        initEncodings();
 
-       boost::shared_ptr<GuiView> view_ptr(new GuiView(width, height));
+       boost::shared_ptr<GuiView> 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);
        }
Index: frontends/qt4/GuiView.h
===================================================================
--- frontends/qt4/GuiView.h     (revision 14157)
+++ frontends/qt4/GuiView.h     (working copy)
@@ -48,8 +48,8 @@
 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 @@
 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 @@
        static QMainWindow* mainWidget_;
 
        GuiImplementation frontend_;
+
+       ///
+       void updateFloatingGeometry();
+       ///
+       QRect floatingGeometry_;
 };
 
 } // namespace frontend
Index: frontends/qt4/GuiView.C
===================================================================
--- frontends/qt4/GuiView.C     (revision 14157)
+++ frontends/qt4/GuiView.C     (working copy)
@@ -45,8 +45,6 @@
 #include <QToolBar>
 #include <QCloseEvent>
 #include <QAction>
-//#include <QMenu>
-//#include <QMenuBar>
 
 #include "support/lstrings.h"
 
@@ -70,7 +68,7 @@
 } // namespace anon
 
 
-GuiView::GuiView(unsigned int width, unsigned int height)
+GuiView::GuiView()
        : QMainWindow(), LyXView(), commandbuffer_(0), frontend_(*this)
 {
        mainWidget_ = this;
@@ -78,7 +76,8 @@
 //     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 @@
        return qApp->activeWindow() == this;
 }
 
+void  GuiView::updateFloatingGeometry() 
+{
+       if (!isMaximized()) {
+               // setX/Y changes the size!
+               floatingGeometry_.setX(x()); // == frameGeometry().x()
+               floatingGeometry_.setY(y()); // == frameGeometry().y()
+               floatingGeometry_.setWidth(width()); // == geometry().width()
+               floatingGeometry_.setHeight(height());// == geometry().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();
+#else
+       updateFloatingGeometry();
+       QRect geometry = floatingGeometry_;     
+#endif
+       
+       // save windows size and position
        Session & session = LyX::ref().session();
-       // save windows size and position
        session.saveSessionInfo("WindowWidth", 
convert<string>(geometry.width()));
        session.saveSessionInfo("WindowHeight", 
convert<string>(geometry.height()));
        session.saveSessionInfo("WindowIsMaximized", (isMaximized() ? "yes" : 
"no"));
@@ -199,6 +231,7 @@
 {
        QMainWindow::setWindowTitle(qt_("LyX"));
        QMainWindow::show();
+       updateFloatingGeometry();
 }
 
 
Index: lyx_main.C
===================================================================
--- lyx_main.C  (revision 14157)
+++ lyx_main.C  (working copy)
@@ -170,7 +170,7 @@
 
 
 LyX::LyX()
-       : first_start(false)
+       : first_start(false), geometryOption_(false)
 {}
 
 
@@ -335,7 +335,14 @@
                        if (!val.empty())
                                posy = convert<int>(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 @@
                std::map<string, cmd_helper>::const_iterator it
                        = cmdmap.find(argv[i]);
 
+               // check for X11 -geometry option
+               if (argv[i] == string("-geometry"))
+                       geometryOption_ = true;
+
                // don't complain if not found - may be parsed later
                if (it == cmdmap.end())
                        continue;
Index: lyx_main.h
===================================================================
--- lyx_main.h  (revision 14157)
+++ lyx_main.h  (working copy)
@@ -107,6 +107,10 @@
        ///
        typedef std::list<boost::shared_ptr<LyXView> > ViewList;
        ViewList views_;
+
+       /// 
+       bool geometryOption_;
+
 };
 
 #endif // LYX_MAIN_H

Reply via email to