ui: basic search view
- Added a basic SearchView (+ controller and qt implementation) - SearchView can set the active element of other views by dispatching a message. - SearchView adjusts its text when the active element is changed by other views. - Added wrappers for Button and EditBox that allow the usage of simple callback functions.
This commit is contained in:
@@ -3,8 +3,10 @@
|
||||
#include "component/Component.h"
|
||||
#include "component/controller/CodeController.h"
|
||||
#include "component/controller/GraphController.h"
|
||||
#include "component/controller/SearchController.h"
|
||||
#include "component/view/CodeView.h"
|
||||
#include "component/view/GraphView.h"
|
||||
#include "component/view/SearchView.h"
|
||||
#include "component/view/ViewLayout.h"
|
||||
#include "gui/GuiFactory.h"
|
||||
|
||||
@@ -44,6 +46,15 @@ std::shared_ptr<Component> ComponentFactory::createGraphComponent()
|
||||
return component;
|
||||
}
|
||||
|
||||
std::shared_ptr<Component> ComponentFactory::createSearchComponent()
|
||||
{
|
||||
std::shared_ptr<SearchView> view = m_guiFactory->createSearchView(m_viewLayout);
|
||||
std::shared_ptr<SearchController> controller = std::make_shared<SearchController>(m_graphAccess);
|
||||
|
||||
std::shared_ptr<Component> component = std::make_shared<Component>(view, controller);
|
||||
return component;
|
||||
}
|
||||
|
||||
ComponentFactory::ComponentFactory()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ public:
|
||||
|
||||
std::shared_ptr<Component> createCodeComponent();
|
||||
std::shared_ptr<Component> createGraphComponent();
|
||||
std::shared_ptr<Component> createSearchComponent();
|
||||
|
||||
private:
|
||||
ComponentFactory();
|
||||
|
||||
@@ -28,11 +28,13 @@ void ComponentManager::setup()
|
||||
GraphView* graphView = graphComponent->getView<GraphView>();
|
||||
graphView->addNode(Vec2i(-100, -100), "foo");
|
||||
graphView->addNode(Vec2i(50, 50), "bar");
|
||||
|
||||
m_components.push_back(graphComponent);
|
||||
|
||||
std::shared_ptr<Component> codeComponent = m_componentFactory->createCodeComponent();
|
||||
m_components.push_back(codeComponent);
|
||||
|
||||
std::shared_ptr<Component> searchComponent = m_componentFactory->createSearchComponent();
|
||||
m_components.push_back(searchComponent);
|
||||
}
|
||||
|
||||
ComponentManager::ComponentManager()
|
||||
|
||||
@@ -17,7 +17,9 @@ struct AnnotatedText
|
||||
Id tokenId;
|
||||
};
|
||||
|
||||
class CodeController: public Controller, public MessageListener<MessageActivateToken>
|
||||
class CodeController
|
||||
: public Controller
|
||||
, public MessageListener<MessageActivateToken>
|
||||
{
|
||||
public:
|
||||
CodeController(std::shared_ptr<LocationAccess> locationAccess);
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
#include "component/controller/SearchController.h"
|
||||
|
||||
#include "component/view/SearchView.h"
|
||||
#include "data/access/GraphAccess.h"
|
||||
#include "utility/messaging/type/MessageActivateToken.h"
|
||||
|
||||
SearchController::SearchController(std::shared_ptr<GraphAccess> graphAccess)
|
||||
: m_graphAccess(graphAccess)
|
||||
{
|
||||
}
|
||||
|
||||
SearchController::~SearchController()
|
||||
{
|
||||
}
|
||||
|
||||
void SearchController::search(const std::string& s)
|
||||
{
|
||||
LOG_INFO("searching string: \"" + s + "\"");
|
||||
Id nodeId = m_graphAccess->getIdForNodeWithName(s);
|
||||
if (nodeId > 0)
|
||||
{
|
||||
LOG_INFO("Node with name \"" + s + "\" found.");
|
||||
MessageActivateToken message(nodeId);
|
||||
message.dispatch();
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_INFO("Node with name \"" + s + "\" not found.");
|
||||
}
|
||||
}
|
||||
|
||||
void SearchController::handleMessage(MessageActivateToken* message)
|
||||
{
|
||||
getView()->setText(m_graphAccess->getNameForNodeWithId(message->tokenId));
|
||||
}
|
||||
|
||||
SearchView* SearchController::getView()
|
||||
{
|
||||
return Controller::getView<SearchView>();
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifndef SEARCH_CONTROLLER_H
|
||||
#define SEARCH_CONTROLLER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "component/controller/Controller.h"
|
||||
#include "utility/messaging/MessageListener.h"
|
||||
#include "utility/messaging/type/MessageActivateToken.h"
|
||||
|
||||
class GraphAccess;
|
||||
class SearchView;
|
||||
|
||||
class SearchController
|
||||
: public Controller
|
||||
, public MessageListener<MessageActivateToken>
|
||||
{
|
||||
public:
|
||||
SearchController(std::shared_ptr<GraphAccess> graphAccess);
|
||||
~SearchController();
|
||||
|
||||
void search(const std::string& s);
|
||||
//void autocomplete(const std::string& s);
|
||||
|
||||
private:
|
||||
virtual void handleMessage(MessageActivateToken* message);
|
||||
SearchView* getView();
|
||||
|
||||
std::shared_ptr<GraphAccess> m_graphAccess;
|
||||
};
|
||||
|
||||
#endif // SEARCH_CONTROLLER_H
|
||||
@@ -0,0 +1,22 @@
|
||||
#include "component/view/SearchView.h"
|
||||
|
||||
#include "component/controller/SearchController.h"
|
||||
|
||||
SearchView::SearchView(ViewLayout* viewLayout)
|
||||
: View(viewLayout, Vec2i(100, 100))
|
||||
{
|
||||
}
|
||||
|
||||
SearchView::~SearchView()
|
||||
{
|
||||
}
|
||||
|
||||
std::string SearchView::getName() const
|
||||
{
|
||||
return "SearchView";
|
||||
}
|
||||
|
||||
SearchController* SearchView::getController()
|
||||
{
|
||||
return View::getController<SearchController>();
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef SEARCH_VIEW_H
|
||||
#define SEARCH_VIEW_H
|
||||
|
||||
#include "component/view/View.h"
|
||||
|
||||
class SearchController;
|
||||
|
||||
class SearchView : public View
|
||||
{
|
||||
public:
|
||||
SearchView(ViewLayout* viewLayout);
|
||||
virtual ~SearchView();
|
||||
|
||||
virtual std::string getName() const;
|
||||
|
||||
virtual void setText(const std::string& s) const = 0;
|
||||
|
||||
protected:
|
||||
SearchController* getController();
|
||||
};
|
||||
|
||||
#endif // SEARCH_VIEW_H
|
||||
Reference in New Issue
Block a user