src/qvgui/qvcanvas.h

Go to the documentation of this file.
00001 /*
00002  *      Copyright (C) 2007. PARP Research Group.
00003  *      <http://perception.inf.um.es>
00004  *      University of Murcia, Spain.
00005  *
00006  *      This file is part of the QVision library.
00007  *
00008  *      QVision is free software: you can redistribute it and/or modify
00009  *      it under the terms of the GNU Lesser General Public License as
00010  *      published by the Free Software Foundation, version 3 of the License.
00011  *
00012  *      QVision is distributed in the hope that it will be useful,
00013  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *      GNU Lesser General Public License for more details.
00016  *
00017  *      You should have received a copy of the GNU Lesser General Public
00018  *      License along with QVision. If not, see <http://www.gnu.org/licenses/>.
00019  */
00020 
00024 
00025 #ifndef QVCANVAS_H
00026 #define QVCANVAS_H
00027 
00028 #include <QGLWidget>
00029 #include <QPainter>
00030 #include <QString>
00031 #include <QMenu>
00032 
00033 #include <qvcore/qvimage.h>
00034 
00035 class QwtScaleWidget;
00036 class QwtLinearScaleEngine;
00037 class QwtScaleDiv;
00038 class QToolButton;
00039 class QStatusBar;
00040 class QVImageArea;
00041 
00042 // Not documented for now
00043 #ifndef DOXYGEN_IGNORE_THIS
00044 enum TPolyMode {
00045         LINE = 0x01,
00046         LIST = 0x02,
00047         CIRCLE = 0x03
00048 };
00049 
00050 class QVPainter: public QPainter
00051 {
00052 friend class QVImageArea;
00053 
00054 private:
00055         // Nobody except QVImageArea should create or destroy QVPainters:
00056         QVPainter(QVImageArea *imageArea): QPainter()
00057                 { this->imageArea = imageArea;};
00058         ~QVPainter() { };
00059 public:
00060         void drawQVImage(QVGenericImage *image,bool adaptsize=TRUE,float low=0.0, float high=255.0);
00061         void drawTextUnscaled(const QPointF & position, const QString & text);
00062         void drawTextUnscaled(const QPoint & position, const QString & text);
00063         void drawTextUnscaled(const QRectF & rectangle, int flags, const QString & text, QRectF * boundingRect = 0);
00064         void drawTextUnscaled(const QRect & rectangle, int flags, const QString & text, QRect * boundingRect = 0);
00065         void drawTextUnscaled(int x, int y, const QString & text);
00066         void drawTextUnscaled(int x, int y, int width, int height, int flags, const QString & text, QRect * boundingRect = 0);
00067         void drawTextUnscaled(const QRectF & rectangle, const QString & text, const QTextOption & option = QTextOption());
00068 
00069 private:
00070         // QVPainter keeps a private reference to its corresponding QVImageArea:
00071         QVImageArea *imageArea; 
00072 };
00073 
00074 
00075 /************************* QVImageArea auxiliary class ************************/
00076 
00077 // Auxiliary class, not available to library users (only to be used by
00078 // QVCanvas, which will be its friend). Thus, everything is private.
00079 // Note.- Not declared as a nested class because of QT moc limitations
00080 // with the Q_OBJECT macro.
00081 
00082 class QVImageArea : public QGLWidget
00083 {
00084         Q_OBJECT
00085 
00086 friend class QVCanvas;
00087 friend class QVPainter;
00088 
00089 private:
00090         // static class pointer to first instance of QVImageArea. The rest of
00091         // imageAreas will share context with it, in order to be fast enough
00092         // (otherwise, use of multiple context can make the application very
00093         // slow on some graphic cards!).
00094         static QVImageArea *first_image_area;
00095         
00096         void initObject(int w, int h); // Auxiliary function for constructors.
00097 
00098         // Nobody except QVCanvas should create or destroy QVImageArea's:
00099         // Constructor for first instance:
00100         QVImageArea(int w, int h,QWidget *parent);
00101         // Constructor for second and subsequent instances:
00102         QVImageArea(int w, int h,QWidget *parent,QGLWidget *other);
00103         ~QVImageArea() {};
00104         
00105         enum TMouseMode {
00106                 NONE = 0x01,
00107                 DRAG = 0x02,
00108                 SEL = 0x03,
00109                 POLY = 0x04,
00110                 ZOOM = 0x05
00111         };
00112 
00113 signals:
00114         void newGeometry(int origheight,int origwidth,int topleftx,int toplefty,int width,int height, int zoom);
00115         void newMousePosition(float x,float y);
00116         void mouseLeavesImageArea(bool leaves);
00117         void rectSelected(QRect rect);
00118         void polySelected(QPoint point, bool reset, TPolyMode mode);
00119         void circleSelected(QPoint center, float radius);
00120 
00121 protected:
00122         // void initializeGL() {};
00123         void wheelEvent(QWheelEvent *event);
00124         void resizeGL(int width, int height);
00125         void paintEvent(QPaintEvent *event);
00126         void mousePressEvent(QMouseEvent *event);
00127         void mouseMoveEvent(QMouseEvent *event);
00128         void mouseReleaseEvent(QMouseEvent *event);
00129         void leaveEvent(QEvent *event);
00130 
00131 private:
00132         const int max_zoom;
00133         void drawQVImage(QVGenericImage *image,bool adaptsize,float low,float high);
00134         void centerZoom(int zoom);
00135         void resizeImageArea(int w,int h);
00136         int zoom,origheight,origwidth;
00137         QPoint topLeft;
00138         QRect selRect,zoomRect;
00139         QRect innerRect();
00140         QRect outerRect();
00141         TMouseMode mouseMode;
00142         TPolyMode polyMode;
00143         QPoint firstPos,lastPos;
00144         bool dragging;
00145         QRectF intuitiveRect(QRect rect);
00146         QVPainter *painter;
00147         QList<QVGenericImage*> imageList;
00148 };
00149 
00150 class QVCanvas : public QWidget
00151 {
00152 
00153 friend class QVImageArea;
00154         Q_OBJECT
00155 public:
00156         QVCanvas(QWidget *parent = 0);
00157         ~QVCanvas();
00158         int getZoom() { return imageArea->zoom; }
00159         QRect getViewport() { return QRect(imageArea->topLeft,QSize(imageArea->width(),imageArea->height())); } //OJO, document in the manual that all viewport is multiplied by actual zoom.
00160         QSize getSize() { return QSize(imageArea->origwidth,imageArea->origheight); }
00161         QVPainter *getQVPainter() { return imageArea->painter; };
00162         QRect getSelectionRectangle() { return imageArea->selRect; }
00163 
00164 protected:
00165         virtual void viewer() { /* Default is to paint nothing. */ };
00166 
00167 signals:
00168         void newGeometry(int origwidth,int origheight,int topleftx,int toplefty,int width,int height, int zoom);
00169         //void refreshed();
00170 
00171 public slots:
00172         void setGeometry(int origwidth,int origheight,int topleftx,int toplefty,int width,int height, int zoom);
00173         void refreshImageArea();
00174         virtual void rectSelectedSlot(QRect rect) {
00175                 /* Default is to do nothing. */ if (rect == rect) ;
00176         };
00177         virtual void polySelectedSlot(QPoint point, bool reset, TPolyMode mode) {
00178                 /* Default is to do nothing. */ if (point == point || reset == reset || mode == mode) ;
00179         };
00180         virtual void circleSelectedSlot(QPoint center, float radius) {
00181                 /* Default is to do nothing. */ if (center == center || radius == radius) ;
00182         };
00183 
00184 private slots:
00185         void zoomRectClicked(bool checked);
00186         void selPoliClicked(bool checked);
00187         void selPoliChangedToLine();
00188         void selPoliChangedToList();
00189         void selPoliChangedToCircle();
00190         void selRectClicked(bool checked);
00191         void dragClicked(bool checked);
00192         void zoomInClicked();
00193         void zoomOutClicked();
00194         void zoomOriginalClicked();
00195         void newMousePositionSlot(float x,float y);
00196         void mouseLeavesImageAreaSlot(bool leaves);
00197 
00198 private:
00199         QwtScaleWidget *scaleWidgetX,*scaleWidgetY;
00200         QwtLinearScaleEngine *scaleEngineX,*scaleEngineY;
00201         QVImageArea *imageArea;
00202         QToolButton *buttonZoomIn,*buttonZoomOut,*buttonZoomOriginal,*buttonZoomRect,*buttonSelPoli,*buttonSelRect,*buttonDrag;
00203         QMenu *menuSelPoli;
00204         QStatusBar *statusBar;
00205         void resizeEvent(QResizeEvent *event);
00206         int scaleWidgetsFixedWidth,statusBarWidgetFixedHeight;
00207         float mousePosX,mousePosY;
00208         bool mouseIsOut;
00209         QString statusMessage();
00210         TPolyMode polyMode;
00211 };
00212 #endif
00213 #endif

Generated on Thu Jul 17 17:23:28 2008 for QVision by  doxygen 1.5.3