ui: gui wrapper extension
- added classes for qt layout abstraction. review id = 18
This commit is contained in:
@@ -5,6 +5,8 @@ add_files(
|
||||
qt/element/QtArea.h
|
||||
qt/element/QtCanvas.cpp
|
||||
qt/element/QtCanvas.h
|
||||
qt/element/QtLayout.cpp
|
||||
qt/element/QtLayout.h
|
||||
|
||||
qt/QtWidgetWrapper.cpp
|
||||
qt/QtWidgetWrapper.h
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "qt/element/QtArea.h"
|
||||
#include "qt/element/QtCanvas.h"
|
||||
#include "qt/element/QtLayout.h"
|
||||
#include "qt/QtWindow.h"
|
||||
|
||||
QtElementFactory::QtElementFactory()
|
||||
@@ -23,3 +24,8 @@ std::shared_ptr<GuiCanvas> QtElementFactory::createCanvas(std::shared_ptr<GuiWin
|
||||
window->setCanvas(canvas);
|
||||
return canvas;
|
||||
}
|
||||
|
||||
std::shared_ptr<GuiLayout> QtElementFactory::createLayout() const
|
||||
{
|
||||
return std::make_shared<QtLayout>();
|
||||
}
|
||||
|
||||
@@ -3,10 +3,6 @@
|
||||
|
||||
#include "gui/GuiElementFactory.h"
|
||||
|
||||
class GuiArea;
|
||||
class GuiCanvas;
|
||||
class GuiWindow;
|
||||
|
||||
class QtElementFactory: public GuiElementFactory
|
||||
{
|
||||
public:
|
||||
@@ -15,6 +11,7 @@ public:
|
||||
|
||||
virtual std::shared_ptr<GuiArea> createArea() const;
|
||||
virtual std::shared_ptr<GuiCanvas> createCanvas(std::shared_ptr<GuiWindow> window) const;
|
||||
virtual std::shared_ptr<GuiLayout> createLayout() const;
|
||||
};
|
||||
|
||||
# endif // QT_ELEMENT_FACTORY_H
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
QtCanvas::QtCanvas()
|
||||
: GuiCanvas(std::make_shared<QtWidgetWrapper>(std::make_shared<QGroupBox>()))
|
||||
{
|
||||
QBoxLayout *layout = new QBoxLayout(QBoxLayout::TopToBottom); // gets deleted by qt
|
||||
QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom); // gets deleted by qt
|
||||
getWidget()->setLayout(layout);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
#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);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#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
|
||||
@@ -81,6 +81,8 @@ add_files(
|
||||
gui/GuiElement.h
|
||||
gui/GuiElementFactory.cpp
|
||||
gui/GuiElementFactory.h
|
||||
gui/GuiLayout.cpp
|
||||
gui/GuiLayout.h
|
||||
gui/GuiWindow.cpp
|
||||
gui/GuiWindow.h
|
||||
gui/WidgetWrapper.cpp
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
class GuiArea;
|
||||
class GuiCanvas;
|
||||
class GuiLayout;
|
||||
class GuiWindow;
|
||||
|
||||
class GuiElementFactory
|
||||
@@ -14,6 +15,7 @@ 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;
|
||||
};
|
||||
|
||||
#endif // GUI_ELEMENT_FACTORY_H
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
#include "gui/GuiLayout.h"
|
||||
|
||||
GuiLayout::GuiLayout(std::shared_ptr<WidgetWrapper> widgetWrapper)
|
||||
: GuiContainer(widgetWrapper)
|
||||
{
|
||||
}
|
||||
|
||||
GuiLayout::~GuiLayout()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#ifndef GUI_LAYOUT_H
|
||||
#define GUI_LAYOUT_H
|
||||
|
||||
#include "gui/GuiContainer.h"
|
||||
|
||||
class GuiLayout: public GuiContainer
|
||||
{
|
||||
public:
|
||||
enum LayoutDirectionType
|
||||
{
|
||||
LAYOUT_DIRECTION_HORIZONTAL,
|
||||
LAYOUT_DIRECTION_VERTICAL
|
||||
};
|
||||
|
||||
GuiLayout(std::shared_ptr<WidgetWrapper> widgetWrapper);
|
||||
virtual ~GuiLayout();
|
||||
|
||||
virtual void setDirection(LayoutDirectionType direction) = 0;
|
||||
|
||||
virtual void addChild(std::shared_ptr<GuiElement> element) = 0;
|
||||
virtual void removeChild(std::shared_ptr<GuiElement> element) = 0;
|
||||
};
|
||||
|
||||
#endif // GUI_LAYOUT_H
|
||||
Reference in New Issue
Block a user