From 8cea2b4e76271d2095c1bcf507bd55091f05480a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D0=BB=D0=B8=D0=BF=D0=B5=D0=BD=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD?= Date: Tue, 17 Sep 2019 16:36:24 +0000 Subject: [PATCH] git-svn-id: svn://db.shs.com.ru/libs@591 a8b55f48-bf90-11e4-a774-851b48703e85 --- qad/widgets/session_manager.cpp | 72 ++++++++++++++++++++++++++++----- 1 file changed, 62 insertions(+), 10 deletions(-) diff --git a/qad/widgets/session_manager.cpp b/qad/widgets/session_manager.cpp index a602cf5..95dd158 100644 --- a/qad/widgets/session_manager.cpp +++ b/qad/widgets/session_manager.cpp @@ -1,6 +1,11 @@ #include #include #include +#if QT_VERSION < 0x050000 +# include +#else +# include +#endif #include "session_manager.h" @@ -101,23 +106,70 @@ void SessionManager::save() { } +void restoreWindowState(QWidget * w, QPIConfig & sr, QString name) { + int wstate = (int)sr.getValue(name + " window state", 0); + QByteArray ba0 = sr.getValue(name + " geometry 0", QByteArray()); + w->setWindowState(Qt::WindowNoState); + w->restoreGeometry(ba0); + if (wstate == Qt::WindowMaximized) + w->setWindowState((Qt::WindowState)wstate); + bool wnd_ok = false; + QRect srect; +#if QT_VERSION < 0x050000 + wnd_ok = (QApplication::desktop()->screenNumber(w) >= 0); + if (!wnd_ok) { + w->setGeometry(0, 0, w->width(), w->height()); + srect = QApplication::desktop(w)->geometry(); + } +#else + QList sl = QApplication::screens(); + foreach (QScreen * s, sl) { + if (s->geometry().contains(w->geometry())) { + wnd_ok = true; + break; + } + } + srect = QApplication::primaryScreen()->geometry(); +#endif + if (!wnd_ok) { + w->setWindowState(Qt::WindowNoState); + w->setGeometry(srect.x() + (srect.width () - w->width ()) / 2, + srect.y() + (srect.height() - w->height()) / 2, + w->width(), w->height()); + } + /*if (w->windowState().testFlag(Qt::WindowMaximized)) { + foreach (QScreen * s, sl) { + if (s->geometry().contains(w->geometry())) { + //w->setGeometry(s->availableGeometry()); + break; + } + } + }*/ +} + + void SessionManager::load(bool onlyMainwindow) { if (file_.isEmpty()) return; QPIConfig sr(file_); QObjectList tsc; for (int i = 0; i < mwindows.size(); ++i) { - tsc << mwindows[i].second; - mwindows[i].second->restoreState(sr.getValue(mwindows[i].first + " state", QByteArray())); - mwindows[i].second->restoreGeometry(sr.getValue(mwindows[i].first + " geometry " + QString::number((int)mwindows[i].second->windowState()), QByteArray())); - mwindows[i].second->setWindowState((Qt::WindowState)(int)sr.getValue(mwindows[i].first + " window state", 0)); - QList sp = mwindows[i].second->findChildren(); - foreach (QSplitter * s, sp) - s->restoreState(sr.getValue(mwindows[i].first + " splitter " + s->objectName(), QByteArray())); + QMainWindow * mw = mwindows[i].second; + tsc << mw; + QByteArray ba = sr.getValue(mwindows[i].first + " state", QByteArray()); + if (!ba.isEmpty()) + mw->restoreState(ba); + QList sp = mw->findChildren(); + foreach (QSplitter * s, sp) { + ba = sr.getValue(mwindows[i].first + " splitter " + s->objectName(), QByteArray()); + if (!ba.isEmpty()) + s->restoreState(ba); + } + restoreWindowState(mw, sr, mwindows[i].first); } for (int i = 0; i < widgets.size(); ++i) { - tsc << widgets[i].second; - widgets[i].second->restoreGeometry(sr.getValue(widgets[i].first + " geometry " + QString::number((int)widgets[i].second->windowState()), QByteArray())); - widgets[i].second->setWindowState((Qt::WindowState)(int)sr.getValue(widgets[i].first + " window state", 0)); + QWidget * mw = widgets[i].second; + tsc << mw; + restoreWindowState(mw, sr, widgets[i].first); } if (onlyMainwindow) return; for (int i = 0; i < checks.size(); ++i)