From b29209a79e68fa3b9a471594c9e6478017159ec3 Mon Sep 17 00:00:00 2001 From: malte_langkabel Date: Mon, 19 May 2014 11:44:04 +0200 Subject: [PATCH] ui: gui wrapper extension - added classes for qt layout abstraction. review id = 18 --- src/app/CMakeLists.txt | 2 + src/app/qt/QtElementFactory.cpp | 6 +++ src/app/qt/QtElementFactory.h | 5 +-- src/app/qt/element/QtCanvas.cpp | 2 +- src/app/qt/element/QtLayout.cpp | 70 +++++++++++++++++++++++++++++++++ src/app/qt/element/QtLayout.h | 33 ++++++++++++++++ src/lib/CMakeLists.txt | 2 + src/lib/gui/GuiElementFactory.h | 2 + src/lib/gui/GuiLayout.cpp | 10 +++++ src/lib/gui/GuiLayout.h | 24 +++++++++++ 10 files changed, 151 insertions(+), 5 deletions(-) create mode 100644 src/app/qt/element/QtLayout.cpp create mode 100644 src/app/qt/element/QtLayout.h create mode 100644 src/lib/gui/GuiLayout.cpp create mode 100644 src/lib/gui/GuiLayout.h diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 53e1d67d..9743d682 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -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 diff --git a/src/app/qt/QtElementFactory.cpp b/src/app/qt/QtElementFactory.cpp index dc811450..754425e4 100644 --- a/src/app/qt/QtElementFactory.cpp +++ b/src/app/qt/QtElementFactory.cpp @@ -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 QtElementFactory::createCanvas(std::shared_ptrsetCanvas(canvas); return canvas; } + +std::shared_ptr QtElementFactory::createLayout() const +{ + return std::make_shared(); +} diff --git a/src/app/qt/QtElementFactory.h b/src/app/qt/QtElementFactory.h index 9e82672d..9d81b00d 100644 --- a/src/app/qt/QtElementFactory.h +++ b/src/app/qt/QtElementFactory.h @@ -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 createArea() const; virtual std::shared_ptr createCanvas(std::shared_ptr window) const; + virtual std::shared_ptr createLayout() const; }; # endif // QT_ELEMENT_FACTORY_H diff --git a/src/app/qt/element/QtCanvas.cpp b/src/app/qt/element/QtCanvas.cpp index 93e05fe0..630ffa09 100644 --- a/src/app/qt/element/QtCanvas.cpp +++ b/src/app/qt/element/QtCanvas.cpp @@ -9,7 +9,7 @@ QtCanvas::QtCanvas() : GuiCanvas(std::make_shared(std::make_shared())) { - QBoxLayout *layout = new QBoxLayout(QBoxLayout::TopToBottom); // gets deleted by qt + QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom); // gets deleted by qt getWidget()->setLayout(layout); } diff --git a/src/app/qt/element/QtLayout.cpp b/src/app/qt/element/QtLayout.cpp new file mode 100644 index 00000000..9ea52754 --- /dev/null +++ b/src/app/qt/element/QtLayout.cpp @@ -0,0 +1,70 @@ +#include "qt/element/QtLayout.h" + +#include +#include + +#include "qt/QtWidgetWrapper.h" +#include "utility/utilityQt.h" + +QtLayout::QtLayout() + : GuiLayout(std::make_shared(std::make_shared())) +{ + 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 element) +{ + m_layout->addWidget(QtWidgetWrapper::getWidgetOfElement(element).get()); +} + +void QtLayout::removeChild(std::shared_ptr element) +{ + std::shared_ptr 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 QtLayout::getWidget() +{ + return QtWidgetWrapper::getWidgetOfElement(this); +} diff --git a/src/app/qt/element/QtLayout.h b/src/app/qt/element/QtLayout.h new file mode 100644 index 00000000..9d0ea7c7 --- /dev/null +++ b/src/app/qt/element/QtLayout.h @@ -0,0 +1,33 @@ +#ifndef QT_LAYOUT_H +#define QT_LAYOUT_H + +#include +#include + +#include "gui/GuiLayout.h" + +class QtLayout: public GuiLayout +{ +public: + QtLayout(); + virtual ~QtLayout(); + + virtual void setDirection(LayoutDirectionType direction); + + virtual void addChild(std::shared_ptr element); + virtual void removeChild(std::shared_ptr 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 getWidget(); + + QBoxLayout* m_layout; +}; + +# endif // QT_LAYOUT_H diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 38dc28b4..6db84a59 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -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 diff --git a/src/lib/gui/GuiElementFactory.h b/src/lib/gui/GuiElementFactory.h index 785c0fef..34ca532c 100644 --- a/src/lib/gui/GuiElementFactory.h +++ b/src/lib/gui/GuiElementFactory.h @@ -5,6 +5,7 @@ class GuiArea; class GuiCanvas; +class GuiLayout; class GuiWindow; class GuiElementFactory @@ -14,6 +15,7 @@ public: virtual std::shared_ptr createArea() const = 0; virtual std::shared_ptr createCanvas(std::shared_ptr window) const = 0; + virtual std::shared_ptr createLayout() const = 0; }; #endif // GUI_ELEMENT_FACTORY_H diff --git a/src/lib/gui/GuiLayout.cpp b/src/lib/gui/GuiLayout.cpp new file mode 100644 index 00000000..7682ecad --- /dev/null +++ b/src/lib/gui/GuiLayout.cpp @@ -0,0 +1,10 @@ +#include "gui/GuiLayout.h" + +GuiLayout::GuiLayout(std::shared_ptr widgetWrapper) + : GuiContainer(widgetWrapper) +{ +} + +GuiLayout::~GuiLayout() +{ +} diff --git a/src/lib/gui/GuiLayout.h b/src/lib/gui/GuiLayout.h new file mode 100644 index 00000000..5aaf609a --- /dev/null +++ b/src/lib/gui/GuiLayout.h @@ -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); + virtual ~GuiLayout(); + + virtual void setDirection(LayoutDirectionType direction) = 0; + + virtual void addChild(std::shared_ptr element) = 0; + virtual void removeChild(std::shared_ptr element) = 0; +}; + +#endif // GUI_LAYOUT_H