ImagingTools Core SDK
CQuickApplicationCompBase.h
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ImtCore-Commercial
2#pragma once
3
4
5// ACF includes
6#include <istd/CGeneralTimeStamp.h>
7#include <imod/TModelWrap.h>
8#include <icomp/CComponentBase.h>
9#include <ibase/IApplication.h>
10#include <ibase/IApplicationInfo.h>
11#include <ibase/IRuntimeStatusProvider.h>
12#include <iqt/ITranslationManager.h>
13#include <iqtgui/IGuiObject.h>
14
15// ImtCore includes
16#include <imtqml/IQuickObject.h>
17
18
19namespace imtqml
20{
21
22
23class CQuickApplicationCompBase:
24 public icomp::CComponentBase,
25 virtual public ibase::IApplication
26{
27public:
28 typedef icomp::CComponentBase BaseClass;
29
30 I_BEGIN_BASE_COMPONENT(CQuickApplicationCompBase);
31 I_REGISTER_INTERFACE(ibase::IApplication);
32 I_REGISTER_SUBELEMENT(RuntimeStatus);
33 I_REGISTER_SUBELEMENT_INTERFACE(RuntimeStatus, ibase::IRuntimeStatusProvider, ExtractRuntimeStatus);
34 I_REGISTER_SUBELEMENT_INTERFACE(RuntimeStatus, imod::IModel, ExtractRuntimeStatus);
35 I_REGISTER_SUBELEMENT_INTERFACE(RuntimeStatus, istd::IChangeable, ExtractRuntimeStatus);
36 I_ASSIGN(m_splashScreenCompPtr, "SplashScreen", "Splash screen shown before application is launched", false, "SplashScreen");
37 I_ASSIGN(m_applicationInfoCompPtr, "ApplicationInfo", "Application info used to set main window title", false, "ApplicationInfo");
38 I_ASSIGN(m_translationManagerCompPtr, "TranslationManager", "Translation manager", false, "TranslationManager");
39 I_ASSIGN(m_splashTimeAttrPtr, "SplashTime", "Minimal time splash screen will be shown", true, 2);
40 I_ASSIGN(m_iconPathAttrPtr, "IconPath", "file path for the application icon", true, ":/Icons/AcfLogo");
41 I_ASSIGN(m_titleFormatAttrPtr, "TitleFormat", "Describe format of title bar, tags:\n\t$(CompanyName) - name of company\n\t$(ProductName) - product name\n\t$(AppName) - application name\n\t$(AppSubName) - application sub name\n\t$(AppType) - type of application\n\t$(Version) - main application version", true, "$(AppName)");
42 I_ASSIGN_MULTI_0(m_componentsToInitializeCompPtr, "ComponentsToInitialize", "List of components to be initialized after creation of the application instance (QCoreApplication)", false);
43 I_ASSIGN_MULTI_0(m_componentsToPreInitializeCompPtr, "ComponentsToPreInitialize", "List of components to be initialized after creation of the application instance (QCoreApplication) but before the loop was started", false);
44 I_END_COMPONENT;
45
46 CQuickApplicationCompBase();
47
48 // reimplemented (ibase::IApplication)
49 virtual bool InitializeApplication(int argc, char** argv) override;
50 virtual QStringList GetApplicationArguments() const override;
51
52protected:
53 QGuiApplication* GetQtApplication() const;
54 bool TryShowSplashScreen();
55 void HideSplashScreen();
56 void InitializeComponentApplication();
57 void InitializeComponents();
58
59 // reimplemented (icomp::CComponentBase)
60 virtual void OnComponentCreated() override;
61
62private:
63 class RuntimeStatus : public ibase::IRuntimeStatusProvider
64 {
65 public:
66 RuntimeStatus();
67
68 void SetRuntimeStatus(IRuntimeStatusProvider::RuntimeStatus runtimeStatus);
69
70 // reimplemented (ibase::IRuntimeStatusProvider)
71 virtual IRuntimeStatusProvider::RuntimeStatus GetRuntimeStatus() const override;
72
73 private:
74 IRuntimeStatusProvider::RuntimeStatus m_status;
75 };
76
77 // static template methods for sub element access
78 template <class InterfaceType>
79 static InterfaceType* ExtractRuntimeStatus(CQuickApplicationCompBase& component)
80 {
81 return &component.m_runtimeStatus;
82 }
83
84protected:
85 imod::TModelWrap<RuntimeStatus> m_runtimeStatus;
86
87private:
88 I_REF(iqtgui::IGuiObject, m_splashScreenCompPtr);
89 I_REF(ibase::IApplicationInfo, m_applicationInfoCompPtr);
90 I_REF(iqt::ITranslationManager, m_translationManagerCompPtr);
91 I_ATTR(double, m_splashTimeAttrPtr);
92 I_ATTR(QString, m_iconPathAttrPtr);
93 I_ATTR(QString, m_titleFormatAttrPtr);
94 I_MULTIREF(istd::IPolymorphic, m_componentsToInitializeCompPtr);
95 I_MULTIREF(istd::IPolymorphic, m_componentsToPreInitializeCompPtr);
96
97 bool m_useSplashScreen;
98 istd::CGeneralTimeStamp m_splashScreenTimer;
99
100 istd::TDelPtr<QGuiApplication> m_applicationPtr;
101
102 QStringList m_applicationArguments;
103};
104
105
106} // namespace imtqml
107
108