casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
QtMouseToolBar.qo.h
Go to the documentation of this file.
00001 //# QtMouseToolBar.qo.h: 'mouse-tool' toolbar for qtviewer display panel.
00002 //# Copyright (C) 2005
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 
00028 
00029 #ifndef QTMOUSETOOLBAR_H
00030 #define QTMOUSETOOLBAR_H
00031 
00032 #include <casa/aips.h>
00033 #include <casa/BasicSL/String.h>
00034 #include <casa/Arrays/Vector.h>
00035 #include <display/QtViewer/QtMouseToolState.qo.h>
00036 #include <display/Utilities/Lowlevel.h>
00037 #include <map>
00038 #include <string>
00039 
00040 
00041 #include <graphics/X11/X_enter.h>
00042 #  include <QMouseEvent>
00043 #  include <QContextMenuEvent>
00044 #  include <QToolBar>
00045 #  include <QToolButton>
00046 #  include <QTimer>
00047 #include <graphics/X11/X_exit.h>
00048 
00049 namespace casa {
00050 
00051 class QtDisplayPanel;
00052 
00053 
00054 
00055 class QtMouseToolButton: public QToolButton {
00056   
00057   Q_OBJECT      //# Allows slot/signal definition.  Must only occur in
00058                 //# implement/.../*.h files; also, makefile must include
00059                 //# name of this file in 'mocs' section.
00060 
00061  public: 
00062  
00063   QtMouseToolButton(const std::string &type, QWidget* parent = 0);
00064   virtual ~QtMouseToolButton() {  }
00065 
00066   virtual std::string getIconStr(Int) const;
00067   
00068  protected:
00069   
00070   virtual void mousePressEvent(QMouseEvent*);
00071   void mouseMoveEvent   (QMouseEvent *) {  }
00072   void mouseReleaseEvent(QMouseEvent *) {  }
00073   
00074   // (Prevents interference with right mouse button).
00075   void contextMenuEvent(QContextMenuEvent *event) { event->accept();  }
00076   
00077  signals:
00078  
00079   void mouseToolBtnPress(String tool, Int btn);
00080   void mouseToolBtnState(String tool, Int state);
00081 
00082  private:
00083   std::string tool_;
00084 
00085 };
00086 
00087 
00088 
00089 class QtPointToolButton: public QtMouseToolButton {
00090   
00091   Q_OBJECT      //# Allows slot/signal definition.  Must only occur in
00092                 //# implement/.../*.h files; also, makefile must include
00093                 //# name of this file in 'mocs' section.
00094 
00095  public: 
00096  
00097   QtPointToolButton(QWidget* parent = 0);
00098   ~QtPointToolButton() { delete timer; }
00099 
00100  protected:
00101 
00102   Casarc &rc;
00103 
00104   virtual void mousePressEvent(QMouseEvent*);
00105   virtual void mouseReleaseEvent(QMouseEvent*);
00106 
00107   QTimer *timer;
00108   QPoint popup_menu_pos;
00109   
00110  protected slots:
00111   void show_context_menu( const QPoint & );
00112   void popup_options_menu( );
00113 
00114 };
00115 
00116 
00117 
00118 
00119 class QtMouseToolBar: public QToolBar {
00120   
00121   Q_OBJECT      //# Allows slot/signal definition.  Must only occur in
00122                 //# implement/.../*.h files; also, makefile must include
00123                 //# name of this file in 'mocs' section.
00124 
00125 
00126  public: 
00127  
00128   QtMouseToolBar(QtMouseToolState* msbtns, QtDisplayPanel* qdp = 0,
00129                  QWidget* parent = 0);
00130   ~QtMouseToolBar() {  }
00131 
00132   QtMouseToolButton *button( const std::string &name );
00133   
00134  
00135  protected slots:
00136   
00137   // Connected to the QtMouseToolState::mouseBtnChg() signal.  Changes the
00138   // tool button's (QAction's) state (icon, whether checked), to reflect
00139   // the [new] mouse button assignment for a given mouse tool.
00140   virtual void chgMouseBtn_(std::string tool, Int button);
00141   
00142   // Overridden from QToolBar, responding to clicks from any mouse button.
00143   // Relays that mouse button to central registry for assignment to 
00144   // desired tool.
00145   //void mouseReleaseEvent(QMouseEvent *event);
00146 
00147  
00148  protected:
00149  
00150   // Holds button state for all mouse-tool bars and display panels.
00151   QtMouseToolState* msbtns_;
00152   
00153   // Names of tools within this toolbar (in order)
00154   Vector<String> tools_;
00155 
00156   std::map<std::string,QtMouseToolButton*> buttons_;
00157   
00158 };
00159 
00160 
00161 } //# NAMESPACE CASA - END
00162 
00163 #endif
00164