Bo Peng wrote:
> On 6/16/06, Peter Kümmel <[EMAIL PROTECTED]> wrote:
>> I've fixed the save/restore and -geometry problem for Qt4.
>> Therefore I have to remember lyx if there was the geometry option,
>> and I have to emulate the QWidget::normalGeometry() function.
>>
>> I've tested it with Linux and Windows.
>
> I do not really like this big patch, although this may be the only way
> out. I moved most common behaviors of all frontends to lyx_main.C,
> hoping to result in simpler logic in the frontends. Now, things would
> be clearer if all geometry handling goes back to the frontends.
>
> At the very least, geometryOption_ can be passed as an additional
> variable, just as isMaximized, or better, handled in lyx_main.C so
> frontends do not have to worry about it.

I've changed the code so that the geometryOption is now passed as
argument to lyx_gui::start. But I don't see a way to handle the
geometry option in lyx_main.

Now you could run lyx with the geometry option maximize the window
and close it maximized and it will remember the geometry values so
that they are not longer needed for the next start of lyx.

I've also reported the X11 workaround,

+#ifdef Q_OS_WIN32
+                       view.setGeometry(posx, posy, width, height);
+#else
+                       // X11: use frameGeometry position
+                       view.setGeometry(0, 0, width, height);
+                       view.move(posx, posy);
+#endif

as bug at Trolltech.


Attached the new patch.

(The added event handlers of QtView are needed to remember
the last geometry values)

Peter

Index: frontends/gtk/lyx_gui.C
===================================================================
--- frontends/gtk/lyx_gui.C     (revision 14139)
+++ frontends/gtk/lyx_gui.C     (working copy)
@@ -123,7 +123,7 @@
 
 
 void lyx_gui::start(string const & batch, std::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, bool)
 {
        boost::shared_ptr<GView> view_ptr(new GView);
        LyX::ref().addLyXView(view_ptr);
Index: frontends/qt3/lyx_gui.C
===================================================================
--- frontends/qt3/lyx_gui.C     (revision 14140)
+++ frontends/qt3/lyx_gui.C     (working copy)
@@ -222,7 +222,7 @@
 
 
 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, 
bool)
 {
        // this can't be done before because it needs the Languages object
        initEncodings();
Index: frontends/qt4/lyx_gui.C
===================================================================
--- frontends/qt4/lyx_gui.C     (revision 14139)
+++ frontends/qt4/lyx_gui.C     (working copy)
@@ -228,24 +228,32 @@
 
 
 void start(string const & batch, vector<string> const & files,
-          unsigned int width, unsigned int height, int posx, int posy, bool 
maximize)
+          unsigned int width, unsigned int height, int posx, int posy, bool 
maximize,
+          bool geometryOption)
 {
        // 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();
 
        view.init();
-               
-       if (posx != -1 && posy != -1) {         
-               view.setGeometry(posx, posy, width, height);
-               if (maximize)
-                       view.setWindowState(Qt::WindowMaximized);
-       }
 
+       if (!geometryOption)
+               if (posx != -1 && posy != -1) { 
+#ifndef Q_OS_WIN32
+                       // X11: use frameGeometry position
+                       view.setGeometry(0, 0, width, height);
+                       view.move(posx, posy);
+#else
+                       view.setGeometry(posx, posy, width, height);
+#endif
+                       if (maximize)
+                               view.setWindowState(Qt::WindowMaximized);
+               }
+
        view.show();
 
        // FIXME: some code below needs moving
Index: frontends/qt4/QtView.C
===================================================================
--- frontends/qt4/QtView.C      (revision 14139)
+++ frontends/qt4/QtView.C      (working copy)
@@ -70,7 +70,7 @@
 } // namespace anon
 
 
-QtView::QtView(unsigned int width, unsigned int height)
+QtView::QtView()
        : QMainWindow(), LyXView(), commandbuffer_(0)
 {
        mainWidget_ = this;
@@ -78,7 +78,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,10 +177,44 @@
        return qApp->activeWindow() == this;
 }
 
+#ifndef Q_OS_WIN32
 
