casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QtMouseToolState.qo.h
Go to the documentation of this file.
1 //# QtMouseToolState.qo.h: constants and [global] mouse-button state
2 //# for the qtviewer 'mouse-tools' used by its display panel[s].
3 //# Copyright (C) 2005
4 //# Associated Universities, Inc. Washington DC, USA.
5 //#
6 //# This library is free software; you can redistribute it and/or modify it
7 //# under the terms of the GNU Library General Public License as published by
8 //# the Free Software Foundation; either version 2 of the License, or (at your
9 //# option) any later version.
10 //#
11 //# This library is distributed in the hope that it will be useful, but WITHOUT
12 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14 //# License for more details.
15 //#
16 //# You should have received a copy of the GNU Library General Public License
17 //# along with this library; if not, write to the Free Software Foundation,
18 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
19 //#
20 //# Correspondence concerning AIPS++ should be addressed as follows:
21 //# Internet email: aips2-request@nrao.edu.
22 //# Postal address: AIPS++ Project Office
23 //# National Radio Astronomy Observatory
24 //# 520 Edgemont Road
25 //# Charlottesville, VA 22903-2475 USA
26 //#
27 //# $Id$
28 
29 
30 #ifndef QTMOUSETOOLSTATE_QO_H_
31 #define QTMOUSETOOLSTATE_QO_H_
32 
33 #include <casa/aips.h>
34 #include <casa/BasicSL/String.h>
37 
38 #include <graphics/X11/X_enter.h>
39 # include <QObject>
40 #include <graphics/X11/X_exit.h>
41 #include <map>
42 
43 namespace casa { //# NAMESPACE CASA - BEGIN
44 
45 
46  class QtViewerBase;
47 
48 
49 // <synopsis>
50 // QtMouseToolState records the currently-active mouse button (if any)
51 // of each type of Qt mouse tool. There may be a QtMouseToolBar for each
52 // QtDisplayPanel (and in principle each may display a different subset
53 // of all the possible tools, though this is not implemented yet (7/06)).
54 // However, each mouse button (Left, Middle, Right) may be assigned to
55 // at most one type of tool type, and that assignment should be the same
56 // on each QtMouseToolBar.
57 //
58 // To accomplish that, this class signals current button assignments
59 // whenever such assignments change. All display panels and/or their mouse
60 // tool bars may connect to this signal to keep Toolbar button icons and the
61 // actual core library mouse tools (such as MWCZoomer) in sync.
62 //
63 // This button state is therefore also essentially global or static, but this
64 // class cannot be purely static because it must be a real QObject
65 // to send out such a signal. Instead, there should be only one
66 // QtMouseToolState object (managed by the [one] QtViewer[Base] object),
67 // and all listeners should use that object for setting and responding to
68 // current mouse tool button state.
69 // </synopsis>
70 
71  class QtMouseToolState : public QObject {
72 
73 
74  Q_OBJECT //# Allows slot/signal definition. Must only occur in
75  //# implement/.../*.h files; also, makefile must include
76  //# name of this file in 'mocs' section.
77 
78 
79  public:
80 
81  // Returns button currently assigned to a tool (0 = no button assigned).
84  }
85 
86  // Returns name of tool currently assigned to a mouse button (1, 2, or 3).
87  // (Returns NONE if passed mousebtn is 0 or no tool is assigned to it).
90  }
91 
92  int getButtonState(const std::string &tool) const;
93 
94 
95  public slots:
96 
97  // Request reassignment of a given mouse button to a tool.
98  // NB: _This_ is where guis, etc. should request a button change, so that
99  // all stay on the same page (not directly to tool or displaypanel, e.g.).
100  void chgMouseBtn(casacore::String tool, int mousebtn);
101  void mouseBtnStateChg(casacore::String tool, int state);
102 
103  // Request signalling of the current mouse button setting for every
104  // type of tool. Call this if you want to assure that everyone's
105  // up-to-date on mouse button settings.
106  void emitBtns();
107 
108 
109  signals:
110 
111  // Notification of a tool's [new] mouse button.
112  void mouseBtnChg(std::string tool, int mousebtn);
113 
114 
115  protected:
117 
118  // Only QtviewerBase is intended to create/destroy
119  // a [single] instance of this class.
122  friend class QtViewerBase;
123 
124  // Returns index of tool currently assigned to a mouse button (1, 2, or 3).
125  // (Returns nTools if passed mousebtn is 0 or no tool is assigned to it).
126  int toolIndexOnButton_(int mousebtn);
127 
128 
129  // The button currently assigned to the various types of mouse tool.
130  //
131  // mousebtns_ value Corresp. internal library value
132  // ---------------- -------------------------------
133  // 0: <no button> Display::K_None
134  // 1: LeftButton Display::K_Pointer_Button1
135  // 2: MidButton Display::K_Pointer_Button2
136  // 3: RightButton Display::K_Pointer_Button3
138  //# Initial values; correspond to QtMouseToolNames::tools[], above.
139  //# mousebtns_[nTools] is an entry for an invalid tool.
140  //# At most one of the above will be 1,2,3; the rest will be 0.
141 
142  private:
143  std::map<std::string,int> tool_state;
144  void initButtonState( std::string, int );
145  void initToolState( );
146 
147  };
148 
149 } //# NAMESPACE CASA - END
150 
151 #endif
static int mousebtns_[QtMouseToolNames::nTools+1]
The button currently assigned to the various types of mouse tool.
QtMouseToolState()
Only QtviewerBase is intended to create/destroy a [single] instance of this class.
void chgMouseBtn(casacore::String tool, int mousebtn)
Request reassignment of a given mouse button to a tool.
std::string toolName(int toolindex)
void initButtonState(std::string, int)
void emitBtns()
Request signalling of the current mouse button setting for every type of tool.
void mouseBtnChg(std::string tool, int mousebtn)
Notification of a tool&#39;s [new] mouse button.
int toolIndex(std::string tool)
Return index of named tool within the master list.
int toolIndexOnButton_(int mousebtn)
Returns index of tool currently assigned to a mouse button (1, 2, or 3).
int buttonOf(casacore::String tool)
Returns button currently assigned to a tool (0 = no button assigned).
void mouseBtnStateChg(casacore::String tool, int state)
int getButtonState(const std::string &tool) const
std::map< std::string, int > tool_state
String: the storage and methods of handling collections of characters.
Definition: String.h:223
casacore::String toolOnButton(int mousebtn)
Returns name of tool currently assigned to a mouse button (1, 2, or 3).