#ifndef ICL_GUI_H #define ICL_GUI_H #include #include #include #include #include #include #include /** \cond */ class QLayout; /** \endcond */ namespace icl{ /** \cond */ class GUIWidget; class ProxyLayout; /** \endcond */ // documentation in GUIDocumentation.h ! class GUI{ public: /// cell width (all sizes are given in this unit) static const int CELLW = 20; /// cell height (all sizes are given in this unit) static const int CELLH = 20; /// default constructor GUI(const std::string &definition="vbox", QWidget *parent=0); /// copy constructor GUI(const GUI &gui,QWidget *parent=0); /// Destructor virtual ~GUI(); /// stream operator to add new widgets virtual GUI &operator<<(const std::string &definition); /// stream operator to add new other GUIs virtual GUI &operator<<(const GUI &g); /// wraps the data-stores allocValue function template inline T &allocValue(const std::string &id, const T&val=T()){ return m_oDataStore.allocValue(id,val); } /// wraps the data-stores allocArray function template inline T *allocArray(const std::string &id,unsigned int n){ return m_oDataStore.allocArray(id,n); } /// wraps the datastores release function template inline void release(const std::string &id){ m_oDataStore.release(id); } /// wraps the datastores getValue function template T &getValue(const std::string &id, bool typeCheck=true){ return m_oDataStore.getValue(id,typeCheck); } /// wraps the datastores getArray function template inline T* getArray(const std::string &id, int *lenDst=0){ return m_oDataStore.getArray(id,lenDst); } /// returns a Data instance from the datastore DataStore::Data operator[](const std::string &key){ return m_oDataStore.operator[](key); } /// returns whether this gui is actually visible virtual bool isVisible() const; /// internally creates everything virtual void create(); /// internally creates everything (and makes the gui visible) virtual void show(); /// make this gui invisible (nothing more) virtual void hide(); /// if widget is visible, this hides the widget, otherwise the widget is shown virtual void switchVisibility(); /// returns the root widget of the gui (only avialable after create() or show()) inline GUIWidget *getRootWidget(){ return m_poWidget; } /// internally locks the datastore inline void lockData() { m_oDataStore.lock(); } /// internally unlocks the data store inline void unlockData() { m_oDataStore.unlock(); } /// waits for the gui to be created completely void waitForCreation(); /// returns the GUI internal dataStore const DataStore &getDataStore() const { return m_oDataStore; } /// Callback helper class: Default implementation calls a callback function class Callback{ /// typedef to wrapped function (only for default implementation) typedef void (*callback_function)(void); /// typedef to wrapped function (only used if exec(const std::string&) is not overloaded!) typedef void (*complex_callback_function)(const std::string&); /// internally used default callback function callback_function m_func; /// internally used comples callback function complex_callback_function m_cfunc; protected: /// create a new callback object Callback():m_func(0),m_cfunc(0){} public: /// Default implementations constructor with given callback function Callback(callback_function func):m_func(func),m_cfunc(0){} /// Default implementations constructor with given complex callback function Callback(complex_callback_function cfunc):m_func(0),m_cfunc(cfunc){} /// vitual execution function virtual void exec(){ if(m_func) m_func(); } /// virtual complex execution function /** the complex function is called with given component's handle name, so it can be */ virtual void exec(const std::string &handle){ if(m_cfunc) m_cfunc(handle); } }; typedef SmartPtr CallbackPtr; /// registers a callback function on each component /** @param cb callback to execute @param handleNamesList comma-separated list of handle names ownership is passed to the childrens; deletion is performed by the smart pointers that are used... */ void registerCallback(CallbackPtr cb, const std::string &handleNamesList); /// removes all callbacks from components void removeCallbacks(const std::string &handleNamesList); private: void create(QLayout *parentLayout,ProxyLayout *proxy, QWidget *parentWidget, DataStore *ds); /// own definition string std::string m_sDefinition; std::vector m_vecChilds; GUIWidget *m_poWidget; DataStore m_oDataStore; bool m_bCreated; QWidget *m_poParent; }; } #endif