Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
GUIComponents.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/GUIComponents.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/Any.h>
00035 #include <ICLQt/GUIComponentWithOutput.h>
00036 
00037 namespace icl{  
00039   namespace utils{
00040     class Configurable;
00041   }
00044   namespace qt{
00046 
00050     struct Button : public GUIComponentWithOutput{
00051       private:
00053       static std::string form_args(const std::string &text, const std::string &toggledText, bool initiallyToggled){
00054         if(!toggledText.length()){
00055           return text;
00056         }
00057         std::ostringstream str;
00058         str << text << ',';
00059         if(initiallyToggled) str << '!';
00060         str << toggledText;
00061         return str.str();
00062       }
00063       public:
00065       Button(const std::string &text, const std::string &toggledText="", bool initiallyToggled=false):
00066       GUIComponentWithOutput(toggledText.length() ? "togglebutton" : "button",form_args(text,toggledText,initiallyToggled)){}
00067     };
00068       
00070 
00071     struct ButtonGroup : public GUIComponentWithOutput{
00072       ButtonGroup(const std::string &commaSepTexts):
00073       GUIComponentWithOutput("buttongroup",commaSepTexts){}
00074     };
00075   
00077 
00078     struct CheckBox : public GUIComponentWithOutput{
00080       CheckBox(const std::string &label, bool checked=false):
00081       GUIComponentWithOutput("checkbox",label+','+(checked ? "checked":"unchecked")){}
00082     };
00083       
00085 
00086     struct Label : public GUIComponent{
00088       Label(const std::string &text=""):GUIComponent("label",text){}
00089     };
00090   
00092 
00094     struct Slider : public GUIComponentWithOutput{
00096       Slider(int min=0, int max=100, int curr=50, bool vertical=false):
00097       GUIComponentWithOutput("slider",form_args_4(min,max,curr,vertical?"vertical":"horizontal")){}
00098   
00100       Slider(const utils::Range32f &r, int curr, bool vertical=false):
00101       GUIComponentWithOutput("slider",form_args_4(r.minVal,r.maxVal,curr,vertical?"vertical":"horizontal")){}
00102     };
00103   
00105 
00107     struct FSlider : public GUIComponentWithOutput{
00109       FSlider(float min=0, float max=1, float curr=0.5, bool vertical=false):
00110       GUIComponentWithOutput("fslider",form_args_4(min,max,curr,vertical?"vertical":"horizontal")){}
00111       
00113       FSlider(const utils::Range32f &r, float curr=0.5, bool vertical=false):
00114       GUIComponentWithOutput("fslider",form_args_4(r.minVal,r.maxVal,curr,vertical?"vertical":"horizontal")){}
00115     };
00116   
00118 
00119     struct Int : public GUIComponentWithOutput{
00121       Int(int min=0, int max=100, int curr=50):
00122       GUIComponentWithOutput("int",form_args_3(min, max, curr)){}
00123     };
00124   
00126 
00127     struct Float : public GUIComponentWithOutput{
00129       Float(float min=0, float max=1, float curr=0.5):
00130       GUIComponentWithOutput("float",form_args_3(min, max, curr)){}
00131     };
00132   
00134 
00135     struct String : public GUIComponent{
00137       String(const std::string &initText, int maxLen=100):GUIComponent("string",initText+','+utils::str(maxLen)){}
00138     };
00139   
00141 
00142     struct Disp : public GUIComponent{
00143       Disp(int nxCells, int nyCells):
00144       GUIComponent("disp",utils::str(nxCells)+','+utils::str(nyCells)){}
00145     };
00146   
00148 
00149     struct Image : public GUIComponent{
00151       Image():GUIComponent("image"){}
00152     };
00153   
00155 
00156     struct Draw : public GUIComponent{
00158 
00160       Draw(const utils::Size &defaultViewPortsize=utils::Size::VGA):
00161       GUIComponent("draw",str(defaultViewPortsize)){}
00162     };
00163   
00165 
00168     struct Draw3D : public GUIComponent{
00170 
00172       Draw3D(const utils::Size &defaultViewPortsize=utils::Size::VGA):
00173       GUIComponent("draw3D",str(defaultViewPortsize)){}
00174     };
00175   
00177 
00178     struct Plot : public GUIComponent{
00179       private:
00181       static std::string form_args(const utils::Range32f xRange, 
00182                                    const utils::Range32f yRange, bool useOpenGL,
00183                                    const std::string &xLabel,  const std::string &yLabel){
00184         std::ostringstream str;
00185         str << xRange.minVal << ',' << xRange.maxVal << ',' << yRange.minVal << ',' << yRange.maxVal << ','
00186             << (useOpenGL ? "gl" : "noGL");
00187         if(xLabel.length()){
00188           str << ',' << xLabel;
00189           if(xLabel.length()){
00190             str << ',' << yLabel;
00191           }
00192         }
00193         return str.str();
00194       }
00195   
00196       public:
00198 
00204       Plot(const utils::Range32f xRange=utils::Range32f(0,0),
00205            const utils::Range32f yRange=utils::Range32f(0,0),
00206            bool useOpenGL=false,
00207            const std::string &xLabel="",
00208            const std::string &yLabel=""): 
00209       GUIComponent("plot",form_args(xRange,xRange, useOpenGL, xLabel, yLabel)){}
00210   
00212 
00213       Plot(float minX, float maxX=0, float minY=0, float maxY=0,
00214            bool useOpenGL=false,
00215            const std::string &xLabel="",
00216            const std::string &yLabel=""): 
00217       GUIComponent("plot",form_args(utils::Range32f(minX,maxX),utils::Range32f(minY,maxY), useOpenGL, xLabel, yLabel)){}
00218     };
00219 
00220 
00221 
00222       
00224 
00225     struct Combo : public GUIComponent{
00226       private:
00228       static std::string form_args(const std::string &entries, int initialIndex){
00229         if(!initialIndex) return entries;
00230         std::vector<std::string> ls = utils::tok(entries,",");
00231         if(initialIndex < 0 || initialIndex >= (int)ls.size()){
00232           throw utils::ICLException("Combo::Combo(entries,initialIndex): initialIndex is invalid");
00233         }
00234         ls[initialIndex] = '!' + ls[initialIndex];
00235         return utils::cat(ls,",");
00236       }
00237       public:
00239       Combo(const std::string &commaSepEntries, int initialIndex=0):
00240       GUIComponent("combo",form_args(commaSepEntries,initialIndex)){}
00241     };
00242       
00244 
00245     struct Spinner : public GUIComponentWithOutput{
00247       Spinner(int min, int max, int curr):
00248       GUIComponentWithOutput("spinner",form_args_3(min,max,curr)){}
00249     };
00250       
00251   
00253 
00255     struct Fps : public GUIComponent{
00257       Fps(int timeWindowSize=10):
00258       GUIComponent("fps",utils::str(timeWindowSize)){}
00259     };
00260       
00262 
00269     struct CamCfg : public GUIComponent{
00270       private:
00272       static inline std::string form_args(const std::string &a, const std::string &b){
00273         std::ostringstream str;
00274         if(a.length()){
00275           str << a;
00276           if(b.length()){
00277             str << ',' << b;
00278           }
00279         }
00280         return str.str();
00281       }
00282       public:
00284       CamCfg(const std::string &deviceTypeHint="", const std::string &deviceIDHint=""):GUIComponent("camcfg",form_args(deviceTypeHint,deviceIDHint)){}
00285     };
00286   
00288 
00292     struct Prop : public GUIComponent{
00294       Prop(const std::string &configurableID):GUIComponent("prop",configurableID){}
00295       
00297       Prop(const utils::Configurable *cfg) throw (utils::ICLException) : GUIComponent("prop","@pointer@:"+utils::Any::ptr(cfg)){
00298         ICLASSERT_THROW(cfg, utils::ICLException("GUIComponent Prop(NULL-Pointer) cannot be created!"));
00299       }
00300 
00302       Prop(const utils::Configurable &cfg):GUIComponent("prop","@pointer@:"+utils::Any::ptr(&cfg)){}
00303     };
00304   
00306 
00307     struct ColorSelect : public GUIComponentWithOutput{
00309 
00310       ColorSelect(int r, int g, int b, int a=-1):GUIComponentWithOutput("color",a>=0 ? form_args_4(r,g,b,a) : form_args_3(r,g,b)){}
00311     };
00312       
00314 
00315     struct Ps : public GUIComponent{
00317       Ps(int updatePFS=10):GUIComponent("ps",utils::str(updatePFS)){}
00318     };
00319   
00321     struct Dummy : public GUIComponent{
00322       Dummy():GUIComponent(""){}
00323     };
00324       
00326     struct Show : public GUIComponent{
00327       Show():GUIComponent("!show"){};
00328     };
00329   
00331     struct Create : public GUIComponent{
00332       Create():GUIComponent("!create"){};
00333     };
00334   
00335   } // namespace qt
00336 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines