CGuiComponentBase.h
Go to the documentation of this file.
1 #ifndef iqtgui_CGuiComponentBase_included
2 #define iqtgui_CGuiComponentBase_included
3 
4 
5 // Qt includes
6 #include <QtCore/QString>
7 #include <QtGui/QIcon>
8 
9 // ACF includes
10 #include <imod/TModelWrap.h>
11 #include <icomp/CComponentBase.h>
12 #include <ibase/TLocalizableWrap.h>
13 #include <iqtgui/IGuiObject.h>
14 #include <iqtgui/IVisualStatus.h>
15 
16 
17 namespace iqtgui
18 {
19 
20 
25  public QObject,
26  public ibase::TLocalizableWrap<icomp::CComponentBase>,
27  virtual public IGuiObject
28 {
29 public:
31 
32  I_BEGIN_BASE_COMPONENT(CGuiComponentBase);
33  I_REGISTER_INTERFACE(IGuiObject);
34  I_REGISTER_SUBELEMENT(VisualStatus);
38  I_ASSIGN(m_defaultStatusIconPathAttrPtr, "DefaultStatusIcon", "Path of status icon used by default", false, "");
39  I_ASSIGN(m_defaultStatusTextAttrPtr, "DefaultStatusText", "Status text used by default", true, "");
40  I_ASSIGN(m_styleSheetPathAttrPtr, "StyleSheet", "Path to the style sheet file used for this UI component.", false, "");
41  I_ASSIGN(m_objectIdAttrPtr, "ObjectId", "ID of the widget", false, "");
42  I_ASSIGN(m_fixedWidthAttrPtr, "FixedWidth", "Fixed width of the widget", false, 300);
43  I_ASSIGN(m_fixedHeightAttrPtr, "FixedHeight", "Fixed height of the widget", false, 300);
44  I_END_COMPONENT;
45 
47 
48  bool IsGuiShown() const;
49 
50  // reimplemented (iqtgui::IGuiObject)
51  virtual bool IsGuiCreated() const;
52  virtual bool CreateGui(QWidget* parentPtr);
53  virtual bool DestroyGui();
54  virtual QWidget* GetWidget() const;
55  virtual void OnTryClose(bool* ignoredPtr = NULL);
56 
57 #if _MSC_VER < 1500
58 public:
59 #else
60 protected:
61 #endif
62  class VisualStatus: virtual public IVisualStatus
63  {
64  public:
65  // reimplemented (iqtgui::IVisualStatus)
66  virtual QIcon GetStatusIcon() const;
67  virtual QString GetStatusText() const;
68 
69  friend class CGuiComponentBase;
70 
71  private:
72  QIcon m_statusIcon;
73  QString m_statusText;
74  };
75 
76 protected:
80  virtual void OnGuiShown();
81 
85  virtual void OnGuiHidden();
86 
91  virtual bool OnKeyPressed(QKeyEvent* event);
92 
96  virtual void OnRetranslate();
97 
101  virtual void OnGuiRetranslate();
102 
106  virtual void OnGuiCreated();
107 
111  virtual void OnGuiDestroyed();
112 
116  void SetStatusIcon(const QIcon& icon);
120  void SetStatusText(const QString& text);
121 
122  // reimplemented (ibase::TLocalizableWrap)
123  virtual void OnLanguageChanged();
124 
125  // reimplemented (QObject)
126  virtual bool eventFilter(QObject* sourcePtr, QEvent* eventPtr);
127 
128  // reimplemented (icomp::CComponentBase)
129  virtual void OnComponentCreated();
130 
131  // abstract methods
135  virtual QWidget* CreateQtWidget(QWidget* parentPtr) = 0;
136 
137  // attributes
139 
140 private:
141  void MakeAutoSlotConnection();
142 
143  I_ATTR(QString, m_defaultStatusIconPathAttrPtr);
144  I_TEXTATTR(m_defaultStatusTextAttrPtr);
145  I_ATTR(QString, m_styleSheetPathAttrPtr);
146  I_ATTR(QByteArray, m_objectIdAttrPtr);
147  I_ATTR(int, m_fixedWidthAttrPtr);
148  I_ATTR(int, m_fixedHeightAttrPtr);
149 
150  QWidget* m_widgetPtr;
151  bool m_isGuiShown;
152 
153  QIcon m_defaultStatusIcon;
154 
155  // static template methods for subelement access
156  template <class InterfaceType>
157  static InterfaceType* ExtractVisualStatus(CGuiComponentBase& component)
158  {
159  return &component.m_visualStatus;
160  }
161 };
162 
163 
164 // inline methods
165 
166 inline bool CGuiComponentBase::IsGuiShown() const
167 {
168  return m_isGuiShown;
169 }
170 
171 
172 // reimplemented (iqtgui::IGuiObject)
173 
174 inline QWidget* CGuiComponentBase::GetWidget() const
175 {
176  return m_widgetPtr;
177 }
178 
179 
180 } // namespace iqtgui
181 
182 
183 #endif // !iqtgui_CGuiComponentBase_included
184 
185 
virtual void OnRetranslate()
Called when non-GUI elements (like commands) should be retranslated.
virtual QString GetStatusText() const
Get status text.
I_REGISTER_SUBELEMENT_INTERFACE_T(VisualStatus, IVisualStatus, ExtractVisualStatus)
virtual QWidget * CreateQtWidget(QWidget *parentPtr)=0
Create slave widget object.
Base class for classes implementing interface iqtgui::IGuiObject.
Extends standard information provider to provide additional visual informations.
Definition: IVisualStatus.h:19
imod::TModelWrap< VisualStatus > m_visualStatus
virtual bool CreateGui(QWidget *parentPtr)
Initialize GUI and connect it to the parent.
virtual void OnGuiShown()
Called from widget event filter when slave widget is shown.
Base class for component implementation.
virtual bool IsGuiCreated() const
Inform if GUI was initilized.
virtual void OnGuiRetranslate()
Called from widget event filter when GUI should be retranslated.
virtual bool DestroyGui()
Release GUI and disconnect it from parent.
virtual void OnLanguageChanged()
virtual void OnTryClose(bool *ignoredPtr=NULL)
Called on trying to close application.
Common interface for data model objects, which can be changed.
Definition: IChangeable.h:24
Common interface for GUI objects using in component context.
Definition: IGuiObject.h:25
virtual void OnGuiCreated()
Called just after GUI is initialized.
virtual QIcon GetStatusIcon() const
Get the icon describing current status.
#define NULL
Definition: istd.h:64
This model wrapper provides a simple connection between a concrete istd::IChangeable implementation a...
Definition: TModelWrap.h:24
virtual QWidget * GetWidget() const
Get access to internal QWidget object.
Common interface for model objects, that supports Model/Observer design pattern.
Definition: IModel.h:23
virtual void OnComponentCreated()
virtual bool eventFilter(QObject *sourcePtr, QEvent *eventPtr)
void SetStatusText(const QString &text)
Set status text;.
#define I_TEXTATTR(member)
Declare translatable text attribute member.
icomp::CComponentBase BaseClass
virtual bool OnKeyPressed(QKeyEvent *event)
Called from widget event filter when key is pressed.
void SetStatusIcon(const QIcon &icon)
Set status icon;.
virtual void OnGuiHidden()
Called from widget event filter when slave widget is hidden.
virtual void OnGuiDestroyed()
Called just before GUI is released.

© 2007-2017 Witold Gantzke and Kirill Lepskiy