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 #include <QVPolyline>
00035 #include <QVCameraPose>
00036
00037 class QwtScaleWidget;
00038 class QwtLinearScaleEngine;
00039 class QwtScaleDiv;
00040 class QToolButton;
00041 class QStatusBar;
00042 class QVImageArea;
00043
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
00069 void drawQVImage(QVGenericImage *image,bool adaptsize=TRUE,float low=0.0, float high=255.0);
00070
00074 void drawTextUnscaled(const QPointF & position, const QString & text);
00075
00079 void drawTextUnscaled(const QPoint & position, const QString & text);
00080
00084 void drawTextUnscaled(const QRectF & rectangle, int flags, const QString & text, QRectF * boundingRect = 0);
00085
00089 void drawTextUnscaled(const QRect & rectangle, int flags, const QString & text, QRect * boundingRect = 0);
00090
00094 void drawTextUnscaled(int x, int y, const QString & text);
00095
00099 void drawTextUnscaled(int x, int y, int width, int height, int flags, const QString & text, QRect * boundingRect = 0);
00100
00104 void drawTextUnscaled(const QRectF & rectangle, const QString & text, const QTextOption & option = QTextOption());
00105
00106 private:
00107
00108 QVImageArea *imageArea;
00109 };
00110
00111
00112
00113
00114
00115 enum TPolyMode {
00116 LIST = 0x01,
00117 LINE = 0x02,
00118 CLOSED = 0x03
00119 };
00120
00121
00122
00123
00124
00125
00126
00127
00128 class QVImageArea : public QGLWidget
00129 {
00130 Q_OBJECT
00131
00132 friend class QVCanvas;
00133 friend class QVPainter;
00134
00135 private:
00136
00137
00138
00139
00140 static QList<QVImageArea *> image_areas;
00141
00142 void initObject(int w, int h);
00143
00144
00145
00146 QVImageArea(int w, int h,QWidget *parent);
00147
00148 QVImageArea(int w, int h,QWidget *parent,QGLWidget *other);
00149 ~QVImageArea() {};
00150
00151 enum TMouseMode {
00152 NONE = 0x01,
00153 DRAG = 0x02,
00154 SEL = 0x03,
00155 POLY = 0x04,
00156 ZOOM = 0x05
00157 };
00158
00159 signals:
00160 void newGeometry(int origheight,int origwidth,int topleftx,int toplefty,int width,int height, int zoom);
00161 void newMousePosition(float x,float y);
00162 void mouseLeavesImageArea(bool leaves);
00163 void rectSelected(QRect rect);
00164 void polySelected(QPoint point, bool reset, TPolyMode mode);
00165
00166 protected:
00167
00168 void wheelEvent(QWheelEvent *event);
00169 void resizeGL(int width, int height);
00170 void paintEvent(QPaintEvent *event);
00171 void mousePressEvent(QMouseEvent *event);
00172 void mouseMoveEvent(QMouseEvent *event);
00173 void mouseReleaseEvent(QMouseEvent *event);
00174 void leaveEvent(QEvent *event);
00175 void beginDrawWorldFromCamera(const double fx, const double fy, const QVCameraPose &cameraPosition);
00176 void endDrawWorldFromCamera();
00177
00178 private:
00179 const int max_zoom;
00180 void drawQVImage(QVGenericImage *image,bool adaptsize,float low,float high);
00181 void centerZoom(int zoom);
00182 void resizeImageArea(int w,int h);
00183 int zoom,origheight,origwidth;
00184 QPoint topLeft;
00185 QRect selRect,zoomRect;
00186 QVPolyline selPoly;
00187 QRect innerRect();
00188 QRect outerRect();
00189 TMouseMode mouseMode;
00190 TPolyMode polyMode;
00191 QPoint firstPos,lastPos;
00192 bool dragging,drawSel;
00193 QRectF intuitiveRect(QRect rect);
00194 QVPainter *painter;
00195 QList<QVGenericImage*> imageList;
00196 };
00197
00198 class QVCanvas : public QWidget
00199 {
00200 friend class QVImageArea;
00201 Q_OBJECT
00202 public:
00203
00204 void qglColor(const QColor &color)
00205 {
00206 glColor3ub(color.red(), color.green(), color.blue());
00207 }
00208
00209 QVCanvas(QWidget *parent = 0);
00210 ~QVCanvas();
00211 int getZoom() const { return imageArea->zoom; }
00212 QRect getViewport() const { return QRect(imageArea->topLeft,QSize(imageArea->width(),imageArea->height())); }
00213 QSize getSize() const { return QSize(imageArea->origwidth,imageArea->origheight); }
00214 QVPainter *getQVPainter() const { return imageArea->painter; };
00215 QRect getSelectionRectangle() const { return imageArea->selRect; }
00216 void beginDrawWorldFromCamera(const double fx, const double fy, const QVCameraPose &cameraPosition)
00217 {
00218 imageArea->beginDrawWorldFromCamera(fx,fy,cameraPosition);
00219 }
00220 void endDrawWorldFromCamera() {
00221 imageArea->endDrawWorldFromCamera();
00222 }
00223 const QVImage<uChar, 3> contentImage() const { return QVImage<uChar, 3>(imageArea->renderPixmap().toImage()); }
00224
00225 protected:
00226 virtual void viewer() { };
00227
00228 signals:
00229 void newGeometry(int origwidth,int origheight,int topleftx,int toplefty,int width,int height, int zoom);
00230
00231
00232 public slots:
00233 void setGeometry(int origwidth,int origheight,int topleftx,int toplefty,int width,int height, int zoom);
00234 void refreshImageArea();
00235 virtual void rectSelectedSlot(QRect rect) = 0 ;
00236 virtual void polySelectedSlot(QPoint point, bool reset, TPolyMode mode) =0;
00237
00238 private slots:
00239 void drawSelClicked(bool checked);
00240 void zoomRectClicked(bool checked);
00241 void selPolyClicked(bool checked);
00242 void selPolyChangedToList();
00243 void selPolyChangedToLine();
00244 void selPolyChangedToClosed();
00245 void selRectClicked(bool checked);
00246 void dragClicked(bool checked);
00247 void zoomInClicked();
00248 void zoomOutClicked();
00249 void zoomOriginalClicked();
00250 void newMousePositionSlot(float x,float y);
00251 void mouseLeavesImageAreaSlot(bool leaves);
00252
00253 protected:
00254 QVImageArea *imageArea;
00255
00256 private:
00257 #ifdef QVQWT
00258 QwtScaleWidget *scaleWidgetX,*scaleWidgetY;
00259 QwtLinearScaleEngine *scaleEngineX,*scaleEngineY;
00260 #endif
00261
00262 QToolButton *buttonDrawSel,*buttonZoomIn,*buttonZoomOut,*buttonZoomOriginal,*buttonZoomRect,
00263 *buttonselPoly,*buttonSelRect,*buttonDrag;
00264 QMenu *menuselPoly;
00265 QStatusBar *statusBar;
00266 void resizeEvent(QResizeEvent *event);
00267 int scaleWidgetsFixedWidth,statusBarWidgetFixedHeight;
00268 float mousePosX,mousePosY;
00269 bool mouseIsOut;
00270 QString statusMessage();
00271 TPolyMode polyMode;
00272 };
00273
00274 #endif