Image Component Library (ICL)
|
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.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 <ICLQt/GUIComponentWithOutput.h> 00034 #include <ICLUtils/Any.h> 00035 00036 namespace icl{ 00038 namespace utils{ 00039 class Configurable; 00040 } 00043 namespace qt{ 00045 00049 struct Button : public GUIComponentWithOutput{ 00050 private: 00052 static std::string form_args(const std::string &text, const std::string &toggledText, bool initiallyToggled){ 00053 if(!toggledText.length()){ 00054 return text; 00055 } 00056 std::ostringstream str; 00057 str << text << ','; 00058 if(initiallyToggled) str << '!'; 00059 str << toggledText; 00060 return str.str(); 00061 } 00062 public: 00064 Button(const std::string &text, const std::string &toggledText="", bool initiallyToggled=false): 00065 GUIComponentWithOutput(toggledText.length() ? "togglebutton" : "button",form_args(text,toggledText,initiallyToggled)){} 00066 }; 00067 00069 00070 struct ButtonGroup : public GUIComponentWithOutput{ 00071 ButtonGroup(const std::string &commaSepTexts): 00072 GUIComponentWithOutput("buttongroup",commaSepTexts){} 00073 }; 00074 00076 00077 struct CheckBox : public GUIComponentWithOutput{ 00079 CheckBox(const std::string &label, bool checked=false): 00080 GUIComponentWithOutput("checkbox",label+','+(checked ? "checked":"unchecked")){} 00081 }; 00082 00084 00085 struct Label : public GUIComponent{ 00087 Label(const std::string &text=""):GUIComponent("label",text){} 00088 }; 00089 00091 00093 struct Slider : public GUIComponentWithOutput{ 00095 Slider(int min=0, int max=100, int curr=50, bool vertical=false): 00096 GUIComponentWithOutput("slider",form_args_4(min,max,curr,vertical?"vertical":"horizontal")){} 00097 00099 Slider(const utils::Range32f &r, int curr, bool vertical=false): 00100 GUIComponentWithOutput("slider",form_args_4(r.minVal,r.maxVal,curr,vertical?"vertical":"horizontal")){} 00101 }; 00102 00104 00106 struct FSlider : public GUIComponentWithOutput{ 00108 FSlider(float min=0, float max=1, float curr=0.5, bool vertical=false): 00109 GUIComponentWithOutput("fslider",form_args_4(min,max,curr,vertical?"vertical":"horizontal")){} 00110 00112 FSlider(const utils::Range32f &r, float curr=0.5, bool vertical=false): 00113 GUIComponentWithOutput("fslider",form_args_4(r.minVal,r.maxVal,curr,vertical?"vertical":"horizontal")){} 00114 }; 00115 00117 00118 struct Int : public GUIComponentWithOutput{ 00120 Int(int min=0, int max=100, int curr=50): 00121 GUIComponentWithOutput("int",form_args_3(min, max, curr)){} 00122 }; 00123 00125 00126 struct Float : public GUIComponentWithOutput{ 00128 Float(float min=0, float max=1, float curr=0.5): 00129 GUIComponentWithOutput("float",form_args_3(min, max, curr)){} 00130 }; 00131 00133 00134 struct String : public GUIComponent{ 00136 String(const std::string &initText, int maxLen=100):GUIComponent("string",initText+','+utils::str(maxLen)){} 00137 }; 00138 00140 00141 struct Disp : public GUIComponent{ 00142 Disp(int nxCells, int nyCells): 00143 GUIComponent("disp",utils::str(nxCells)+','+utils::str(nyCells)){} 00144 }; 00145 00147 00148 struct Image : public GUIComponent{ 00150 Image():GUIComponent("image"){} 00151 }; 00152 00154 00155 struct Draw : public GUIComponent{ 00157 00159 Draw(const utils::Size &defaultViewPortsize=utils::Size::VGA): 00160 GUIComponent("draw",str(defaultViewPortsize)){} 00161 }; 00162 00164 00167 struct Draw3D : public GUIComponent{ 00169 00171 Draw3D(const utils::Size &defaultViewPortsize=utils::Size::VGA): 00172 GUIComponent("draw3D",str(defaultViewPortsize)){} 00173 }; 00174 00176 00177 struct Plot : public GUIComponent{ 00178 private: 00180 static std::string form_args(const utils::Range32f xRange, 00181 const utils::Range32f yRange, bool useOpenGL, 00182 const std::string &xLabel, const std::string &yLabel){ 00183 std::ostringstream str; 00184 str << xRange.minVal << ',' << xRange.maxVal << ',' << yRange.minVal << ',' << yRange.maxVal << ',' 00185 << (useOpenGL ? "gl" : "noGL"); 00186 if(xLabel.length()){ 00187 str << ',' << xLabel; 00188 if(xLabel.length()){ 00189 str << ',' << yLabel; 00190 } 00191 } 00192 return str.str(); 00193 } 00194 00195 public: 00197 00203 Plot(const utils::Range32f xRange=utils::Range32f(0,0), 00204 const utils::Range32f yRange=utils::Range32f(0,0), 00205 bool useOpenGL=false, 00206 const std::string &xLabel="", 00207 const std::string &yLabel=""): 00208 GUIComponent("plot",form_args(xRange,xRange, useOpenGL, xLabel, yLabel)){} 00209 00211 00212 Plot(float minX, float maxX=0, float minY=0, float maxY=0, 00213 bool useOpenGL=false, 00214 const std::string &xLabel="", 00215 const std::string &yLabel=""): 00216 GUIComponent("plot",form_args(utils::Range32f(minX,maxX),utils::Range32f(minY,maxY), useOpenGL, xLabel, yLabel)){} 00217 }; 00218 00219 00220 00221 00223 00224 struct Combo : public GUIComponent{ 00225 private: 00227 static std::string form_args(const std::string &entries, int initialIndex){ 00228 if(!initialIndex) return entries; 00229 std::vector<std::string> ls = utils::tok(entries,","); 00230 if(initialIndex < 0 || initialIndex >= (int)ls.size()){ 00231 throw utils::ICLException("Combo::Combo(entries,initialIndex): initialIndex is invalid"); 00232 } 00233 ls[initialIndex] = '!' + ls[initialIndex]; 00234 return utils::cat(ls,","); 00235 } 00236 public: 00238 Combo(const std::string &commaSepEntries, int initialIndex=0): 00239 GUIComponent("combo",form_args(commaSepEntries,initialIndex)){} 00240 }; 00241 00243 00244 struct Spinner : public GUIComponentWithOutput{ 00246 Spinner(int min, int max, int curr): 00247 GUIComponentWithOutput("spinner",form_args_3(min,max,curr)){} 00248 }; 00249 00250 00252 00254 struct Fps : public GUIComponent{ 00256 Fps(int timeWindowSize=10): 00257 GUIComponent("fps",utils::str(timeWindowSize)){} 00258 }; 00259 00261 00268 struct CamCfg : public GUIComponent{ 00269 private: 00271 static inline std::string form_args(const std::string &a, const std::string &b){ 00272 std::ostringstream str; 00273 if(a.length()){ 00274 str << a; 00275 if(b.length()){ 00276 str << ',' << b; 00277 } 00278 } 00279 return str.str(); 00280 } 00281 public: 00283 CamCfg(const std::string &deviceTypeHint="", const std::string &deviceIDHint=""):GUIComponent("camcfg",form_args(deviceTypeHint,deviceIDHint)){} 00284 }; 00285 00287 00291 struct Prop : public GUIComponent{ 00293 Prop(const std::string &configurableID):GUIComponent("prop",configurableID){} 00294 00296 Prop(const utils::Configurable *cfg) throw (utils::ICLException) : GUIComponent("prop","@pointer@:"+utils::Any::ptr(cfg)){ 00297 ICLASSERT_THROW(cfg, utils::ICLException("GUIComponent Prop(NULL-Pointer) cannot be created!")); 00298 } 00299 00301 Prop(const utils::Configurable &cfg):GUIComponent("prop","@pointer@:"+utils::Any::ptr(&cfg)){} 00302 }; 00303 00305 00306 struct ColorSelect : public GUIComponentWithOutput{ 00308 00309 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)){} 00310 }; 00311 00313 00314 struct Ps : public GUIComponent{ 00316 Ps(int updatePFS=10):GUIComponent("ps",utils::str(updatePFS)){} 00317 }; 00318 00320 struct Dummy : public GUIComponent{ 00321 Dummy():GUIComponent(""){} 00322 }; 00323 00325 struct Show : public GUIComponent{ 00326 Show():GUIComponent("!show"){}; 00327 }; 00328 00330 struct Create : public GUIComponent{ 00331 Create():GUIComponent("!create"){}; 00332 }; 00333 00334 } // namespace qt 00335 }