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
00036
00037 #ifndef DOXYGEN_IGNORE_THIS
00038
00039 class QwtScaleWidget;
00040 class QwtLinearScaleEngine;
00041 class QwtScaleDiv;
00042 class QToolButton;
00043 class QStatusBar;
00044 class QVImageArea;
00045
00046 enum TPolyMode {
00047 LINE = 0x01,
00048 LIST = 0x02,
00049 CIRCLE = 0x03
00050 };
00051
00052 class QVPainter: public QPainter
00053 {
00054 friend class QVImageArea;
00055
00056 private:
00057
00058 QVPainter(QVImageArea *imageArea): QPainter()
00059 { this->imageArea = imageArea;};
00060 ~QVPainter() { };
00061 public:
00062 void drawQVImage(QVGenericImage *image,bool adaptsize=TRUE,float low=0.0, float high=255.0);
00063 void drawTextUnscaled(const QPointF & position, const QString & text);
00064 void drawTextUnscaled(const QPoint & position, const QString & text);
00065 void drawTextUnscaled(const QRectF & rectangle, int flags, const QString & text, QRectF * boundingRect = 0);
00066 void drawTextUnscaled(const QRect & rectangle, int flags, const QString & text, QRect * boundingRect = 0);
00067 void drawTextUnscaled(int x, int y, const QString & text);
00068 void drawTextUnscaled(int x, int y, int width, int height, int flags, const QString & text, QRect * boundingRect = 0);
00069 void drawTextUnscaled(const QRectF & rectangle, const QString & text, const QTextOption & option = QTextOption());
00070
00071 private:
00072
00073 QVImageArea *imageArea;
00074 };
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 class QVImageArea : public QGLWidget
00085 {
00086 Q_OBJECT
00087
00088 friend class QVCanvas;
00089 friend class QVPainter;
00090
00091 private:
00092
00093
00094
00095
00096 static QList<QVImageArea *> image_areas;
00097
00098 void initObject(int w, int h);
00099
00100
00101
00102 QVImageArea(int w, int h,QWidget *parent);
00103
00104 QVImageArea(int w, int h,QWidget *parent,QGLWidget *other);
00105 ~QVImageArea() {};
00106
00107 enum TMouseMode {
00108 NONE = 0x01,
00109 DRAG = 0x02,
00110 SEL = 0x03,
00111 POLY = 0x04,
00112 ZOOM = 0x05
00113 };
00114
00115 signals:
00116 void newGeometry(int origheight,int origwidth,int topleftx,int toplefty,int width,int height, int zoom);
00117 void newMousePosition(float x,float y);
00118 void mouseLeavesImageArea(bool leaves);
00119 void rectSelected(QRect rect);
00120 void polySelected(QPoint point, bool reset, TPolyMode mode);
00121 void circleSelected(QPoint center, float radius);
00122
00123 protected:
00124
00125 void wheelEvent(QWheelEvent *event);
00126 void resizeGL(int width, int height);
00127 void paintEvent(QPaintEvent *event);
00128 void mousePressEvent(QMouseEvent *event);
00129 void mouseMoveEvent(QMouseEvent *event);
00130 void mouseReleaseEvent(QMouseEvent *event);
00131 void leaveEvent(QEvent *event);
00132
00133 private:
00134 const int max_zoom;
00135 void drawQVImage(QVGenericImage *image,bool adaptsize,float low,float high);
00136 void centerZoom(int zoom);
00137 void resizeImageArea(int w,int h);
00138 int zoom,origheight,origwidth;
00139 QPoint topLeft;
00140 QRect selRect,zoomRect;
00141 QRect innerRect();
00142 QRect outerRect();
00143 TMouseMode mouseMode;
00144 TPolyMode polyMode;
00145 QPoint firstPos,lastPos;
00146 bool dragging;
00147 QRectF intuitiveRect(QRect rect);
00148 QVPainter *painter;
00149 QList<QVGenericImage*> imageList;
00150 };
00151
00152 class QVCanvas : public QWidget
00153 {
00154
00155 friend class QVImageArea;
00156 Q_OBJECT
00157 public:
00158 QVCanvas(QWidget *parent = 0);
00159 ~QVCanvas();
00160 int getZoom() { return imageArea->zoom; }
00161 QRect getViewport() { return QRect(imageArea->topLeft,QSize(imageArea->width(),imageArea->height())); }
00162 QSize getSize() { return QSize(imageArea->origwidth,imageArea->origheight); }
00163 QVPainter *getQVPainter() { return imageArea->painter; };
00164 QRect getSelectionRectangle() { return imageArea->selRect; }
00165
00166 const QVImage<uChar, 3> contentImage() const { return QVImage<uChar, 3>(imageArea->renderPixmap().toImage()); }
00167
00168 protected:
00169 virtual void viewer() { };
00170
00171 signals:
00172 void newGeometry(int origwidth,int origheight,int topleftx,int toplefty,int width,int height, int zoom);
00173
00174
00175 public slots:
00176 void setGeometry(int origwidth,int origheight,int topleftx,int toplefty,int width,int height, int zoom);
00177 void refreshImageArea();
00178 virtual void rectSelectedSlot(QRect rect) {
00179 if (rect == rect) {} ;
00180 };
00181 virtual void polySelectedSlot(QPoint point, bool reset, TPolyMode mode) {
00182 if (point == point || reset == reset || mode == mode) {} ;
00183 };
00184 virtual void circleSelectedSlot(QPoint center, float radius) {
00185 if (center == center || radius == radius) {} ;
00186 };
00187
00188 private slots:
00189 void zoomRectClicked(bool checked);
00190 void selPoliClicked(bool checked);
00191 void selPoliChangedToLine();
00192 void selPoliChangedToList();
00193 void selPoliChangedToCircle();
00194 void selRectClicked(bool checked);
00195 void dragClicked(bool checked);
00196 void zoomInClicked();
00197 void zoomOutClicked();
00198 void zoomOriginalClicked();
00199 void newMousePositionSlot(float x,float y);
00200 void mouseLeavesImageAreaSlot(bool leaves);
00201
00202 private:
00203 QwtScaleWidget *scaleWidgetX,*scaleWidgetY;
00204 QwtLinearScaleEngine *scaleEngineX,*scaleEngineY;
00205 QVImageArea *imageArea;
00206 QToolButton *buttonZoomIn,*buttonZoomOut,*buttonZoomOriginal,*buttonZoomRect,*buttonSelPoli,*buttonSelRect,*buttonDrag;
00207 QMenu *menuSelPoli;
00208 QStatusBar *statusBar;
00209 void resizeEvent(QResizeEvent *event);
00210 int scaleWidgetsFixedWidth,statusBarWidgetFixedHeight;
00211 float mousePosX,mousePosY;
00212 bool mouseIsOut;
00213 QString statusMessage();
00214 TPolyMode polyMode;
00215 };
00216 #endif
00217 #endif