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.LGPL **
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 <ICLUtils/CompatMacros.h>
00034 #include <ICLUtils/SmartPtr.h>
00035 #include <ICLUtils/Function.h>
00036 #include <ICLQt/DataStore.h>
00037 #include <ICLQt/GUIComponents.h>
00038 #include <QLayout>
00039 #include <QWidget>
00040 #include <QApplication>
00041 #include <string>
00042 #include <vector>
00043 
00045 class QLayout;
00048 namespace icl{
00049   namespace qt{
00050   
00052     class GUIWidget;
00053     class ProxyLayout;
00054     class GUIDefinition;
00057 
00058 
00059     class ICLQt_API GUI{
00060       private:
00062 
00063       virtual GUI &operator<<(const std::string &definition);
00064   
00065       protected:
00067       GUI(const std::string &definition, QWidget *parent);
00068   
00069   
00070       public:
00072       typedef utils::Function<GUIWidget*,const GUIDefinition&> CreatorFunction;
00073       
00075 
00077       static void register_widget_type(const std::string &tag, CreatorFunction f);
00078       
00080       static const int CELLW = 20;
00082       static const int CELLH = 20;
00083       
00085       GUI(QWidget *parent=0);
00086       
00088       GUI(const GUIComponent &component, QWidget *parent=0);
00089       
00091       GUI(const GUI &gui,QWidget *parent=0);
00092   
00094       GUI &operator=(const GUI &other);
00095   
00097       virtual ~GUI();
00098   
00100       virtual GUI &operator<<(const GUIComponent &component);
00101       
00103 
00104       virtual GUI &operator<<(const GUI &g);
00105       
00107       template<class T>
00108       inline T &allocValue(const std::string &id, const T&val=T()){
00109         return m_oDataStore.allocValue<T>(id,val);
00110       }
00111   
00113       template<class T>
00114       inline void release(const std::string &id){
00115         m_oDataStore.release<T>(id);
00116       }
00117       
00118       template<class T> 
00119       T &get(const std::string &id, bool typeCheck=true){
00120         return m_oDataStore.getValue<T>(id,typeCheck);
00121       }
00122   
00124       DataStore::Data operator[](const std::string &key){
00125         return m_oDataStore.operator[](key);
00126       }
00127       
00129       template<class T>
00130       std::vector<T> collect(const std::vector<std::string> &keys){
00131         return m_oDataStore.collect<T>(keys);
00132       }
00133       
00135       virtual bool isVisible() const;
00136       
00138       virtual void create();
00139   
00141       virtual void show();
00142       
00144       virtual void hide();
00145       
00147       virtual void switchVisibility();
00148       
00150       inline GUIWidget *getRootWidget(){
00151         return m_poWidget;
00152       }
00153       
00155       inline void lockData() {
00156         m_oDataStore.lock();
00157       }
00159       inline void unlockData() {
00160         m_oDataStore.unlock();
00161       }
00163       void waitForCreation();
00164   
00166       const DataStore &getDataStore() const { return m_oDataStore; }
00167       
00169 
00170       typedef utils::Function<void> Callback;
00171       
00173 
00176       typedef utils::Function<void, const std::string&> ComplexCallback;
00177       
00178       
00180 
00186       void registerCallback(const Callback &cb, const std::string &handleNamesList, char listDelim=',');
00187       
00189 
00190       void registerCallback(const ComplexCallback &cb, const std::string &handleNamesList, char listDelim=',');
00191   
00193       void removeCallbacks(const std::string &handleNamesList, char listDelim=',');
00194   
00196 
00200       inline bool isDummy() const { return m_sDefinition == "" || m_sDefinition == "dummy"; }
00201       
00203       bool hasBeenCreated() const;
00204   
00205       protected:
00207       virtual std::string createDefinition() const { return m_sDefinition; }
00208   
00209       private:
00210   
00211       void create(QLayout *parentLayout,ProxyLayout *proxy, QWidget *parentWidget, DataStore *ds);
00212   
00214       std::string m_sDefinition;
00215       std::vector<GUI*> m_children;
00216       GUIWidget *m_poWidget;
00217       DataStore m_oDataStore;
00218       bool m_bCreated;
00219       QWidget *m_poParent;
00220     };
00221   } // namespace qt
00222 }
00223 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines