ui: Abstracting the UI on view level instead of element level
This change switches the view creation architecture from element based creation in the lib to view based creation in the app. This avoids wrapping of the Qt elements and instead defines interfaces for the different View implementations. * GuiElementFactory was renamed to GuiFactory and is now responsible for View creation instead of Element creation. * WidgetWrappers are now used on Views to access their root widget. * Removed DummyView and DummyController. * Removed GuiElement and corresponding QtElement files. * Removed ViewManager, functionality is now handled via MainView. * Added MainView, where Views are registered via the ViewLayout interface. * Added QtMainWindow, derived from QMainWindow and instantiated by QtMainView, which displays the Views as QDockWidgets. fortune cookie message = All your hard work will soon pay off.
This commit is contained in:
@@ -1,43 +0,0 @@
|
||||
#include "qt/element/QtArea.h"
|
||||
|
||||
#include <qframe.h>
|
||||
|
||||
#include "qt/QtWidgetWrapper.h"
|
||||
#include "utility/utilityQt.h"
|
||||
|
||||
QtArea::QtArea()
|
||||
: GuiArea(std::make_shared<QtWidgetWrapper>(std::make_shared<QFrame>()))
|
||||
{
|
||||
}
|
||||
|
||||
QtArea::~QtArea()
|
||||
{
|
||||
}
|
||||
|
||||
void QtArea::setPosition(Vec2i position)
|
||||
{
|
||||
}
|
||||
|
||||
Vec2i QtArea::getPosition() const
|
||||
{
|
||||
return Vec2i();
|
||||
}
|
||||
|
||||
void QtArea::setSize(Vec2i size)
|
||||
{
|
||||
}
|
||||
|
||||
Vec2i QtArea::getSize() const
|
||||
{
|
||||
return Vec2i();
|
||||
}
|
||||
|
||||
void QtArea::setBackgroundColor(Colori color)
|
||||
{
|
||||
utility::setWidgetBackgroundColor(getWidget(), color);
|
||||
}
|
||||
|
||||
std::shared_ptr<QWidget> QtArea::getWidget()
|
||||
{
|
||||
return QtWidgetWrapper::getWidgetOfElement(this);
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
#ifndef QT_AREA_H
|
||||
#define QT_AREA_H
|
||||
|
||||
#include <qwidget.h>
|
||||
|
||||
#include "gui/GuiArea.h"
|
||||
|
||||
class QtArea: public GuiArea
|
||||
{
|
||||
public:
|
||||
QtArea();
|
||||
virtual ~QtArea();
|
||||
|
||||
virtual void setPosition(Vec2i position);
|
||||
virtual Vec2i getPosition() const;
|
||||
virtual void setSize(Vec2i size);
|
||||
virtual Vec2i getSize() const;
|
||||
|
||||
virtual void setBackgroundColor(Colori color);
|
||||
|
||||
private:
|
||||
std::shared_ptr<QWidget> getWidget();
|
||||
};
|
||||
|
||||
# endif // QT_AREA_H
|
||||
@@ -1,59 +0,0 @@
|
||||
#include "qt/element/QtCanvas.h"
|
||||
|
||||
#include <qgroupbox.h>
|
||||
#include <qlayout.h>
|
||||
|
||||
#include "qt/QtWidgetWrapper.h"
|
||||
#include "utility/utilityQt.h"
|
||||
|
||||
QtCanvas::QtCanvas()
|
||||
: GuiCanvas(std::make_shared<QtWidgetWrapper>(std::make_shared<QGroupBox>()))
|
||||
{
|
||||
QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom); // gets deleted by qt
|
||||
getWidget()->setLayout(layout);
|
||||
}
|
||||
|
||||
QtCanvas::~QtCanvas()
|
||||
{
|
||||
}
|
||||
|
||||
void QtCanvas::addChild(std::shared_ptr<GuiElement> element)
|
||||
{
|
||||
getWidget()->layout()->addWidget(QtWidgetWrapper::getWidgetOfElement(element).get());
|
||||
}
|
||||
|
||||
void QtCanvas::removeChild(std::shared_ptr<GuiElement> element)
|
||||
{
|
||||
std::shared_ptr<QWidget> widgetToRemove = QtWidgetWrapper::getWidgetOfElement(element);
|
||||
getWidget()->layout()->removeWidget(widgetToRemove.get());
|
||||
widgetToRemove->setGeometry(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
void QtCanvas::setPosition(Vec2i position)
|
||||
{
|
||||
}
|
||||
|
||||
Vec2i QtCanvas::getPosition() const
|
||||
{
|
||||
return Vec2i();
|
||||
}
|
||||
|
||||
void QtCanvas::setSize(Vec2i size)
|
||||
{
|
||||
}
|
||||
|
||||
Vec2i QtCanvas::getSize() const
|
||||
{
|
||||
return Vec2i();
|
||||
}
|
||||
|
||||
void QtCanvas::setBackgroundColor(Colori color)
|
||||
{
|
||||
utility::setWidgetBackgroundColor(getWidget(), color);
|
||||
}
|
||||
|
||||
std::shared_ptr<QWidget> QtCanvas::getWidget()
|
||||
{
|
||||
return QtWidgetWrapper::getWidgetOfElement(this);
|
||||
}
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
#ifndef QT_CANVAS_H
|
||||
#define QT_CANVAS_H
|
||||
|
||||
#include <qwidget.h>
|
||||
#include <QtWidgets/QMainWindow>
|
||||
|
||||
#include "gui/GuiCanvas.h"
|
||||
|
||||
class QtCanvas: public GuiCanvas
|
||||
{
|
||||
public:
|
||||
QtCanvas();
|
||||
virtual ~QtCanvas();
|
||||
|
||||
virtual void addChild(std::shared_ptr<GuiElement> element);
|
||||
virtual void removeChild(std::shared_ptr<GuiElement> element);
|
||||
|
||||
virtual void setPosition(Vec2i position);
|
||||
virtual Vec2i getPosition() const;
|
||||
virtual void setSize(Vec2i size);
|
||||
virtual Vec2i getSize() const;
|
||||
|
||||
virtual void setBackgroundColor(Colori color);
|
||||
|
||||
private:
|
||||
std::shared_ptr<QWidget> getWidget();
|
||||
};
|
||||
|
||||
# endif // QT_CANVAS_H
|
||||
@@ -1,70 +0,0 @@
|
||||
#include "qt/element/QtLayout.h"
|
||||
|
||||
#include <qgroupbox.h>
|
||||
#include <qlayout.h>
|
||||
|
||||
#include "qt/QtWidgetWrapper.h"
|
||||
#include "utility/utilityQt.h"
|
||||
|
||||
QtLayout::QtLayout()
|
||||
: GuiLayout(std::make_shared<QtWidgetWrapper>(std::make_shared<QGroupBox>()))
|
||||
{
|
||||
m_layout = new QBoxLayout(QBoxLayout::TopToBottom); // gets deleted by qt
|
||||
getWidget()->setLayout(m_layout);
|
||||
}
|
||||
|
||||
QtLayout::~QtLayout()
|
||||
{
|
||||
}
|
||||
|
||||
void QtLayout::setDirection(LayoutDirectionType direction)
|
||||
{
|
||||
switch (direction)
|
||||
{
|
||||
case LAYOUT_DIRECTION_HORIZONTAL:
|
||||
m_layout->setDirection(QBoxLayout::LeftToRight);
|
||||
case LAYOUT_DIRECTION_VERTICAL:
|
||||
m_layout->setDirection(QBoxLayout::TopToBottom);
|
||||
}
|
||||
getWidget()->setLayout(m_layout);
|
||||
}
|
||||
|
||||
void QtLayout::addChild(std::shared_ptr<GuiElement> element)
|
||||
{
|
||||
m_layout->addWidget(QtWidgetWrapper::getWidgetOfElement(element).get());
|
||||
}
|
||||
|
||||
void QtLayout::removeChild(std::shared_ptr<GuiElement> element)
|
||||
{
|
||||
std::shared_ptr<QWidget> widgetToRemove = QtWidgetWrapper::getWidgetOfElement(element);
|
||||
m_layout->removeWidget(widgetToRemove.get());
|
||||
widgetToRemove->setGeometry(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
void QtLayout::setPosition(Vec2i position)
|
||||
{
|
||||
}
|
||||
|
||||
Vec2i QtLayout::getPosition() const
|
||||
{
|
||||
return Vec2i();
|
||||
}
|
||||
|
||||
void QtLayout::setSize(Vec2i size)
|
||||
{
|
||||
}
|
||||
|
||||
Vec2i QtLayout::getSize() const
|
||||
{
|
||||
return Vec2i();
|
||||
}
|
||||
|
||||
void QtLayout::setBackgroundColor(Colori color)
|
||||
{
|
||||
utility::setWidgetBackgroundColor(getWidget(), color);
|
||||
}
|
||||
|
||||
std::shared_ptr<QWidget> QtLayout::getWidget()
|
||||
{
|
||||
return QtWidgetWrapper::getWidgetOfElement(this);
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
#ifndef QT_LAYOUT_H
|
||||
#define QT_LAYOUT_H
|
||||
|
||||
#include <qwidget.h>
|
||||
#include <qlayout.h>
|
||||
|
||||
#include "gui/GuiLayout.h"
|
||||
|
||||
class QtLayout: public GuiLayout
|
||||
{
|
||||
public:
|
||||
QtLayout();
|
||||
virtual ~QtLayout();
|
||||
|
||||
virtual void setDirection(LayoutDirectionType direction);
|
||||
|
||||
virtual void addChild(std::shared_ptr<GuiElement> element);
|
||||
virtual void removeChild(std::shared_ptr<GuiElement> element);
|
||||
|
||||
virtual void setPosition(Vec2i position);
|
||||
virtual Vec2i getPosition() const;
|
||||
virtual void setSize(Vec2i size);
|
||||
virtual Vec2i getSize() const;
|
||||
|
||||
virtual void setBackgroundColor(Colori color);
|
||||
|
||||
private:
|
||||
std::shared_ptr<QWidget> getWidget();
|
||||
|
||||
QBoxLayout* m_layout;
|
||||
};
|
||||
|
||||
# endif // QT_LAYOUT_H
|
||||
@@ -0,0 +1,37 @@
|
||||
#include "qt/element/QtMainWindow.h"
|
||||
|
||||
#include <QDockWidget>
|
||||
|
||||
#include "component/view/View.h"
|
||||
#include "qt/QtWidgetWrapper.h"
|
||||
|
||||
QtMainWindow::QtMainWindow()
|
||||
{
|
||||
setObjectName("QtMainWindow");
|
||||
setCentralWidget(nullptr);
|
||||
}
|
||||
|
||||
QtMainWindow::~QtMainWindow()
|
||||
{
|
||||
}
|
||||
|
||||
void QtMainWindow::addView(View* view)
|
||||
{
|
||||
QDockWidget* dock = new QDockWidget(tr(view->getName().c_str()), this);
|
||||
dock->setWidget(QtWidgetWrapper::getWidgetOfView(view));
|
||||
addDockWidget(Qt::TopDockWidgetArea, dock);
|
||||
m_dockWidgets.push_back(std::make_pair(view, dock));
|
||||
}
|
||||
|
||||
void QtMainWindow::removeView(View* view)
|
||||
{
|
||||
for (size_t i = 0; i < m_dockWidgets.size(); i++)
|
||||
{
|
||||
if (m_dockWidgets[i].first == view)
|
||||
{
|
||||
removeDockWidget(m_dockWidgets[i].second);
|
||||
m_dockWidgets.erase(m_dockWidgets.begin() + i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef QT_MAIN_WINDOW_H
|
||||
#define QT_MAIN_WINDOW_H
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <QtWidgets/QMainWindow>
|
||||
|
||||
class QDockWidget;
|
||||
class View;
|
||||
|
||||
class QtMainWindow: public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QtMainWindow();
|
||||
~QtMainWindow();
|
||||
|
||||
void addView(View* view);
|
||||
void removeView(View* view);
|
||||
|
||||
private:
|
||||
std::vector<std::pair<View*, QDockWidget*> > m_dockWidgets;
|
||||
};
|
||||
|
||||
#endif // QT_MAIN_WINDOW_H
|
||||
Reference in New Issue
Block a user