Image Component Library (ICL)
GUIComponent.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Image Component Library (ICL) **
3 ** **
4 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld **
5 ** Neuroinformatics Group **
6 ** Website: www.iclcv.org and **
7 ** http://opensource.cit-ec.de/projects/icl **
8 ** **
9 ** File : ICLQt/src/ICLQt/GUIComponent.h **
10 ** Module : ICLQt **
11 ** Authors: Christof Elbrechter **
12 ** **
13 ** **
14 ** GNU LESSER GENERAL PUBLIC LICENSE **
15 ** This file may be used under the terms of the GNU Lesser General **
16 ** Public License version 3.0 as published by the **
17 ** **
18 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
19 ** included in the packaging of this file. Please review the **
20 ** following information to ensure the license requirements will **
21 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
22 ** **
23 ** The development of this software was supported by the **
24 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
25 ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
26 ** Forschungsgemeinschaft (DFG) in the context of the German **
27 ** Excellence Initiative. **
28 ** **
29 ********************************************************************/
30 
31 #pragma once
32 
33 #include <ICLUtils/CompatMacros.h>
34 #include <ICLUtils/StringUtils.h>
35 #include <ICLUtils/Range.h>
36 #include <ICLUtils/Size.h>
37 
38 namespace icl{
39  namespace qt{
40 
42 
44  class GUIComponent{
45 
47  friend struct ContainerGUIComponent;
48 
50  friend class GUI;
51 
52  public:
54  struct Options {
55  Options():margin(-1),spacing(-1), hide(false){}
56  std::string handle;
57  std::string out;
58  std::string in;
59  std::string label;
60  std::string tooltip;
61  int margin;
62  int spacing;
66  bool hide;
67  };
68  protected:
69 
71  mutable Options m_options;
72 
74  template<class A, class B, class C>
75  static std::string form_args_3(const A &a, const B &b, const C &c){
76  std::ostringstream str;
77  str << a << ',' << b << ',' << c;
78  return str.str();
79  }
80 
82  template<class A, class B, class C, class D>
83  static std::string form_args_4(const A &a, const B &b, const C &c, const D &d){
84  std::ostringstream str;
85  str << a << ',' << b << ',' << c << ',' << d;
86  return str.str();
87  }
88 
90  template<class A, class B, class C, class D, class E>
91  static std::string form_args_5(const A &a, const B &b, const C &c, const D &d, const E &e){
92  std::ostringstream str;
93  str << a << ',' << b << ',' << c << ',' << d << "," << e;
94  return str.str();
95  }
96 
98  template<class A, class B, class C, class D, class E, class F>
99  static std::string form_args_6(const A &a, const B &b, const C &c, const D &d, const E &e, const F &f){
100  std::ostringstream str;
101  str << a << ',' << b << ',' << c << ',' << d << "," << e << "," << f;
102  return str.str();
103  }
104 
106  std::string m_type;
107 
109  std::string m_params;
110 
112 
113  GUIComponent(const std::string &type, const std::string &params=""):
114  m_type(type),m_params(params){}
115  public:
116 
118  const GUIComponent &handle(const std::string &handle) const{
120  return *this;
121  }
122 
124  const GUIComponent &label(const std::string &label) const{
126  return *this;
127  }
128 
130  const GUIComponent &tooltip(const std::string &tooltip) const{
132  return *this;
133  }
134 
136  const GUIComponent &size(const utils::Size &size) const {
137  m_options.size = size;
138  return *this;
139  }
140 
142  const GUIComponent &size(int w, int h) const {
143  return size(utils::Size(w,h));
144  }
145 
147  const GUIComponent &minSize(const utils::Size &minSize) const {
149  return *this;
150  }
151 
153  const GUIComponent &minSize(int w, int h) const {
154  return minSize(utils::Size(w,h));
155  }
156 
158  const GUIComponent &maxSize(const utils::Size &maxSize) const {
160  return *this;
161  }
162 
164  const GUIComponent &maxSize(int w, int h) const {
165  return maxSize(utils::Size(w,h));
166  }
167 
169 
180  const GUIComponent &hideIf(bool flag) const{
181  if(flag) m_options.hide = true;
182  return *this;
183  }
184 
186  GUIComponent &handle(std::string &handle) {
188  return *this;
189  }
190 
192  GUIComponent &label(std::string &label) {
194  return *this;
195  }
196 
198  GUIComponent &tooltip(std::string &tooltip) {
200  return *this;
201  }
202 
205  m_options.size = size;
206  return *this;
207  }
208 
210  GUIComponent &size(int w, int h) {
211  m_options.size = utils::Size(w,h);
212  return *this;
213  }
214 
218  return *this;
219  }
220 
222  GUIComponent &minSize(int w, int h) {
224  return *this;
225  }
226 
230  return *this;
231  }
232 
234  GUIComponent &maxSize(int w, int h) {
236  return *this;
237  }
238 
240 
241  GUIComponent &hideIf(bool flag) {
242  if(flag) m_options.hide = true;
243  return *this;
244  }
245 
247  std::string toString() const {
248  if(m_options.hide) return "";
249  std::ostringstream str;
250  str << m_type;
251  if(m_params.length()){
252  str << '(' << m_params << ')';
253  }
254  if(m_options.handle.length() ||
255  m_options.label.length() ||
256  m_options.out.length() ||
257  m_options.in.length() ||
258  m_options.tooltip.length() ||
259  m_options.margin > 0 ||
260  m_options.spacing > 0 ||
264  str << '[';
265  if(m_options.handle.length()) str << "@handle=" << m_options.handle;
266  if(m_options.out.length()) str << "@out=" << m_options.out;
267  if(m_options.in.length()) str << "@in=" << m_options.in;
268  if(m_options.label.length()) str << "@label=" << m_options.label;
269  if(m_options.tooltip.length()) str << "@tooltip=" << m_options.tooltip;
270  if(m_options.margin > 0) str << "@margin=" << m_options.margin;
271  if(m_options.spacing > 0) str << "@spacing=" << m_options.spacing;
272  if(m_options.minSize != utils::Size::null ) str << "@minsize=" << m_options.minSize;
273  if(m_options.maxSize != utils::Size::null ) str << "@maxsize=" << m_options.maxSize;
274  if(m_options.size != utils::Size::null ) str << "@size=" << m_options.size;
275  str << "]";
276  }
277  return str.str();
278  }
279  };
280  } // namespace qt
281 }
282 
GUIComponent(const std::string &type, const std::string &params="")
creates a component with given type and optionally given parameters
Definition: GUIComponent.h:113
GUIComponent & size(utils::Size &size)
sets the component initial size
Definition: GUIComponent.h:204
const GUIComponent & size(const utils::Size &size) const
sets the component initial size
Definition: GUIComponent.h:136
GUIComponent & tooltip(std::string &tooltip)
sets the component tooltip
Definition: GUIComponent.h:198
Special GUI extension, that mimics the GUIComponent interface.
Definition: ContainerGUIComponent.h:44
static std::string form_args_4(const A &a, const B &b, const C &c, const D &d)
utility method to concatenate 4 values
Definition: GUIComponent.h:83
undocument this line if you encounter any issues!
Definition: Any.h:37
static const Size null
null is w=0, h=0
Definition: Size.h:64
utils::Size size
intial size of the component (in units of 20px)
Definition: GUIComponent.h:65
Main Class of ICL's GUI creation framework.
Definition: GUI.h:60
GUIComponent & maxSize(int w, int h)
sets the component maximum size constraint
Definition: GUIComponent.h:234
const GUIComponent & handle(const std::string &handle) const
sets the component handle
Definition: GUIComponent.h:118
const GUIComponent & minSize(const utils::Size &minSize) const
sets the component minimum size constraint
Definition: GUIComponent.h:147
const GUIComponent & maxSize(int w, int h) const
sets the component maximum size constraint
Definition: GUIComponent.h:164
const GUIComponent & hideIf(bool flag) const
hides the component if the given flag is true
Definition: GUIComponent.h:180
std::string label
label (results in a titeld border
Definition: GUIComponent.h:59
GUIComponent & size(int w, int h)
sets the component initial size
Definition: GUIComponent.h:210
const GUIComponent & maxSize(const utils::Size &maxSize) const
sets the component maximum size constraint
Definition: GUIComponent.h:158
std::string tooltip
component tooltip (not for containers)
Definition: GUIComponent.h:60
std::string m_params
component parameters
Definition: GUIComponent.h:109
GUIComponent & label(std::string &label)
sets the component label
Definition: GUIComponent.h:192
GUIComponent & hideIf(bool flag)
hides the component if the given flag is true
Definition: GUIComponent.h:241
int margin
layout margin (only for containers)
Definition: GUIComponent.h:61
GUIComponent & maxSize(utils::Size &maxSize)
sets the component maximum size constraint
Definition: GUIComponent.h:228
Size class of the ICL.
Definition: Size.h:61
utils::Size minSize
minimum size constraint of the component (in units of 20px)
Definition: GUIComponent.h:63
const GUIComponent & size(int w, int h) const
sets the component initial size
Definition: GUIComponent.h:142
The GUIComponent class servers as a generic interface for GUI definitions.
Definition: GUIComponent.h:44
static std::string form_args_3(const A &a, const B &b, const C &c)
utility method to concatenate 3 values
Definition: GUIComponent.h:75
utils::Size maxSize
maximum size constraint of the component (in units of 20px)
Definition: GUIComponent.h:64
bool hide
if true, the component is not created at all
Definition: GUIComponent.h:66
std::string str(const T &t)
convert a data type into a string using an std::ostringstream instance
Definition: StringUtils.h:136
std::string toString() const
creates a string representation of the component
Definition: GUIComponent.h:247
static std::string form_args_6(const A &a, const B &b, const C &c, const D &d, const E &e, const F &f)
utility method to concatenate 5 values
Definition: GUIComponent.h:99
GUIComponent & minSize(int w, int h)
sets the component minimum size constraint
Definition: GUIComponent.h:222
const GUIComponent & tooltip(const std::string &tooltip) const
sets the component tooltip
Definition: GUIComponent.h:130
Options m_options
all component options (mutable for C++-reasons)
Definition: GUIComponent.h:71
GUIComponent & handle(std::string &handle)
sets the component handle
Definition: GUIComponent.h:186
static std::string form_args_5(const A &a, const B &b, const C &c, const D &d, const E &e)
utility method to concatenate 5 values
Definition: GUIComponent.h:91
const GUIComponent & label(const std::string &label) const
sets the component label
Definition: GUIComponent.h:124
std::string handle
the component handle
Definition: GUIComponent.h:56
int spacing
layout spacing (onyl for containers)
Definition: GUIComponent.h:62
Actual options (set using the .xxx methods)
Definition: GUIComponent.h:54
GUIComponent & minSize(utils::Size &minSize)
sets the component minimum size constraint
Definition: GUIComponent.h:216
std::string out
the component output (only GUIComponentWithOutput subclasses)
Definition: GUIComponent.h:57
const GUIComponent & minSize(int w, int h) const
sets the component minimum size constraint
Definition: GUIComponent.h:153
std::string m_type
component type
Definition: GUIComponent.h:106
Options()
Definition: GUIComponent.h:55
std::string in
not used!
Definition: GUIComponent.h:58