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
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
00043 class QVPainter: public QPainter
00044 {
00045 friend class QVImageArea;
00046
00047 private:
00048
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
00064 QVImageArea *imageArea;
00065 };
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 class QVImageArea : public QGLWidget
00076 {
00077 Q_OBJECT
00078
00079 friend class QVCanvas;
00080 friend class QVPainter;
00081
00082 private:
00083
00084
00085
00086
00087 static QVImageArea *first_image_area;
00088
00089 void initObject(int w, int h);
00090
00091
00092
00093 QVImageArea(int w, int h,QWidget *parent);
00094
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
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())); }
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() { };
00154
00155 signals:
00156 void newGeometry(int origwidth,int origheight,int topleftx,int toplefty,int width,int height, int zoom);
00157
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