git-svn-id: svn://db.shs.com.ru/libs@591 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
#include <QApplication>
|
||||
#include <QFileInfo>
|
||||
#include <QMetaMethod>
|
||||
#if QT_VERSION < 0x050000
|
||||
# include <QDesktopWidget>
|
||||
#else
|
||||
# include <QScreen>
|
||||
#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<QScreen*> 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<QSplitter * > sp = mwindows[i].second->findChildren<QSplitter * >();
|
||||
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<QSplitter * > sp = mw->findChildren<QSplitter * >();
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user