Medical Imaging Interaction Toolkit  2021.10.99-1c4db16f
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 
85  virtual void ControlMoved(ControlEvent::Pointer)
86  {
87  }
88 
93  {
94  }
95 
97  {
98  }
99 
101  {
102  }
103 
104 };
105 
106 template<typename R>
108 {
109  typedef R Listener;
110  typedef void
111  (R::*Callback)(ControlEvent::Pointer);
112 
113  ControlMovedAdapter(R* l, Callback c) :
114  listener(l), callback(c)
115  {
116  poco_assert(listener);
117  poco_assert(callback);
118  }
119 
120  Events::Types GetEventTypes() const override
121  {
122  return Events::MOVED;
123  }
124 
126  {
127  (listener->*callback)(e);
128  }
129 
130 private:
131 
132  Listener* listener;
133  Callback callback;
134 };
135 
136 template<typename R>
138 {
139  typedef R Listener;
140  typedef void
141  (R::*Callback)(ControlEvent::Pointer);
142 
143  ControlResizedAdapter(R* l, Callback c) :
144  listener(l), callback(c)
145  {
146  poco_assert(listener);
147  poco_assert(callback);
148  }
149 
150  Events::Types GetEventTypes() const override
151  {
152  return Events::RESIZED;
153  }
154 
156  {
157  (listener->*callback)(e);
158  }
159 
160 private:
161 
162  Listener* listener;
163  Callback callback;
164 };
165 
166 template<typename R>
168 {
169  typedef R Listener;
170  typedef void
171  (R::*Callback)(ControlEvent::Pointer);
172 
173  ControlActivatedAdapter(R* l, Callback c) :
174  listener(l), callback(c)
175  {
176  poco_assert(listener);
177  poco_assert(callback);
178  }
179 
180  Events::Types GetEventTypes() const override
181  {
182  return Events::ACTIVATED;
183  }
184 
186  {
187  (listener->*callback)(e);
188  }
189 
190 private:
191 
192  Listener* listener;
193  Callback callback;
194 };
195 
196 template<typename R>
198 {
199  typedef R Listener;
200  typedef void
201  (R::*Callback)(ControlEvent::Pointer);
202 
203  ControlDestroyedAdapter(R* l, Callback c) :
204  listener(l), callback(c)
205  {
206  poco_assert(listener);
207  poco_assert(callback);
208  }
209 
210  Events::Types GetEventTypes() const override
211  {
212  return Events::DESTROYED;
213  }
214 
216  {
217  (listener->*callback)(e);
218  }
219 
220 private:
221 
222  Listener* listener;
223  Callback callback;
224 };
225 
226 }
227 
228 }
229 
230 Q_DECLARE_OPERATORS_FOR_FLAGS(berry::GuiTk::IControlListener::Events::Types)
231 
232 #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