+QRect QtView::qtViewGeometry() const
+{
+       QRect rec;
+       // setX/Y changes the size!
+       rec.setX(frameGeometry().x());
+       rec.setY(frameGeometry().y());
+       rec.setWidth(geometry().width());
+       rec.setHeight(geometry().height());
+       return rec;
+}
+
+void QtView::resizeEvent(QResizeEvent *)
+{
+       if(!isMaximized())
+               showGeometry_ = qtViewGeometry();
+}
+
+void QtView::moveEvent(QMoveEvent *)
+{
+       if(!isMaximized())
+               showGeometry_ = qtViewGeometry();
+}
+#endif
+
 void QtView::closeEvent(QCloseEvent *)
 {
+#ifndef Q_OS_WIN32
+       QRect geometry;
+       if (isMaximized()) 
+               geometry = showGeometry_;       
+       else
+               geometry = qtViewGeometry();
+#else
        QRect geometry = normalGeometry();
+#endif
+
        Session & session = LyX::ref().session();
        // save windows size and position
        session.saveSessionInfo("WindowWidth", 
convert<string>(geometry.width()));
@@ -199,6 +234,10 @@
 {
        QMainWindow::setWindowTitle(qt_("LyX"));
        QMainWindow::show();
+#ifndef Q_OS_WIN32
+       if(!isMaximized())
+               showGeometry_ = qtViewGeometry();
+#endif
 }
 
 
Index: frontends/qt4/QtView.h
===================================================================
--- frontends/qt4/QtView.h      (revision 14139)
+++ frontends/qt4/QtView.h      (working copy)
@@ -46,8 +46,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();
 
@@ -84,6 +84,15 @@
 protected:
        /// make sure we quit cleanly
        virtual void closeEvent(QCloseEvent * e);
+
+#ifndef Q_OS_WIN32
+       /// 
+       virtual void resizeEvent(QResizeEvent * e);
+
+       /// 
+       virtual void moveEvent(QMoveEvent * e);
+#endif
+
 private:
        /// focus the command buffer widget
        void focus_command_widget();
@@ -105,6 +114,14 @@
 
        ///
        static QMainWindow* mainWidget_;
+
+#ifndef Q_OS_WIN32
+       ///
+       QRect qtViewGeometry() const;
+       
+       ///
+       QRect showGeometry_;
+#endif
 };
 
 } // namespace frontend
Index: frontends/xforms/lyx_gui.C
===================================================================
--- frontends/xforms/lyx_gui.C  (revision 14139)
+++ frontends/xforms/lyx_gui.C  (working copy)
@@ -256,7 +256,7 @@
 
 
 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, 
bool)
 {
        int const geometryBitmask =
                XParseGeometry(geometry, &posx, &posy, &width, &height);
Index: frontends/lyx_gui.h
===================================================================
--- frontends/lyx_gui.h (revision 14139)
+++ frontends/lyx_gui.h (working copy)
@@ -57,7 +57,8 @@
  * batch commands, and loading the given documents
  */
 void start(std::string const & batch, std::vector<std::string> const & files,
-           unsigned int width, unsigned int height, int posx, int posy, bool 
maximize);
+           unsigned int width, unsigned int height, int posx, int posy, bool 
maximize,
+           bool geometryOption);
 
 /**
  * Enter the main event loop (\sa LyX::exec2)
Index: lyx_main.C
===================================================================
--- lyx_main.C  (revision 14139)
+++ lyx_main.C  (working copy)
@@ -170,7 +170,7 @@
 
 
 LyX::LyX()
-       : first_start(false)
+       : first_start(false), geometryOption_(false)
 {}
 
 
@@ -335,7 +335,7 @@
                        if (!val.empty())
                                posy = convert<int>(val);
                }
-               lyx_gui::start(batch_command, files, width, height, posx, posy, 
maximize);
+               lyx_gui::start(batch_command, files, width, height, posx, posy, 
maximize, geometryOption_);
        } else {
                // Something went wrong above
                quitLyX(false);
@@ -995,6 +995,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 14139)
+++ 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