guiqt.cpp: Save QDockWidget state for TextWinow.
parent
102cad6927
commit
f67c3e32dd
|
@ -308,39 +308,34 @@ FileDialogRef CreateSaveFileDialog(WindowRef parentWindow) {
|
||||||
|
|
||||||
class SettingsImplQt final : public Settings {
|
class SettingsImplQt final : public Settings {
|
||||||
public:
|
public:
|
||||||
QSettings* _qset;
|
QSettings qset;
|
||||||
|
|
||||||
SettingsImplQt() {
|
SettingsImplQt() : qset("SolveSpace", "solvespace") {
|
||||||
_qset = new QSettings("SolveSpace", "solvespace");
|
|
||||||
}
|
|
||||||
|
|
||||||
~SettingsImplQt() {
|
|
||||||
delete _qset;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FreezeInt(const std::string& key, uint32_t value) override {
|
void FreezeInt(const std::string& key, uint32_t value) override {
|
||||||
_qset->setValue(QString::fromStdString(key), value);
|
qset.setValue(QString::fromStdString(key), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t ThawInt(const std::string& key, uint32_t defaultValue = 0) override {
|
uint32_t ThawInt(const std::string& key, uint32_t defaultValue = 0) override {
|
||||||
return _qset->value(QString::fromStdString(key), defaultValue).toInt();
|
return qset.value(QString::fromStdString(key), defaultValue).toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FreezeFloat(const std::string& key, double value) override{
|
void FreezeFloat(const std::string& key, double value) override{
|
||||||
_qset->setValue(QString::fromStdString(key), value);
|
qset.setValue(QString::fromStdString(key), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
double ThawFloat(const std::string& key, double defaultValue = 0.0) override {
|
double ThawFloat(const std::string& key, double defaultValue = 0.0) override {
|
||||||
return _qset->value(QString::fromStdString(key), defaultValue).toDouble();
|
return qset.value(QString::fromStdString(key), defaultValue).toDouble();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FreezeString(const std::string& key, const std::string& value) override {
|
void FreezeString(const std::string& key, const std::string& value) override {
|
||||||
_qset->setValue(QString::fromStdString(key),
|
qset.setValue(QString::fromStdString(key),
|
||||||
QString::fromStdString(value));
|
QString::fromStdString(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ThawString(const std::string& key, const std::string& defaultValue = "") override {
|
std::string ThawString(const std::string& key, const std::string& defaultValue = "") override {
|
||||||
return _qset->value(QString::fromStdString(key),
|
return qset.value(QString::fromStdString(key),
|
||||||
QString::fromStdString(defaultValue)).toString().toStdString();
|
QString::fromStdString(defaultValue)).toString().toStdString();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -792,6 +787,9 @@ public:
|
||||||
scrollBar = twin->scrollBar;
|
scrollBar = twin->scrollBar;
|
||||||
view = twin->ssView;
|
view = twin->ssView;
|
||||||
|
|
||||||
|
// Set object name for saveState settings.
|
||||||
|
twin->setObjectName("TextWindow");
|
||||||
|
|
||||||
QMainWindow* mwin = qobject_cast<QMainWindow*>(qparent);
|
QMainWindow* mwin = qobject_cast<QMainWindow*>(qparent);
|
||||||
if(mwin) {
|
if(mwin) {
|
||||||
mwin->addDockWidget(Qt::RightDockWidgetArea, twin);
|
mwin->addDockWidget(Qt::RightDockWidgetArea, twin);
|
||||||
|
@ -873,44 +871,24 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void FreezePosition(SettingsRef settings, const std::string& key) override {
|
void FreezePosition(SettingsRef settings, const std::string& key) override {
|
||||||
if (!(ssWindow->isVisible())) return;
|
// Geometry is only saved for the main window; the TextWindow dock
|
||||||
|
// widget is part of the saveState().
|
||||||
int left, top, width, height;
|
QMainWindow* mwin = qobject_cast<QMainWindow*>(ssWindow);
|
||||||
#if 0
|
if (mwin) {
|
||||||
QPoint topLeftPoint = ssWindow->geometry().topLeft();
|
QSettings& qset = std::static_pointer_cast<SettingsImplQt>(settings)->qset;
|
||||||
left = topLeftPoint.x();
|
QString qkey = QString::fromStdString(key);
|
||||||
top = topLeftPoint.y();
|
qset.setValue(qkey + "_Geometry", mwin->saveGeometry());
|
||||||
#endif
|
qset.setValue(qkey + "_State", mwin->saveState());
|
||||||
QPoint windowPos = ssWindow->pos();
|
}
|
||||||
left = windowPos.x();
|
|
||||||
top = windowPos.y();
|
|
||||||
width = ssWindow->geometry().width();
|
|
||||||
height = ssWindow->geometry().height();
|
|
||||||
bool isMaximized = ssWindow->isMaximized();
|
|
||||||
|
|
||||||
settings->FreezeInt(key + "_Left", left);
|
|
||||||
settings->FreezeInt(key + "_Top", top);
|
|
||||||
settings->FreezeInt(key + "_Width", width);
|
|
||||||
settings->FreezeInt(key + "_Height", height);
|
|
||||||
settings->FreezeBool(key + "_Maximized", isMaximized);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThawPosition(SettingsRef settings, const std::string& key) override {
|
void ThawPosition(SettingsRef settings, const std::string& key) override {
|
||||||
int left = 100, top = 100, width = 0, height = 0;
|
QMainWindow* mwin = qobject_cast<QMainWindow*>(ssWindow);
|
||||||
|
if (mwin) {
|
||||||
left = settings->ThawInt(key + "_Left", left);
|
QSettings& qset = std::static_pointer_cast<SettingsImplQt>(settings)->qset;
|
||||||
top = settings->ThawInt(key + "_Top", top);
|
QString qkey = QString::fromStdString(key);
|
||||||
width = settings->ThawInt(key + "_Width", width);
|
mwin->restoreGeometry(qset.value(qkey + "_Geometry").toByteArray());
|
||||||
height = settings->ThawInt(key + "_Height", height);
|
mwin->restoreState(qset.value(qkey + "_State").toByteArray());
|
||||||
|
|
||||||
if(width != 0 && height != 0) {
|
|
||||||
ssWindow->move(left, top);
|
|
||||||
ssWindow->resize(width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (settings->ThawBool(key + "_Maximized", false)) {
|
|
||||||
// ssWindow->SetFullScreen(true);
|
|
||||||
ssWindow->setWindowState(Qt::WindowMaximized);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue