QtMouseToolState.qo.h

Go to the documentation of this file.
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 
00086                 // Returns name of tool currently assigned to a mouse button (1, 2, or 3).
00087                 // (Returns NONE if passed mousebtn is 0 or no tool is assigned to it).
00088                 String toolOnButton(Int mousebtn) {
00089                         return QtMouseToolNames::toolName(toolIndexOnButton_(mousebtn));
00090                 }
00091 
00092                 int getButtonState(const std::string &tool) const;
00093 
00094 
00095         public slots:
00096 
00097                 // Request reassignment of a given mouse button to a tool.
00098                 // NB: _This_ is where guis, etc. should request a button change, so that
00099                 // all stay on the same page (not directly to tool or displaypanel, e.g.).
00100                 void chgMouseBtn(String tool, Int mousebtn);
00101                 void mouseBtnStateChg(String tool, Int state);
00102 
00103                 // Request signalling of the current mouse button setting for every
00104                 // type of tool.  Call this if you want to assure that everyone's
00105                 // up-to-date on mouse button settings.
00106                 void emitBtns();
00107 
00108 
00109         signals:
00110 
00111                 // Notification of a tool's [new] mouse button.
00112                 void mouseBtnChg(std::string tool, Int mousebtn);
00113 
00114 
00115         protected:
00116                 Casarc &rc;
00117 
00118                 // Only QtviewerBase is intended to create/destroy
00119                 // a [single] instance of this class.
00120                 QtMouseToolState();
00121                 ~QtMouseToolState() {  }
00122                 friend class QtViewerBase;
00123 
00124                 // Returns index of tool currently assigned to a mouse button (1, 2, or 3).
00125                 // (Returns nTools if passed mousebtn is 0 or no tool is assigned to it).
00126                 Int toolIndexOnButton_(Int mousebtn);
00127 
00128 
00129                 // The button currently assigned to the various types of mouse tool.
00130                 //
00131                 // mousebtns_ value    Corresp. internal library value
00132                 // ----------------     -------------------------------
00133                 // 0:  <no button>     Display::K_None
00134                 // 1:  LeftButton      Display::K_Pointer_Button1
00135                 // 2:  MidButton       Display::K_Pointer_Button2
00136                 // 3:  RightButton     Display::K_Pointer_Button3
00137                 static Int mousebtns_[QtMouseToolNames::nTools+1];
00138                 //# Initial values; correspond to QtMouseToolNames::tools[], above.
00139                 //# mousebtns_[nTools] is an entry for an invalid tool.
00140                 //# At most one of the above will be 1,2,3; the rest will be 0.
00141 
00142         private:
00143                 std::map<std::string,int> tool_state;
00144                 void initButtonState( std::string, int );
00145                 void initToolState( );
00146 
00147         };
00148 
00149 } //# NAMESPACE CASA - END
00150 
00151 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1