Add in the parts to load and save widgets between uses
This commit is contained in:
@@ -1,2 +1,5 @@
|
||||
add_subdirectory(WebBrowserPlugin)
|
||||
add_subdirectory(CalculatorPlugin)
|
||||
add_subdirectory(IrcClientPlugin)
|
||||
add_subdirectory(TerminalPlugin)
|
||||
add_subdirectory(ScreenShotPlugin)
|
||||
|
||||
@@ -9,10 +9,10 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
createActions();
|
||||
createMenus();
|
||||
this->setWindowIcon(QIcon::fromTheme(QIcon::ThemeIcon::Computer));
|
||||
initSettings();
|
||||
mdi = new QMdiArea;
|
||||
this->setCentralWidget(mdi);
|
||||
loadPlugins();
|
||||
initSettings();
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
@@ -64,22 +64,70 @@ void MainWindow::about()
|
||||
void MainWindow::initSettings()
|
||||
{
|
||||
QSettings settings("SOM", "SOM");
|
||||
if (!settings.contains("window/size")) {
|
||||
settings.setValue("window/size", QSize(800, 600));
|
||||
settings.setValue("window/position", (this->screen()->geometry().center() - this->frameGeometry().center()));
|
||||
|
||||
if (!settings.contains("window/geometry")) {
|
||||
this->resize(QSize(800, 600));
|
||||
this->move(this->screen()->geometry().center() - this->frameGeometry().center());
|
||||
settings.setValue("window/geometry", this->saveGeometry());
|
||||
settings.sync();
|
||||
}
|
||||
resize(settings.value("window/size", QSize(800, 600)).toSize());
|
||||
move(settings.value("window/position", QPoint(100, 100)).toPoint());
|
||||
this->restoreGeometry(settings.value("window/geometry").toByteArray());
|
||||
|
||||
settings.beginGroup("Plugins");
|
||||
for (const QString &group : settings.childGroups()) {
|
||||
settings.beginGroup(group);
|
||||
|
||||
QString pluginName = group.section('_', 0, 0);
|
||||
pluginName = QUrl::fromPercentEncoding(pluginName.toUtf8());
|
||||
|
||||
Interface *iPlugin = nullptr;
|
||||
|
||||
for (QAction *action : toolsMenu->actions()) {
|
||||
auto candidate = qobject_cast<Interface *>(action->parent());
|
||||
if (candidate && candidate->pname() == pluginName) {
|
||||
iPlugin = candidate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (iPlugin) {
|
||||
QWidget *pluginWidget = iPlugin->pcontent();
|
||||
if (pluginWidget) {
|
||||
QMdiSubWindow *sub = mdi->addSubWindow(pluginWidget);
|
||||
sub->setProperty("uniqueId", group);
|
||||
sub->restoreGeometry(settings.value("geometry").toByteArray());
|
||||
sub->setAttribute(Qt::WA_DeleteOnClose);
|
||||
sub->show();
|
||||
}
|
||||
}
|
||||
|
||||
settings.endGroup();
|
||||
}
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::saveSettings()
|
||||
{
|
||||
QSettings settings("SOM", "SOM");
|
||||
settings.setValue("window/size", size());
|
||||
settings.setValue("window/position", pos());
|
||||
settings.setValue("window/geometry", this->saveGeometry());
|
||||
|
||||
settings.beginGroup("Plugins");
|
||||
settings.remove("");
|
||||
settings.endGroup();
|
||||
|
||||
settings.beginGroup("Plugins");
|
||||
QList<QMdiSubWindow*> subWindows = mdi->subWindowList();
|
||||
for (QMdiSubWindow* sub : subWindows) {
|
||||
QString id = sub->windowTitle() + "_" + sub->property("uniqueId").toString();
|
||||
settings.beginGroup(id);
|
||||
settings.setValue("geometry", sub->saveGeometry());
|
||||
settings.endGroup();
|
||||
}
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
saveSettings();
|
||||
@@ -107,7 +155,6 @@ void MainWindow::loadPlugins()
|
||||
if (plugin) {
|
||||
|
||||
populateMenu(plugin);
|
||||
pluginFileNames += fileName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -122,8 +169,11 @@ void MainWindow::changePlugin()
|
||||
if (!iPlugin)
|
||||
return;
|
||||
|
||||
QString pluginName = iPlugin->pname();
|
||||
QString uniqueId = QUuid::createUuid().toString();
|
||||
QWidget* pluginContent = iPlugin->pcontent();
|
||||
auto *sub = mdi->addSubWindow(pluginContent);
|
||||
sub->setProperty("uniqueId", uniqueId);
|
||||
sub->setAttribute(Qt::WA_DeleteOnClose);
|
||||
sub->show();
|
||||
}
|
||||
|
||||
@@ -41,7 +41,6 @@ private:
|
||||
QAction *aboutAct;
|
||||
QAction *aboutQtAct;
|
||||
QAction *settingsAct;
|
||||
QStringList pluginFileNames;
|
||||
QDir pluginsDir;
|
||||
QMdiArea *mdi;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user