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 
00032 #include <qvcore/qvimage.h>
00033 
00034 class QwtScaleWidget;
00035 class QwtLinearScaleEngine;
00036 class QwtScaleDiv;
00037 class QToolButton;
00038 class QStatusBar;
00039 class QVImageArea;
00040 
00041 // Not documented for now
00043 class QVPainter: public QPainter
00044 {
00045 friend class QVImageArea;
00046 
00047 private:
00048         // Nobody except QVImageArea should create or destroy QVPainters:
00049         QVPainter(QVImageArea *imageArea): QPainter()
00050                 { this->imageArea = imageArea;};
00051         ~QVPainter() { };
00052 public:
00053         void drawQVImage(QVGenericImage *image,bool adaptsize=TRUE,float low=0.0, float high=255.0);
00054         void drawTextUnscaled(const QPointF & position, const QString & text);
00055         void drawTextUnscaled(const QPoint & position, const QString & text);
00056         void drawTextUnscaled(const QRectF & rectangle, int flags, const QString & text, QRectF * boundingRect = 0);
00057         void drawTextUnscaled(const QRect & rectangle, int flags, const QString & text, QRect * boundingRect = 0);
00058         void drawTextUnscaled(int x, int y, const QString & text);
00059         void drawTextUnscaled(int x, int y, int width, int height, int flags, const QString & text, QRect * boundingRect = 0);
00060         void drawTextUnscaled(const QRectF & rectangle, const QString & text, const QTextOption & option = QTextOption());
00061 
00062 private:
00063         // QVPainter keeps a private reference to its corresponding QVImageArea:
00064         QVImageArea *imageArea; 
00065 };
00066 
00067 
00068 /************************* QVImageArea auxiliary class ************************/
00069 
00070 // Auxiliary class, not available to library users (only to be used by
00071 // QVCanvas, which will be its friend). Thus, everything is private.
00072 // Note.- Not declared as a nested class because of QT moc limitations
00073 // with the Q_OBJECT macro.
00074 
00075 class QVImageArea : public QGLWidget
00076 {
00077         Q_OBJECT
00078 
00079 friend class QVCanvas;
00080 friend class QVPainter;
00081 
00082 private:
00083         // static class pointer to first instance of QVImageArea. The rest of
00084         // imageAreas will share context with it, in order to be fast enough
00085         // (otherwise, use of multiple context can make the application very
00086         // slow on some graphic cards!).
00087         static QVImageArea *first_image_area;
00088         
00089         void initObject(int w, int h); // Auxiliary function for constructors.
00090 
00091         // Nobody except QVCanvas should create or destroy QVImageArea's:
00092         // Constructor for first instance:
00093         QVImageArea(int w, int h,QWidget *parent);
00094         // Constructor for second and subsequent instances:
00095         QVImageArea(int w, int h,QWidget *parent,QGLWidget *other);
00096         ~QVImageArea() {};
00097         
00098         enum TMouseMode {
00099                 noneMode = 0x01,
00100                 dragMode = 0x02,
00101                 selMode = 0x03,
00102                 zoomMode = 0x04
00103         };
00104 
00105 signals:
00106         void newGeometry(int origheight,int origwidth,int topleftx,int toplefty,int width,int height, int zoom);
00107         void newMousePosition(float x,float y);
00108         void mouseLeavesImageArea(bool leaves);
00109 
00110 protected:
00111         // void initializeGL() {};
00112         void wheelEvent(QWheelEvent *event);
00113         void resizeGL(int width, int height);
00114         void paintEvent(QPaintEvent *event);
00115         void mousePressEvent(QMouseEvent *event);
00116         void mouseMoveEvent(QMouseEvent *event);
00117         void mouseReleaseEvent(QMouseEvent *event);
00118         void leaveEvent(QEvent *event);
00119 
00120 private:
00121         const int max_zoom;
00122         void drawQVImage(QVGenericImage *image,bool adaptsize,float low,float high);
00123         void centerZoom(int zoom);
00124         void resizeImageArea(int w,int h);
00125         int zoom,origheight,origwidth;
00126         QPoint topLeft;
00127         QRect selRect,zoomRect;
00128         QRect innerRect();
00129         QRect outerRect();
00130         TMouseMode mouseMode;
00131         QPoint firstPos,lastPos;
00132         bool dragging;
00133         QRectF intuitiveRect(QRect rect);
00134         QVPainter *painter;
00135         QList<QVGenericImage*> imageList;
00136 };
00137 
00138 class QVCanvas : public QWidget
00139 {
00140 
00141 friend class QVImageArea;
00142         Q_OBJECT
00143 public:
00144         QVCanvas(QWidget *parent = 0);
00145         ~QVCanvas();
00146         int getZoom() { return imageArea->zoom; }
00147         QRect getViewport() { return QRect(imageArea->topLeft,QSize(imageArea->width(),imageArea->height())); } //OJO, document in the manual that all viewport is multiplyed by actual zoom.
00148         QSize getSize() { return QSize(imageArea->origwidth,imageArea->origheight); }
00149         QVPainter *getQVPainter() { return imageArea->painter; };
00150         QRect getSelectionRectangle() { return imageArea->selRect; }
00151 
00152 protected:
00153         virtual void viewer() { /* Default is to paint nothing. */ };
00154 
00155 signals:
00156         void newGeometry(int origwidth,int origheight,int topleftx,int toplefty,int width,int height, int zoom);
00157         //void refreshed();
00158 
00159 public slots:
00160         void setGeometry(int origwidth,int origheight,int topleftx,int toplefty,int width,int height, int zoom);
00161         void refreshImageArea();
00162 
00163 private slots:
00164         void zoomRectClicked(bool checked);
00165         void selRectClicked(bool checked);
00166         void dragClicked(bool checked);
00167         void zoomInClicked();
00168         void zoomOutClicked();
00169         void zoomOriginalClicked();
00170         void newMousePositionSlot(float x,float y);
00171         void mouseLeavesImageAreaSlot(bool leaves);
00172 
00173 private:
00174         QwtScaleWidget *scaleWidgetX,*scaleWidgetY;
00175         QwtLinearScaleEngine *scaleEngineX,*scaleEngineY;
00176         QVImageArea *imageArea;
00177         QToolButton *buttonZoomIn,*buttonZoomOut,*buttonZoomOriginal,*buttonZoomRect,*buttonSelRect,*buttonDrag;
00178         QStatusBar *statusBar;
00179         void resizeEvent(QResizeEvent *event);
00180         int scaleWidgetsFixedWidth,statusBarWidgetFixedHeight;
00181         float mousePosX,mousePosY;
00182         bool mouseIsOut;
00183         QString statusMessage();
00184 };
00186 #endif

Generated on Fri Feb 22 18:26:55 2008 for QVision by  doxygen 1.5.3