ui: graphView

Added basic graph view with simple nodes (just text, no edges or anything...)

fortune cookie message = Don't be afraid to take that big step.
This commit is contained in:
Manuel Dobusch
2014-07-02 16:14:56 +02:00
parent 5251e3ecb6
commit a8e32af5dd
16 changed files with 220 additions and 2 deletions
+5
View File
@@ -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
+6
View File
@@ -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<CodeView> QtGuiFactory::createCodeView(ViewLayout* viewLayout) c
{
return View::create<QtCodeView>(viewLayout);
}
std::shared_ptr<GraphView> QtGuiFactory::createGraphView(ViewLayout* viewLayout) const
{
return View::create<QtGraphView>(viewLayout);
}
+1
View File
@@ -11,6 +11,7 @@ public:
virtual std::shared_ptr<MainView> createMainView() const;
virtual std::shared_ptr<CodeView> createCodeView(ViewLayout* viewLayout) const;
virtual std::shared_ptr<GraphView> createGraphView(ViewLayout* viewLayout) const;
};
#endif // QT_GUI_FACTORY_H
+67
View File
@@ -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<QtWidgetWrapper>(std::make_shared<QFrame>()));
}
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<QGraphicsView*>("");
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");
}
}
+19
View File
@@ -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
@@ -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()
{
}
@@ -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