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/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.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/StringUtils.h> 00035 #include <ICLUtils/Range.h> 00036 #include <ICLUtils/Size.h> 00037 00038 namespace icl{ 00039 namespace qt{ 00040 00042 00044 class GUIComponent{ 00045 00047 friend struct ContainerGUIComponent; 00048 00050 friend class GUI; 00051 00052 public: 00054 struct Options { 00055 Options():margin(-1),spacing(-1), hide(false){} 00056 std::string handle; 00057 std::string out; 00058 std::string in; 00059 std::string label; 00060 std::string tooltip; 00061 int margin; 00062 int spacing; 00063 utils::Size minSize; 00064 utils::Size maxSize; 00065 utils::Size size; 00066 bool hide; 00067 }; 00068 protected: 00069 00071 mutable Options m_options; 00072 00074 template<class A, class B, class C> 00075 static std::string form_args_3(const A &a, const B &b, const C &c){ 00076 std::ostringstream str; 00077 str << a << ',' << b << ',' << c; 00078 return str.str(); 00079 } 00080 00082 template<class A, class B, class C, class D> 00083 static std::string form_args_4(const A &a, const B &b, const C &c, const D &d){ 00084 std::ostringstream str; 00085 str << a << ',' << b << ',' << c << ',' << d; 00086 return str.str(); 00087 } 00088 00090 std::string m_type; 00091 00093 std::string m_params; 00094 00096 00097 GUIComponent(const std::string &type, const std::string ¶ms=""): 00098 m_type(type),m_params(params){} 00099 public: 00100 00102 const GUIComponent &handle(const std::string &handle) const{ 00103 m_options.handle = handle; return *this; 00104 } 00105 00107 const GUIComponent &label(const std::string &label) const{ 00108 m_options.label = label; return *this; 00109 } 00110 00112 const GUIComponent &tooltip(const std::string &tooltip) const{ 00113 m_options.tooltip = tooltip; return *this; 00114 } 00115 00117 const GUIComponent &size(const utils::Size &size) const { 00118 m_options.size = size; return *this; 00119 } 00120 00122 const GUIComponent &size(int w, int h) const { 00123 return size(utils::Size(w,h)); 00124 } 00125 00127 const GUIComponent &minSize(const utils::Size &minSize) const { 00128 m_options.minSize = minSize; return *this; 00129 } 00130 00132 const GUIComponent &minSize(int w, int h) const { 00133 return minSize(utils::Size(w,h)); 00134 } 00135 00137 const GUIComponent &maxSize(const utils::Size &maxSize) const { 00138 m_options.maxSize = maxSize; return *this; 00139 } 00140 00142 const GUIComponent &maxSize(int w, int h) const { 00143 return maxSize(utils::Size(w,h)); 00144 } 00145 00147 00158 const GUIComponent &hideIf(bool flag) const{ 00159 if(flag) m_options.hide = true; return *this; 00160 } 00161 00163 GUIComponent &handle(std::string &handle) { 00164 m_options.handle = handle; return *this; 00165 } 00166 00168 GUIComponent &label(std::string &label) { 00169 m_options.label = label; return *this; 00170 } 00171 00173 GUIComponent &tooltip(std::string &tooltip) { 00174 m_options.tooltip = tooltip; return *this; 00175 } 00176 00178 GUIComponent &size(utils::Size &size) { 00179 m_options.size = size; return *this; 00180 } 00181 00183 GUIComponent &size(int w, int h) { 00184 m_options.size = utils::Size(w,h); return *this; 00185 } 00186 00188 GUIComponent &minSize(utils::Size &minSize) { 00189 m_options.minSize = minSize; return *this; 00190 } 00191 00193 GUIComponent &minSize(int w, int h) { 00194 m_options.minSize = utils::Size(w,h); return *this; 00195 } 00196 00198 GUIComponent &maxSize(utils::Size &maxSize) { 00199 m_options.maxSize = maxSize; return *this; 00200 } 00201 00203 GUIComponent &maxSize(int w, int h) { 00204 m_options.maxSize = utils::Size(w,h); return *this; 00205 } 00206 00208 00209 GUIComponent &hideIf(bool flag) { 00210 if(flag) m_options.hide = true; return *this; 00211 } 00212 00214 std::string toString() const { 00215 if(m_options.hide) return ""; 00216 std::ostringstream str; 00217 str << m_type; 00218 if(m_params.length()){ 00219 str << '(' << m_params << ')'; 00220 } 00221 if(m_options.handle.length() || 00222 m_options.label.length() || 00223 m_options.out.length() || 00224 m_options.in.length() || 00225 m_options.tooltip.length() || 00226 m_options.margin > 0 || 00227 m_options.spacing > 0 || 00228 m_options.minSize != utils::Size::null || 00229 m_options.maxSize != utils::Size::null || 00230 m_options.size != utils::Size::null ){ 00231 str << '['; 00232 if(m_options.handle.length()) str << "@handle=" << m_options.handle; 00233 if(m_options.out.length()) str << "@out=" << m_options.out; 00234 if(m_options.in.length()) str << "@in=" << m_options.in; 00235 if(m_options.label.length()) str << "@label=" << m_options.label; 00236 if(m_options.tooltip.length()) str << "@tooltip=" << m_options.tooltip; 00237 if(m_options.margin > 0) str << "@margin=" << m_options.margin; 00238 if(m_options.spacing > 0) str << "@spacing=" << m_options.spacing; 00239 if(m_options.minSize != utils::Size::null ) str << "@minsize=" << m_options.minSize; 00240 if(m_options.maxSize != utils::Size::null ) str << "@maxsize=" << m_options.maxSize; 00241 if(m_options.size != utils::Size::null ) str << "@size=" << m_options.size; 00242 str << "]"; 00243 } 00244 return str.str(); 00245 } 00246 }; 00247 } // namespace qt 00248 } 00249