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 <QApplication>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QMetaMethod>
|
#include <QMetaMethod>
|
||||||
|
#if QT_VERSION < 0x050000
|
||||||
|
# include <QDesktopWidget>
|
||||||
|
#else
|
||||||
|
# include <QScreen>
|
||||||
|
#endif
|
||||||
#include "session_manager.h"
|
#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) {
|
void SessionManager::load(bool onlyMainwindow) {
|
||||||
if (file_.isEmpty()) return;
|
if (file_.isEmpty()) return;
|
||||||
QPIConfig sr(file_);
|
QPIConfig sr(file_);
|
||||||
QObjectList tsc;
|
QObjectList tsc;
|
||||||
for (int i = 0; i < mwindows.size(); ++i) {
|
for (int i = 0; i < mwindows.size(); ++i) {
|
||||||
tsc << mwindows[i].second;
|
QMainWindow * mw = mwindows[i].second;
|
||||||
mwindows[i].second->restoreState(sr.getValue(mwindows[i].first + " state", QByteArray()));
|
tsc << mw;
|
||||||
mwindows[i].second->restoreGeometry(sr.getValue(mwindows[i].first + " geometry " + QString::number((int)mwindows[i].second->windowState()), QByteArray()));
|
QByteArray ba = sr.getValue(mwindows[i].first + " state", QByteArray());
|
||||||
mwindows[i].second->setWindowState((Qt::WindowState)(int)sr.getValue(mwindows[i].first + " window state", 0));
|
if (!ba.isEmpty())
|
||||||
QList<QSplitter * > sp = mwindows[i].second->findChildren<QSplitter * >();
|
mw->restoreState(ba);
|
||||||
foreach (QSplitter * s, sp)
|
QList<QSplitter * > sp = mw->findChildren<QSplitter * >();
|
||||||
s->restoreState(sr.getValue(mwindows[i].first + " splitter " + s->objectName(), QByteArray()));
|
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) {
|
for (int i = 0; i < widgets.size(); ++i) {
|
||||||
tsc << widgets[i].second;
|
QWidget * mw = widgets[i].second;
|
||||||
widgets[i].second->restoreGeometry(sr.getValue(widgets[i].first + " geometry " + QString::number((int)widgets[i].second->windowState()), QByteArray()));
|
tsc << mw;
|
||||||
widgets[i].second->setWindowState((Qt::WindowState)(int)sr.getValue(widgets[i].first + " window state", 0));
|
restoreWindowState(mw, sr, widgets[i].first);
|
||||||
}
|
}
|
||||||
if (onlyMainwindow) return;
|
if (onlyMainwindow) return;
|
||||||
for (int i = 0; i < checks.size(); ++i)
|
for (int i = 0; i < checks.size(); ++i)
|
||||||
|
|||||||
Reference in New Issue
Block a user