diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 51696964..3f5e2e44 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -9,8 +9,13 @@ add_files( qt/utility/utilityQt.cpp qt/utility/utilityQt.h + qt/view/graphElements/QtGraphNode.cpp + qt/view/graphElements/QtGraphNode.h + qt/view/QtCodeView.cpp qt/view/QtCodeView.h + qt/view/QtGraphView.cpp + qt/view/QtGraphView.h qt/view/QtMainView.cpp qt/view/QtMainView.h diff --git a/src/app/qt/QtGuiFactory.cpp b/src/app/qt/QtGuiFactory.cpp index da6e69c9..5f040101 100644 --- a/src/app/qt/QtGuiFactory.cpp +++ b/src/app/qt/QtGuiFactory.cpp @@ -1,6 +1,7 @@ #include "qt/QtGuiFactory.h" #include "qt/view/QtCodeView.h" +#include "qt/view/QtGraphView.h" #include "qt/view/QtMainView.h" QtGuiFactory::QtGuiFactory() @@ -20,3 +21,8 @@ std::shared_ptr QtGuiFactory::createCodeView(ViewLayout* viewLayout) c { return View::create(viewLayout); } + +std::shared_ptr QtGuiFactory::createGraphView(ViewLayout* viewLayout) const +{ + return View::create(viewLayout); +} diff --git a/src/app/qt/QtGuiFactory.h b/src/app/qt/QtGuiFactory.h index af0e2700..95787346 100644 --- a/src/app/qt/QtGuiFactory.h +++ b/src/app/qt/QtGuiFactory.h @@ -11,6 +11,7 @@ public: virtual std::shared_ptr createMainView() const; virtual std::shared_ptr createCodeView(ViewLayout* viewLayout) const; + virtual std::shared_ptr createGraphView(ViewLayout* viewLayout) const; }; #endif // QT_GUI_FACTORY_H diff --git a/src/app/qt/view/QtGraphView.cpp b/src/app/qt/view/QtGraphView.cpp new file mode 100644 index 00000000..a12a8812 --- /dev/null +++ b/src/app/qt/view/QtGraphView.cpp @@ -0,0 +1,67 @@ +#include "QtGraphView.h" + +#include "qboxlayout.h" +#include "qgraphicsitem.h" +#include "qgraphicsproxywidget.h" +#include "qgraphicsscene.h" +#include "qgraphicsview.h" +#include "qpushbutton.h" + +#include "qt/utility/utilityQt.h" + +#include "qt/QtWidgetWrapper.h" +#include "qt/view/graphElements/QtGraphNode.h" + +QtGraphView::QtGraphView(ViewLayout* viewLayout) + : GraphView(viewLayout) +{ +} + +QtGraphView::~QtGraphView() +{ +} + +void QtGraphView::createWidgetWrapper() +{ + setWidgetWrapper(std::make_shared(std::make_shared())); +} + +void QtGraphView::initGui() +{ + QWidget* widget = QtWidgetWrapper::getWidgetOfView(this); + utility::setWidgetBackgroundColor(widget, Colori(100, 20, 200, 255)); + + QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom); + layout->setSpacing(3); + layout->setContentsMargins(3, 3, 3, 3); + widget->setLayout(layout); + + QGraphicsScene* scene = new QGraphicsScene(widget); + + QGraphicsView* view = new QGraphicsView(widget); + view->setScene(scene); + + widget->layout()->addWidget(view); +} + +void QtGraphView::addNode(const Vec2i& position, const std::string& name) +{ + QWidget* widget = QtWidgetWrapper::getWidgetOfView(this); + + QLayout* layout = widget->layout(); + + QObjectList children = widget->children(); + + QGraphicsView* view = widget->findChild(""); + + if(view != NULL) + { + QtGraphNode* node = new QtGraphNode(position, name); + view->scene()->addItem(node); + node->setFlag(QGraphicsItem::ItemIsMovable); + } + else + { + LOG_WARNING("Unable to retrieve view from widget"); + } +} diff --git a/src/app/qt/view/QtGraphView.h b/src/app/qt/view/QtGraphView.h new file mode 100644 index 00000000..891cfe1a --- /dev/null +++ b/src/app/qt/view/QtGraphView.h @@ -0,0 +1,19 @@ +#ifndef QT_GRAPH_VIEW_H +#define QT_GRAPH_VIEW_H + +#include "component/view/GraphView.h" + +class QtGraphView : public GraphView +{ +public: + QtGraphView(ViewLayout* viewLayout); + virtual ~QtGraphView(); + + // View implementation + virtual void createWidgetWrapper(); + virtual void initGui(); + + virtual void addNode(const Vec2i& position, const std::string& name); +}; + +#endif // QT_GRAPH_VIEW_H diff --git a/src/app/qt/view/graphElements/QtGraphNode.cpp b/src/app/qt/view/graphElements/QtGraphNode.cpp new file mode 100644 index 00000000..38037b67 --- /dev/null +++ b/src/app/qt/view/graphElements/QtGraphNode.cpp @@ -0,0 +1,20 @@ +#include "qt/view/graphElements/QtGraphNode.h" + +#include "qgraphicsscene.h" + + + +QtGraphNode::QtGraphNode(const Vec2i& position, const std::string& name) +{ + this->setRect(position.x, position.y, 100, 100); + QBrush brush(Qt::lightGray); + this->setBrush(brush); + + m_text = new QGraphicsTextItem(this); + m_text->setPos(position.x, position.y); + m_text->setPlainText(QString(name.c_str())); +} + +QtGraphNode::~QtGraphNode() +{ +} \ No newline at end of file diff --git a/src/app/qt/view/graphElements/QtGraphNode.h b/src/app/qt/view/graphElements/QtGraphNode.h new file mode 100644 index 00000000..7ff1d8ce --- /dev/null +++ b/src/app/qt/view/graphElements/QtGraphNode.h @@ -0,0 +1,22 @@ +#ifndef QT_GRAPH_NODE_H +#define QT_GRAPH_NODE_H + +#include "qgraphicsitem.h" + +#include "utility/math/Vector2.h" + +#include "component/view/graphElements/GraphNode.h" + +class QtGraphNode: + public GraphNode, + public QGraphicsRectItem +{ +public: + QtGraphNode(const Vec2i& position, const std::string& name); + virtual ~QtGraphNode(); + +private: + QGraphicsTextItem* m_text; +}; + +#endif // QT_GRAPH_NODE_H diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index df182c5d..1096ec67 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -21,15 +21,20 @@ add_files( component/controller/Controller.cpp component/controller/Controller.h + component/view/graphElements/GraphNode.cpp + component/view/graphElements/GraphNode.h + component/view/CodeView.cpp component/view/CodeView.h + component/view/GraphView.cpp + component/view/GraphView.h component/view/MainView.cpp component/view/MainView.h component/view/View.cpp component/view/View.h component/view/ViewLayout.cpp - component/view/ViewLayout.h - + component/view/ViewLayout.h + component/Component.cpp component/Component.h component/ComponentFactory.cpp diff --git a/src/lib/component/ComponentFactory.cpp b/src/lib/component/ComponentFactory.cpp index 1140b4d4..c53feb25 100644 --- a/src/lib/component/ComponentFactory.cpp +++ b/src/lib/component/ComponentFactory.cpp @@ -2,6 +2,7 @@ #include "component/controller/CodeController.h" #include "component/view/CodeView.h" +#include "component/view/GraphView.h" #include "component/view/ViewLayout.h" #include "gui/GuiFactory.h" @@ -32,6 +33,15 @@ std::shared_ptr ComponentFactory::createCodeComponent() return component; } +std::shared_ptr ComponentFactory::createGraphComponent() +{ + std::shared_ptr view = m_guiFactory->createGraphView(m_viewLayout); + std::shared_ptr controller = std::make_shared(); + + std::shared_ptr component = std::make_shared(view, controller); + return component; +} + ComponentFactory::ComponentFactory() { } diff --git a/src/lib/component/ComponentFactory.h b/src/lib/component/ComponentFactory.h index ef74b800..2205c130 100644 --- a/src/lib/component/ComponentFactory.h +++ b/src/lib/component/ComponentFactory.h @@ -22,6 +22,7 @@ public: ~ComponentFactory(); std::shared_ptr createCodeComponent(); + std::shared_ptr createGraphComponent(); private: ComponentFactory(); diff --git a/src/lib/component/ComponentManager.cpp b/src/lib/component/ComponentManager.cpp index d8e451f7..a8e58d0e 100644 --- a/src/lib/component/ComponentManager.cpp +++ b/src/lib/component/ComponentManager.cpp @@ -1,6 +1,7 @@ #include "component/ComponentManager.h" #include "component/view/CodeView.h" +#include "component/view/GraphView.h" #include "component/view/ViewLayout.h" std::shared_ptr ComponentManager::create( @@ -20,6 +21,13 @@ ComponentManager::~ComponentManager() void ComponentManager::setup() { + std::shared_ptr graphComponent = m_componentFactory->createGraphComponent(); + GraphView* graphView = dynamic_cast(graphComponent->getView()); + graphView->addNode(Vec2i(-100, -100), "foo"); + graphView->addNode(Vec2i(50, 50), "bar"); + + m_components.push_back(graphComponent); + std::shared_ptr codeComponent = m_componentFactory->createCodeComponent(); m_components.push_back(codeComponent); diff --git a/src/lib/component/view/GraphView.cpp b/src/lib/component/view/GraphView.cpp new file mode 100644 index 00000000..a6bab76f --- /dev/null +++ b/src/lib/component/view/GraphView.cpp @@ -0,0 +1,15 @@ +#include "component/view/GraphView.h" + +GraphView::GraphView(ViewLayout* viewLayout) + : View(viewLayout, Vec2i(100, 100)) +{ +} + +GraphView::~GraphView() +{ +} + +std::string GraphView::getName() const +{ + return "GraphView"; +} diff --git a/src/lib/component/view/GraphView.h b/src/lib/component/view/GraphView.h new file mode 100644 index 00000000..716503c2 --- /dev/null +++ b/src/lib/component/view/GraphView.h @@ -0,0 +1,17 @@ +#ifndef GRAPH_VIEW_H +#define GRAPH_VIEW_H + +#include "component/view/View.h" + +class GraphView : public View +{ +public: + GraphView(ViewLayout* viewLayout); + virtual ~GraphView(); + + virtual std::string getName() const; + + virtual void addNode(const Vec2i& position, const std::string& name) = 0; +}; + +#endif // GRAPH_VIEW_H \ No newline at end of file diff --git a/src/lib/component/view/graphElements/GraphNode.cpp b/src/lib/component/view/graphElements/GraphNode.cpp new file mode 100644 index 00000000..d9c8fdea --- /dev/null +++ b/src/lib/component/view/graphElements/GraphNode.cpp @@ -0,0 +1,9 @@ +#include "component/view/graphElements/GraphNode.h" + +GraphNode::GraphNode() +{ +} + +GraphNode::~GraphNode() +{ +} diff --git a/src/lib/component/view/graphElements/GraphNode.h b/src/lib/component/view/graphElements/GraphNode.h new file mode 100644 index 00000000..0f4b42c7 --- /dev/null +++ b/src/lib/component/view/graphElements/GraphNode.h @@ -0,0 +1,11 @@ +#ifndef GRAPH_NODE_H +#define GRAPH_NODE_H + +class GraphNode +{ +public: + GraphNode(); + virtual ~GraphNode(); +}; + +#endif // GRAPH_NODE_H diff --git a/src/lib/gui/GuiFactory.h b/src/lib/gui/GuiFactory.h index f0b35c93..736df1fe 100644 --- a/src/lib/gui/GuiFactory.h +++ b/src/lib/gui/GuiFactory.h @@ -4,6 +4,7 @@ #include class CodeView; +class GraphView; class MainView; class ViewLayout; @@ -15,6 +16,7 @@ public: virtual std::shared_ptr createMainView() const = 0; virtual std::shared_ptr createCodeView(ViewLayout* viewLayout) const = 0; + virtual std::shared_ptr createGraphView(ViewLayout* viewLayout) const = 0; }; #endif // GUI_FACTORY_H