ui: save and load view layout
* QtMainWindow now saves and loads its layout parameters.
This commit is contained in:
@@ -7,4 +7,6 @@
|
||||
/bin/test/Release/
|
||||
/bin/test/data/log/
|
||||
|
||||
/bin/app/data/window_settings.ini
|
||||
|
||||
.DS_Store
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <QDockWidget>
|
||||
#include <QMenuBar>
|
||||
#include <QMessageBox>
|
||||
#include <QSettings>
|
||||
|
||||
#include "component/view/View.h"
|
||||
#include "qt/QtWidgetWrapper.h"
|
||||
@@ -86,6 +87,60 @@ void QtMainWindow::removeView(View* view)
|
||||
}
|
||||
}
|
||||
|
||||
void QtMainWindow::loadLayout()
|
||||
{
|
||||
QSettings settings("data/window_settings.ini", QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup("MainWindow");
|
||||
resize(settings.value("size", QSize(600, 400)).toSize());
|
||||
move(settings.value("position", QPoint(200, 200)).toPoint());
|
||||
if (settings.value("maximized", false).toBool())
|
||||
{
|
||||
showMaximized();
|
||||
}
|
||||
settings.endGroup();
|
||||
|
||||
for (size_t i = 0; i < m_dockWidgets.size(); i++)
|
||||
{
|
||||
View* view = m_dockWidgets[i].first;
|
||||
QDockWidget* dockWidget = m_dockWidgets[i].second;
|
||||
|
||||
settings.beginGroup(view->getName().c_str());
|
||||
dockWidget->setFloating(settings.value("floating", false).toBool());
|
||||
dockWidget->setHidden(settings.value("hidden", false).toBool());
|
||||
dockWidget->resize(settings.value("size", QSize(400, 400)).toSize());
|
||||
dockWidget->move(settings.value("position", QPoint(200, 200)).toPoint());
|
||||
settings.endGroup();
|
||||
}
|
||||
}
|
||||
|
||||
void QtMainWindow::saveLayout()
|
||||
{
|
||||
QSettings settings("data/window_settings.ini", QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup("MainWindow");
|
||||
settings.setValue("maximized", isMaximized());
|
||||
if (!isMaximized())
|
||||
{
|
||||
settings.setValue("size", size());
|
||||
settings.setValue("position", pos());
|
||||
}
|
||||
settings.endGroup();
|
||||
|
||||
for (size_t i = 0; i < m_dockWidgets.size(); i++)
|
||||
{
|
||||
View* view = m_dockWidgets[i].first;
|
||||
QDockWidget* dockWidget = m_dockWidgets[i].second;
|
||||
|
||||
settings.beginGroup(view->getName().c_str());
|
||||
settings.setValue("floating", dockWidget->isFloating());
|
||||
settings.setValue("hidden", dockWidget->isHidden());
|
||||
settings.setValue("size", dockWidget->size());
|
||||
settings.setValue("position", dockWidget->pos());
|
||||
settings.endGroup();
|
||||
}
|
||||
}
|
||||
|
||||
void QtMainWindow::setupProjectMenu()
|
||||
{
|
||||
QMenu *menu = new QMenu(tr("&Project"), this);
|
||||
|
||||
@@ -20,6 +20,9 @@ public:
|
||||
void addView(View* view);
|
||||
void removeView(View* view);
|
||||
|
||||
void loadLayout();
|
||||
void saveLayout();
|
||||
|
||||
public slots:
|
||||
void about();
|
||||
void newProject();
|
||||
|
||||
@@ -31,3 +31,13 @@ void QtMainView::removeView(View* view)
|
||||
m_window->removeView(view);
|
||||
m_views.erase(it);
|
||||
}
|
||||
|
||||
void QtMainView::loadLayout()
|
||||
{
|
||||
m_window->loadLayout();
|
||||
}
|
||||
|
||||
void QtMainView::saveLayout()
|
||||
{
|
||||
m_window->saveLayout();
|
||||
}
|
||||
|
||||
@@ -19,6 +19,9 @@ public:
|
||||
void addView(View* view);
|
||||
void removeView(View* view);
|
||||
|
||||
virtual void loadLayout();
|
||||
virtual void saveLayout();
|
||||
|
||||
private:
|
||||
std::shared_ptr<QtMainWindow> m_window;
|
||||
std::vector<View*> m_views;
|
||||
|
||||
@@ -27,6 +27,7 @@ std::shared_ptr<Application> Application::create(GuiFactory* guiFactory)
|
||||
guiFactory, ptr->m_mainView.get(), ptr->m_graphAccessProxy.get(), ptr->m_locationAccessProxy.get());
|
||||
|
||||
ptr->m_componentManager->setup();
|
||||
ptr->m_mainView->loadLayout();
|
||||
|
||||
return ptr;
|
||||
}
|
||||
@@ -39,6 +40,7 @@ Application::Application()
|
||||
Application::~Application()
|
||||
{
|
||||
MessageQueue::getInstance()->stopMessageLoop();
|
||||
m_mainView->saveLayout();
|
||||
}
|
||||
|
||||
void Application::loadProject(const std::string& projectSettingsFilePath)
|
||||
|
||||
@@ -22,12 +22,6 @@ ComponentManager::~ComponentManager()
|
||||
void ComponentManager::setup()
|
||||
{
|
||||
std::shared_ptr<Component> graphComponent = m_componentFactory->createGraphComponent();
|
||||
|
||||
GraphView* graphView = graphComponent->getView<GraphView>();
|
||||
/*std::weak_ptr<GraphNode> node0 = graphView->addNode(Vec2i(-50, -50), "foo");
|
||||
graphView->addEdge(node0, graphView->addNode(Vec2i(100, 100), "bar"));
|
||||
graphView->addEdge(node0, graphView->addNode(Vec2i(50, -50), "war production co-ordinating commitee"));*/
|
||||
|
||||
m_components.push_back(graphComponent);
|
||||
|
||||
std::shared_ptr<Component> codeComponent = m_componentFactory->createCodeComponent();
|
||||
|
||||
@@ -11,6 +11,9 @@ public:
|
||||
|
||||
virtual void addView(View* view) = 0;
|
||||
virtual void removeView(View* view) = 0;
|
||||
|
||||
virtual void loadLayout() = 0;
|
||||
virtual void saveLayout() = 0;
|
||||
};
|
||||
|
||||
#endif // VIEW_LAYOUT_H
|
||||
|
||||
Reference in New Issue
Block a user