Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
GUIComponent.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/GUIComponent.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 <ICLUtils/StringUtils.h>
00034 #include <ICLUtils/Range.h>
00035 #include <ICLUtils/Size.h>
00036 
00037 namespace icl{
00038   namespace qt{
00039   
00041 
00043     class GUIComponent{
00044     
00046       friend class ContainerGUIComponent;
00047       
00049       friend class GUI;
00050   
00051       public:
00053       struct Options {
00054       Options():margin(-1),spacing(-1), hide(false){}
00055         std::string handle;  
00056         std::string out;     
00057         std::string in;      
00058         std::string label;   
00059         std::string tooltip; 
00060         int margin;          
00061         int spacing;         
00062         utils::Size minSize;        
00063         utils::Size maxSize;        
00064         utils::Size size;           
00065         bool hide;           
00066       };
00067       protected:
00068       
00070       mutable Options m_options;
00071       
00073       template<class A, class B, class C> 
00074       static std::string form_args_3(const A &a, const B &b, const C &c){
00075         std::ostringstream str;
00076         str << a << ',' << b << ',' << c;
00077         return str.str();
00078       }
00079       
00081       template<class A, class B, class C, class D> 
00082       static std::string form_args_4(const A &a, const B &b, const C &c, const D &d){
00083         std::ostringstream str;
00084         str << a << ',' << b << ',' << c << ',' << d;
00085         return str.str();
00086       }
00087       
00089       std::string m_type;
00090       
00092       std::string m_params;
00093       
00095 
00096       GUIComponent(const std::string &type, const std::string &params=""):
00097       m_type(type),m_params(params){}
00098       public:
00099         
00101       const GUIComponent &handle(const std::string &handle) const{
00102         m_options.handle = handle; return *this;
00103       }
00104   
00106       const GUIComponent &label(const std::string &label) const{
00107         m_options.label = label; return *this;
00108       }
00109   
00111       const GUIComponent &tooltip(const std::string &tooltip) const{
00112         m_options.tooltip = tooltip; return *this;
00113       }
00114   
00116       const GUIComponent &size(const utils::Size &size) const {
00117         m_options.size = size; return *this;
00118       }
00119   
00121       const GUIComponent &size(int w, int h) const {
00122         return size(utils::Size(w,h));
00123       }
00124   
00126       const GUIComponent &minSize(const utils::Size &minSize) const {
00127         m_options.minSize = minSize; return *this;
00128       }
00129         
00131       const GUIComponent &minSize(int w, int h) const {
00132         return minSize(utils::Size(w,h));
00133       }
00134       
00136       const GUIComponent &maxSize(const utils::Size &maxSize) const {
00137         m_options.maxSize = maxSize; return *this;
00138       }
00139   
00141       const GUIComponent &maxSize(int w, int h) const {
00142         return maxSize(utils::Size(w,h));
00143       }
00144   
00146 
00157       const GUIComponent &hideIf(bool flag) const{
00158         if(flag) m_options.hide = true; return *this;
00159       }
00160   
00162       GUIComponent &handle(std::string &handle) {
00163         m_options.handle = handle; return *this;
00164       }
00165       
00167       GUIComponent &label(std::string &label) {
00168         m_options.label = label; return *this;
00169       }
00170       
00172       GUIComponent &tooltip(std::string &tooltip) {
00173         m_options.tooltip = tooltip; return *this;
00174       }
00175       
00177       GUIComponent &size(utils::Size &size)  {
00178         m_options.size = size; return *this;
00179       }
00180       
00182       GUIComponent &size(int w, int h)  {
00183         m_options.size = utils::Size(w,h); return *this;
00184       }
00185       
00187       GUIComponent &minSize(utils::Size &minSize)  {
00188         m_options.minSize = minSize; return *this;
00189       }
00190   
00192       GUIComponent &minSize(int w, int h)  {
00193         m_options.minSize = utils::Size(w,h); return *this;
00194       }
00195       
00197       GUIComponent &maxSize(utils::Size &maxSize)  {
00198         m_options.maxSize = maxSize; return *this;
00199       }
00200       
00202       GUIComponent &maxSize(int w, int h)  {
00203         m_options.maxSize = utils::Size(w,h); return *this;
00204       }
00205   
00207 
00208       GUIComponent &hideIf(bool flag)  {
00209         if(flag) m_options.hide = true; return *this;
00210       }
00211       
00213       std::string toString() const {
00214         if(m_options.hide) return "";
00215         std::ostringstream str;
00216         str << m_type;
00217         if(m_params.length()){
00218           str << '(' << m_params << ')';
00219         }
00220         if(m_options.handle.length() ||
00221            m_options.label.length() ||
00222            m_options.out.length() ||
00223            m_options.in.length() ||
00224            m_options.tooltip.length() ||
00225            m_options.margin > 0 ||
00226            m_options.spacing > 0 ||
00227            m_options.minSize != utils::Size::null ||
00228            m_options.maxSize != utils::Size::null ||
00229            m_options.size != utils::Size::null ){
00230           str << '[';
00231           if(m_options.handle.length()) str << "@handle=" << m_options.handle;
00232           if(m_options.out.length()) str << "@out=" << m_options.out;
00233           if(m_options.in.length()) str << "@in=" << m_options.in;
00234           if(m_options.label.length()) str << "@label=" << m_options.label;
00235           if(m_options.tooltip.length()) str << "@tooltip=" << m_options.tooltip;
00236           if(m_options.margin > 0) str << "@margin=" << m_options.margin;
00237           if(m_options.spacing > 0) str << "@spacing=" << m_options.spacing;
00238           if(m_options.minSize != utils::Size::null ) str << "@minsize=" << m_options.minSize;
00239           if(m_options.maxSize != utils::Size::null ) str << "@maxsize=" << m_options.maxSize;
00240           if(m_options.size != utils::Size::null ) str << "@size=" << m_options.size;
00241           str << "]";
00242         }
00243         return str.str();
00244       }
00245     };
00246   } // namespace qt
00247 }
00248 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines