diff --git a/CMakeLists.txt b/CMakeLists.txt index ff66353e..cfc29b2b 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -124,6 +124,7 @@ add_executable(Bloom # Insight src/Insight/Insight.cpp src/Insight/InsightWorker.cpp + src/Insight/UserInterfaces/InsightWindow/UiLoader.cpp src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp src/Insight/UserInterfaces/InsightWindow/AboutWindow.cpp src/Insight/UserInterfaces/InsightWindow/Widgets/SvgWidget.cpp diff --git a/src/Insight/UserInterfaces/InsightWindow/UiLoader.cpp b/src/Insight/UserInterfaces/InsightWindow/UiLoader.cpp new file mode 100644 index 00000000..e00941d6 --- /dev/null +++ b/src/Insight/UserInterfaces/InsightWindow/UiLoader.cpp @@ -0,0 +1,84 @@ +#include "UiLoader.hpp" + +#include + +#include "Widgets/RotatableLabel.hpp" +#include "Widgets/SlidingHandleWidget.hpp" +#include "Widgets/SvgWidget.hpp" +#include "Widgets/SvgToolButton.hpp" +#include "Widgets/ExpandingWidget.hpp" +#include "Widgets/ExpandingHeightScrollAreaWidget.hpp" +#include "Widgets/TargetRegistersPane/TargetRegistersPaneWidget.hpp" + +#include "src/Logger/Logger.hpp" + +using namespace Bloom; +using namespace Bloom::Widgets; + +UiLoader::UiLoader(QObject* parent): QUiLoader(parent) { + this->customWidgetConstructorsByWidgetName = decltype(this->customWidgetConstructorsByWidgetName) { + { + "RotatableLabel", + [this](QWidget* parent, const QString& name) { + auto widget = new RotatableLabel("", parent); + widget->setObjectName(name); + widget->setStyleSheet(parent->styleSheet()); + return widget; + } + }, + { + "SlidingHandleWidget", + [this](QWidget* parent, const QString& name) { + auto widget = new SlidingHandleWidget(parent); + widget->setObjectName(name); + widget->setStyleSheet(parent->styleSheet()); + return widget; + } + }, + { + "ExpandingWidget", + [this](QWidget* parent, const QString& name) { + auto widget = new ExpandingWidget(parent); + widget->setObjectName(name); + widget->setStyleSheet(parent->styleSheet()); + return widget; + } + }, + { + "ExpandingHeightScrollAreaWidget", + [this](QWidget* parent, const QString& name) { + auto widget = new ExpandingHeightScrollAreaWidget(parent); + widget->setObjectName(name); + widget->setStyleSheet(parent->styleSheet()); + return widget; + } + }, + { + "SvgWidget", + [this](QWidget* parent, const QString& name) { + auto widget = new SvgWidget(parent); + widget->setObjectName(name); + widget->setStyleSheet(parent->styleSheet()); + return widget; + } + }, + { + "SvgToolButton", + [this](QWidget* parent, const QString& name) { + auto widget = new SvgToolButton(parent); + widget->setObjectName(name); + widget->setStyleSheet(parent->styleSheet()); + return widget; + } + }, + }; +} + +QWidget* UiLoader::createWidget(const QString& className, QWidget* parent, const QString& name) { + if (this->customWidgetConstructorsByWidgetName.contains(className)) { + // This is a custom widget - call the mapped constructor + return this->customWidgetConstructorsByWidgetName.at(className)(parent, name); + } + + return QUiLoader::createWidget(className, parent, name); +} diff --git a/src/Insight/UserInterfaces/InsightWindow/UiLoader.hpp b/src/Insight/UserInterfaces/InsightWindow/UiLoader.hpp new file mode 100644 index 00000000..7985b5ae --- /dev/null +++ b/src/Insight/UserInterfaces/InsightWindow/UiLoader.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include +#include + +namespace Bloom +{ + class UiLoader: public QUiLoader + { + Q_OBJECT + private: + std::map> customWidgetConstructorsByWidgetName = {}; + + public: + explicit UiLoader(QObject* parent); + + QWidget* createWidget(const QString& className, QWidget* parent, const QString& name) override; + }; +}