From bfa1709e369e97a4a15ad12b5e3be21494fcf6d2 Mon Sep 17 00:00:00 2001 From: sguionni Date: Sat, 22 Jun 2024 16:54:45 +0200 Subject: [PATCH] App creation --- lib/app/include/app/vtx_app.hpp | 1 + lib/app/src/app/vtx_app.cpp | 5 ++ .../include/ui/core/base_ui_application.hpp | 21 +++-- lib/ui/qt/conanfile.py | 2 +- lib/ui/qt/include/qt/application_qt.hpp | 23 ++---- lib/ui/qt/src/qt/application_qt.cpp | 81 +++++-------------- lib/ui/src/ui/core/base_ui_application.cpp | 22 ++--- 7 files changed, 57 insertions(+), 98 deletions(-) diff --git a/lib/app/include/app/vtx_app.hpp b/lib/app/include/app/vtx_app.hpp index 50cc27aff..2a134ae70 100644 --- a/lib/app/include/app/vtx_app.hpp +++ b/lib/app/include/app/vtx_app.hpp @@ -51,6 +51,7 @@ namespace VTX::App inline const Mode::BaseMode & getCurrentMode() const { return *_currentMode; } Util::Callback<> onStart; + Util::Callback<> onStartUI; Util::Callback onPreUpdate; Util::Callback onUpdate; diff --git a/lib/app/src/app/vtx_app.cpp b/lib/app/src/app/vtx_app.cpp index 898c88fd3..a23223ad4 100644 --- a/lib/app/src/app/vtx_app.cpp +++ b/lib/app/src/app/vtx_app.cpp @@ -68,6 +68,11 @@ namespace VTX::App _handleArgs( p_args ); + // Internal::initSettings( App::SETTINGS() ); + + //_currentMode = std::make_unique(); + //_currentMode->enter(); + onStart(); } diff --git a/lib/ui/include/ui/core/base_ui_application.hpp b/lib/ui/include/ui/core/base_ui_application.hpp index 6bf9ab4c8..3daa95186 100644 --- a/lib/ui/include/ui/core/base_ui_application.hpp +++ b/lib/ui/include/ui/core/base_ui_application.hpp @@ -8,19 +8,28 @@ namespace VTX::UI::Core { + struct LayoutDescriptor + { + struct ButtonDescriptor + { + std::string name; + Util::Callback<> callback; + }; + }; + class BaseUIApplication : public App::VTXApp { public: BaseUIApplication(); - virtual void start( const std::vector & p_args ); - virtual void stop() {} + void start( const std::vector & p_args ) override; + void stop() override; protected: - void _buildUI(); - - virtual void _initUI( const std::vector & p_args ) = 0; - virtual void _startUI( const std::vector & p_args ) = 0; + // TODO: concept? + virtual void _init( const std::vector & p_args ) = 0; + virtual void _build( const LayoutDescriptor & ) = 0; + virtual void _start( const std::vector & p_args ) = 0; }; } // namespace VTX::UI::Core diff --git a/lib/ui/qt/conanfile.py b/lib/ui/qt/conanfile.py index 3926f185f..8fc7b88ac 100644 --- a/lib/ui/qt/conanfile.py +++ b/lib/ui/qt/conanfile.py @@ -19,7 +19,7 @@ class VTXUiRecipe(ConanFile): def requirements(self): self.requires("vtx_util/1.0") self.requires("vtx_ui/1.0") - self.requires("qt/6.6.3") + self.requires("qt/6.6.3", transitive_headers=True) def config_options(self): if self.settings.os == "Windows": diff --git a/lib/ui/qt/include/qt/application_qt.hpp b/lib/ui/qt/include/qt/application_qt.hpp index 4b224c93c..fd975b866 100644 --- a/lib/ui/qt/include/qt/application_qt.hpp +++ b/lib/ui/qt/include/qt/application_qt.hpp @@ -4,16 +4,14 @@ #include #include +class QApplication; + namespace VTX::UI::QT { - class QApplication; class MainWindow; - class ApplicationQt : public UI::Core::BaseUIApplication //, public QApplication + class ApplicationQt : public UI::Core::BaseUIApplication { - public: - // static void configure(); - private: inline static const std::string INPUT_MANAGER_KEY = "INPUT_MANAGER"; @@ -23,9 +21,6 @@ namespace VTX::UI::QT ApplicationQt & operator=( const ApplicationQt & ) = delete; ~ApplicationQt(); - void start( const std::vector & p_args ) override; - void stop() override; - inline MainWindow & getMainWindow() { return *_mainWindow; } inline const MainWindow & getMainWindow() const { return *_mainWindow; } @@ -34,15 +29,13 @@ namespace VTX::UI::QT void softQuit(); protected: - void _initUI( const std::vector & p_args ) override; - void _startUI( const std::vector & p_args ) override; - - void _initQt(); - void _instantiateMainWindow(); + void _init( const std::vector & p_args ) override; + void _build( const UI::Core::LayoutDescriptor & p_layout ) override; + void _start( const std::vector & p_args ) override; private: - QApplication * _qApplication = nullptr; - MainWindow * _mainWindow = nullptr; + QApplication * _qApplication; + MainWindow * _mainWindow; }; inline ApplicationQt * const QT_APP() { return &Util::Generic::UniqueInstance::get(); } diff --git a/lib/ui/qt/src/qt/application_qt.cpp b/lib/ui/qt/src/qt/application_qt.cpp index c3c4c52a8..55f92703b 100644 --- a/lib/ui/qt/src/qt/application_qt.cpp +++ b/lib/ui/qt/src/qt/application_qt.cpp @@ -3,7 +3,7 @@ #include "qt/style.hpp" #include "qt/widget/renderer/dialog.hpp" #include "qt/widget_factory.hpp" -#include +#include #include #include #include @@ -18,63 +18,32 @@ namespace VTX::UI::QT { - /* - void ApplicationQt::configure() - { - // Setup some Qt static configuration. - QCoreApplication::setAttribute( Qt::AA_UseDesktopOpenGL ); - QCoreApplication::setAttribute( Qt::AA_DontCheckOpenGLContextThreadAffinity ); - } - */ - int ZERO = 0; ApplicationQt::ApplicationQt() : UI::Core::BaseUIApplication() //, QApplication( ZERO, nullptr ) { VTX_DEBUG( "ApplicationQt::ApplicationQt()" ); - // connect( this, &QCoreApplication::aboutToQuit, this, &ApplicationQt::stop ); } - ApplicationQt::~ApplicationQt() {} - /* - void ApplicationQt::init() + ApplicationQt::~ApplicationQt() { - const FilePath path = VTX::Util::Filesystem::getExecutableDir() / "logs"; - std::filesystem::create_directory( path ); - VTX::Util::Logger::get().init( path ); - - UI::Core::BaseUIApplication::init(); - - //_currentMode = std::make_unique(); + if ( _mainWindow != nullptr ) + { + delete _mainWindow; + } } - */ - void ApplicationQt::start( const std::vector & p_args ) + void ApplicationQt::_init( const std::vector & p_args ) { - UI::Core::BaseUIApplication::start( p_args ); - //_currentMode->enter(); - - //_returnCode = exec(); - } + // Setup some Qt static configuration. + QCoreApplication::setAttribute( Qt::AA_UseDesktopOpenGL ); + QCoreApplication::setAttribute( Qt::AA_DontCheckOpenGLContextThreadAffinity ); - void ApplicationQt::_initUI( const std::vector & p_args ) - { // Internal::initSettings( App::SETTINGS() ); //// Init Modes. // App::Core::init( dynamic_cast( *_currentMode ) ); //_currentMode->enter(); - // Create UI. - _initQt(); - - _instantiateMainWindow(); - - _mainWindow->getMainMenu().setCurrentTab( 0 ); - //_renderWidget->setFocus(); - } - - void ApplicationQt::_initQt() - { /* setWindowIcon( QIcon( ":/sprite/logo.png" ) ); setStyle( QString::fromStdString( Style::DEFAULT_STYLE_FACTORY ) ); @@ -84,33 +53,23 @@ namespace VTX::UI::QT setPalette( appPalette ); */ -#ifdef _DEBUG - QLoggingCategory::setFilterRules( QStringLiteral( "qt.gamepad.debug=true" ) ); -#endif - } + _qApplication = new QApplication( ZERO, nullptr ); + _qApplication->connect( _qApplication, &QApplication::aboutToQuit, [ this ]() { BaseUIApplication::stop(); } ); - void ApplicationQt::_instantiateMainWindow() - { _mainWindow = WidgetFactory::get().instantiateWidget( nullptr, "MainWindow" ); } - void ApplicationQt::_startUI( const std::vector & p_args ) + void ApplicationQt::_build( const UI::Core::LayoutDescriptor & p_layout ) {} + + void ApplicationQt::_start( const std::vector & p_args ) { + _mainWindow->getMainMenu().setCurrentTab( 0 ); _mainWindow->show(); _mainWindow->initWindowLayout(); - } - - void ApplicationQt::stop() - { - // TODO BaseUIApplication::stop() called here because some model are strongly linked to _gl - BaseUIApplication::stop(); - - if ( _mainWindow != nullptr ) - { - delete _mainWindow; - } + //_renderWidget->setFocus(); - //_currentMode = nullptr; + // TODO: return code? + _qApplication->exec(); } /* @@ -136,6 +95,4 @@ namespace VTX::UI::QT // closeAllWindows(); } - // App::Mode::BaseMode & MODE() { return QT_APP()->getCurrentMode(); } - } // namespace VTX::UI::QT diff --git a/lib/ui/src/ui/core/base_ui_application.cpp b/lib/ui/src/ui/core/base_ui_application.cpp index 5ff6299ec..49702800a 100644 --- a/lib/ui/src/ui/core/base_ui_application.cpp +++ b/lib/ui/src/ui/core/base_ui_application.cpp @@ -15,22 +15,16 @@ namespace VTX::UI::Core void BaseUIApplication::start( const std::vector & p_args ) { - _initUI( p_args ); - _buildUI(); - _startUI( p_args ); - } + VTXApp::start( p_args ); - void BaseUIApplication::_buildUI() - { - // TODO; - /* - const FilePath layoutPath = Util::Filesystem::getExecutableDir() / "data" / "tool_config.json"; - UI::Core::IO::VTXLayoutReader reader = UI::Core::IO::VTXLayoutReader(); - reader.read( layoutPath ); + LayoutDescriptor layoutDescriptor; + + _init( p_args ); + _build( layoutDescriptor ); + _start( p_args ); - UI::Core::LayoutBuilder layoutBuilder = UI::Core::LayoutBuilder(); - layoutBuilder.build( reader.getResult().layoutDescriptor ); - */ + onStartUI(); } + void BaseUIApplication::stop() { VTXApp::stop(); } } // namespace VTX::UI::Core