CSimpleMainWindowGuiComp.h
Go to the documentation of this file.
1 #ifndef iqtgui_CSimpleMainWindowGuiComp_included
2 #define iqtgui_CSimpleMainWindowGuiComp_included
3 
4 
5 // Qt includes
6 #include <QtCore/QtGlobal>
7 #if QT_VERSION >= 0x050000
8 #include <QtWidgets/QMainWindow>
9 #include <QtWidgets/QMenuBar>
10 #else
11 #include <QtGui/QMainWindow>
12 #include <QtGui/QMenuBar>
13 #endif
14 
15 // ACF includes
18 #include <ifile/IFileNameParam.h>
19 #include <iprm/IOptionsManager.h>
21 #include <iqtgui/IDialog.h>
24 #include <iqtgui/CCommandTools.h>
25 #include <ilog/IMessageConsumer.h>
26 
27 
28 namespace iqtgui
29 {
30 
31 
36 class CSimpleMainWindowGuiCompBase: public iqtgui::TRestorableGuiWrap< iqtgui::TGuiComponentBase<QMainWindow> >
37 {
38 public:
40 
41  I_BEGIN_BASE_COMPONENT(CSimpleMainWindowGuiCompBase);
42  I_ASSIGN(m_workspaceCompPtr, "Workspace", "Main widget", true, "Workspace");
43  I_ASSIGN_TO(m_workspaceCommandsCompPtr, m_workspaceCompPtr, false);
44  I_ASSIGN_TO(m_workspaceCommandsModelCompPtr, m_workspaceCompPtr, false);
45  I_ASSIGN(m_aboutDialogCompPtr, "AboutDialog", "Gui displayed if 'About' action is triggered", false, "AboutDialog");
46  I_ASSIGN(m_settingsDialogCompPtr, "SettingsDialog", "Dialog window displayed if 'Settings' action is triggered", false, "SettingsDialog");
47  I_ASSIGN_MULTI_0(m_mainWindowComponentsCompPtr, "MainWindowComponents", "Additional GUI components", false);
48  I_ASSIGN_TO(m_mainWindowCommandsCompPtr, m_mainWindowComponentsCompPtr, false);
49  I_ASSIGN_TO(m_mainWindowCommandsModelCompPtr, m_mainWindowComponentsCompPtr, false);
50  I_ASSIGN(m_isNestingEnabledAttrPtr, "IsNestingEnabled", "If true, docking nesting is enabled,\nmore than one docking widget is allowed on the same size", true, false);
51  I_ASSIGN(m_isAllowTabbedDockAttrPtr, "IsTabbedDockAllowed", "If true, stacking docking windows on each other is enabled", true, false);
52  I_ASSIGN(m_isMenuVisibleAttrPtr, "IsMenuVisible", "If true, menu bar will be visible", true, true);
53  I_ASSIGN(m_isToolbarVisibleAttrPtr, "IsToolbarVisible", "If true, tool bar will be visible", true, true);
54  I_ASSIGN(m_toolBarAreaAttrPtr, "ToolBarArea", "Specify the area where the standard toolbar will be placed\n 0 - left\n 1 - right\n 2 - top\n 3 - bottom", false, 0);
55  I_ASSIGN(m_toolBarDockFeaturesAttrPtr, "ToolBarDockFeatures", "Specify the dock features for the standard tool bar\nIt is combination of options:\n2 - moveable\n4 - floatable", true, IMainWindowComponent::WCF_MOVEABLE | IMainWindowComponent::WCF_FLOATABLE);
56  I_ASSIGN(m_iconSizeAttrPtr, "IconSize", "Size of icons using in the main window", false, 16);
57  I_ASSIGN(m_useIconTextAttrPtr, "UseIconText", "Enable text under the tool bar icons", false, false);
58  I_ASSIGN(m_helpFilePathPtr, "HelpFile", "Path to the help (manual) file opened by F1", false, "HelpFile");
59  I_END_COMPONENT;
60 
61 protected:
62  I_REF(iqtgui::IGuiObject, m_workspaceCompPtr);
63  I_REF(ibase::ICommandsProvider, m_workspaceCommandsCompPtr);
64  I_REF(imod::IModel, m_workspaceCommandsModelCompPtr);
65  I_MULTIREF(ibase::ICommandsProvider, m_mainWindowCommandsCompPtr);
66  I_MULTIREF(imod::IModel, m_mainWindowCommandsModelCompPtr);
67  I_REF(iqtgui::IDialog, m_aboutDialogCompPtr);
68  I_REF(iqtgui::IDialog, m_settingsDialogCompPtr);
69  I_MULTIREF(iqtgui::IMainWindowComponent, m_mainWindowComponentsCompPtr);
70  I_ATTR(bool, m_isNestingEnabledAttrPtr);
71  I_ATTR(bool, m_isAllowTabbedDockAttrPtr);
72  I_ATTR(bool, m_isMenuVisibleAttrPtr);
73  I_ATTR(bool, m_isToolbarVisibleAttrPtr);
74  I_ATTR(int, m_toolBarAreaAttrPtr);
75  I_ATTR(int, m_toolBarDockFeaturesAttrPtr);
76  I_ATTR(int, m_iconSizeAttrPtr);
77  I_ATTR(bool, m_useIconTextAttrPtr);
78  I_REF(ifile::IFileNameParam, m_helpFilePathPtr);
79 };
80 
81 
83 {
84  Q_OBJECT
85 
86 public:
88 
89  I_BEGIN_COMPONENT(CSimpleMainWindowGuiComp);
90  I_REGISTER_SUBELEMENT(VisibleWindowsManager);
91  I_REGISTER_SUBELEMENT_INTERFACE(VisibleWindowsManager, iprm::IOptionsManager, GetVisibleWindowsManager);
92  I_REGISTER_SUBELEMENT_INTERFACE(VisibleWindowsManager, iprm::IOptionsList, GetVisibleWindowsManager);
93  I_REGISTER_SUBELEMENT_INTERFACE(VisibleWindowsManager, imod::IModel, GetVisibleWindowsManager);
94  I_REGISTER_SUBELEMENT_INTERFACE(VisibleWindowsManager, istd::IChangeable, GetVisibleWindowsManager);
95  I_ASSIGN(m_progressMessagesComsumerCompPtr, "ProgressMessagesConsumer", "Consumer of the progress messages", false, "");
96  I_END_COMPONENT;
97 
98  enum GroupId
99  {
100  GI_SETTINGS = 0x400
101  };
102 
103  enum ModelId
104  {
106  };
107 
109 
110  // reimplemented (iqtgui::IGuiObject)
111  virtual void OnTryClose(bool* ignoredPtr = NULL);
112 
113 protected:
114  virtual void UpdateMenuActions();
115 
116  virtual void SetupMainWindowComponents(QMainWindow& mainWindow);
117 
118  virtual void AddMainComponent(int componentIndex, iqtgui::IMainWindowComponent* componentPtr);
119  virtual void RemoveMainComponent(iqtgui::IMainWindowComponent* componentPtr);
120 
121  virtual void CreateMenuBar();
122  virtual void CreateDefaultToolBar();
123  virtual void SetToolBarsVisible(bool isVisible = true);
124  virtual void SetupMenu();
125 
126  virtual void UpdateFixedCommands(iqtgui::CHierarchicalCommand& fixedCommands);
127  virtual void UpdateViewCommands(iqtgui::CHierarchicalCommand& viewCommand);
128  virtual void UpdateToolsCommands(iqtgui::CHierarchicalCommand& toolsCommand);
129  virtual void UpdateHelpCommands(iqtgui::CHierarchicalCommand& helpCommand);
130  virtual void AppendMenuActions(iqtgui::CHierarchicalCommand& menuCommands);
135  virtual bool IsMainWindowActive(int index) const;
136 
137  // reimplemented (TRestorableGuiWrap)
138  virtual void OnRestoreSettings(const QSettings& settings);
139  virtual void OnSaveSettings(QSettings& settings) const;
140 
141  // reimplemented (iqtgui::CGuiComponentBase)
142  virtual void OnGuiCreated();
143  virtual void OnGuiDestroyed();
144  virtual void OnRetranslate();
145  virtual void OnGuiShown();
146 
147  // reimplemented (QObject)
148  virtual bool eventFilter(QObject* sourcePtr, QEvent* eventPtr);
149 
150 protected Q_SLOTS:
151  void OnShowToolbars();
152  void OnFullScreen();
153  void OnAbout();
154  void OnHelpManual();
155  void OnSettings();
156  void OnShowOtherCommandTriggered(bool enabled);
157 
158 protected:
160  {
161  public:
163 
164  explicit CommandsObserver(CSimpleMainWindowGuiComp& parent);
165 
166  // reimplemented (imod::CMultiModelDispatcherBase)
167  void OnModelChanged(int modelId, const istd::IChangeable::ChangeSet& changeSet);
168 
169  private:
170  CSimpleMainWindowGuiComp& m_parent;
171  };
172 
174 
175 private:
176  class VisibleWindowsManager: public iprm::IOptionsManager
177  {
178  public:
179  VisibleWindowsManager();
180 
181  void SetParent(CSimpleMainWindowGuiComp* parentPtr);
182 
183  // reimplemented (iprm::IOptionsManager)
184  virtual int GetOptionOperationFlags(int index = -1) const;
185  virtual bool SetOptionEnabled(int index, bool isEnabled = true);
186  virtual bool RemoveOption(int index);
187  virtual bool InsertOption(
188  const QString& optionName,
189  const QByteArray& optionId,
190  const QString& optionDescription = QString(),
191  int index = -1);
192  virtual bool SwapOptions(int index1, int index2);
193  virtual bool SetOptionName(int optionIndex, const QString& optionName);
194  virtual bool SetOptionDescription(int optionIndex, const QString& optionDescription);
195 
196  // reimplemented (iprm::IOptionsList)
197  virtual int GetOptionsFlags() const;
198  virtual int GetOptionsCount() const;
199  virtual QString GetOptionName(int index) const;
200  virtual QString GetOptionDescription(int index) const;
201  virtual QByteArray GetOptionId(int index) const;
202  virtual bool IsOptionEnabled(int index) const;
203 
204  // reimplemented (iprm::ISelectionParam)
205  virtual const iprm::IOptionsList* GetSelectionConstraints() const;
206  virtual int GetSelectedOptionIndex() const;
207  virtual bool SetSelectedOptionIndex(int index);
208  virtual iprm::ISelectionParam* GetSubselection(int index) const;
209 
210  // reimplemented (iser::ISerializable)
211  virtual bool Serialize(iser::IArchive& archive);
212 
213  private:
214  CSimpleMainWindowGuiComp* m_parentPtr;
215  };
216 
217  template <class InterfaceType>
218  static InterfaceType* GetVisibleWindowsManager(CSimpleMainWindowGuiComp& parent)
219  {
220  return &parent.m_visibleWindowsManager;
221  }
222 
223  istd::TDelPtr<QMenuBar> m_menuBarPtr;
224  istd::TDelPtr<QToolBar> m_standardToolBarPtr;
225 
226  istd::TOptPointerVector<QToolBar> m_toolBarsList;
227 
228  iqtgui::CHierarchicalCommand m_menuCommands;
229 
230  iqtgui::CHierarchicalCommand m_viewCommand;
231  iqtgui::CHierarchicalCommand m_toolsCommand;
232  iqtgui::CHierarchicalCommand m_helpCommand;
233 
234  // view menu group
235  iqtgui::CHierarchicalCommand m_showToolBarsCommand;
236  iqtgui::CHierarchicalCommand m_showOtherWindows;
237 #if !defined(Q_OS_MAC)
238  iqtgui::CHierarchicalCommand m_fullScreenCommand;
239 #endif
240 
241  // tools menu group
242  iqtgui::CHierarchicalCommand m_settingsCommand;
243 
244  // help menu group
245  iqtgui::CHierarchicalCommand m_aboutCommand;
246  iqtgui::CHierarchicalCommand m_manualCommand;
247 
248  iqtgui::CHierarchicalCommand m_fixedCommands;
249 
250  QByteArray m_beforeFullScreenGeometry;
251  QByteArray m_beforeFullScreenState;
252 
253  imod::TModelWrap<VisibleWindowsManager> m_visibleWindowsManager;
254 
255  typedef QMap<int, int> IndexToIndexMap;
256 
257  IndexToIndexMap m_commandIndexToMainCompMap;
258 
259  I_REF(ilog::IMessageConsumer, m_progressMessagesComsumerCompPtr);
260 };
261 
262 
263 } // namespace iqtgui
264 
265 
266 #endif // !iqtgui_CSimpleMainWindowGuiComp_included
267 
268 
Implementation of hierarchical command based on QAction from Qt.
virtual void UpdateFixedCommands(iqtgui::CHierarchicalCommand &fixedCommands)
CSimpleMainWindowGuiCompBase BaseClass
virtual void OnGuiShown()
Called from widget event filter when slave widget is shown.
virtual void OnSaveSettings(QSettings &settings) const
virtual void OnGuiDestroyed()
Called just before GUI is released.
virtual void AddMainComponent(int componentIndex, iqtgui::IMainWindowComponent *componentPtr)
Generic implementation of a data model changes notifier.
virtual bool IsMainWindowActive(int index) const
Constraints of selection from set of possibilities.
Definition: IOptionsList.h:22
void OnShowOtherCommandTriggered(bool enabled)
virtual void OnRetranslate()
Called when non-GUI elements (like commands) should be retranslated.
virtual void UpdateViewCommands(iqtgui::CHierarchicalCommand &viewCommand)
Common interface for the management of the dynamic selection constraints.
A wrapper for saving/restoring of GUI component states in the application settings.
Interface for a provider of the heriarchical commands.
virtual void UpdateMainWindowComponentsVisibility()
Set main window visible or invisible, depending on menu commands.
Common interface for any file system item name (e.g directory, file or URL path)
A common interface for main window component such as dock widget, tool bar and so on...
Represent input/output persistence archive.
Definition: IArchive.h:30
Common interface for data model objects, which can be changed.
Definition: IChangeable.h:24
CommandsObserver(CSimpleMainWindowGuiComp &parent)
virtual void OnGuiCreated()
Called just after GUI is initialized.
Common interface for GUI objects using in component context.
Definition: IGuiObject.h:25
virtual void OnTryClose(bool *ignoredPtr=NULL)
Called on trying to close application.
#define NULL
Definition: istd.h:64
virtual void UpdateToolsCommands(iqtgui::CHierarchicalCommand &toolsCommand)
virtual bool eventFilter(QObject *sourcePtr, QEvent *eventPtr)
virtual void UpdateHelpCommands(iqtgui::CHierarchicalCommand &helpCommand)
virtual void OnRestoreSettings(const QSettings &settings)
Common interface for a message container consuming information objects (messages).
Element can be float from the main window to be standalone window.
void OnModelChanged(int modelId, const istd::IChangeable::ChangeSet &changeSet)
Common interface for model objects, that supports Model/Observer design pattern.
Definition: IModel.h:23
Set of change flags (its IDs).
Definition: IChangeable.h:30
virtual void AppendMenuActions(iqtgui::CHierarchicalCommand &menuCommands)
Interface allowing to select single option from list of options.
virtual void SetToolBarsVisible(bool isVisible=true)
Interface for a dialog widget.
Definition: IDialog.h:17
virtual void SetupMainWindowComponents(QMainWindow &mainWindow)
virtual void RemoveMainComponent(iqtgui::IMainWindowComponent *componentPtr)
iqtgui::TRestorableGuiWrap< iqtgui::TGuiComponentBase< QMainWindow > > BaseClass

© 2007-2017 Witold Gantzke and Kirill Lepskiy