Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
GUI.h
Go to the documentation of this file.
00001 /********************************************************************
00002 **                Image Component Library (ICL)                    **
00003 **                                                                 **
00004 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld          **
00005 **                         Neuroinformatics Group                  **
00006 ** Website: www.iclcv.org and                                      **
00007 **          http://opensource.cit-ec.de/projects/icl               **
00008 **                                                                 **
00009 ** File   : ICLQt/src/ICLQt/GUI.h                                  **
00010 ** Module : ICLQt                                                  **
00011 ** Authors: Christof Elbrechter                                    **
00012 **                                                                 **
00013 **                                                                 **
00014 ** GNU LESSER GENERAL PUBLIC LICENSE                               **
00015 ** This file may be used under the terms of the GNU Lesser General **
00016 ** Public License version 3.0 as published by the                  **
00017 **                                                                 **
00018 ** Free Software Foundation and appearing in the file LICENSE.GPL  **
00019 ** included in the packaging of this file.  Please review the      **
00020 ** following information to ensure the license requirements will   **
00021 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt                **
00022 **                                                                 **
00023 ** The development of this software was supported by the           **
00024 ** Excellence Cluster EXC 277 Cognitive Interaction Technology.    **
00025 ** The Excellence Cluster EXC 277 is a grant of the Deutsche       **
00026 ** Forschungsgemeinschaft (DFG) in the context of the German       **
00027 ** Excellence Initiative.                                          **
00028 **                                                                 **
00029 ********************************************************************/
00030 
00031 #pragma once
00032 
00033 #include <string>
00034 #include <vector>
00035 #include <ICLUtils/SmartPtr.h>
00036 #include <ICLUtils/Function.h>
00037 #include <ICLQt/DataStore.h>
00038 #include <ICLQt/GUIComponents.h>
00039 #include <QtGui/QLayout>
00040 #include <QtGui/QWidget>
00041 #include <QtGui/QApplication>
00042 
00044 class QLayout;
00047 namespace icl{
00048   namespace qt{
00049   
00051     class GUIWidget;
00052     class ProxyLayout;
00053     class GUIDefinition;
00056 
00057 
00058     class GUI{
00059       private:
00061 
00062       virtual GUI &operator<<(const std::string &definition);
00063   
00064       protected:
00066       GUI(const std::string &definition, QWidget *parent);
00067   
00068   
00069       public:
00071       typedef utils::Function<GUIWidget*,const GUIDefinition&> CreatorFunction;
00072       
00074 
00076       static void register_widget_type(const std::string &tag, CreatorFunction f);
00077       
00079       static const int CELLW = 20;
00081       static const int CELLH = 20;
00082       
00084       GUI(QWidget *parent=0);
00085       
00087       GUI(const GUIComponent &component, QWidget *parent=0);
00088       
00090       GUI(const GUI &gui,QWidget *parent=0);
00091   
00093       GUI &operator=(const GUI &other);
00094   
00096       virtual ~GUI();
00097   
00099       virtual GUI &operator<<(const GUIComponent &component);
00100       
00102 
00103       virtual GUI &operator<<(const GUI &g);
00104       
00106       template<class T>
00107       inline T &allocValue(const std::string &id, const T&val=T()){
00108         return m_oDataStore.allocValue<T>(id,val);
00109       }
00110   
00112       template<class T>
00113       inline void release(const std::string &id){
00114         m_oDataStore.release<T>(id);
00115       }
00116       
00117       template<class T> 
00118       T &get(const std::string &id, bool typeCheck=true){
00119         return m_oDataStore.getValue<T>(id,typeCheck);
00120       }
00121   
00123       DataStore::Data operator[](const std::string &key){
00124         return m_oDataStore.operator[](key);
00125       }
00126       
00128       template<class T>
00129       std::vector<T> collect(const std::vector<std::string> &keys){
00130         return m_oDataStore.collect<T>(keys);
00131       }
00132       
00134       virtual bool isVisible() const;
00135       
00137       virtual void create();
00138   
00140       virtual void show();
00141       
00143       virtual void hide();
00144       
00146       virtual void switchVisibility();
00147       
00149       inline GUIWidget *getRootWidget(){
00150         return m_poWidget;
00151       }
00152       
00154       inline void lockData() {
00155         m_oDataStore.lock();
00156       }
00158       inline void unlockData() {
00159         m_oDataStore.unlock();
00160       }
00162       void waitForCreation();
00163   
00165       const DataStore &getDataStore() const { return m_oDataStore; }
00166       
00168 
00169       typedef utils::Function<void> Callback;
00170       
00172 
00175       typedef utils::Function<void,const std::string&> ComplexCallback;
00176       
00177       
00179 
00185       void registerCallback(const Callback &cb, const std::string &handleNamesList, char listDelim=',');
00186       
00188 
00189       void registerCallback(const ComplexCallback &cb, const std::string &handleNamesList, char listDelim=',');
00190   
00192       void removeCallbacks(const std::string &handleNamesList, char listDelim=',');
00193   
00195 
00199       inline bool isDummy() const { return m_sDefinition == "" || m_sDefinition == "dummy"; }
00200       
00202       bool hasBeenCreated() const;
00203   
00204       protected:
00206       virtual std::string createDefinition() const { return m_sDefinition; }
00207   
00208       private:
00209   
00210       void create(QLayout *parentLayout,ProxyLayout *proxy, QWidget *parentWidget, DataStore *ds);
00211   
00213       std::string m_sDefinition;
00214       std::vector<GUI*> m_children;
00215       GUIWidget *m_poWidget;
00216       DataStore m_oDataStore;
00217       bool m_bCreated;
00218       QWidget *m_poParent;
00219     };
00220   } // namespace qt
00221 }
00222 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines