src/baseframe.h

00001 /***************************************************************************
00002                           baseframe.h  -  description
00003                              -------------------
00004     begin                : Wed Feb 18 2004
00005     copyright            : (C) 2004 by Lynn Hazan
00006     email                : lynn.hazan@myrealbox.com
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #ifndef BASEFRAME_H
00019 #define BASEFRAME_H
00020 
00021 // include files for QT
00022 #include <qwidget.h>
00023 #include <qframe.h>
00024 #include <qcursor.h>
00025 
00026 //include files for the application
00027 #include "zoomwindow.h"
00028 
00029 //General C++ include files
00030 #include <iostream>
00031 using namespace std;
00032 
00048 class BaseFrame : public QFrame  {
00049    Q_OBJECT
00050    
00051 public:
00052 
00056   typedef int Mode;
00057 
00060   enum {ZOOM = 1};
00061 
00079   BaseFrame(int Xborder,int Yborder,QWidget* parent=0, const char* name=0,QColor backgroundColor = Qt::black,
00080            int minSize = 500, int maxSize = 4000, int windowTopLeft = -500,int windowBottomRight = 1001, int border = 0);
00081      ~BaseFrame();
00082   
00084   virtual inline void willBeKilled(){};
00085 
00092   inline void setBorders(int x,int y){
00093    Xborder = x;
00094    Yborder = y; 
00095   };
00096   
00097 public slots:
00098 
00100   virtual inline void updateDrawing(){};
00101 
00106   virtual inline void dockBeingClosed(){emit parentDockBeingClosed(this);};
00107 
00109   virtual void changeBackgroundColor(QColor color);
00110 
00114   virtual inline void setMode(BaseFrame::Mode selectedMode){mode = selectedMode;};
00115   
00116 signals:
00117    /*s*Signals that the enclosing dockwidget is being closed
00118    * @param viewWidget pointer on the the current object.
00119    */
00120    void parentDockBeingClosed(QWidget* viewWidget);
00121 
00122 protected:
00127   virtual void drawContents(QPainter* p)=0;
00128 
00132   virtual void resizeEvent(QResizeEvent* event);
00133 
00137   virtual void mousePressEvent(QMouseEvent* event); 
00138 
00142   virtual void mouseReleaseEvent(QMouseEvent* event);  
00143 
00147   virtual void mouseMoveEvent(QMouseEvent* event);
00148 
00152   virtual void mouseDoubleClickEvent(QMouseEvent* event);
00153 
00160   QPoint viewportToWorld(int vx, int vy);
00161 
00168   inline QPoint viewportToWorld(const QPoint& point){
00169     return viewportToWorld(point.x(), point.y());
00170   };
00171 
00178   QPoint worldToViewport(int wx, int wy);
00179 
00186   inline QPoint worldToViewport(const QPoint& point){
00187     return worldToViewport(point.x(), point.y());
00188   };
00189 
00194   long worldToViewportAbscissa(long wx);
00195 
00200   long worldToViewportOrdinate(long wy);
00201 
00205   void  drawRubber();
00206 
00212   inline long worldToViewportWidth(long width){
00213     float widthRatio = (static_cast<float>(viewport.width())/static_cast<float>(((QRect)window).width()));
00214     return static_cast<long>(width * widthRatio);
00215   };
00216 
00222   inline long worldToViewportHeight(long height){
00223     float heightRatio = (static_cast<float>(viewport.height())/static_cast<float>(((QRect)window).height()));
00224     return static_cast<long>(height * heightRatio);
00225   };
00226 
00232   inline long viewportToWorldWidth(long width){
00233     float widthRatio = (static_cast<float>(((QRect)window).width())/static_cast<float>(viewport.width()));
00234     return static_cast<long>(width * widthRatio);
00235   };
00236 
00242   inline long viewportToWorldHeight(long height){
00243     float heightRatio = (static_cast<float>(((QRect)window).height())/static_cast<float>(viewport.height()));
00244     return static_cast<long>(height * heightRatio);
00245   };
00246 
00251   inline void drawRubberBand(bool draw,bool vertical = false){
00252    isRubberBandToBeDrawn = draw;
00253    wholeHeightRectangle = vertical;
00254   };
00255 
00256 //Members
00257 
00262   enum DrawContentsMode{REFRESH=1, UPDATE=2,REDRAW=3};
00263 
00264   const int MIN_SIZE; //Default 500
00265   const int MAX_SIZE; //Default 4000
00266   const int BORDER; //Default 0
00267   const int WINDOW_TOP_LEFT; //Default -500
00268   const int WINDOW_BOTTOM_RIGHT; //Default 1001
00269 
00270   QSize oldSize;
00271   QRect viewport;
00272 
00276   ZoomWindow window;
00280   QPoint firstClick;
00284   bool isDoubleClick;
00288   QRect* rubber;
00289 
00291   DrawContentsMode drawContentsMode;
00292 
00296    Mode mode;
00297 
00299   QCursor zoomCursor;
00300 
00303   int Xborder;
00304 
00307   int Yborder;
00308 
00310   bool isRubberBandToBeDrawn;
00311 
00315   bool wholeHeightRectangle;
00316 
00318   QColor colorLegend;
00319   
00320 };
00321 
00322 #endif

Generated on Mon Sep 17 20:47:30 2007 for NeuroScope by  doxygen 1.5.1