Skip to content

Commit

Permalink
App creation
Browse files Browse the repository at this point in the history
  • Loading branch information
sguionni committed Jun 22, 2024
1 parent 37738d2 commit bfa1709
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 98 deletions.
1 change: 1 addition & 0 deletions lib/app/include/app/vtx_app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ namespace VTX::App
inline const Mode::BaseMode & getCurrentMode() const { return *_currentMode; }

Util::Callback<> onStart;
Util::Callback<> onStartUI;

Util::Callback<float> onPreUpdate;
Util::Callback<float> onUpdate;
Expand Down
5 changes: 5 additions & 0 deletions lib/app/src/app/vtx_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ namespace VTX::App

_handleArgs( p_args );

// Internal::initSettings( App::SETTINGS() );

//_currentMode = std::make_unique<App::Mode::Visualization>();
//_currentMode->enter();

onStart();
}

Expand Down
21 changes: 15 additions & 6 deletions lib/ui/include/ui/core/base_ui_application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> & p_args );
virtual void stop() {}
void start( const std::vector<std::string> & p_args ) override;
void stop() override;

protected:
void _buildUI();

virtual void _initUI( const std::vector<std::string> & p_args ) = 0;
virtual void _startUI( const std::vector<std::string> & p_args ) = 0;
// TODO: concept?
virtual void _init( const std::vector<std::string> & p_args ) = 0;
virtual void _build( const LayoutDescriptor & ) = 0;
virtual void _start( const std::vector<std::string> & p_args ) = 0;
};

} // namespace VTX::UI::Core
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/qt/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
23 changes: 8 additions & 15 deletions lib/ui/qt/include/qt/application_qt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
#include <ui/core/base_ui_application.hpp>
#include <util/types.hpp>

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";

Expand All @@ -23,9 +21,6 @@ namespace VTX::UI::QT
ApplicationQt & operator=( const ApplicationQt & ) = delete;
~ApplicationQt();

void start( const std::vector<std::string> & p_args ) override;
void stop() override;

inline MainWindow & getMainWindow() { return *_mainWindow; }
inline const MainWindow & getMainWindow() const { return *_mainWindow; }

Expand All @@ -34,15 +29,13 @@ namespace VTX::UI::QT
void softQuit();

protected:
void _initUI( const std::vector<std::string> & p_args ) override;
void _startUI( const std::vector<std::string> & p_args ) override;

void _initQt();
void _instantiateMainWindow();
void _init( const std::vector<std::string> & p_args ) override;
void _build( const UI::Core::LayoutDescriptor & p_layout ) override;
void _start( const std::vector<std::string> & p_args ) override;

private:
QApplication * _qApplication = nullptr;
MainWindow * _mainWindow = nullptr;
QApplication * _qApplication;
MainWindow * _mainWindow;
};

inline ApplicationQt * const QT_APP() { return &Util::Generic::UniqueInstance<ApplicationQt>::get(); }
Expand Down
81 changes: 19 additions & 62 deletions lib/ui/qt/src/qt/application_qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "qt/style.hpp"
#include "qt/widget/renderer/dialog.hpp"
#include "qt/widget_factory.hpp"
#include <QCoreApplication>
#include <QApplication>
#include <QIcon>
#include <QLoggingCategory>
#include <QPalette>
Expand All @@ -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<App::Mode::Visualization>();
if ( _mainWindow != nullptr )
{
delete _mainWindow;
}
}
*/

void ApplicationQt::start( const std::vector<std::string> & p_args )
void ApplicationQt::_init( const std::vector<std::string> & 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<std::string> & p_args )
{
// Internal::initSettings( App::SETTINGS() );

//// Init Modes.
// App::Core::init( dynamic_cast<App::Mode::Visualization &>( *_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 ) );
Expand All @@ -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<QT::MainWindow>( nullptr, "MainWindow" );
}

void ApplicationQt::_startUI( const std::vector<std::string> & p_args )
void ApplicationQt::_build( const UI::Core::LayoutDescriptor & p_layout ) {}

void ApplicationQt::_start( const std::vector<std::string> & 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();
}

/*
Expand All @@ -136,6 +95,4 @@ namespace VTX::UI::QT
// closeAllWindows();
}

// App::Mode::BaseMode & MODE() { return QT_APP()->getCurrentMode(); }

} // namespace VTX::UI::QT
22 changes: 8 additions & 14 deletions lib/ui/src/ui/core/base_ui_application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,16 @@ namespace VTX::UI::Core

void BaseUIApplication::start( const std::vector<std::string> & 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

0 comments on commit bfa1709

Please sign in to comment.