00001 #ifndef __VIEW_H 00002 #define __VIEW_H 00003 00004 #include <qwidget.h> 00005 #include <qevent.h> 00006 #include <qimage.h> 00007 #include <qpixmap.h> 00008 #include <qpainter.h> 00009 #include <qtimer.h> 00010 #include <qapplication.h> 00011 00012 #include <string> 00013 00014 #include "histogramdatasource.h" 00015 #include "histogramuser.h" 00016 #include "image.h" 00017 #include "shape.h" 00018 #include "viewstate.h" 00019 #include "vectorlayerset.h" 00020 00028 class View : public QWidget, public HistogramDataSource { 00029 Q_OBJECT 00030 public: 00031 typedef enum { 00032 NO_TOOL, 00033 PAN_HAND, 00034 ZOOMIN_BOX, 00035 ZOOMOUT_BOX, 00036 ZOOMIN_INC, 00037 ZOOMOUT_INC, 00038 LINE, 00039 GLACIER_ID, 00040 POINTER, 00041 SELECTION 00042 } Tool; 00043 00047 typedef struct { 00048 double x; 00049 double y; 00050 } MousePos; 00051 00055 typedef struct { 00056 Rect dim; 00057 bool moving; 00058 Rect origpos; 00059 int xoff; 00060 int yoff; 00061 } Box; 00062 00066 typedef struct { 00067 MousePos mCurPos; 00068 MousePos mStartPos; 00069 MousePos mLastPos; 00070 bool mLeftButDown; 00071 bool mRightButDown; 00072 bool mMidButDown; 00073 } MouseState; 00074 00075 static Tool mTool; 00076 static HistogramUser mGlbHistUser; 00077 00078 protected: 00079 ViewState mState; 00080 MouseState mMouse; 00081 Rect mVirDims; 00082 Rect mDspDims; 00083 Rect mLnkDims; 00084 Rect mLinkLimits; 00085 Box mLinkBox; 00086 bool mChildLinked; 00087 bool mParentLinked; 00088 Rect mSelBox; 00089 Image *mImage; 00090 VectorLayerSet *mLyrSet; 00091 bool mDspImg; 00092 bool mDspVec; 00093 QPixmap* mCurScreen; 00094 QImage* mCurImg; 00095 bool mFullRedraw; 00096 QTimer* mTimer; 00097 bool mCTableNew; 00098 bool mPaning; 00099 00100 ImageFormat::ScaleType mSclType; 00101 00102 00103 public: 00104 View( QWidget *parent ); 00105 View( QWidget *parent, Image* img, VectorLayerSet * ); 00106 virtual ~View( ); 00107 00108 void init( ); 00109 void setImage( Image *img ); 00110 void setVectorLayerSet( VectorLayerSet *lyrset ) { 00111 mLyrSet = lyrset; 00112 } 00113 void setLinkChild( View *linkview ); 00114 void setLinkParent( View *linkview ); 00115 void setZoomAttr( ZoomAttr attr ); 00116 ZoomAttr* getZoomAttr( ) const; 00117 void captureImage( ); 00118 void calcDims( ); 00119 void fullRedraw( ); 00120 const Rect& getVirDims( ) const; 00121 void dspToVir( double &x, double &y ); 00122 void virToDsp( double &x, double &y ); 00123 void dspToVir( int &x, int &y ); 00124 void virToDsp( int &x, int &y ); 00125 Rect virDimToDsp( const Rect &dim ); 00126 void initView( ); 00127 void resetView( ); 00128 00129 void loadCaption( ) { 00130 char buf[16]; 00131 double z_per = mState.mZoom.factor * 100.0; 00132 sprintf( buf, "%5.2f", z_per ); 00133 00134 setCaption( ( mState.mName + " @" + buf ).c_str() ); 00135 } 00136 00137 void setViewName( std::string name ) { 00138 mState.mName = name; 00139 loadCaption(); 00140 } 00141 00142 ViewState& getViewState( ) { 00143 return mState; 00144 } 00145 00146 void centerOn( double x, double y ); 00147 00148 void setEditable( bool b ) { 00149 mState.mEditable = b; 00150 } 00151 00152 MouseState& getMouseState( ) { 00153 return mMouse; 00154 } 00155 00156 void setRSM( ImageFormat::ScaleType st ) { 00157 mSclType = st; fullRedraw(); 00158 } 00159 ImageFormat::ScaleType getRSM( ) { 00160 return mSclType; 00161 } 00162 00163 public: 00164 void paintEvent( QPaintEvent * ); 00165 void mouseMoveEvent( QMouseEvent * ); 00166 void mousePressEvent( QMouseEvent * ); 00167 void mouseReleaseEvent( QMouseEvent * ); 00168 void keyPressEvent( QKeyEvent * ); 00169 void keyReleaseEvent( QKeyEvent * ); 00170 void resizeEvent( QResizeEvent * ); 00171 00172 public: 00173 virtual char* getHistName( ) const; 00174 virtual HistogramSet getHistSet( ) const; 00175 00176 public slots: 00177 void timerDone(); 00178 void setLinkLimits( Rect ); 00179 void setVirDims( Rect ); 00180 void setLinkBoxDims( Rect ); 00181 void selBoxChanged( Rect & ); 00182 void ctableChanged( ); 00183 00184 signals: 00185 void parentVirDimsChanged( Rect ); 00186 void parentLinkBoxChanged( Rect ); 00187 void childVirDimsChanged( Rect ); 00188 void mousePosChanged( View::MousePos, View::MousePos ); 00189 void viewMouseMove( QMouseEvent *, View::MouseState & ); 00190 void viewMousePress( QMouseEvent *, View::MouseState & ); 00191 void viewMouseRelease( QMouseEvent *, View::MouseState & ); 00192 void viewKeyPress( QKeyEvent * ); 00193 void viewKeyRelease( QKeyEvent * ); 00194 // void viewPaintEvent( QPainter &, Rect & ); 00195 }; 00196 00197 #endif 00198 00199 00200
Home |
Search |
Disclaimers & Privacy |
Contact Us GLIMSView Maintainer: dsoltesz@usgs.gov |