ui: basic CodeView with syntax highlighting

Added CodeView interface and QtCodeView implementation for showing syntax highlighted code snippets. This change avoids
using the GuiElement hierarchy by using directly using QtClasses and creating QtCodeView in the QtElementFactory.
This commit is contained in:
Eberhard Graether
2014-06-30 13:50:19 +02:00
parent 1045ce4ab9
commit 73b74cb618
17 changed files with 325 additions and 17 deletions
+4 -2
View File
@@ -23,6 +23,8 @@ add_files(
component/controller/DummyController.cpp
component/controller/DummyController.h
component/view/CodeView.cpp
component/view/CodeView.h
component/view/DummyView.cpp
component/view/DummyView.h
component/view/View.cpp
@@ -114,10 +116,10 @@ add_files(
utility/messaging/MessageListenerBase.h
utility/messaging/MessageQueue.cpp
utility/messaging/MessageQueue.h
utility/text/TextAccess.cpp
utility/text/TextAccess.h
utility/ConfigManager.cpp
utility/ConfigManager.h
utility/FileSystem.cpp
+10
View File
@@ -9,3 +9,13 @@ Component::Component(std::shared_ptr<View> view, std::shared_ptr<Controller> con
Component::~Component()
{
}
Controller* Component::getController() const
{
return m_controller.get();
}
View* Component::getView() const
{
return m_view.get();
}
+5 -3
View File
@@ -10,12 +10,14 @@ class Component
{
public:
Component(std::shared_ptr<View> view, std::shared_ptr<Controller> controller);
~Component();
Controller* getController() const;
View* getView() const;
private:
std::shared_ptr<Controller> m_controller;
std::shared_ptr<View> m_view;
const std::shared_ptr<Controller> m_controller;
const std::shared_ptr<View> m_view;
};
+12 -1
View File
@@ -1,7 +1,9 @@
#include "component/ComponentFactory.h"
#include "component/view/DummyView.h"
#include "component/controller/CodeController.h"
#include "component/controller/DummyController.h"
#include "component/view/CodeView.h"
#include "component/view/DummyView.h"
std::shared_ptr<ComponentFactory> ComponentFactory::create(
std::shared_ptr<ViewManager> viewManager,
@@ -30,6 +32,15 @@ std::shared_ptr<Component> ComponentFactory::createDummyComponent()
return component;
}
std::shared_ptr<Component> ComponentFactory::createCodeComponent()
{
std::shared_ptr<View> view = m_guiElementFactory->createCodeView(m_viewManger);
std::shared_ptr<Controller> controller = std::make_shared<CodeController>();
std::shared_ptr<Component> component = std::make_shared<Component>(view, controller);
return component;
}
ComponentFactory::ComponentFactory()
{
}
+1
View File
@@ -21,6 +21,7 @@ public:
~ComponentFactory();
std::shared_ptr<Component> createDummyComponent();
std::shared_ptr<Component> createCodeComponent();
private:
ComponentFactory();
+10
View File
@@ -1,5 +1,7 @@
#include "component/ComponentManager.h"
#include "component/view/CodeView.h"
std::shared_ptr<ComponentManager> ComponentManager::create(
std::shared_ptr<ViewManager> viewManager,
std::shared_ptr<GuiElementFactory> guiElementFactory,
@@ -14,6 +16,14 @@ std::shared_ptr<ComponentManager> ComponentManager::create(
void ComponentManager::setup()
{
m_components.push_back(m_componentFactory->createDummyComponent());
std::shared_ptr<Component> codeComponent = m_componentFactory->createCodeComponent();
m_components.push_back(codeComponent);
CodeView* codeView = dynamic_cast<CodeView*>(codeComponent->getView());
codeView->addCodeSnippet("class HelloWorld;");
codeView->addCodeSnippet("static int n = 42; // the answer.");
// codeView->clearCodeSnippets();
}
ComponentManager::ComponentManager()
+10
View File
@@ -0,0 +1,10 @@
#include "component/view/CodeView.h"
CodeView::CodeView(std::shared_ptr<ViewManager> viewManager, std::shared_ptr<GuiElement> rootElement)
: View(viewManager, rootElement, Vec2i(100, 100))
{
}
CodeView::~CodeView()
{
}
+20
View File
@@ -0,0 +1,20 @@
#ifndef CODE_VIEW_H
#define CODE_VIEW_H
#include <string>
#include "component/view/View.h"
class GuiElementFactory;
class CodeView: public View
{
public:
CodeView(std::shared_ptr<ViewManager> viewManager, std::shared_ptr<GuiElement> rootElement);
virtual ~CodeView();
virtual void addCodeSnippet(std::string str) = 0;
virtual void clearCodeSnippets() = 0;
};
#endif // CODE_VIEW_H
+6
View File
@@ -3,11 +3,15 @@
#include <memory>
class CodeView;
class GuiArea;
class GuiCanvas;
class GuiLayout;
class GuiWindow;
class ViewManager;
class GuiElementFactory
{
public:
@@ -16,6 +20,8 @@ public:
virtual std::shared_ptr<GuiArea> createArea() const = 0;
virtual std::shared_ptr<GuiCanvas> createCanvas(std::shared_ptr<GuiWindow> window) const = 0;
virtual std::shared_ptr<GuiLayout> createLayout() const = 0;
virtual std::shared_ptr<CodeView> createCodeView(std::shared_ptr<ViewManager> viewManager) const = 0;
};
#endif // GUI_ELEMENT_FACTORY_H