ImagingTools Core SDK
CMenuPanelComp.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 <ibase/TModelObserverCompWrap.h>
7#include <iqtgui/TGuiObserverWrap.h>
8#include <iqtgui/TGuiComponentBase.h>
9#include <iprm/ISelectionParam.h>
10#include <iprm/IEnableableParam.h>
11#include <imod/CMultiModelDispatcherBase.h>
12
13// ImtCore includes
14#include <imtgui/IWidgetProvider.h>
15#include <imtgui/IMonitorInfoProvider.h>
16#include <imtwidgets/CMenuPanel.h>
17#include <imtwidgets/IMenuPanelDelegate.h>
18
19namespace imtgui
20{
21
22
23class CMenuPanelCompBase:
24 public ibase::TModelObserverCompBaseWrap<
25 iqtgui::TGuiObserverWrap<
26 iqtgui::TGuiComponentBase<imtwidgets::CMenuPanel>,
27 imod::TSingleModelObserverBase<iprm::ISelectionParam>>>
28{
29public:
30 typedef ibase::TModelObserverCompBaseWrap<
31 iqtgui::TGuiObserverWrap<
32 iqtgui::TGuiComponentBase<imtwidgets::CMenuPanel>,
33 imod::TSingleModelObserverBase<iprm::ISelectionParam>>> BaseClass;
34
35 I_BEGIN_COMPONENT(CMenuPanelCompBase);
36 I_ASSIGN(m_animationDelayAttrPtr, "AnimationDelay", "Animation delay", true, 800);
37 I_ASSIGN(m_animationDurationAttrPtr, "AnimationDuration", "Animation duration", true, 150);
38 I_ASSIGN(m_animationEnabledAttrPtr, "AnimationEnabled", "Animation enabled", true, true);
39 I_ASSIGN(m_isShowOverAttrPtr, "ShowOver", "Show expanded menu over the underlaying widget", true, true);
40 I_ASSIGN(m_physicalResolutionAttrPtr, "PhysicalResolution", "Physical monitor resolution", true, 3.5);
41 I_ASSIGN(m_indentAttrPtr, "Indent", "Item indentation", true, 6);
42 I_ASSIGN(m_itemHeightAttrPtr, "ItemHeight", "Item Height", true, 15);
43 I_ASSIGN(m_iconSizeRatioAttrPtr, "IconSizeRatio", "Icon size ratio relative to item height", true, 1);
44 I_ASSIGN(m_iconSizeHoverRatioAttrPtr, "IconSizeHoverRatio", "Icon size ratio under mouse (relative to item normal size)", true, 1.2);
45 I_ASSIGN(m_fontSizeRatioAttrPtr, "FontSizeRatio", "Font pixel size ratio relative to icon size", true, 0.3);
46 I_ASSIGN(m_topPaddingAttrPtr, "TopPadding", "Top panel padding", true, 1);
47 I_ASSIGN(m_leftPaddingAttrPtr, "LeftPadding", "Left item padding", true, 0);
48 I_ASSIGN(m_rightPaddingAttrPtr, "RightPadding", "Right item padding", true, 20);
49 I_ASSIGN(m_iconToTextPaddingAttrPtr, "IconToTextPadding", "Icon to text item padding", true, 1);
50 I_ASSIGN_MULTI_0(m_bottomPagesIdsAttrPtr, "BottomPagesIds", "The list of pages ids that should be placed at bottom of the page", false);
51 I_END_COMPONENT;
52
53protected:
54 I_ATTR(int, m_animationDelayAttrPtr);
55 I_ATTR(int, m_animationDurationAttrPtr);
56 I_ATTR(bool, m_animationEnabledAttrPtr);
57 I_ATTR(bool, m_isShowOverAttrPtr);
58 I_MULTIATTR(QByteArray, m_bottomPagesIdsAttrPtr);
59 I_ATTR(double, m_physicalResolutionAttrPtr);
60 I_ATTR(double, m_indentAttrPtr);
61 I_ATTR(double, m_itemHeightAttrPtr);
62 I_ATTR(double, m_iconSizeRatioAttrPtr);
63 I_ATTR(double, m_iconSizeHoverRatioAttrPtr);
64 I_ATTR(double, m_fontSizeRatioAttrPtr);
65 I_ATTR(double, m_topPaddingAttrPtr);
66 I_ATTR(double, m_leftPaddingAttrPtr);
67 I_ATTR(double, m_rightPaddingAttrPtr);
68 I_ATTR(double, m_iconToTextPaddingAttrPtr);
69};
70
71
72class CMenuPanelComp: public CMenuPanelCompBase
73{
74public:
75 typedef CMenuPanelCompBase BaseClass;
76
77 I_BEGIN_COMPONENT(CMenuPanelComp);
78 I_ASSIGN(m_menuPanelVisibilityCompPtr, "MenuPanelVisibility", "Menu panel visibility status", false, "MenuPanelVisibility");
79 I_ASSIGN_TO(m_menuPanelVisibilityModelCompPtr, m_menuPanelVisibilityCompPtr, false);
80 I_ASSIGN(m_widgetProviderCompPtr, "WidgetProvider", "Widget provider for parent widget", false, "WidgetProvider");
81 I_ASSIGN(m_monitorInfoProviderCompPtr, "MonitorInfoProvider", "Monitor info provider (count, size, resolution, etc.)", false, "MonitorInfoProvider");
82 I_ASSIGN_TO(m_monitorInfoProviderModelPtr, m_monitorInfoProviderCompPtr, false);
83 I_ASSIGN(m_menuPanelDelegateCompPtr, "MenuPanelDelegate", "Delegate for menu panel", true, "MenuPanelDelegate");
84 I_ASSIGN(m_hideDisabledAttrPtr, "HideDisabled", "Hide disabled items", true, false);
85 I_END_COMPONENT;
86
87 CMenuPanelComp();
88
89protected:
90 void OnPageIdChanged(const QByteArray& selectedPageId, const QByteArray& deselectedPageId);
91
92 // reimplemented (iqtgui::TGuiObserverWrap)
93 virtual void UpdateGui(const istd::IChangeable::ChangeSet& changeSet) override;
94 virtual void OnGuiModelAttached() override;
95 virtual void OnGuiModelDetached() override;
96
97 // reimplemented (iqtgui::CGuiComponentBase)
98 virtual void OnGuiCreated() override;
99 virtual void OnGuiRetranslate() override;
100 virtual void OnGuiDesignChanged() override;
101
102private:
103 class PageSubselectionObserver: public imod::CMultiModelDispatcherBase
104 {
105 public:
106 explicit PageSubselectionObserver(CMenuPanelComp& parent);
107
108 // reimplemented (imod::CMultiModelDispatcherBase)
109 virtual void OnModelChanged(int modelId, const istd::IChangeable::ChangeSet& changeSet) override;
110
111 private:
112 CMenuPanelComp& m_parent;
113 };
114
115 class PageVisualStatusObserver: public imod::CMultiModelDispatcherBase
116 {
117 public:
118 explicit PageVisualStatusObserver(CMenuPanelComp& parent);
119
120 // reimplemented (imod::CMultiModelDispatcherBase)
121 virtual void OnModelChanged(int modelId, const istd::IChangeable::ChangeSet& changeSet) override;
122
123 private:
124 CMenuPanelComp& m_parent;
125 };
126
127 class MonitorsInfoObserver: public imod::TSingleModelObserverBase<imtgui::IMonitorInfoProvider>
128 {
129 public:
130 explicit MonitorsInfoObserver(CMenuPanelComp& parent);
131
132 // reimplemented (imod::CSingleModelObserverBase)
133 virtual void OnUpdate(const istd::IChangeable::ChangeSet& changeSet);
134
135 private:
136 CMenuPanelComp& m_parent;
137 };
138
139 class MenuPanelVisibility: public imod::TSingleModelObserverBase<iprm::IEnableableParam>
140 {
141 public:
142 explicit MenuPanelVisibility(CMenuPanelComp& parent);
143
144 // reimplemented (imod::CSingleModelObserverBase)
145 virtual void OnUpdate(const istd::IChangeable::ChangeSet& changeSet);
146
147 private:
148 CMenuPanelComp& m_parent;
149 };
150
151 struct PageInfo
152 {
153 QByteArray parentPageId;
154 const iprm::ISelectionParam* selectionPtr;
155 int pageIndex;
156 };
157
158 QMap<QByteArray, PageInfo> m_pagesInfoMap;
159 int m_subselectionModelIndex;
160 int m_visualStatusModelIndex;
161 PageSubselectionObserver m_pageSubselectionObserver;
162 PageVisualStatusObserver m_pageVisualStatusObserver;
163 MonitorsInfoObserver m_monitorInfoObserver;
164 MenuPanelVisibility m_menuPanelVisibilityObserver;
165
166 I_REF(iprm::IEnableableParam, m_menuPanelVisibilityCompPtr);
167 I_REF(imod::IModel, m_menuPanelVisibilityModelCompPtr);
168 I_REF(imtgui::IWidgetProvider, m_widgetProviderCompPtr);
169 I_REF(imtgui::IMonitorInfoProvider, m_monitorInfoProviderCompPtr);
170 I_REF(imod::IModel, m_monitorInfoProviderModelPtr);
171 I_REF(imtwidgets::IMenuPanelDelegate, m_menuPanelDelegateCompPtr);
172 I_ATTR(bool, m_hideDisabledAttrPtr);
173
174 double m_resolutionX;
175 double m_resolutionY;
176 double m_scale;
177
178private:
179 bool IsPageEnabled(const QByteArray& pageId) const;
180 void UpdateSelection(const iprm::ISelectionParam& selection, const QByteArray& parentId);
181 void CreatePageTree(const iprm::ISelectionParam& selection, const QByteArray& parentId);
182 QByteArray FindSelectedItem();
183 void UpdatePageSubselection();
184 void UpdatePageState();
185 void UpdateMonitorsInfo();
186 void UpdateWidgetSizeAttributes();
187 void UpdateMenuPanelVisibility();
188};
189
190
191} // namespace imtgui
192
193