From bfa87eda2fda2edb7c23528fa15db0d95fc57e22 Mon Sep 17 00:00:00 2001 From: Wieczorek Bartosz Date: Wed, 15 Mar 2017 17:29:44 +0100 Subject: [PATCH] refactor --- src/eedb/widgets/MainWindow.cpp | 72 ++++++++++++++++++++++++++------- src/eedb/widgets/MainWindow.hpp | 2 + src/eedb/widgets/Theme.cpp | 2 +- 3 files changed, 60 insertions(+), 16 deletions(-) diff --git a/src/eedb/widgets/MainWindow.cpp b/src/eedb/widgets/MainWindow.cpp index 373e42c..be3102a 100644 --- a/src/eedb/widgets/MainWindow.cpp +++ b/src/eedb/widgets/MainWindow.cpp @@ -14,8 +14,48 @@ #include #include +#include +#include +#include +#include +#include + +#include +#include + namespace eedb { +auto make_tree() { + Wt::WTree * tree = new Wt::WTree(); + + tree->setSelectionMode(Wt::ExtendedSelection); + + Wt::WIconPair * folderIcon = new Wt::WIconPair("icons/yellow-folder-closed.png", "icons/yellow-folder-open.png", false); + + Wt::WTreeNode * node = new Wt::WTreeNode("Furniture", folderIcon); + + tree->setTreeRoot(node); + node->label()->setTextFormat(Wt::PlainText); + node->setLoadPolicy(Wt::WTreeNode::NextLevelLoading); + node->addChildNode(new Wt::WTreeNode("Table")); + node->addChildNode(new Wt::WTreeNode("Cupboard")); + + Wt::WTreeNode * three = new Wt::WTreeNode("Chair"); + node->addChildNode(three); + node->addChildNode(new Wt::WTreeNode("Coach")); + node->expand(); + + three->addChildNode(new Wt::WTreeNode("Doc")); + three->addChildNode(new Wt::WTreeNode("Grumpy")); + three->addChildNode(new Wt::WTreeNode("Happy")); + three->addChildNode(new Wt::WTreeNode("Sneezy")); + three->addChildNode(new Wt::WTreeNode("Dopey")); + three->addChildNode(new Wt::WTreeNode("Bashful")); + three->addChildNode(new Wt::WTreeNode("Sleepy")); + + return tree; +} + eedb::Home::Home(Wt::WContainerWidget * container, Wt::Auth::Login * login) : _login(login) { // Create a navigation bar with a link to a web page. auto navigation = new Wt::WNavigationBar(container); @@ -57,23 +97,25 @@ eedb::Home::Home(Wt::WContainerWidget * container, Wt::Auth::Login * login) : _l sessionMenu->addItem(sessionItem); navigation->addMenu(sessionMenu, Wt::AlignRight); - Wt::WBorderLayout * layout = new Wt::WBorderLayout(); - container->setLayout(layout); + Wt::WVBoxLayout * vbox = new Wt::WVBoxLayout(); + container->setLayout(vbox); + vbox->addWidget(navigation, 1); + + Wt::WHBoxLayout * hbox = new Wt::WHBoxLayout(); + vbox->addLayout(hbox, 30); Wt::WStackedWidget * contents = new Wt::WStackedWidget(); - layout->addWidget(navigation, Wt::WBorderLayout::North); - - layout->addWidget(new Wt::WText("West"), Wt::WBorderLayout::West); - - auto item = new Wt::WText(Wt::WString("East")); - item->setStyleClass("green-box"); - layout->addWidget(item, Wt::WBorderLayout::East); - - item = new Wt::WText(Wt::WString("South")); - item->setStyleClass("green-box"); - layout->addWidget(item, Wt::WBorderLayout::South); - - layout->addWidget(contents, Wt::WBorderLayout::Center); + _categoryTree = make_tree(); + _categoryTree->itemSelectionChanged().connect([=](auto...) { + auto nodes = _categoryTree->selectedNodes(); + for(const auto & node : nodes) { + Wt::log("notice") << "selected node:" << node->label()->text(); + } + Wt::log("notice") << "Item selection changed"; + }); + hbox->addWidget(_categoryTree, 1); + hbox->addWidget(contents, 2); + hbox->setResizable(0, true); } } diff --git a/src/eedb/widgets/MainWindow.hpp b/src/eedb/widgets/MainWindow.hpp index 930200c..5977d36 100644 --- a/src/eedb/widgets/MainWindow.hpp +++ b/src/eedb/widgets/MainWindow.hpp @@ -1,5 +1,6 @@ namespace Wt { class WContainerWidget; +class WTree; } namespace Wt::Auth { class Login; @@ -12,5 +13,6 @@ class Home { private: const Wt::Auth::Login * _login; + Wt::WTree * _categoryTree; }; } diff --git a/src/eedb/widgets/Theme.cpp b/src/eedb/widgets/Theme.cpp index 122e5c8..a847609 100644 --- a/src/eedb/widgets/Theme.cpp +++ b/src/eedb/widgets/Theme.cpp @@ -7,7 +7,7 @@ BootstrapTheme::BootstrapTheme(Wt::WObject * parent) : _parent(parent) {} Wt::WTheme * BootstrapTheme::create() const { auto theme = new Wt::WBootstrapTheme(_parent); - theme->setVersion(Wt::WBootstrapTheme::Version3); + theme->setVersion(Wt::WBootstrapTheme::Version2); // theme->setResponsive(true); return theme; }