From 775c81601bab33ad1363138bae065c2c16eebf1f Mon Sep 17 00:00:00 2001 From: Antoine Chavasse Date: Wed, 11 Jul 2007 18:56:58 +0200 Subject: [PATCH] gui-tool: qt wrapping work. --- editor/main.cpp | 45 +++++++++++++++++++++++++++++++-------------- gui/game/Factory.cpp | 4 ++-- gui/gui.h | 12 ++++++++++++ gui/tool/Button.h | 33 +++++++++++++++++++++++++++++++++ gui/tool/Container.h | 18 ++++++++++++++++++ gui/tool/Factory.cpp | 9 +++++---- gui/tool/QtAwfulContainer.h | 24 ++++++++++++++++++++++++ gui/tool/Widget.h | 16 ++++++++++++++++ gui/tool/guitool.aidl | 4 ++++ toolservices/CMakeLists.txt | 8 ++++++++ 10 files changed, 153 insertions(+), 20 deletions(-) rewrite editor/main.cpp (98%) create mode 100644 gui/gui.h create mode 100644 gui/tool/Button.h create mode 100644 gui/tool/Container.h create mode 100644 gui/tool/QtAwfulContainer.h create mode 100644 gui/tool/Widget.h diff --git a/editor/main.cpp b/editor/main.cpp dissimilarity index 98% index 321f097..24048e9 100644 --- a/editor/main.cpp +++ b/editor/main.cpp @@ -1,14 +1,31 @@ - #include - #include - - int main(int argc, char *argv[]) - { - QApplication app(argc, argv); - - QPushButton hello("Hello world!"); - hello.resize(100, 30); - - hello.show(); - return app.exec(); - } - \ No newline at end of file +#include "gui/gui.h" +#include "gui/tool/Factory.h" +#include "gui/tool/QtAwfulContainer.h" +#include +#include + +using namespace awful; + +Pointer< gui::Widget_i > testGui( const Pointer< gui::Factory_i >& pFactory, const Pointer< gui::Container_i >& pParent ) +{ + return pFactory->newButton( pParent, "for the lulz" ); +} + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + QWidget window; + window.resize(200, 120); + + Pointer< gui::tool::QtAwfulContainer > pQAC = new gui::tool::QtAwfulContainer( &window ); + + Pointer< gui::Factory_i > pFactory = gui::tool::Factory::GetInstance().raw(); + Pointer< gui::Widget_i > pLulz = testGui( pFactory, pQAC.raw() ); + + //QPushButton hello("Hello world!"); + //hello.resize(100, 30); + + window.show(); + return app.exec(); +} diff --git a/gui/game/Factory.cpp b/gui/game/Factory.cpp index d0d7b36..f614b27 100644 --- a/gui/game/Factory.cpp +++ b/gui/game/Factory.cpp @@ -39,11 +39,11 @@ VGroup_i* Factory::newVGroup( Container_i* pParent_ ) return new VGroup( pContainer ); } -Button_i* Factory::newButton( Container_i* pParent_, const std::string& Label_ ) +Button_i* Factory::newButton( Container_i* pParent_, const std::string& Label ) { Container* pContainer = dynamic_cast< Container* >( pParent_ ); if( !pContainer ) return 0; - return new Button( pContainer, Label_ ); + return new Button( pContainer, Label ); } diff --git a/gui/gui.h b/gui/gui.h new file mode 100644 index 0000000..f65a703 --- /dev/null +++ b/gui/gui.h @@ -0,0 +1,12 @@ +#ifndef AWFUL_GUI_H +#define AWFUL_GUI_H + +#include "Container_i.h" +#include "Widget_i.h" +#include "Window_i.h" +#include "HGroup_i.h" +#include "VGroup_i.h" +#include "Button_i.h" +#include "Factory_i.h" + +#endif diff --git a/gui/tool/Button.h b/gui/tool/Button.h new file mode 100644 index 0000000..8b4ca61 --- /dev/null +++ b/gui/tool/Button.h @@ -0,0 +1,33 @@ +#ifndef AWFUL_GUI_TOOL_BUTTON_H_ +#define AWFUL_GUI_TOOL_BUTTON_H_ + +#include "core/core.h" +#include "Container.h" +#include "gui/Button_i.h" +#include + +namespace awful { namespace gui { namespace tool +{ + class Button : public Button_i, public Widget + { + public: + Button( Container* pParent, const std::string& Label ) : + m_QButton( Label.c_str(), &pParent->getQWidget() ) + { + } + + virtual QWidget& getQWidget() + { + return m_QButton; + } + + virtual const std::string& getLabel() const { return lulz; } + virtual void setLabel( const std::string& Label ) { lulz = Label; } + + private: + QPushButton m_QButton; + std::string lulz; + }; +}}} + +#endif diff --git a/gui/tool/Container.h b/gui/tool/Container.h new file mode 100644 index 0000000..33bf02a --- /dev/null +++ b/gui/tool/Container.h @@ -0,0 +1,18 @@ +#ifndef AWFUL_GUI_TOOL_CONTAINER_H_ +#define AWFUL_GUI_TOOL_CONTAINER_H_ + +#include "core/core.h" +#include "Widget.h" +#include "gui/Container_i.h" +#include + +namespace awful { namespace gui { namespace tool +{ + class Container : virtual public Container_i, public Widget + { + public: + + }; +}}} + +#endif diff --git a/gui/tool/Factory.cpp b/gui/tool/Factory.cpp index 9b642c1..77402e4 100644 --- a/gui/tool/Factory.cpp +++ b/gui/tool/Factory.cpp @@ -1,4 +1,6 @@ #include "Factory.h" +#include "Container.h" +#include "Button.h" using namespace awful; using namespace awful::gui; @@ -36,12 +38,11 @@ VGroup_i* Factory::newVGroup( Container_i* pParent_ ) return new VGroup( pContainer );*/ } -Button_i* Factory::newButton( Container_i* pParent_, const std::string& Label_ ) +Button_i* Factory::newButton( Container_i* pParent_, const std::string& Label ) { - return 0; -/* Container* pContainer = dynamic_cast< Container* >( pParent_ ); + Container* pContainer = dynamic_cast< Container* >( pParent_ ); if( !pContainer ) return 0; - return new Button( pContainer, Label_ );*/ + return new Button( pContainer, Label ); } diff --git a/gui/tool/QtAwfulContainer.h b/gui/tool/QtAwfulContainer.h new file mode 100644 index 0000000..40508c0 --- /dev/null +++ b/gui/tool/QtAwfulContainer.h @@ -0,0 +1,24 @@ +#ifndef AWFUL_GUI_TOOL_QTAWFULCONTAINER_H_ +#define AWFUL_GUI_TOOL_QTAWFULCONTAINER_H_ + +#include "core/core.h" +#include "Container.h" +#include + +namespace awful { namespace gui { namespace tool +{ + // This is both a Qt widget and an awful widget container. + // This is to be used as a bridge to embed awful::gui::tool + // widgets and awful::gui widgets into pure Qt code. + class QtAwfulContainer : public QWidget, public Container + { + public: + QtAwfulContainer( QWidget* pParent ) : QWidget( pParent ) {} + virtual QWidget& getQWidget() + { + return *this; + } + }; +}}} + +#endif diff --git a/gui/tool/Widget.h b/gui/tool/Widget.h new file mode 100644 index 0000000..ea4aada --- /dev/null +++ b/gui/tool/Widget.h @@ -0,0 +1,16 @@ +#ifndef AWFUL_GUI_TOOL_WIDGET_H_ +#define AWFUL_GUI_TOOL_WIDGET_H_ + +#include "core/core.h" +#include + +namespace awful { namespace gui { namespace tool +{ + class Widget : virtual public Widget_i + { + public: + virtual QWidget& getQWidget() = 0; + }; +}}} + +#endif diff --git a/gui/tool/guitool.aidl b/gui/tool/guitool.aidl index ff72614..ede4466 100644 --- a/gui/tool/guitool.aidl +++ b/gui/tool/guitool.aidl @@ -7,4 +7,8 @@ namespace awful { namespace gui { namespace tool { static Pointer< Factory > GetInstance(); }; + + class Button : Button_i + { + }; }}} diff --git a/toolservices/CMakeLists.txt b/toolservices/CMakeLists.txt index 9d6fcf7..a859e38 100644 --- a/toolservices/CMakeLists.txt +++ b/toolservices/CMakeLists.txt @@ -1,3 +1,11 @@ +find_package( Qt4 REQUIRED ) + +# Sigh... Why do people define functions that returns things like "const char"? +# Now I have to disable a warning that pops all over the place in Qt headers. +add_definitions( ${QT_DEFINITIONS} -Wno-return-type ) +include_directories( ${QT_INCLUDES} ) +link_directories( ${QT_LIBRARY_DIR} ) + include_directories( ${PROJECT_BINARY_DIR}/gui ) include_directories( ${PROJECT_SOURCE_DIR}/gui ) include_directories( ${PROJECT_BINARY_DIR}/gui/tool ) -- 2.11.4.GIT