| TerraLib 4.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

E:/Projetos_Primeiro_Semestre_2012/TerraView/terralib/src/terralib/drivers/qt/TeQtCanvas.h
Go to the documentation of this file.

    00001 /************************************************************************************
    00002 TerraView - visualization and exploration of geographical databases
    00003 using TerraLib.
    00004 Copyright � 2001-2007 INPE and Tecgraf/PUC-Rio.
    00005 This file is part of TerraView. TerraView is free software; you can redistribute it
    00006 and/or modify it under the terms of the GNU General Public License as published by
    00007 the Free Software Foundation; either version 2 of the License, or
    00008 (at your option) any later version.
    00009
    00010 You should have received a copy of the GNU General Public License
    00011 along with TerraView.
    00012 The authors reassure the license terms regarding the warranties.
    00013 They specifically disclaim any warranties, including, but not limited to,
    00014 the implied warranties of merchantability and fitness for a particular purpose.
    00015 The software provided hereunder is on an "as is" basis, and the authors have no
    00016 obligation to provide maintenance, support, updates, enhancements, or modifications.
    00017 In no event shall INPE and Tecgraf / PUC-Rio be held liable to any party for direct,
    00018 indirect, special, incidental, or consequential damages arising out of the use of
    00019 this program and its documentation.
    00020 *************************************************************************************/
    00021
    00022 #ifndef  __QTCANVAS_H
    00023 #define  __QTCANVAS_H
    00024
    00025 #include "../../kernel/TeDatabase.h"
    00026 #include "../../kernel/TeRaster.h"
    00027
    00028 #include "../../kernel/TeDefines.h"
    00029
    00030 #include <qpainter.h>
    00031 #include <qbrush.h>
    00032 #include <qpixmap.h>
    00033 #include <qimage.h>
    00034 #include <qbitmap.h>
    00035 #include <qprinter.h>
    00036 #include <qscrollview.h>
    00037 #include <qpopupmenu.h>
    00038
    00039 class TeQtProgress;
    00040
    00041 #include <string>
    00042 using namespace std;
    00043
    00044
    00045 class TL_DLL TeQtCanvas : public QScrollView
    00046 {
    00047    Q_OBJECT
    00048
    00049 public:
    00050     enum CursorMode { Pointer, Area, Pan, Hand, SizeVer, SizeBDiag,
    00051                        UpArrow, Edit, Distance, Information, ZoomIn, ZoomOut };
    00052
    00053            // Constructor
    00054            TeQtCanvas(QWidget *parent=0, const char *name=0);
    00055
    00056            // Destructor
    00057            ~TeQtCanvas();
    00058
    00059            // Set the initial position for the area cursor
    00060            void initCursorArea (QPoint p);
    00061
    00062            // Set the cursor type
    00063            void setMode (CursorMode);
    00064
    00065            // Get the cursor type
    00066            CursorMode getCursorMode() { return cursorMode_;}
    00067
    00068            // Get the cursor box in world coordinates
    00069            TeBox getCursorBox (){ return TeBox (xul_,ylr_,xlr_,yul_); }
    00070
    00071            // Copy the pixmap contents to the viewport
    00072            void copyPixmapToWindow();
    00073
    00074            // Set the dimensions of the paint device, according the box
    00075            // given in world coordinates
    00076            bool setWorld(TeBox b, int w = 0, int h = 0, QPaintDevice *pd = 0);
    00077
    00078            // Set the dimensions of the paint device, creating or recreating the
    00079            // pixmaps accordingly
    00080            virtual bool setView(int w = 0, int h = 0, QPaintDevice* pd = 0);
    00081
    00082            // Adjust the box in world coordinates if the extend flag is true or set
    00083            // the canvas dimensions if the extend flag is false
    00084            void setTransformation(double xmin, double xmax, double ymin, double ymax, bool extend = true);
    00085
    00086            // Get the canvas box in world coordinates
    00087            TeBox getWorld() {return wc_ ;}
    00088
    00089            // Get the data box in world coordinates
    00090            TeBox getDataWorld();
    00091
    00092            // Clear the canvas viewport
    00093            void clear();
    00094
    00095            // Clear the viewport area corresponding to the given box
    00096            void clear(TeBox box);
    00097
    00098            // Clear the viewport and all the pixmaps
    00099            void clearAll();
    00100
    00101            // Clear the area of the viewport and the area of all of the
    00102            // pixmaps corresponding to the given box
    00103            void clearAll(TeBox box);
    00104
    00105            // Get the position of the viewport relative to the total canvas area
    00106            QPoint offset() {return QPoint(contentsX(), contentsY());}
    00107
    00108            // Map the given point in data world coordinates to
    00109            // the corresponding point in the viewport
    00110            QPoint mapDWtoV(const TeCoord2D& dw);
    00111
    00112            // Map the given box in data world coordinates to
    00113            // the corresponding box in the viewport
    00114            void mapDWtoV(TeBox& box);
    00115
    00116            // Map the points of a line in data world coordinates to
    00117            // the corresponding points in the viewport
    00118            QPointArray mapDWtoV(const TeLine2D&);
    00119
    00120            // Map the value in data world coordinates to
    00121            // the corresponding value in the viewport
    00122            int mapDWtoV(double);
    00123
    00124            // Map the value in pixels in the viewport to
    00125            // the corresponding value in the canvas world
    00126            double mapVtoCW(int);
    00127
    00128            // Map the point in the viewport to the
    00129            // corresponding point in the canvas world
    00130            TeCoord2D mapVtoCW(const QPoint&);
    00131
    00132            // Map the box in the viewport to the
    00133            // corresponding box in the canvas world
    00134            void mapVtoCW(TeBox& box);
    00135
    00136            // Map the value in pixels in the viewport to
    00137            // the corresponding value in the data world
    00138            double mapVtoDW(int);
    00139
    00140            // Map the point in the viewport to the
    00141            // corresponding point in the data world
    00142            TeCoord2D mapVtoDW(const QPoint&);
    00143
    00144            // Map the box in the canvas world coordinates to
    00145            // the corresponding box in the data world coordinates
    00146            void mapCWtoDW(TeBox& box);
    00147
    00148            // Map the box in the data world coordinates to
    00149            // the corresponding box in the canvas world coordinates
    00150            void mapDWtoCW(TeBox& box);
    00151
    00152            // Map the box in the canvas world coordinates to
    00153            // the corresponding box in the viewport
    00154            void mapCWtoV(TeBox& box);
    00155
    00156            // Map the point in the canvas world coordinates to
    00157            // the corresponding point in the viewport
    00158            QPoint mapCWtoV(const TeCoord2D& c);
    00159
    00160 // Pixel size in world coordinates
    00161            double pixelSize () { return (xmax_-xmin_)/(double)width_; }
    00162
    00163 // Set the projection of the next incoming data
    00164            void  setDataProjection ( TeProjection* proj );
    00165
    00166 // Set the projection
    00167            void  setProjection ( TeProjection* proj);
    00168
    00169 // Retrieve the canvas projection
    00170            TeProjection* projection() { return canvasProjection_; }
    00171
    00172 // Retrieve flag that compare canvas projection and data projection
    00173            bool canvasAndDataProjectionEqual() {return canvasAndDataProjectionEqual_;};
    00174
    00175 // Plotting primitives
    00176
    00177            QPainter* getPainter () {return &painter_;}
    00178            void plotOnWindow ();
    00179            void plotOnPixmap0 ();
    00180            void plotOnPixmap1 ();
    00181            void plotOnPixmap2 ();
    00182            virtual void copyPixmapToWindow(QPixmap*, int, int, int, int);
    00183            virtual void copyPixmap0ToPrinter();
    00184            virtual void copyPixmap0To(QPaintDevice*);
    00185            virtual void copyPixmap0ToWindow();
    00186            virtual void copyPixmap1ToWindow();
    00187            virtual void copyPixmap0ToWindow(int, int, int, int);
    00188            virtual void copyPixmap0ToPixmap1();
    00189            virtual void copyPixmap0ToPixmap1(int, int, int, int);
    00190            virtual void copyPixmap1ToPixmap0();
    00191            virtual void copyPixmap1ToPixmap0(int, int, int, int);
    00192            virtual void copyPixmap1ToPixmap2();
    00193            virtual void copyPixmap1ToPixmap2(int, int, int, int);
    00194            virtual void copyPixmap2ToPixmap1();
    00195            virtual void copyPixmap2ToPixmap1(int, int, int, int);
    00196            virtual void copyPanArea(int, int);
    00197
    00198            void plotPoint (const TeCoord2D &p);
    00199            void plotPoint (const TePoint &p){ plotPoint(p.location()); }
    00200
    00201            void setPointColor (int r, int g, int b);
    00202            void setPointStyle (int s, int w = 3);
    00203            void setPointPixmap (char* p);
    00204
    00205            void plotCell (TeCell &s, const bool& restoreBackground = false);
    00206
    00207            QRect getLegendRect (QPoint p, const QPixmap* pix, string tx);
    00208            void plotLegend (QPoint p, const QPixmap* pix, string tx);
    00209
    00210            void plotPolygon (const TePolygon &p, const bool& restoreBackground = false);
    00211            void setPolygonColor (int r, int g, int b);
    00212            void setPolygonStyle (int s, int width = 1);
    00213            void setPolygonLineColor (int r, int g, int b);
    00214            void setPolygonLineStyle (int s, int width = 1);
    00215
    00216            void plotLine (TeLine2D &l);
    00217            void plotArrow(QPointArray a);
    00218            void plotMiddleLineArrow(QPoint ptBegin, QPoint ptEnd);
    00219            void plotMiddleLineArrow(const TeLine2D &lne, QPointArray a);
    00220            void setLineColor (int r, int g, int b);
    00221            void setLineStyle (int s, int w = 1);
    00222            QPointArray           getArrow(QPoint ptBegin, QPoint ptEnd, double size);
    00223
    00224            void plotNode (TeNode &n);
    00225            void setNodeColor (int r, int g, int b);
    00226            void setNodeStyle (int s, int w = 4);
    00227            void setNodePixmap (char* p);
    00228
    00229            void plotArc (TeArc &a);
    00230            void setArcColor (int r, int g, int b);
    00231            void setArcStyle ( int s, int w = 1 );
    00232
    00233            void plotPie (double x, double y, double w, double h, double a, double alen);
    00234            void setPieColor (int r, int g, int b);
    00235            void plotRect (double x, double y, double w, double h, int transp=0, bool legend=false);
    00236            void plotRect (QRect&);
    00237            void setRectColor (int r, int g, int b);
    00238
    00239            void plotText (const TeCoord2D &p, const string &str, double angle = 0., double alignh = 0., double alignv = 0.);
    00240            void plotText (const TeText &tx, const TeVisual& visual);
    00241            QRect textRect (const TeText &tx, TeVisual visual);
    00242            void plotTextRects (TeText &tx, TeVisual visual);
    00243            void setTextColor (int r, int g, int b);
    00244            void setTextSize (int size);
    00245            void setTextStyle (string& family, int size, bool bold, bool italic);
    00246            void textExtent ( string &str, int &w, int &h, double angle = 0.);
    00247            void plotXorPolyline (QPointArray& PA, bool cdev=true);
    00248            void plotXorTextDistance(vector<QPointArray> xorPointArrayVec, double unitConv, string unit);
    00249
    00250            void setDB (TeDatabase* db) { db_ = db; }
    00251            void plotRaster (TeRaster* raster, TeRasterTransform* transf, TeQtProgress *progress);
    00252            void clearRaster();
    00253            void endPrinting();
    00254
    00255            QPixmap* getPixmap0 () {return pixmap0_; }
    00256            QPixmap* getPixmap1 () {return pixmap1_; }
    00257            QPixmap* getPixmap2 () {return pixmap2_; }
    00258
    00259            void plotGraphicScale(TeVisual& visual, double offsetX, double offsetY, double unitConv=1, const string& dunit="");
    00260
    00261            void setClipRegion(int x, int y, int w, int h);
    00262            void setClipRegion(QRegion region);
    00263            void setClipping (bool enable);
    00264
    00265            TeRasterParams& getParams()
    00266            {          return params_; }
    00267
    00268            double scaleApx() {return scaleApx_;}
    00269            void scaleApx(double);
    00270
    00271            double printerFactor() {return printerFactor_;}
    00272            void widthRef2PrinterFactor(int w) {widthRef2PrinterFactor_ = w;}
    00273            void plotLegend (const QPoint& p, TeLegendEntry* leg, const string& tx);
    00274            void plotLegend (const QPoint& p, const TeColor& cor, const string& tx);
    00275            bool locateGraphicScale(const QPoint& p);
    00276            QRect& graphicScaleRect() { return graphicScaleRect_;}
    00277            void numberOfPixmaps(int n) {numberOfPixmaps_ = n;}
    00278            int numberOfPixmaps() {return numberOfPixmaps_;}
    00279            QPopupMenu* popupCanvas() { return popupCanvas_; }
    00280
    00281
    00282 signals:
    00283            void mousePressed (TeCoord2D&, int, QPoint&);
    00284            void mouseDoublePressed (TeCoord2D&, int, QPoint&);
    00285            void mouseRightButtonPressed (TeCoord2D&, int, QPoint&);
    00286            void mouseMoved (TeCoord2D&, int, QPoint&);
    00287            void mouseReleased (TeCoord2D&, int, QPoint&);
    00288            void mouseLeave ();
    00289            void paintEvent ();
    00290            void popupCanvasSignal(QMouseEvent*);
    00291            void keyPressed(QKeyEvent*);
    00292            void keyReleased(QKeyEvent*);
    00293            void zoomArea();
    00294
    00295 protected:
    00296
    00297            TeDatabase*           db_;
    00298
    00299            QPainter   painter_;
    00300            QImage                qimage_;
    00301            QPopupMenu* popupCanvas_;
    00302            QPixmap*   pixmap0_;
    00303            QPixmap*   pixmap1_;
    00304            QPixmap*   pixmap2_;
    00305            int                              numberOfPixmaps_;
    00306
    00307            TeProjection*         canvasProjection_;
    00308            TeProjection*         dataProjection_;
    00309
    00310            TeRaster*             backRaster_;
    00311            TeRasterParams        params_;
    00312
    00313            double     printerFactor_;
    00314            int                   widthRef2PrinterFactor_;
    00315            QRect      graphicScaleRect_;
    00316            bool       canvasAndDataProjectionEqual_;
    00317
    00318            // Sizes and transformations
    00319            TeBox      wc_;
    00320            double     xmin_;
    00321            double     xmax_;
    00322            double     ymin_;
    00323            double     ymax_;
    00324            int                   x0_;
    00325            int                   y0_;
    00326            int                   width_;
    00327            int                   height_;
    00328            double     f_;
    00329            double     scaleApx_;
    00330            int                   scale_;
    00331            int                   lx1_;
    00332            int                   ly1_;
    00333            int                   lx2_;
    00334            int                   ly2_;
    00335
    00336 // Area Cursor section
    00337            CursorMode cursorMode_;
    00338            bool       down_;
    00339            double     xul_; // cursor world coordinates
    00340            double     xlr_;
    00341            double     yul_;
    00342            double     ylr_;
    00343            int        ixul_; // cursor screen coordinates
    00344            int        ixlr_;
    00345            int        iyul_;
    00346            int        iylr_;
    00347
    00348 // Pie
    00349            QBrush                pieBrush_;
    00350            QColor                pieColor_;
    00351            QBrush                rectBrush_;
    00352            QColor                rectColor_;
    00353
    00354 // Polygon
    00355            int                              polygonTransparency_;
    00356            QBrush                polygonBrush_;
    00357            QPen                  polygonPen_;
    00358            QColor                polygonColor_;
    00359            map<TePolyBasicType, Qt::BrushStyle> brushStyleMap_;
    00360
    00361 // Line
    00362            QPen                  linePen_;
    00363            QColor                lineColor_;
    00364            map<TeLnBasicType, Qt::PenStyle> penStyleMap_;
    00365            TeLnBasicType         _penStyle;
    00366
    00367 // Point
    00368            int                              pointStyle_;
    00369            int                              pointSize_;
    00370            QPen                  pointPen_;
    00371            QColor                pointColor_;
    00372            QPixmap*   pointPixmap_;
    00373
    00374 // Arc
    00375            QPen                  arcPen_;
    00376            QColor                arcColor_;
    00377
    00378 // Node
    00379            int                              nodeStyle_;
    00380            int                              nodeSize_;
    00381            QPen                  nodePen_;
    00382            QColor                nodeColor_;
    00383            QPixmap*   nodePixmap_;
    00384
    00385 // Text
    00386            QPen                  textPen_;
    00387            QColor                textColor_;
    00388            QFont                 textFont_;
    00389            int                              textSize_;
    00390
    00391 // Draw Representations
    00392            void drawPolygonRep (QPoint p, int w, int h, TeVisual& v);
    00393            void drawLineRep (QPoint p, TeVisual& v);
    00394            void drawPointRep (QPoint p, TeVisual& v);
    00395            void plotMark(QPoint &p, int s, int w);
    00396
    00397 // Mouse events
    00398            void contentsMousePressEvent( QMouseEvent* );
    00399            void contentsMouseMoveEvent ( QMouseEvent* );
    00400            void contentsMouseReleaseEvent ( QMouseEvent* );
    00401            void contentsMouseDoubleClickEvent ( QMouseEvent* );
    00402            void contentsContextMenuEvent( QContextMenuEvent* );
    00403
    00404 // Leave Event
    00405            void leaveEvent(QEvent*);
    00406
    00407 // Key events
    00408            void keyPressEvent(QKeyEvent*);
    00409            void keyReleaseEvent(QKeyEvent*);
    00410
    00411 // Other events
    00412            void viewportPaintEvent(QPaintEvent* e);
    00413            void resizeEvent(QResizeEvent*);
    00414
    00415 // Correct scrolling when there are scrollbars
    00416            void correctScrolling(QPoint &p);
    00417
    00418 // Build Raster
    00419            bool buildRaster();
    00420 };
    00421
    00422 #endif
    00423

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines