QtNovelUI/WordsIDE/vsessionmaintenance.cpp

90 lines
3.5 KiB
C++
Raw Normal View History

2023-08-27 14:09:46 +00:00
#include "vsessionmaintenance.h"
#include "messagespresent.h"
#include "presentcontainer.h"
#include "projectpresent.h"
using namespace Config;
using namespace Core;
using namespace SplitFrame;
using namespace Components;
VSessionMaintenance::VSessionMaintenance(Config::Configration *port) : recover_port(port) {}
void VSessionMaintenance::initPresentView(ViewPresent *host, PresentContainer *center_frame, ProjectPresent *project_present,
QStandardItemModel *error_model) {
auto project_panel = host->appendView(project_present, QIcon(":/ui/icons/dir_icon.jpg"), tr("项目管理"));
host->markFreedom(project_panel);
view_store[project_panel->title()] = project_panel;
auto edit_panel = host->appendView(center_frame, QIcon(":/ui/icons/file_icon.jpg"), tr("编辑窗口"));
host->resetEngross(edit_panel);
view_store[edit_panel->title()] = edit_panel;
auto msg_view = MessagesPresent::gen(host, error_model, host->bind());
auto msg_panel = host->appendView(msg_view, QIcon(":/ui/icons/file_icon.jpg"), "信息提示");
host->markFreedom(msg_panel);
view_store[msg_panel->title()] = msg_panel;
}
const QList<QString> base_path = {"sys-config", "front-end", "view-state"};
void views_state_store(Config::Configration *port, const QList<QString> &base_path, const QList<RectCom *> &child) {
for (auto &it : child) {
if (!it)
continue;
auto keys_path = base_path;
keys_path << QString("rect_%1").arg(child.indexOf(it));
auto conv = dynamic_cast<SplitRect *>(it);
if (conv) { // split
QHash<QString, QString> values;
values["rect-type"] = "split";
values["split-type"] = QString("%1").arg((int)conv->splitType());
values["split-width"] = QString("%1").arg(conv->splitterWidth());
values["split-pos"] = QString("%1").arg(conv->splitterPos());
port->setMap(keys_path, values);
auto split_childs = conv->child();
views_state_store(port, keys_path, QList<RectCom *>() << split_childs.first << split_childs.second);
} else { // view
QHash<QString, QString> values;
values["rect-type"] = "view";
values["view-title"] = it->title();
port->setMap(keys_path, values);
}
}
}
void VSessionMaintenance::viewStatesSave(SplitFrame::ViewPresent *root) {
recover_port->deleteX(base_path);
auto childs = root->child();
auto win = root->bind()->parentWidget();
QHash<QString, QString> values;
values["win-width"] = win->width();
values["win-height"] = win->height();
values["win-xpos"] = win->rect().topLeft().x();
values["win-ypos"] = win->rect().topLeft().y();
recover_port->setMap(base_path, values);
views_state_store(recover_port, base_path, QList<RectCom *>() << childs.first << childs.second);
}
RectCom *views_state_restore(const QHash<QString, RectCom *> &cache, const QList<QString> &target_path, Config::Configration *port) {
auto values = port->getMap(target_path);
if (!values.size())
return nullptr;
}
void VSessionMaintenance::viewStatesRestore(SplitFrame::ViewPresent *root) {
auto values = recover_port->getMap(base_path);
auto win = root->bind()->parentWidget();
auto width = values["win-width"].toFloat();
auto height = values["win-height"].toFloat();
auto xpos = values["win-xpos"].toFloat();
auto ypos = values["win-ypos"].toFloat();
win->setGeometry(xpos, ypos, width, height);
}