mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
split layout is now saved too
This commit is contained in:
parent
199e87896b
commit
3266f8ad4f
3 changed files with 83 additions and 6 deletions
|
@ -230,7 +230,7 @@ Notebook::save(boost::property_tree::ptree &tree)
|
||||||
boost::property_tree::ptree pChats = page->save();
|
boost::property_tree::ptree pChats = page->save();
|
||||||
|
|
||||||
if (pChats.size() > 0) {
|
if (pChats.size() > 0) {
|
||||||
pTab.add_child("chats", pChats);
|
pTab.add_child("columns", pChats);
|
||||||
}
|
}
|
||||||
|
|
||||||
tabs.push_back(std::make_pair("", pTab));
|
tabs.push_back(std::make_pair("", pTab));
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
|
#include <QObject>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
@ -242,30 +243,104 @@ NotebookPage::paintEvent(QPaintEvent *)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::pair<int, int>
|
||||||
|
getWidgetPositionInLayout(QLayout *layout, const ChatWidget *chatWidget)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < layout->count(); ++i) {
|
||||||
|
printf("xD\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::make_pair(-1, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::pair<int, int>
|
||||||
|
NotebookPage::getChatPosition(const ChatWidget *chatWidget)
|
||||||
|
{
|
||||||
|
auto layout = this->hbox.layout();
|
||||||
|
|
||||||
|
if (layout == nullptr) {
|
||||||
|
return std::make_pair(-1, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return getWidgetPositionInLayout(layout, chatWidget);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
NotebookPage::load(const boost::property_tree::ptree &tree)
|
NotebookPage::load(const boost::property_tree::ptree &tree)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
BOOST_FOREACH (const boost::property_tree::ptree::value_type &v,
|
int column = 0;
|
||||||
tree.get_child("chats.")) {
|
for (const auto &v : tree.get_child("columns.")) {
|
||||||
auto widget = new ChatWidget();
|
int row = 0;
|
||||||
widget->load(v.second);
|
for (const auto &innerV : v.second.get_child("")) {
|
||||||
this->addToLayout(widget, std::pair<int, int>(-1, -1));
|
auto widget = new ChatWidget();
|
||||||
|
widget->load(innerV.second);
|
||||||
|
this->addToLayout(widget, std::pair<int, int>(column, row));
|
||||||
|
++row;
|
||||||
|
}
|
||||||
|
++column;
|
||||||
}
|
}
|
||||||
} catch (boost::property_tree::ptree_error &) {
|
} catch (boost::property_tree::ptree_error &) {
|
||||||
// can't read tabs
|
// can't read tabs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
saveFromLayout(QLayout *layout, boost::property_tree::ptree &tree)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < layout->count(); ++i) {
|
||||||
|
auto item = layout->itemAt(i);
|
||||||
|
|
||||||
|
auto innerLayout = item->layout();
|
||||||
|
if (innerLayout != nullptr) {
|
||||||
|
boost::property_tree::ptree innerLayoutTree;
|
||||||
|
|
||||||
|
saveFromLayout(innerLayout, innerLayoutTree);
|
||||||
|
|
||||||
|
if (innerLayoutTree.size() > 0) {
|
||||||
|
tree.push_back(std::make_pair("", innerLayoutTree));
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto widget = item->widget();
|
||||||
|
|
||||||
|
if (widget == nullptr) {
|
||||||
|
// This layoutitem does not manage a widget for some reason
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ChatWidget *chatWidget = qobject_cast<ChatWidget *>(widget);
|
||||||
|
|
||||||
|
if (chatWidget != nullptr) {
|
||||||
|
boost::property_tree::ptree chat = chatWidget->save();
|
||||||
|
|
||||||
|
tree.push_back(std::make_pair("", chat));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
boost::property_tree::ptree
|
boost::property_tree::ptree
|
||||||
NotebookPage::save()
|
NotebookPage::save()
|
||||||
{
|
{
|
||||||
boost::property_tree::ptree tree;
|
boost::property_tree::ptree tree;
|
||||||
|
|
||||||
|
auto layout = this->hbox.layout();
|
||||||
|
|
||||||
|
saveFromLayout(layout, tree);
|
||||||
|
|
||||||
|
/*
|
||||||
for (const auto &chat : this->chatWidgets) {
|
for (const auto &chat : this->chatWidgets) {
|
||||||
boost::property_tree::ptree child = chat->save();
|
boost::property_tree::ptree child = chat->save();
|
||||||
|
|
||||||
|
// Set child position
|
||||||
|
child.put("position", "5,3");
|
||||||
|
|
||||||
tree.push_back(std::make_pair("", child));
|
tree.push_back(std::make_pair("", child));
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
return tree;
|
return tree;
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,6 +72,8 @@ protected:
|
||||||
private:
|
private:
|
||||||
void setPreviewRect(QPoint mousePos);
|
void setPreviewRect(QPoint mousePos);
|
||||||
|
|
||||||
|
std::pair<int, int> getChatPosition(const ChatWidget *chatWidget);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void load(const boost::property_tree::ptree &tree);
|
void load(const boost::property_tree::ptree &tree);
|
||||||
boost::property_tree::ptree save();
|
boost::property_tree::ptree save();
|
||||||
|
|
Loading…
Reference in a new issue