diff --git a/widgets/notebook.cpp b/widgets/notebook.cpp index c850cfad5..cf1ddb8f3 100644 --- a/widgets/notebook.cpp +++ b/widgets/notebook.cpp @@ -230,7 +230,7 @@ Notebook::save(boost::property_tree::ptree &tree) boost::property_tree::ptree pChats = page->save(); if (pChats.size() > 0) { - pTab.add_child("chats", pChats); + pTab.add_child("columns", pChats); } tabs.push_back(std::make_pair("", pTab)); diff --git a/widgets/notebookpage.cpp b/widgets/notebookpage.cpp index 015ee4be4..591ecdbe1 100644 --- a/widgets/notebookpage.cpp +++ b/widgets/notebookpage.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -242,30 +243,104 @@ NotebookPage::paintEvent(QPaintEvent *) } } +static std::pair +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 +NotebookPage::getChatPosition(const ChatWidget *chatWidget) +{ + auto layout = this->hbox.layout(); + + if (layout == nullptr) { + return std::make_pair(-1, -1); + } + + return getWidgetPositionInLayout(layout, chatWidget); +} + void NotebookPage::load(const boost::property_tree::ptree &tree) { try { - BOOST_FOREACH (const boost::property_tree::ptree::value_type &v, - tree.get_child("chats.")) { - auto widget = new ChatWidget(); - widget->load(v.second); - this->addToLayout(widget, std::pair(-1, -1)); + int column = 0; + for (const auto &v : tree.get_child("columns.")) { + int row = 0; + for (const auto &innerV : v.second.get_child("")) { + auto widget = new ChatWidget(); + widget->load(innerV.second); + this->addToLayout(widget, std::pair(column, row)); + ++row; + } + ++column; } } catch (boost::property_tree::ptree_error &) { // 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(widget); + + if (chatWidget != nullptr) { + boost::property_tree::ptree chat = chatWidget->save(); + + tree.push_back(std::make_pair("", chat)); + continue; + } + } +} + boost::property_tree::ptree NotebookPage::save() { boost::property_tree::ptree tree; + auto layout = this->hbox.layout(); + + saveFromLayout(layout, tree); + + /* for (const auto &chat : this->chatWidgets) { boost::property_tree::ptree child = chat->save(); + + // Set child position + child.put("position", "5,3"); + tree.push_back(std::make_pair("", child)); } + */ return tree; } diff --git a/widgets/notebookpage.h b/widgets/notebookpage.h index c7e7f35f5..50c04cc9e 100644 --- a/widgets/notebookpage.h +++ b/widgets/notebookpage.h @@ -72,6 +72,8 @@ protected: private: void setPreviewRect(QPoint mousePos); + std::pair getChatPosition(const ChatWidget *chatWidget); + public: void load(const boost::property_tree::ptree &tree); boost::property_tree::ptree save();