Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
berryGuiTkIControlListener.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef BERRYGUITKICONTROLLISTENER_H_
14 #define BERRYGUITKICONTROLLISTENER_H_
15 
16 #include <berryMacros.h>
17 #include <berryMessage.h>
18 
20 #include "berryGuiTkControlEvent.h"
21 
22 namespace berry
23 {
24 
25 namespace GuiTk
26 {
27 
44 struct BERRY_UI_QT IControlListener: public virtual Object
45 {
46 
48 
50 
51  enum Type {
52  NONE = 0x00000000,
53  MOVED = 0x00000001,
54  RESIZED = 0x00000002,
55  ACTIVATED = 0x00000004,
56  DESTROYED = 0x00000008,
57 
58  ALL = 0xffffffff
59  };
60 
61  Q_DECLARE_FLAGS(Types, Type)
62 
64 
65  EventType movedEvent;
66  EventType resizedEvent;
67  EventType activatedEvent;
68  EventType destroyedEvent;
69 
70  void AddListener(IControlListener::Pointer listener);
71  void RemoveListener(IControlListener::Pointer listener);
72 
73  private:
75  };
76 
77  ~IControlListener() override;
78 
79  virtual Events::Types GetEventTypes() const = 0;
80 
87  virtual void ControlMoved(ControlEvent::Pointer /*e*/)
88  {
89  }
90 
97  {
98  }
99 
101  {
102  }
103 
105  {
106  }
107 
108 };
109 
110 template<typename R>
112 {
113  typedef R Listener;
114  typedef void
115  (R::*Callback)(ControlEvent::Pointer);
116 
117  ControlMovedAdapter(R* l, Callback c) :
118  listener(l), callback(c)
119  {
120  poco_assert(listener);
121  poco_assert(callback);
122  }
123 
124  Events::Types GetEventTypes() const override
125  {
126  return Events::MOVED;
127  }
128 
130  {
131  (listener->*callback)(e);
132  }
133 
134 private:
135 
136  Listener* listener;
137  Callback callback;
138 };
139 
140 template<typename R>
142 {
143  typedef R Listener;
144  typedef void
145  (R::*Callback)(ControlEvent::Pointer);
146 
147  ControlResizedAdapter(R* l, Callback c) :
148  listener(l), callback(c)
149  {
150  poco_assert(listener);
151  poco_assert(callback);
152  }
153 
154  Events::Types GetEventTypes() const override
155  {
156  return Events::RESIZED;
157  }
158 
160  {
161  (listener->*callback)(e);
162  }
163 
164 private:
165 
166  Listener* listener;
167  Callback callback;
168 };
169 
170 template<typename R>
172 {
173  typedef R Listener;
174  typedef void
175  (R::*Callback)(ControlEvent::Pointer);
176 
177  ControlActivatedAdapter(R* l, Callback c) :
178  listener(l), callback(c)
179  {
180  poco_assert(listener);
181  poco_assert(callback);
182  }
183 
184  Events::Types GetEventTypes() const override
185  {
186  return Events::ACTIVATED;
187  }
188 
190  {
191  (listener->*callback)(e);
192  }
193 
194 private:
195 
196  Listener* listener;
197  Callback callback;
198 };
199 
200 template<typename R>
202 {
203  typedef R Listener;
204  typedef void
205  (R::*Callback)(ControlEvent::Pointer);
206 
207  ControlDestroyedAdapter(R* l, Callback c) :
208  listener(l), callback(c)
209  {
210  poco_assert(listener);
211  poco_assert(callback);
212  }
213 
214  Events::Types GetEventTypes() const override
215  {
216  return Events::DESTROYED;
217  }
218 
220  {
221  (listener->*callback)(e);
222  }
223 
224 private:
225 
226  Listener* listener;
227  Callback callback;
228 };
229 
230 }
231 
232 }
233 
234 Q_DECLARE_OPERATORS_FOR_FLAGS(berry::GuiTk::IControlListener::Events::Types)
235 
236 #endif /* BERRYGUITKICONTROLLISTENER_H_ */
Events::Types GetEventTypes() const override
virtual void ControlDestroyed(ControlEvent::Pointer)
Events::Types GetEventTypes() const override
Light weight base class for most BlueBerry classes.
Definition: berryObject.h:72
virtual void ControlActivated(ControlEvent::Pointer)
berry::SmartPointer< Self > Pointer
Definition: berryObject.h:82
virtual void ControlResized(ControlEvent::Pointer)
#define berryObjectMacro(...)
Definition: berryMacros.h:33
Events::Types GetEventTypes() const override
Events::Types GetEventTypes() const override
void ControlMoved(ControlEvent::Pointer e) override
void ControlDestroyed(ControlEvent::Pointer e) override
void ControlResized(ControlEvent::Pointer e) override
void ControlActivated(ControlEvent::Pointer e) override
#define BERRY_UI_QT