00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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 <QVImage>
00034
00035 class QwtScaleWidget;
00036 class QwtLinearScaleEngine;
00037 class QwtScaleDiv;
00038 class QToolButton;
00039 class QStatusBar;
00040 class QVImageArea;
00041
00042
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
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
00071 QVImageArea *imageArea;
00072 };
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 class QVImageArea : public QGLWidget
00083 {
00084 Q_OBJECT
00085
00086 friend class QVCanvas;
00087 friend class QVPainter;
00088
00089 private:
00090
00091
00092
00093
00094 static QList<QVImageArea *> image_areas;
00095
00096 void initObject(int w, int h);
00097
00098
00099
00100 QVImageArea(int w, int h,QWidget *parent);
00101
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
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())); }
00160 QSize getSize() { return QSize(imageArea->origwidth,imageArea->origheight); }
00161 QVPainter *getQVPainter() { return imageArea->painter; };
00162 QRect getSelectionRectangle() { return imageArea->selRect; }
00163
00164 const QVImage<uChar, 3> contentImage() const { return QVImage<uChar, 3>(imageArea->renderPixmap().toImage()); }
00165
00166 protected:
00167 virtual void viewer() { };
00168
00169 signals:
00170 void newGeometry(int origwidth,int origheight,int topleftx,int toplefty,int width,int height, int zoom);
00171
00172
00173 public slots:
00174 void setGeometry(int origwidth,int origheight,int topleftx,int toplefty,int width,int height, int zoom);
00175 void refreshImageArea();
00176 virtual void rectSelectedSlot(QRect rect) {
00177 if (rect == rect) ;
00178 };
00179 virtual void polySelectedSlot(QPoint point, bool reset, TPolyMode mode) {
00180 if (point == point || reset == reset || mode == mode) ;
00181 };
00182 virtual void circleSelectedSlot(QPoint center, float radius) {
00183 if (center == center || radius == radius) ;
00184 };
00185
00186 private slots:
00187 void zoomRectClicked(bool checked);
00188 void selPoliClicked(bool checked);
00189 void selPoliChangedToLine();
00190 void selPoliChangedToList();
00191 void selPoliChangedToCircle();
00192 void selRectClicked(bool checked);
00193 void dragClicked(bool checked);
00194 void zoomInClicked();
00195 void zoomOutClicked();
00196 void zoomOriginalClicked();
00197 void newMousePositionSlot(float x,float y);
00198 void mouseLeavesImageAreaSlot(bool leaves);
00199
00200 private:
00201 QwtScaleWidget *scaleWidgetX,*scaleWidgetY;
00202 QwtLinearScaleEngine *scaleEngineX,*scaleEngineY;
00203 QVImageArea *imageArea;
00204 QToolButton *buttonZoomIn,*buttonZoomOut,*buttonZoomOriginal,*buttonZoomRect,*buttonSelPoli,*buttonSelRect,*buttonDrag;
00205 QMenu *menuSelPoli;
00206 QStatusBar *statusBar;
00207 void resizeEvent(QResizeEvent *event);
00208 int scaleWidgetsFixedWidth,statusBarWidgetFixedHeight;
00209 float mousePosX,mousePosY;
00210 bool mouseIsOut;
00211 QString statusMessage();
00212 TPolyMode polyMode;
00213 };
00214 #endif
00215 #endif