casa
$Rev:20696$
|
00001 //# QtMouseToolState.qo.h: constants and [global] mouse-button state 00002 //# for the qtviewer 'mouse-tools' used by its display panel[s]. 00003 //# Copyright (C) 2005 00004 //# Associated Universities, Inc. Washington DC, USA. 00005 //# 00006 //# This library is free software; you can redistribute it and/or modify it 00007 //# under the terms of the GNU Library General Public License as published by 00008 //# the Free Software Foundation; either version 2 of the License, or (at your 00009 //# option) any later version. 00010 //# 00011 //# This library is distributed in the hope that it will be useful, but WITHOUT 00012 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00013 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00014 //# License for more details. 00015 //# 00016 //# You should have received a copy of the GNU Library General Public License 00017 //# along with this library; if not, write to the Free Software Foundation, 00018 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00019 //# 00020 //# Correspondence concerning AIPS++ should be addressed as follows: 00021 //# Internet email: aips2-request@nrao.edu. 00022 //# Postal address: AIPS++ Project Office 00023 //# National Radio Astronomy Observatory 00024 //# 520 Edgemont Road 00025 //# Charlottesville, VA 22903-2475 USA 00026 //# 00027 //# $Id$ 00028 00029 00030 #ifndef QTMOUSETOOLSTATE_QO_H_ 00031 #define QTMOUSETOOLSTATE_QO_H_ 00032 00033 #include <casa/aips.h> 00034 #include <casa/BasicSL/String.h> 00035 #include <display/Display/MouseToolState.h> 00036 #include <display/Utilities/Lowlevel.h> 00037 00038 #include <graphics/X11/X_enter.h> 00039 # include <QObject> 00040 #include <graphics/X11/X_exit.h> 00041 #include <map> 00042 00043 namespace casa { //# NAMESPACE CASA - BEGIN 00044 00045 00046 class QtViewerBase; 00047 00048 00049 // <synopsis> 00050 // QtMouseToolState records the currently-active mouse button (if any) 00051 // of each type of Qt mouse tool. There may be a QtMouseToolBar for each 00052 // QtDisplayPanel (and in principle each may display a different subset 00053 // of all the possible tools, though this is not implemented yet (7/06)). 00054 // However, each mouse button (Left, Middle, Right) may be assigned to 00055 // at most one type of tool type, and that assignment should be the same 00056 // on each QtMouseToolBar. 00057 // 00058 // To accomplish that, this class signals current button assignments 00059 // whenever such assignments change. All display panels and/or their mouse 00060 // tool bars may connect to this signal to keep Toolbar button icons and the 00061 // actual core library mouse tools (such as MWCZoomer) in sync. 00062 // 00063 // This button state is therefore also essentially global or static, but this 00064 // class cannot be purely static because it must be a real QObject 00065 // to send out such a signal. Instead, there should be only one 00066 // QtMouseToolState object (managed by the [one] QtViewer[Base] object), 00067 // and all listeners should use that object for setting and responding to 00068 // current mouse tool button state. 00069 // </synopsis> 00070 00071 class QtMouseToolState : public QObject { 00072 00073 00074 Q_OBJECT //# Allows slot/signal definition. Must only occur in 00075 //# implement/.../*.h files; also, makefile must include 00076 //# name of this file in 'mocs' section. 00077 00078 00079 public: 00080 00081 // Returns button currently assigned to a tool (0 = no button assigned). 00082 Int buttonOf(String tool) { 00083 return mousebtns_[QtMouseToolNames::toolIndex(tool)]; } 00084 00085 // Returns name of tool currently assigned to a mouse button (1, 2, or 3). 00086 // (Returns NONE if passed mousebtn is 0 or no tool is assigned to it). 00087 String toolOnButton(Int mousebtn) { 00088 return QtMouseToolNames::toolName(toolIndexOnButton_(mousebtn)); } 00089 00090 int getButtonState(const std::string &tool) const; 00091 00092 00093 public slots: 00094 00095 // Request reassignment of a given mouse button to a tool. 00096 // NB: _This_ is where guis, etc. should request a button change, so that 00097 // all stay on the same page (not directly to tool or displaypanel, e.g.). 00098 void chgMouseBtn(String tool, Int mousebtn); 00099 void mouseBtnStateChg(String tool, Int state); 00100 00101 // Request signalling of the current mouse button setting for every 00102 // type of tool. Call this if you want to assure that everyone's 00103 // up-to-date on mouse button settings. 00104 void emitBtns(); 00105 00106 00107 signals: 00108 00109 // Notification of a tool's [new] mouse button. 00110 void mouseBtnChg(std::string tool, Int mousebtn); 00111 00112 00113 protected: 00114 Casarc &rc; 00115 00116 // Only QtviewerBase is intended to create/destroy 00117 // a [single] instance of this class. 00118 QtMouseToolState(); 00119 ~QtMouseToolState() { } 00120 friend class QtViewerBase; 00121 00122 // Returns index of tool currently assigned to a mouse button (1, 2, or 3). 00123 // (Returns nTools if passed mousebtn is 0 or no tool is assigned to it). 00124 Int toolIndexOnButton_(Int mousebtn); 00125 00126 00127 // The button currently assigned to the various types of mouse tool. 00128 // 00129 // mousebtns_ value Corresp. internal library value 00130 // ---------------- ------------------------------- 00131 // 0: <no button> Display::K_None 00132 // 1: LeftButton Display::K_Pointer_Button1 00133 // 2: MidButton Display::K_Pointer_Button2 00134 // 3: RightButton Display::K_Pointer_Button3 00135 static Int mousebtns_[QtMouseToolNames::nTools+1]; 00136 //# Initial values; correspond to QtMouseToolNames::tools[], above. 00137 //# mousebtns_[nTools] is an entry for an invalid tool. 00138 //# At most one of the above will be 1,2,3; the rest will be 0. 00139 00140 private: 00141 std::map<std::string,int> tool_state; 00142 void initButtonState( std::string, int ); 00143 void initToolState( ); 00144 00145 }; 00146 00147 } //# NAMESPACE CASA - END 00148 00149 #endif