Line data Source code
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: casa-feedback@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 :
30 : #include <graphics/GenericPlotter/PlotOptions.h>
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 0 : PlotEvent() { }
44 :
45 0 : 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.
56 : PlotSelectEvent(PlotCanvas* canvas, const PlotRegion& region);
57 :
58 : // Destructor.
59 : ~PlotSelectEvent();
60 :
61 : // Overrides PlotEvent::origin().
62 0 : 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.
99 : PlotMouseEvent(PlotCanvas* canvas, Type type, Button button,
100 : const PlotCoordinate& coord);
101 :
102 : // Destructor.
103 : virtual ~PlotMouseEvent();
104 :
105 : // Overrides PlotEvent::origin().
106 0 : 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.
129 : class PlotClickEvent : public PlotMouseEvent {
130 : public:
131 0 : PlotClickEvent(PlotCanvas* canvas, Button button,
132 0 : const PlotCoordinate& coord) :
133 0 : PlotMouseEvent(canvas, CLICK, button, coord) { }
134 :
135 0 : ~PlotClickEvent() { }
136 : };
137 :
138 : // Convenience class for mouse presses.
139 : class PlotMousePressEvent : public PlotMouseEvent {
140 : public:
141 0 : PlotMousePressEvent(PlotCanvas* canvas, Button button,
142 0 : const PlotCoordinate& coord) :
143 0 : PlotMouseEvent(canvas, PRESS, button, coord) { }
144 :
145 0 : ~PlotMousePressEvent() { }
146 : };
147 :
148 : // Convenience class for mouse releases.
149 : class PlotMouseReleaseEvent : public PlotMouseEvent {
150 : public:
151 0 : PlotMouseReleaseEvent(PlotCanvas* canvas, Button button,
152 0 : const PlotCoordinate& coord) :
153 0 : PlotMouseEvent(canvas, RELEASE, button, coord) { }
154 :
155 0 : ~PlotMouseReleaseEvent() { }
156 : };
157 :
158 : // Convenience class for mouse drags.
159 : class PlotMouseDragEvent : public PlotMouseEvent {
160 : public:
161 0 : PlotMouseDragEvent(PlotCanvas* canvas, Button button,
162 0 : const PlotCoordinate& coord) :
163 0 : PlotMouseEvent(canvas, DRAG, button, coord) { }
164 :
165 0 : ~PlotMouseDragEvent() { }
166 : };
167 :
168 : // Convenience class for mouse moves.
169 : class PlotMouseMoveEvent : public PlotMouseEvent {
170 : public:
171 0 : PlotMouseMoveEvent(PlotCanvas* canvas, Button button,
172 0 : const PlotCoordinate& coord) :
173 0 : PlotMouseEvent(canvas, MOVE, button, coord) { }
174 :
175 0 : ~PlotMouseMoveEvent() { }
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 0 : 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 {
220 : CONTROL, SHIFT, ALT, F
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 0 : 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>
248 0 : static casacore::String modifier(Modifier f) {
249 0 : switch(f) {
250 0 : case CONTROL: return "Ctrl";
251 0 : case ALT: return "Alt";
252 0 : case SHIFT: return "Shift";
253 0 : case F: return "F";
254 :
255 0 : default: return "?";
256 : }
257 : }
258 : static Modifier modifier(casacore::String f) {
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.
289 : ~PlotResizeEvent();
290 :
291 : // Overrides PlotEvent::origin().
292 0 : void* origin() const {
293 0 : if(canvas() != NULL) return canvas();
294 0 : 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.
321 : PlotButtonEvent(PlotButton* button);
322 :
323 : // Destructor.
324 : ~PlotButtonEvent();
325 :
326 : // Overrides PlotEvent::origin().
327 0 : 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.
340 : PlotCheckboxEvent(PlotCheckbox* checkbox);
341 :
342 : // Destructor.
343 : ~PlotCheckboxEvent();
344 :
345 : // Overrides PlotEvent::origin().
346 0 : 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_*/
|