PlotEvent.h

Go to the documentation of this file.
00001 //# PlotEvent.h: Classes for interaction events.
00002 //# Copyright (C) 2008
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id: $
00027 #ifndef PLOTEVENT_H_
00028 #define PLOTEVENT_H_
00029 
00030 #include <graphics/GenericPlotter/PlotOptions.h>
00031 
00032 namespace casa {
00033 
00034 //# Forward Declarations
00035 class Plotter;
00036 class PlotCanvas;
00037 class PlotButton;
00038 class PlotCheckbox;
00039 
00040 // Base class for an event.
00041 class PlotEvent {
00042 public:
00043     PlotEvent() { }
00044     
00045     virtual ~PlotEvent() { }
00046     
00047     // Return the origin of the object that spawned this event.
00048     virtual void* origin() const = 0;
00049 };
00050 
00051 
00052 // Event for when the user selects a region on a plot canvas with the mouse.
00053 class PlotSelectEvent : public virtual PlotEvent {
00054 public:
00055     // Constructor that takes the originating canvas and the selected region.
00056     PlotSelectEvent(PlotCanvas* canvas, const PlotRegion& region);
00057     
00058     // Destructor.
00059     ~PlotSelectEvent();
00060     
00061     // Overrides PlotEvent::origin().
00062     void* origin() const { return canvas(); }
00063     
00064     // Returns the canvas upon which the selection was made.
00065     PlotCanvas* canvas() const;
00066     
00067     // Returns the region that was selected.
00068     PlotRegion region() const;
00069     
00070 protected:
00071     PlotCanvas* m_canvas; // Canvas
00072     PlotRegion m_region;  // Selected Region
00073 };
00074 
00075 
00076 // Generic mouse event where the canvas is the origin, and the type, button,
00077 // and location of the event are provided.
00078 class PlotMouseEvent : public virtual PlotEvent {
00079 public:
00080     // Mouse event types.
00081     enum Type {
00082         CLICK,   // press and release (can be double)
00083         PRESS,   // press
00084         RELEASE, // release
00085         DRAG,    // mouse movement while button is down
00086         MOVE     // mouse movement any time
00087     };
00088     
00089     // Mouse button types that we care about.
00090     enum Button {
00091         SINGLE,  // left button, single click
00092         DOUBLE,  // left button, double click
00093         CONTEXT, // right button
00094         MIDDLE   // middle button
00095     };
00096     
00097     // Constructor which takes the originating canvas, type, button, and
00098     // location.
00099     PlotMouseEvent(PlotCanvas* canvas, Type type, Button button,
00100                    const PlotCoordinate& coord);
00101     
00102     // Destructor.
00103     virtual ~PlotMouseEvent();
00104     
00105     // Overrides PlotEvent::origin().
00106     void* origin() const { return canvas(); }
00107     
00108     // Canvas origin of event.
00109     PlotCanvas* canvas() const;
00110     
00111     // Type of event.
00112     Type type() const;
00113     
00114     // Button of event.
00115     Button button() const;
00116     
00117     // Location of event.
00118     PlotCoordinate where() const;
00119     
00120 protected:
00121     PlotCanvas* m_canvas;   // Canvas
00122     Type m_type;            // Type
00123     Button m_button;        // Button
00124     PlotCoordinate m_coord; // Location
00125 };
00126 
00127 
00128 // Convenience class for mouse clicks.
00129 class PlotClickEvent : public PlotMouseEvent {
00130 public:    
00131     PlotClickEvent(PlotCanvas* canvas, Button button,
00132             const PlotCoordinate& coord) :
00133             PlotMouseEvent(canvas, CLICK, button, coord) { }
00134     
00135     ~PlotClickEvent() { }
00136 };
00137 
00138 // Convenience class for mouse presses.
00139 class PlotMousePressEvent : public PlotMouseEvent {
00140 public:
00141     PlotMousePressEvent(PlotCanvas* canvas, Button button,
00142             const PlotCoordinate& coord) :
00143             PlotMouseEvent(canvas, PRESS, button, coord) { }
00144     
00145     ~PlotMousePressEvent() { }
00146 };
00147 
00148 // Convenience class for mouse releases.
00149 class PlotMouseReleaseEvent : public PlotMouseEvent {
00150 public:
00151     PlotMouseReleaseEvent(PlotCanvas* canvas, Button button,
00152             const PlotCoordinate& coord) :
00153             PlotMouseEvent(canvas, RELEASE, button, coord) { }
00154     
00155     ~PlotMouseReleaseEvent() { }
00156 };
00157 
00158 // Convenience class for mouse drags.
00159 class PlotMouseDragEvent : public PlotMouseEvent {
00160 public:
00161     PlotMouseDragEvent(PlotCanvas* canvas, Button button,
00162             const PlotCoordinate& coord) :
00163             PlotMouseEvent(canvas, DRAG, button, coord) { }
00164     
00165     ~PlotMouseDragEvent() { }
00166 };
00167 
00168 // Convenience class for mouse moves.
00169 class PlotMouseMoveEvent : public PlotMouseEvent {
00170 public:
00171     PlotMouseMoveEvent(PlotCanvas* canvas, Button button,
00172             const PlotCoordinate& coord) :
00173             PlotMouseEvent(canvas, MOVE, button, coord) { }
00174     
00175     ~PlotMouseMoveEvent() { }
00176 };
00177 
00178 
00179 // Event for when the user scrolls the scroll wheel.  The scroll event contains
00180 // a "delta" which is negative when the user scrolls back and positive when
00181 // the user scrolls forward.  The number indicates how many "clicks" the user
00182 // scrolled.
00183 class PlotWheelEvent : public virtual PlotEvent {
00184 public:
00185     // Constructor which takes the originating canvas, the wheel delta, and the
00186     // location.
00187     PlotWheelEvent(PlotCanvas* canvas, int delta, const PlotCoordinate& c);
00188     
00189     // Destructor.
00190     ~PlotWheelEvent();
00191     
00192     // Overrides PlotEvent::origin().
00193     void* origin() const { return canvas(); }
00194     
00195     // Canvas that was scrolled upon.
00196     PlotCanvas* canvas() const;
00197     
00198     // Scroll delta.
00199     int delta() const;
00200     
00201     // Where the scroll happened.
00202     PlotCoordinate where() const;
00203     
00204 protected:
00205     PlotCanvas* m_canvas;   // Canvas
00206     int m_delta;            // Scroll delta
00207     PlotCoordinate m_coord; // Location
00208 };
00209 
00210 
00211 // Event for when the user makes a keyboard command when a canvas has focus.
00212 // An example of a keyboard command would be "ctrl+s" or "n" or "shift+g" or
00213 // "F3".  Note that this event is only valid for key commands that can be
00214 // represented with a char (or, in the case of the F1-F12 keys, the F modifier
00215 // plus the character representation of the number).
00216 class PlotKeyEvent : public virtual PlotEvent {
00217 public:
00218     // Modifier for a key press
00219     enum Modifier {
00220         CONTROL, SHIFT, ALT, F
00221     };
00222     
00223     // Constructor that takes the originating canvas, the key pressed, and any
00224     // modifiers.
00225     PlotKeyEvent(PlotCanvas* canvas, char key, const vector<Modifier>& mods);
00226     
00227     // Destructor.
00228     ~PlotKeyEvent();
00229     
00230     // Overrides PlotEvent::origin().
00231     void* origin() const { return canvas(); }
00232     
00233     // Returns the originating canvas.
00234     PlotCanvas* canvas() const;
00235     
00236     // Returns the pressed character key.
00237     char key() const;
00238     
00239     // Returns the key modifiers.
00240     vector<Modifier> modifiers() const;
00241     
00242     // Returns a String representation of this key event.
00243     String toString() const;
00244     
00245     
00246     // Converts between KeyModifier and its String representation.
00247     // <group>
00248     static String modifier(Modifier f) {
00249         switch(f) {
00250         case CONTROL: return "Ctrl";
00251         case ALT: return "Alt";
00252         case SHIFT: return "Shift";
00253         case F: return "F";
00254         
00255         default: return "?";
00256         }
00257     }    
00258     static Modifier modifier(String f) {
00259         f.downcase();
00260         
00261         if(f == "ctrl" || f == "control") return CONTROL;
00262         if(f == "shift") return SHIFT;
00263         if(f == "alt") return ALT;
00264         if(f == "f" || f == "function") return F;
00265         
00266         return F;
00267     }
00268     // </group>
00269     
00270 protected:
00271     PlotCanvas* m_canvas;    // Canvas
00272     char m_key;              // Character
00273     vector<Modifier> m_mods; // Modifiers
00274 };
00275 
00276 
00277 // Event for when a canvas or plotter is resized.
00278 class PlotResizeEvent : public virtual PlotEvent {
00279 public:
00280     // Canvas resize constructor, which takes the old and new sizes.
00281     PlotResizeEvent(PlotCanvas* canvas, int oldWidth, int oldHeight,
00282                     int newWidth, int newHeight);
00283     
00284     // Plotter resize constructor, which takes the old and new sizes.
00285     PlotResizeEvent(Plotter* plotter, int oldWidth, int oldHeight,
00286                     int newWidth, int newHeight);
00287     
00288     // Destructor.
00289     ~PlotResizeEvent();
00290     
00291     // Overrides PlotEvent::origin().
00292     void* origin() const {
00293         if(canvas() != NULL) return canvas();
00294         else                 return plotter();
00295     }
00296     
00297     // Canvas that was resized, or NULL if it was a plotter.
00298     PlotCanvas* canvas() const;
00299     
00300     // Plotter that was resize, or NULL if it was a canvas.
00301     Plotter* plotter() const;
00302     
00303     // Old size, in pixels.
00304     std::pair<int, int> oldSize() const;
00305     
00306     // New size, in pixels.
00307     std::pair<int, int> newSize() const;
00308     
00309 protected:
00310     Plotter* m_plotter;   // Plotter (or NULL)
00311     PlotCanvas* m_canvas; // Canvas (or NULL)
00312     std::pair<int, int> m_old; // Old size
00313     std::pair<int, int> m_new; // New size
00314 };
00315 
00316 
00317 // Event for when a PlotButton is pressed.
00318 class PlotButtonEvent : public virtual PlotEvent {
00319 public:
00320     // Constructor which takes the originating button.
00321     PlotButtonEvent(PlotButton* button);
00322     
00323     // Destructor.
00324     ~PlotButtonEvent();
00325     
00326     // Overrides PlotEvent::origin().
00327     void* origin() const { return button(); }
00328     
00329     // Returns the button that was clicked.
00330     PlotButton* button() const;
00331     
00332 protected:
00333     PlotButton* m_button; // button
00334 };
00335 
00336 // Event for when a PlotCheckbox is clicked.
00337 class PlotCheckboxEvent : public virtual PlotEvent {
00338 public:
00339     // Constructor which takes the originating checkbox.
00340     PlotCheckboxEvent(PlotCheckbox* checkbox);
00341     
00342     // Destructor.
00343     ~PlotCheckboxEvent();
00344     
00345     // Overrides PlotEvent::origin().
00346     void* origin() const { return checkbox(); }
00347     
00348     // Returns the checkbox that was clicked.
00349     PlotCheckbox* checkbox() const;
00350     
00351 protected:
00352     PlotCheckbox* m_checkbox; // checkbox
00353 };
00354 
00355 }
00356 
00357 #endif /*PLOTEVENT_H_*/
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1