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
This commit is contained in:
Peter Kümmel 2006-06-21 10:30:32 +00:00
parent fe5c0415a4
commit 04cfa65a96
8 changed files with 161 additions and 28 deletions

View File

@ -37,6 +37,8 @@
#include <qpixmap.h>
#include <qstatusbar.h>
#include <algorithm>
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<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 +211,7 @@ void QtView::show()
{
setCaption(qt_("LyX"));
QMainWindow::show();
updateFloatingGeometry();
}

View File

@ -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

View File

@ -222,22 +222,29 @@ void parse_lyxrc()
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);

View File

@ -45,8 +45,6 @@
#include <QToolBar>
#include <QCloseEvent>
#include <QAction>
//#include <QMenu>
//#include <QMenuBar>
#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<string>(geometry.width()));
session.saveSessionInfo("WindowHeight", convert<string>(geometry.height()));
session.saveSessionInfo("WindowIsMaximized", (isMaximized() ? "yes" : "no"));
@ -199,6 +231,7 @@ void GuiView::show()
{
QMainWindow::setWindowTitle(qt_("LyX"));
QMainWindow::show();
updateFloatingGeometry();
}

View File

@ -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

View File

@ -194,15 +194,31 @@ void start(string const & batch, vector<string> const & files,
// 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);
}

View File

@ -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<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 @@ bool LyX::easyParse(int & argc, char * argv[])
std::map<string, cmd_helper>::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;

View File

@ -107,6 +107,10 @@ private:
///
typedef std::list<boost::shared_ptr<LyXView> > ViewList;
ViewList views_;
///
bool geometryOption_;
};
#endif // LYX_MAIN_H