casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PlotEvent.h
Go to the documentation of this file.
1 //# PlotEvent.h: Classes for interaction events.
2 //# Copyright (C) 2008
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id: $
27 #ifndef PLOTEVENT_H_
28 #define PLOTEVENT_H_
29 
31 
32 namespace casa {
33 
34 //# Forward Declarations
35 class Plotter;
36 class PlotCanvas;
37 class PlotButton;
38 class PlotCheckbox;
39 
40 // Base class for an event.
41 class PlotEvent {
42 public:
43  PlotEvent() { }
44 
45  virtual ~PlotEvent() { }
46 
47  // Return the origin of the object that spawned this event.
48  virtual void* origin() const = 0;
49 };
50 
51 
52 // Event for when the user selects a region on a plot canvas with the mouse.
53 class PlotSelectEvent : public virtual PlotEvent {
54 public:
55  // Constructor that takes the originating canvas and the selected region.
57 
58  // Destructor.
60 
61  // Overrides PlotEvent::origin().
62  void* origin() const { return canvas(); }
63 
64  // Returns the canvas upon which the selection was made.
65  PlotCanvas* canvas() const;
66 
67  // Returns the region that was selected.
68  PlotRegion region() const;
69 
70 protected:
71  PlotCanvas* m_canvas; // Canvas
72  PlotRegion m_region; // Selected Region
73 };
74 
75 
76 // Generic mouse event where the canvas is the origin, and the type, button,
77 // and location of the event are provided.
78 class PlotMouseEvent : public virtual PlotEvent {
79 public:
80  // Mouse event types.
81  enum Type {
82  CLICK, // press and release (can be double)
83  PRESS, // press
84  RELEASE, // release
85  DRAG, // mouse movement while button is down
86  MOVE // mouse movement any time
87  };
88 
89  // Mouse button types that we care about.
90  enum Button {
91  SINGLE, // left button, single click
92  DOUBLE, // left button, double click
93  CONTEXT, // right button
94  MIDDLE // middle button
95  };
96 
97  // Constructor which takes the originating canvas, type, button, and
98  // location.
100  const PlotCoordinate& coord);
101 
102  // Destructor.
103  virtual ~PlotMouseEvent();
104 
105  // Overrides PlotEvent::origin().
106  void* origin() const { return canvas(); }
107 
108  // Canvas origin of event.
109  PlotCanvas* canvas() const;
110 
111  // Type of event.
112  Type type() const;
113 
114  // Button of event.
115  Button button() const;
116 
117  // Location of event.
118  PlotCoordinate where() const;
119 
120 protected:
121  PlotCanvas* m_canvas; // Canvas
122  Type m_type; // Type
123  Button m_button; // Button
124  PlotCoordinate m_coord; // Location
125 };
126 
127 
128 // Convenience class for mouse clicks.
130 public:
132  const PlotCoordinate& coord) :
133  PlotMouseEvent(canvas, CLICK, button, coord) { }
134 
136 };
137 
138 // Convenience class for mouse presses.
140 public:
142  const PlotCoordinate& coord) :
143  PlotMouseEvent(canvas, PRESS, button, coord) { }
144 
146 };
147 
148 // Convenience class for mouse releases.
150 public:
152  const PlotCoordinate& coord) :
153  PlotMouseEvent(canvas, RELEASE, button, coord) { }
154 
156 };
157 
158 // Convenience class for mouse drags.
160 public:
162  const PlotCoordinate& coord) :
163  PlotMouseEvent(canvas, DRAG, button, coord) { }
164 
166 };
167 
168 // Convenience class for mouse moves.
170 public:
172  const PlotCoordinate& coord) :
173  PlotMouseEvent(canvas, MOVE, button, coord) { }
174 
176 };
177 
178 
179 // Event for when the user scrolls the scroll wheel. The scroll event contains
180 // a "delta" which is negative when the user scrolls back and positive when
181 // the user scrolls forward. The number indicates how many "clicks" the user
182 // scrolled.
183 class PlotWheelEvent : public virtual PlotEvent {
184 public:
185  // Constructor which takes the originating canvas, the wheel delta, and the
186  // location.
187  PlotWheelEvent(PlotCanvas* canvas, int delta, const PlotCoordinate& c);
188 
189  // Destructor.
190  ~PlotWheelEvent();
191 
192  // Overrides PlotEvent::origin().
193  void* origin() const { return canvas(); }
194 
195  // Canvas that was scrolled upon.
196  PlotCanvas* canvas() const;
197 
198  // Scroll delta.
199  int delta() const;
200 
201  // Where the scroll happened.
202  PlotCoordinate where() const;
203 
204 protected:
205  PlotCanvas* m_canvas; // Canvas
206  int m_delta; // Scroll delta
207  PlotCoordinate m_coord; // Location
208 };
209 
210 
211 // Event for when the user makes a keyboard command when a canvas has focus.
212 // An example of a keyboard command would be "ctrl+s" or "n" or "shift+g" or
213 // "F3". Note that this event is only valid for key commands that can be
214 // represented with a char (or, in the case of the F1-F12 keys, the F modifier
215 // plus the character representation of the number).
216 class PlotKeyEvent : public virtual PlotEvent {
217 public:
218  // Modifier for a key press
219  enum Modifier {
221  };
222 
223  // Constructor that takes the originating canvas, the key pressed, and any
224  // modifiers.
225  PlotKeyEvent(PlotCanvas* canvas, char key, const std::vector<Modifier>& mods);
226 
227  // Destructor.
228  ~PlotKeyEvent();
229 
230  // Overrides PlotEvent::origin().
231  void* origin() const { return canvas(); }
232 
233  // Returns the originating canvas.
234  PlotCanvas* canvas() const;
235 
236  // Returns the pressed character key.
237  char key() const;
238 
239  // Returns the key modifiers.
240  std::vector<Modifier> modifiers() const;
241 
242  // Returns a casacore::String representation of this key event.
243  casacore::String toString() const;
244 
245 
246  // Converts between KeyModifier and its casacore::String representation.
247  // <group>
249  switch(f) {
250  case CONTROL: return "Ctrl";
251  case ALT: return "Alt";
252  case SHIFT: return "Shift";
253  case F: return "F";
254 
255  default: return "?";
256  }
257  }
259  f.downcase();
260 
261  if(f == "ctrl" || f == "control") return CONTROL;
262  if(f == "shift") return SHIFT;
263  if(f == "alt") return ALT;
264  if(f == "f" || f == "function") return F;
265 
266  return F;
267  }
268  // </group>
269 
270 protected:
271  PlotCanvas* m_canvas; // Canvas
272  char m_key; // Character
273  std::vector<Modifier> m_mods; // Modifiers
274 };
275 
276 
277 // Event for when a canvas or plotter is resized.
278 class PlotResizeEvent : public virtual PlotEvent {
279 public:
280  // Canvas resize constructor, which takes the old and new sizes.
281  PlotResizeEvent(PlotCanvas* canvas, int oldWidth, int oldHeight,
282  int newWidth, int newHeight);
283 
284  // Plotter resize constructor, which takes the old and new sizes.
285  PlotResizeEvent(Plotter* plotter, int oldWidth, int oldHeight,
286  int newWidth, int newHeight);
287 
288  // Destructor.
290 
291  // Overrides PlotEvent::origin().
292  void* origin() const {
293  if(canvas() != NULL) return canvas();
294  else return plotter();
295  }
296 
297  // Canvas that was resized, or NULL if it was a plotter.
298  PlotCanvas* canvas() const;
299 
300  // Plotter that was resize, or NULL if it was a canvas.
301  Plotter* plotter() const;
302 
303  // Old size, in pixels.
304  std::pair<int, int> oldSize() const;
305 
306  // New size, in pixels.
307  std::pair<int, int> newSize() const;
308 
309 protected:
310  Plotter* m_plotter; // Plotter (or NULL)
311  PlotCanvas* m_canvas; // Canvas (or NULL)
312  std::pair<int, int> m_old; // Old size
313  std::pair<int, int> m_new; // New size
314 };
315 
316 
317 // Event for when a PlotButton is pressed.
318 class PlotButtonEvent : public virtual PlotEvent {
319 public:
320  // Constructor which takes the originating button.
322 
323  // Destructor.
325 
326  // Overrides PlotEvent::origin().
327  void* origin() const { return button(); }
328 
329  // Returns the button that was clicked.
330  PlotButton* button() const;
331 
332 protected:
333  PlotButton* m_button; // button
334 };
335 
336 // Event for when a PlotCheckbox is clicked.
337 class PlotCheckboxEvent : public virtual PlotEvent {
338 public:
339  // Constructor which takes the originating checkbox.
341 
342  // Destructor.
344 
345  // Overrides PlotEvent::origin().
346  void* origin() const { return checkbox(); }
347 
348  // Returns the checkbox that was clicked.
349  PlotCheckbox* checkbox() const;
350 
351 protected:
352  PlotCheckbox* m_checkbox; // checkbox
353 };
354 
355 }
356 
357 #endif /*PLOTEVENT_H_*/
PlotRegion region() const
Returns the region that was selected.
PlotCanvas * m_canvas
Definition: PlotEvent.h:271
void * origin() const
Overrides PlotEvent::origin().
Definition: PlotEvent.h:193
std::pair< int, int > newSize() const
New size, in pixels.
PlotButton * m_button
Definition: PlotEvent.h:333
Event for when the user selects a region on a plot canvas with the mouse.
Definition: PlotEvent.h:53
PlotCanvas * canvas() const
Returns the originating canvas.
PlotButton * button() const
Returns the button that was clicked.
Convenience class for mouse presses.
Definition: PlotEvent.h:139
char key() const
Returns the pressed character key.
static Modifier modifier(casacore::String f)
Definition: PlotEvent.h:258
PlotResizeEvent(PlotCanvas *canvas, int oldWidth, int oldHeight, int newWidth, int newHeight)
Canvas resize constructor, which takes the old and new sizes.
int delta() const
Scroll delta.
PlotCheckbox * m_checkbox
Definition: PlotEvent.h:352
Event for when a PlotCheckbox is clicked.
Definition: PlotEvent.h:337
PlotCheckbox * checkbox() const
Returns the checkbox that was clicked.
Modifier
Modifier for a key press.
Definition: PlotEvent.h:219
std::pair< int, int > oldSize() const
Old size, in pixels.
virtual void * origin() const =0
Return the origin of the object that spawned this event.
void * origin() const
Overrides PlotEvent::origin().
Definition: PlotEvent.h:292
void * origin() const
Overrides PlotEvent::origin().
Definition: PlotEvent.h:106
Convenience class for mouse moves.
Definition: PlotEvent.h:169
std::vector< Modifier > modifiers() const
Returns the key modifiers.
Generic class for a button that goes on a PlotPanel.
Definition: PlotPanel.h:68
PlotMouseReleaseEvent(PlotCanvas *canvas, Button button, const PlotCoordinate &coord)
Definition: PlotEvent.h:151
PlotCanvas * m_canvas
Definition: PlotEvent.h:311
Button
Mouse button types that we care about.
Definition: PlotEvent.h:90
~PlotCheckboxEvent()
Destructor.
PlotRegion m_region
Definition: PlotEvent.h:72
Event for when the user scrolls the scroll wheel.
Definition: PlotEvent.h:183
PlotWheelEvent(PlotCanvas *canvas, int delta, const PlotCoordinate &c)
Constructor which takes the originating canvas, the wheel delta, and the location.
A Plotter can be thought of as a frame that holds one or more PlotCanvases in a configuration determi...
Definition: Plotter.h:43
Convenience class for mouse clicks.
Definition: PlotEvent.h:129
PlotKeyEvent(PlotCanvas *canvas, char key, const std::vector< Modifier > &mods)
Constructor that takes the originating canvas, the key pressed, and any modifiers.
PlotCheckboxEvent(PlotCheckbox *checkbox)
Constructor which takes the originating checkbox.
PlotMouseEvent(PlotCanvas *canvas, Type type, Button button, const PlotCoordinate &coord)
Constructor which takes the originating canvas, type, button, and location.
Generic class for a checkbox that goes on a PlotPanel.
Definition: PlotPanel.h:126
Event for when the user makes a keyboard command when a canvas has focus.
Definition: PlotEvent.h:216
Plotter * plotter() const
Plotter that was resize, or NULL if it was a canvas.
Button button() const
Button of event.
~PlotResizeEvent()
Destructor.
std::pair< int, int > m_old
Definition: PlotEvent.h:312
void * origin() const
Overrides PlotEvent::origin().
Definition: PlotEvent.h:346
PlotMouseDragEvent(PlotCanvas *canvas, Button button, const PlotCoordinate &coord)
Definition: PlotEvent.h:161
PlotMousePressEvent(PlotCanvas *canvas, Button button, const PlotCoordinate &coord)
Definition: PlotEvent.h:141
PlotCoordinate m_coord
Definition: PlotEvent.h:124
PlotClickEvent(PlotCanvas *canvas, Button button, const PlotCoordinate &coord)
Definition: PlotEvent.h:131
~PlotButtonEvent()
Destructor.
Base class for an event.
Definition: PlotEvent.h:41
PlotButtonEvent(PlotButton *button)
Constructor which takes the originating button.
~PlotWheelEvent()
Destructor.
PlotCanvas * canvas() const
Returns the canvas upon which the selection was made.
PlotCoordinate where() const
Where the scroll happened.
static casacore::String modifier(Modifier f)
Converts between KeyModifier and its casacore::String representation.
Definition: PlotEvent.h:248
Convenience class for mouse drags.
Definition: PlotEvent.h:159
Event for when a canvas or plotter is resized.
Definition: PlotEvent.h:278
std::pair< int, int > m_new
Definition: PlotEvent.h:313
~PlotSelectEvent()
Destructor.
virtual ~PlotEvent()
Definition: PlotEvent.h:45
Generic mouse event where the canvas is the origin, and the type, button, and location of the event a...
Definition: PlotEvent.h:78
~PlotKeyEvent()
Destructor.
PlotSelectEvent(PlotCanvas *canvas, const PlotRegion &region)
Constructor that takes the originating canvas and the selected region.
PlotCanvas * canvas() const
Canvas origin of event.
PlotCanvas is an area for different PlotItems to be attached and drawn.
Definition: PlotCanvas.h:83
virtual ~PlotMouseEvent()
Destructor.
Type
Mouse event types.
Definition: PlotEvent.h:81
PlotCanvas * m_canvas
Definition: PlotEvent.h:121
PlotCanvas * m_canvas
Definition: PlotEvent.h:71
void * origin() const
Overrides PlotEvent::origin().
Definition: PlotEvent.h:231
PlotMouseMoveEvent(PlotCanvas *canvas, Button button, const PlotCoordinate &coord)
Definition: PlotEvent.h:171
const Double c
Fundamental physical constants (SI units):
void * origin() const
Overrides PlotEvent::origin().
Definition: PlotEvent.h:327
String: the storage and methods of handling collections of characters.
Definition: String.h:223
PlotCoordinate m_coord
Definition: PlotEvent.h:207
casacore::String toString() const
Returns a casacore::String representation of this key event.
Event for when a PlotButton is pressed.
Definition: PlotEvent.h:318
std::vector< Modifier > m_mods
Definition: PlotEvent.h:273
PlotCanvas * m_canvas
Definition: PlotEvent.h:205
PlotCanvas * canvas() const
Canvas that was scrolled upon.
A PlotRegion is basically just a wrapper for two PlotCoordinates: an upper left coordinate and a lowe...
Definition: PlotOptions.h:682
Type type() const
Type of event.
PlotCanvas * canvas() const
Canvas that was resized, or NULL if it was a plotter.
void downcase()
internal transformation to lowercase of String
Convenience class for mouse releases.
Definition: PlotEvent.h:149
void * origin() const
Overrides PlotEvent::origin().
Definition: PlotEvent.h:62
PlotCoordinate where() const
Location of event.