00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "TeQtCanvas.h"
00023 #include "../../kernel/TeDecoderMemory.h"
00024 #include "TeQtProgress.h"
00025 #include "../../kernel/TeVectorRemap.h"
00026 #include "../../kernel/TeGeometryAlgorithms.h"
00027 #include "../../kernel/TeDefines.h"
00028 #include "../../kernel/TeRasterRemap.h"
00029 #include "TeDecoderQtImage.h"
00030
00031 #include <qpaintdevice.h>
00032 #include <qpaintdevicemetrics.h>
00033 #include <qapplication.h>
00034
00035 #include <string>
00036 #include <algorithm>
00037 #include <time.h>
00038
00039
00040 TeQtCanvas::TeQtCanvas(QWidget *parent, const char *name)
00041 : QScrollView(parent,name,WNorthWestGravity)
00042 {
00043 pixmap0_ = 0;
00044 pixmap1_ = 0;
00045 pixmap2_ = 0;
00046 backRaster_ = 0;
00047 printerFactor_ = 1.;
00048 numberOfPixmaps_ = 3;
00049
00050 canvasProjection_ = 0;
00051 dataProjection_ = 0;
00052 pointStyle_ = 0;
00053 nodeStyle_ = 0;
00054 pointSize_ = 3;
00055 nodeSize_ = 4;
00056 db_ = 0;
00057
00058
00059 brushStyleMap_[TePolyTypeTransparent] = Qt::NoBrush;
00060 brushStyleMap_[TePolyTypeFill] = Qt::SolidPattern;
00061 brushStyleMap_[TePolyTypeHorizontal] = Qt::HorPattern;
00062 brushStyleMap_[TePolyTypeVertical] = Qt::VerPattern;
00063 brushStyleMap_[TePolyTypeFDiagonal] = Qt::FDiagPattern;
00064 brushStyleMap_[TePolyTypeBDiagonal] = Qt::BDiagPattern;
00065 brushStyleMap_[TePolyTypeCross] = Qt::CrossPattern;
00066 brushStyleMap_[TePolyTypeDiagonalCross] = Qt::DiagCrossPattern;
00067
00068
00069 penStyleMap_[TeLnTypeContinuous] = Qt::SolidLine;
00070 penStyleMap_[TeLnTypeDashed] = Qt::DashLine;
00071 penStyleMap_[TeLnTypeDotted] = Qt::DotLine;
00072 penStyleMap_[TeLnTypeDashDot] = Qt::DashDotLine;
00073 penStyleMap_[TeLnTypeDashDotDot] = Qt::DashDotDotLine;
00074 penStyleMap_[TeLnTypeNone] = Qt::NoPen;
00075
00076 setVScrollBarMode(QScrollView::Auto);
00077 setHScrollBarMode(QScrollView::Auto);
00078 viewport()->setMouseTracking(true);
00079 viewport()->setFocusPolicy(StrongFocus);
00080 viewport()->setBackgroundColor(backgroundColor());
00081 setMargin(0);
00082
00083 width_ = viewport()->width();
00084 height_ = viewport()->height();
00085 popupCanvas_ = new QPopupMenu(this);
00086 _penStyle=TeLnTypeContinuous;
00087 }
00088
00089 TeQtCanvas::~TeQtCanvas()
00090 {
00091 if (dataProjection_)
00092 delete dataProjection_;
00093 if (canvasProjection_)
00094 delete canvasProjection_;
00095
00096 if (backRaster_)
00097 delete backRaster_;
00098 backRaster_ = 0;
00099
00100 QPaintDevice* dev = painter_.device();
00101 if(dev)
00102 painter_.end();
00103
00104 if(pixmap0_)
00105 delete pixmap0_;
00106 pixmap0_ = 0;
00107
00108 if(pixmap1_)
00109 delete pixmap1_;
00110 pixmap1_ = 0;
00111
00112 if(pixmap2_)
00113 delete pixmap2_;
00114 pixmap2_ = 0;
00115 }
00116
00117 void TeQtCanvas::setDataProjection ( TeProjection* proj )
00118 {
00119 if(dataProjection_)
00120 delete dataProjection_;
00121
00122 if (proj == 0)
00123 return;
00124 dataProjection_ = TeProjectionFactory::make(proj->params());
00125
00126 canvasAndDataProjectionEqual_ = true;
00127 if (canvasProjection_ && dataProjection_ && !(*canvasProjection_== *dataProjection_))
00128 {
00129 canvasAndDataProjectionEqual_ = false;
00130 dataProjection_->setDestinationProjection(canvasProjection_);
00131 canvasProjection_->setDestinationProjection(dataProjection_);
00132 }
00133 }
00134
00135 void TeQtCanvas::setProjection ( TeProjection* proj )
00136 {
00137 if (canvasProjection_)
00138 delete canvasProjection_;
00139 canvasProjection_ = TeProjectionFactory::make(proj->params());
00140 params_.projection(canvasProjection_);
00141
00142 canvasAndDataProjectionEqual_ = true;
00143 if(canvasProjection_ && dataProjection_ && !(*canvasProjection_== *dataProjection_))
00144 canvasAndDataProjectionEqual_ = false;
00145 }
00146
00147 void TeQtCanvas::plotOnWindow ()
00148 {
00149 QPaintDevice* dev = painter_.device();
00150 if(dev == viewport())
00151 return;
00152 if(dev)
00153 painter_.end();
00154 painter_.begin(viewport());
00155 }
00156
00157 void TeQtCanvas::plotOnPixmap0 ()
00158 {
00159 QPaintDevice* dev = painter_.device();
00160 if(dev == pixmap0_)
00161 return;
00162 if(dev)
00163 painter_.end();
00164 painter_.begin(pixmap0_);
00165 }
00166
00167 void TeQtCanvas::plotOnPixmap1 ()
00168 {
00169 QPaintDevice* dev = painter_.device();
00170 if(dev == pixmap1_)
00171 return;
00172 if(dev)
00173 painter_.end();
00174 painter_.begin(pixmap1_);
00175 }
00176
00177 void TeQtCanvas::plotOnPixmap2 ()
00178 {
00179 QPaintDevice* dev = painter_.device();
00180 if(dev == pixmap2_)
00181 return;
00182 if(dev)
00183 painter_.end();
00184 painter_.begin(pixmap2_);
00185 }
00186
00187 bool TeQtCanvas::setWorld(TeBox b, int w, int h, QPaintDevice *pd)
00188 {
00189 xmin_= b.x1();
00190 xmax_= b.x2();
00191 ymin_= b.y1();
00192 ymax_= b.y2();
00193 if(setView(w, h, pd) == false)
00194 return false;
00195 bool extend = pd ? false : true;
00196 setTransformation(xmin_, xmax_, ymin_, ymax_, extend);
00197 params_.nBands(3);
00198 double resx = pixelSize();
00199 double resy = pixelSize();
00200 TeBox box(getWorld());
00201 params_.lowerLeftResolutionSize(box.x1_+0.5*resx,box.y1_+0.5*resy,resx,resy,width_,height_);
00202 params_.projection();
00203 params_.mode_ = 'w';
00204 params_.decoderIdentifier_ = "";
00205 return true;
00206 }
00207
00208 void TeQtCanvas::setTransformation(double xmin, double xmax, double ymin, double ymax, bool extend)
00209 {
00210 if (painter_.device() == 0)
00211 return;
00212
00213 xmin_= xmin;
00214 xmax_= xmax;
00215 ymin_= ymin;
00216 ymax_= ymax;
00217
00218 double dxw = xmax_ - xmin_;
00219 double dyw = ymax_ - ymin_;
00220 double dxv = width_;
00221 double dyv = height_;
00222
00223 double fx = dxv/dxw;
00224 double fy = dyv/dyw;
00225
00226 if (fx > fy)
00227 {
00228 f_ = fy;
00229 if (extend)
00230 {
00231 dxw = width_/f_;
00232 xmax_ = xmin_ + dxw;
00233 }
00234 else
00235 width_ = (int)(f_*dxw + .5);
00236 }
00237 else
00238 {
00239 f_ = fx;
00240 if (extend)
00241 {
00242 dyw = height_/f_;
00243 ymax_ = ymin_ + dyw;
00244 }
00245 else
00246 height_ = (int)(f_*dyw + .5);
00247 }
00248
00249 wc_ = TeBox (xmin_,ymin_,xmax_,ymax_);
00250 params_.boundingBoxResolution(xmin_,ymin_,xmax_,ymax_,params_.resx_,params_.resy_);
00251
00252 QPaintDeviceMetrics devMetric(viewport());
00253 double wpixels = devMetric.width();
00254 double wMM = devMetric.widthMM();
00255 double wT = wMM;
00256 if(canvasProjection_)
00257 {
00258 string unit = TeConvertToUpperCase(canvasProjection_->units());
00259 if(unit == "METERS")
00260 wT = wMM / 1000.;
00261 else if(unit == "KILOMETERS")
00262 wT = wMM / 1000000.;
00263 else if(unit == "CENTIMETERS")
00264 wT = wMM / 100.;
00265 else if(unit == "MILLIMETERS")
00266 wT = wMM;
00267 else if(unit == "FEET")
00268 wT = wMM / (12. * 25.4);
00269 else if(unit == "INCHES")
00270 wT = wMM / 25.4;
00271 else if(unit == "DECIMALDEGREES")
00272 wT = wMM / 110000000.;
00273 }
00274 double wp = wT / wpixels;
00275 scaleApx_ = (1. / f_) / wp;
00276 }
00277
00278 void TeQtCanvas::scaleApx(double scale)
00279 {
00280 QPaintDeviceMetrics devMetric(viewport());
00281 double wMM = devMetric.widthMM();
00282 double wT = wMM;
00283 if(canvasProjection_)
00284 {
00285 string unit = TeConvertToUpperCase(canvasProjection_->units());
00286 if(unit == "METERS")
00287 wT = wMM / 1000.;
00288 else if(unit == "KILOMETERS")
00289 wT = wMM / 1000000.;
00290 else if(unit == "CENTIMETERS")
00291 wT = wMM / 100.;
00292 else if(unit == "MILLIMETERS")
00293 wT = wMM;
00294 else if(unit == "FEET")
00295 wT = wMM / (12. * 25.4);
00296 else if(unit == "INCHES")
00297 wT = wMM / 25.4;
00298 else if(unit == "DECIMALDEGREES")
00299 wT = wMM / 110000000.;
00300 }
00301
00302 double ff = scale / scaleApx_;
00303 double xmin, ymin, xmax, ymax;
00304 if(ff < 1)
00305 {
00306 double dx = (wc_.width() - (wc_.width() * ff)) / 2.;
00307 double dy = (wc_.height() - (wc_.height() * ff)) / 2.;
00308 xmin = xmin_ + dx;
00309 ymin = ymin_ + dy;
00310 xmax = xmax_ - dx;
00311 ymax = ymax_ - dy;
00312 }
00313 else
00314 {
00315 double dx = ((wc_.width() * ff) - wc_.width()) / 2.;
00316 double dy = ((wc_.height() * ff) - wc_.height()) / 2.;
00317 xmin = xmin_ - dx;
00318 ymin = ymin_ - dy;
00319 xmax = xmax_ + dx;
00320 ymax = ymax_ + dy;
00321 }
00322
00323 TeBox box(xmin, ymin, xmax, ymax);
00324 setWorld(box, contentsWidth(), contentsHeight());
00325 }
00326
00327 double TeQtCanvas::mapVtoCW(int pixels)
00328 {
00329 TeBox wbox = getDataWorld();
00330 TeCoord2D wpc(wbox.x1_ + wbox.width()/2., wbox.y1_ + wbox.height()/2.);
00331 QPoint pc = mapDWtoV(wpc);
00332 QPoint qp(pc.x()+pixels, pc.y());
00333 TeCoord2D wp = mapVtoCW(qp);
00334 wpc = mapVtoCW(pc);
00335 double d = fabs(wp.x() - wpc.x());
00336 return d;
00337 }
00338
00339 double TeQtCanvas::mapVtoDW(int pixels)
00340 {
00341 TeBox wbox = getDataWorld();
00342 TeCoord2D wpc(wbox.x1_ + wbox.width()/2., wbox.y1_ + wbox.height()/2.);
00343 QPoint pc = mapDWtoV(wpc);
00344 QPoint qp(pc.x()+pixels, pc.y());
00345 TeCoord2D wp = mapVtoDW(qp);
00346 wpc = mapVtoDW(pc);
00347 double d = fabs(wp.x() - wpc.x());
00348 return d;
00349 }
00350
00351 TeCoord2D TeQtCanvas::mapVtoCW(const QPoint& p)
00352 {
00353 TeCoord2D w((p.x()-x0_)/f_ + xmin_,
00354 (height_ - y0_ - p.y())/f_ + ymin_);
00355 return w;
00356 }
00357
00358 TeCoord2D TeQtCanvas::mapVtoDW(const QPoint& v)
00359 {
00360 TeCoord2D w((v.x()-x0_)/f_ + xmin_,
00361 (height_ - y0_ - v.y())/f_ + ymin_);
00362
00363 if(canvasAndDataProjectionEqual_ == false)
00364 {
00365 canvasProjection_->setDestinationProjection(dataProjection_);
00366 dataProjection_->setDestinationProjection(canvasProjection_);
00367 w = canvasProjection_->PC2LL (w);
00368 w = dataProjection_->LL2PC (w);
00369 }
00370 return w;
00371 }
00372
00373
00374 TeBox TeQtCanvas::getDataWorld()
00375 {
00376 if(canvasAndDataProjectionEqual_ == false)
00377 {
00378 TeBox b = TeRemapBox(wc_, canvasProjection_, dataProjection_);
00379 return b;
00380 }
00381 return wc_ ;
00382 }
00383
00384 QPoint TeQtCanvas::mapDWtoV(const TeCoord2D& dw)
00385 {
00386 TeCoord2D w = dw;
00387 if(canvasAndDataProjectionEqual_ == false)
00388 {
00389 canvasProjection_->setDestinationProjection(dataProjection_);
00390 dataProjection_->setDestinationProjection(canvasProjection_);
00391 w = dataProjection_->PC2LL (w);
00392 w = canvasProjection_->LL2PC (w);
00393 }
00394
00395 QPoint v((int)((w.x() - xmin_)*f_ + 0.5)+x0_,
00396 height_ - y0_ - (int)((w.y() - ymin_)*f_ + 0.5));
00397 correctScrolling (v);
00398 return v;
00399 }
00400
00401 QPointArray TeQtCanvas::mapDWtoV(const TeLine2D& line)
00402 {
00403 int i;
00404 int np = line.size();
00405 QPointArray parray(np);
00406 TeCoord2D p;
00407
00408 if(canvasAndDataProjectionEqual_ == false)
00409 {
00410 canvasProjection_->setDestinationProjection(dataProjection_);
00411 dataProjection_->setDestinationProjection(canvasProjection_);
00412 for (i = 0 ; i < np; ++i)
00413 {
00414 p = line[i];
00415 p = dataProjection_->PC2LL(p);
00416 p = canvasProjection_->LL2PC(p);
00417 QPoint v((int)((p.x() - xmin_)*f_ + 0.5)+x0_,
00418 height_ - y0_ - (int)((p.y() - ymin_)*f_ + 0.5));
00419 correctScrolling (v);
00420 parray.setPoint(i, v);
00421 }
00422 }
00423 else
00424 {
00425 for (i = 0 ; i < np; i++)
00426 {
00427 p = line[i];
00428 QPoint v((int)((p.x() - xmin_)*f_ + 0.5)+x0_,
00429 height_ - y0_ - (int)((p.y() - ymin_)*f_ + 0.5));
00430 correctScrolling (v);
00431 parray.setPoint(i, v);
00432 }
00433 }
00434 return parray;
00435 }
00436
00437 void TeQtCanvas::mapDWtoV(TeBox& w)
00438 {
00439 TeCoord2D ll, ur;
00440 if(canvasAndDataProjectionEqual_ == false)
00441 w = TeRemapBox (w, dataProjection_, canvasProjection_);
00442
00443 ll = w.lowerLeft();
00444 ur = w.upperRight();
00445
00446 QPoint p1((int)((ll.x() - xmin_)*f_ + 0.5)+x0_,
00447 height_ - y0_ - (int)((ll.y() - ymin_)*f_ + 0.5));
00448 correctScrolling (p1);
00449
00450 QPoint p2((int)((ur.x() - xmin_)*f_ + 0.5)+x0_,
00451 height_ - y0_ - (int)((ur.y() - ymin_)*f_ + 0.5));
00452 correctScrolling (p2);
00453
00454 w.x1_ = p1.x();
00455 w.y1_ = p2.y();
00456 w.x2_ = p2.x();
00457 w.y2_ = p1.y();
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506 }
00507
00508 void TeQtCanvas::mapCWtoDW(TeBox& box)
00509 {
00510 TeCoord2D ll, ur;
00511 if(canvasAndDataProjectionEqual_ == false)
00512 box = TeRemapBox (box, canvasProjection_, dataProjection_);
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527 }
00528
00529 void TeQtCanvas::mapDWtoCW(TeBox& box)
00530 {
00531 TeCoord2D ll, ur;
00532 if(canvasAndDataProjectionEqual_ == false)
00533 box = TeRemapBox (box, dataProjection_, canvasProjection_);
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548 }
00549
00550 void TeQtCanvas::mapCWtoV(TeBox& box)
00551 {
00552 QPoint p1((int)((box.x1() - xmin_)*f_ + 0.5)+x0_,
00553 height_ - y0_ - (int)((box.y1() - ymin_)*f_ + 0.5));
00554 correctScrolling (p1);
00555
00556 QPoint p2((int)((box.x2() - xmin_)*f_ + 0.5)+x0_,
00557 height_ - y0_ - (int)((box.y2() - ymin_)*f_ + 0.5));
00558 correctScrolling (p2);
00559
00560
00561 box.x1_ = p1.x();
00562 box.y1_ = p2.y();
00563 box.x2_ = p2.x();
00564 box.y2_ = p1.y();
00565 }
00566
00567 void TeQtCanvas::mapVtoCW(TeBox& box)
00568 {
00569
00570 TeCoord2D w1((box.x1()-x0_)/f_ + xmin_,
00571 (height_ - y0_ - box.y2())/f_ + ymin_);
00572
00573 TeCoord2D w2((box.x2()-x0_)/f_ + xmin_,
00574 (height_ - y0_ - box.y1())/f_ + ymin_);
00575
00576 box = TeBox(w1, w2);
00577 }
00578
00579 QPoint TeQtCanvas::mapCWtoV(const TeCoord2D& c)
00580 {
00581 QPoint p((int)((c.x() - xmin_)*f_ + 0.5)+x0_,
00582 height_ - y0_ - (int)((c.y() - ymin_)*f_ + 0.5));
00583 correctScrolling (p);
00584
00585 return p;
00586 }
00587
00588 void TeQtCanvas::setPolygonColor (int r, int g, int b)
00589 {
00590 QRgb cor = qRgba(r, g, b, 50);
00591 polygonColor_.setRgb(cor);
00592 polygonBrush_.setColor (polygonColor_);
00593 }
00594
00595 void TeQtCanvas::setPolygonStyle (int s, int t)
00596 {
00597 polygonBrush_.setStyle(brushStyleMap_[(TePolyBasicType)s]);
00598 polygonTransparency_ = t;
00599 }
00600
00601 void TeQtCanvas::setPolygonLineColor (int r, int g, int b)
00602 {
00603 QColor cor(r, g, b);
00604 polygonPen_.setColor (cor);
00605 }
00606
00607 void TeQtCanvas::setPolygonLineStyle (int s, int w)
00608 {
00609 polygonPen_.setStyle(penStyleMap_[(TeLnBasicType)s]);
00610 polygonPen_.setWidth(w);
00611 }
00612
00613 void TeQtCanvas::setLineColor (int r, int g, int b)
00614 {
00615 lineColor_.setRgb(r,g,b);
00616 linePen_.setColor (lineColor_);
00617 }
00618
00619 void TeQtCanvas::setLineStyle (int s, int w)
00620 {
00621 _penStyle=(TeLnBasicType)s;
00622 if((_penStyle == TeLnTypeArrow) || (_penStyle == TeLnTypeMiddleArrow) ) linePen_.setStyle(Qt::SolidLine);
00623 else linePen_.setStyle(penStyleMap_[(TeLnBasicType)s]);
00624 linePen_.setWidth(w);
00625 }
00626
00627 void TeQtCanvas::setTextColor (int r, int g, int b)
00628 {
00629 textColor_.setRgb(r,g,b);
00630 textPen_.setColor (textColor_);
00631 }
00632
00633 void TeQtCanvas::setTextStyle (string& family, int size, bool bold, bool italic )
00634 {
00635 textFont_.setFamily (family.c_str());
00636 textFont_.setBold (bold);
00637 textFont_.setItalic (italic);
00638 if(size <= 0)
00639 textSize_ = 1;
00640 else
00641 textSize_ = size;
00642
00643 if(pixmap0_ && pixmap1_ && (pixmap0_->rect() != pixmap1_->rect()))
00644 textSize_ = (int)((double)textSize_ * printerFactor_ + .5);
00645
00646 textFont_.setPointSize (textSize_);
00647 }
00648
00649 void TeQtCanvas::setTextSize (int size)
00650 {
00651 if(size <= 0)
00652 textSize_ = 1;
00653 else
00654 textSize_ = size;
00655
00656 if(pixmap0_ && pixmap1_ && (pixmap0_->rect() != pixmap1_->rect()))
00657 textSize_ = (int)((double)textSize_ * printerFactor_ + .5);
00658
00659 textFont_.setPointSize (textSize_);
00660 }
00661
00662
00663 void TeQtCanvas::plotText (const TeCoord2D &pt, const string &str, double angle, double , double )
00664 {
00665 painter_.setPen(textPen_);
00666 painter_.setFont(textFont_);
00667 QPoint p = mapDWtoV (pt);
00668 if (angle != 0.)
00669 {
00670 painter_.save ();
00671 painter_.translate (p.x(),p.y());
00672 painter_.rotate (-angle);
00673 painter_.drawText (0,-4,QString(str.c_str()));
00674 painter_.restore ();
00675 }
00676 else
00677 painter_.drawText (p,QString(str.c_str()));
00678 }
00679
00680 void TeQtCanvas::plotXorTextDistance(vector<QPointArray> xorPointArrayVec, double unitConv, string unit)
00681 {
00682 if(xorPointArrayVec.empty())
00683 return;
00684
00685 QPoint a = xorPointArrayVec[0].point(0);
00686 QPoint b = xorPointArrayVec[0].point(1);
00687 TeCoord2D ppa = mapVtoCW(a);
00688 TeCoord2D ppb = mapVtoCW(b);
00689 double distance = sqrt((ppa.x()-ppb.x()) * (ppa.x()-ppb.x()) + (ppa.y()-ppb.y()) * (ppa.y()-ppb.y()));
00690 string s;
00691 if(unit == "Decimal Degrees")
00692 s = Te2String(distance/unitConv,6) + "(" + unit + ")";
00693 else
00694 s = Te2String(distance/unitConv,1) + "(" + unit + ")";
00695
00696 double dy = (double)(b.y() - a.y());
00697 double dx = (double)(b.x() - a.x());
00698 distance = sqrt(dx * dx + dy * dy);
00699 double txHeight = -7.;
00700 double dd = distance / 2.;
00701 double alfa = atan(dy/dx);
00702 if(dx<0 && dy<0)
00703 alfa = alfa - TePI;
00704 else if(dy>0 && dx<0)
00705 alfa = TePI + alfa;
00706 double beta = atan(txHeight/dd);
00707 double c = dd * cos(beta);
00708
00709 double gama = alfa + beta;
00710 if((dx<0 && dy<0) || (dy>0 && dx<0))
00711 gama = alfa - beta;
00712
00713 double x = c * cos(gama);
00714 x += a.x();
00715 double y = c * sin(gama);
00716 y += a.y();
00717 QPoint p((int)x, (int)y);
00718 alfa = -alfa * 180. / TePI;
00719 if((dx<0 && dy<0) || (dy>0 && dx<0))
00720 alfa = 180. + alfa;
00721
00722 QPen pen(QColor(239, 111, 63));
00723 QFont font("Helvetica", 12);
00724 font.setStyleStrategy(QFont::PreferAntialias);
00725 font.setBold(true);
00726 QFontMetrics fm(font);
00727 QRect rect = fm.boundingRect(s.c_str());
00728 int xp = - rect.width()/2;
00729 int yp = - rect.height()/2;
00730
00731 plotOnPixmap0();
00732 painter_.setRasterOp (Qt::XorROP);
00733 painter_.setPen(pen);
00734 painter_.setFont(font);
00735 if (alfa != 0.)
00736 {
00737 painter_.save ();
00738 painter_.translate (p.x(),p.y());
00739 painter_.rotate (-alfa);
00740 painter_.drawText(xp, yp, rect.width(), rect.height(), Qt::AlignLeft|Qt::DontClip, s.c_str());
00741 painter_.restore ();
00742 }
00743 else
00744 {
00745 xp = p.x() - rect.width()/2;
00746 yp = p.y() - rect.height()/2;
00747 painter_.drawText((int)x, (int)y, rect.width(), rect.height(), Qt::AlignLeft|Qt::DontClip, s.c_str());
00748 }
00749
00750 plotOnWindow();
00751 painter_.setRasterOp (Qt::XorROP);
00752 painter_.setPen(pen);
00753 painter_.setFont(font);
00754 painter_.save ();
00755 painter_.translate (-offset().x(), -offset().y());
00756 if (alfa != 0.)
00757 {
00758 painter_.translate (p.x(),p.y());
00759 painter_.rotate (-alfa);
00760 painter_.drawText(xp, yp, rect.width(), rect.height(), Qt::AlignLeft|Qt::DontClip, s.c_str());
00761 }
00762 else
00763 {
00764 xp = p.x() - rect.width()/2;
00765 yp = p.y() - rect.height()/2;
00766 painter_.drawText(xp, yp, rect.width(), rect.height(), Qt::AlignLeft|Qt::DontClip, s.c_str());
00767 }
00768 painter_.restore ();
00769 }
00770
00771 void TeQtCanvas::plotText (const TeText& tx, const TeVisual& visual)
00772 {
00773 if(tx.textValue().empty())
00774 return;
00775
00776 int x, y;
00777
00778 TeCoord2D pt = tx.location();
00779 QPoint p = mapDWtoV (pt);
00780 double angle = tx.angle();
00781
00782 QRect brect = textRect(tx, visual);
00783 painter_.setFont(textFont_);
00784 painter_.setPen(textPen_);
00785 painter_.setRasterOp (Qt::CopyROP);
00786 string st = tx.textValue();
00787
00788 if (angle != 0.)
00789 {
00790 x = - brect.width()/2;
00791 y = - brect.height()/2;
00792 painter_.save ();
00793 painter_.translate (p.x(), p.y());
00794 painter_.rotate (-angle);
00795 painter_.drawText(x, y, brect.width(), brect.height(), Qt::AlignLeft|Qt::DontClip, st.c_str());
00796 painter_.restore ();
00797 }
00798 else
00799 {
00800 x = p.x() - brect.width()/2;
00801 y = p.y() - brect.height()/2;
00802 painter_.drawText(x, y, brect.width(), brect.height(), Qt::AlignLeft|Qt::DontClip, st.c_str());
00803 }
00804 }
00805
00806 QRect TeQtCanvas::textRect(const TeText& tx, TeVisual visual)
00807 {
00808 QRect rect;
00809 if(tx.textValue().empty())
00810 return rect;
00811
00812 int size;
00813 int fixedSize = visual.fixedSize();
00814 if(fixedSize == false && tx.height() > 0.)
00815 {
00816 TeBox wbox = getDataWorld();
00817 TeCoord2D p1(wbox.x1_, wbox.y1_);
00818 TeCoord2D p2(double(p1.x() + tx.height()), double(p1.y() + tx.height()));
00819 TeBox box(p1, p2);
00820 mapDWtoV(box);
00821 size = int(box.height());
00822 size = (int)((double)size / printerFactor_ + .5);
00823 }
00824 else
00825 size = visual.size();
00826 if(size == 0)
00827 size = 1;
00828
00829 setTextSize(size);
00830 textFont_.setFamily (visual.family().c_str());
00831
00832 TeCoord2D pt = tx.location();
00833 QPoint p = mapDWtoV (pt);
00834
00835 string st = tx.textValue();
00836 QFontMetrics fm(textFont_);
00837 rect = fm.boundingRect(st.c_str());
00838 QPoint cc = rect.center();
00839 QPoint tr = p;
00840 tr = tr - cc;
00841 rect.setRight(rect.right()+tr.x());
00842 rect.setLeft(rect.left()+tr.x());
00843 rect.setTop(rect.top()+tr.y());
00844 rect.setBottom(rect.bottom()+tr.y());
00845 return rect;
00846 }
00847
00848 void TeQtCanvas::plotXorPolyline (QPointArray& PA, bool cdev)
00849 {
00850 QPoint o = offset();
00851 QPen pen(QColor("green"));
00852
00853 plotOnPixmap0();
00854 painter_.save ();
00855 if(cdev == false)
00856 painter_.translate(o.x(), o.y());
00857 painter_.setRasterOp (Qt::XorROP);
00858 painter_.setPen(pen);
00859 painter_.drawPolyline(PA);
00860 painter_.restore ();
00861
00862 plotOnWindow();
00863 painter_.save ();
00864 if(cdev)
00865 painter_.translate(-o.x(), -o.y());
00866 painter_.setRasterOp (Qt::XorROP);
00867 painter_.setPen(pen);
00868 painter_.drawPolyline(PA);
00869 painter_.restore ();
00870
00871 plotOnPixmap0();
00872 }
00873
00874 void TeQtCanvas::plotTextRects (TeText& tx, TeVisual visual)
00875 {
00876 if(tx.textValue().empty())
00877 return;
00878
00879 QPoint o = offset();
00880 QRect rect, l, r, t, b, c;
00881
00882 TeCoord2D pt = tx.location();
00883 plotOnPixmap0();
00884 QPoint p = mapDWtoV (pt);
00885 double angle = tx.angle();
00886
00887 rect = textRect(tx, visual);
00888 if(angle != 0.)
00889 {
00890 rect.setTop(rect.top()-p.y());
00891 rect.setBottom(rect.bottom()-p.y());
00892 rect.setLeft(rect.left()-p.x());
00893 rect.setRight(rect.right()-p.x());
00894 }
00895
00896 l = rect;
00897 l.setTop(rect.top()+rect.height()/2-3);
00898 l.setBottom(rect.top()+rect.height()/2+3);
00899 l.setRight(rect.left() + 6);
00900
00901 r = rect;
00902 r.setTop(l.top());
00903 r.setBottom(l.bottom());
00904 r.setLeft(rect.right() - 6);
00905
00906 t = rect;
00907 t.setLeft(rect.left()+rect.width()/2-3);
00908 t.setRight(rect.left()+rect.width()/2+3);
00909 t.setBottom(rect.top() + 6);
00910
00911 b = rect;
00912 b.setLeft(t.left());
00913 b.setRight(t.right());
00914 b.setTop(rect.bottom() - 6);
00915
00916 c.setLeft(rect.left()+rect.width()/2-3);
00917 c.setRight(c.left() + 6);
00918 c.setTop(rect.top()+rect.height()/2-3);
00919 c.setBottom(c.top() + 6);
00920
00921 QPointArray parL(4);
00922 parL.setPoint(0, l.bottomLeft());
00923 parL.setPoint(1, l.bottomRight());
00924 parL.setPoint(2, l.topRight());
00925 parL.setPoint(3, l.topLeft());
00926
00927 QPointArray parR(4);
00928 parR.setPoint(0, r.bottomRight());
00929 parR.setPoint(1, r.bottomLeft());
00930 parR.setPoint(2, r.topLeft());
00931 parR.setPoint(3, r.topRight());
00932
00933 QPointArray parT(4);
00934 parT.setPoint(0, t.topLeft());
00935 parT.setPoint(1, t.bottomLeft());
00936 parT.setPoint(2, t.bottomRight());
00937 parT.setPoint(3, t.topRight());
00938
00939 QPointArray parB(4);
00940 parB.setPoint(0, b.bottomLeft());
00941 parB.setPoint(1, b.topLeft());
00942 parB.setPoint(2, b.topRight());
00943 parB.setPoint(3, b.bottomRight());
00944
00945 QBrush brush(QColor("green"));
00946
00947 if (angle != 0.)
00948 {
00949 plotOnPixmap0();
00950 painter_.save ();
00951 painter_.setRasterOp (Qt::XorROP);
00952 painter_.setBrush(Qt::NoBrush);
00953 QPen pen(QColor("green"));
00954 painter_.setPen(pen);
00955 painter_.translate (p.x(), p.y());
00956 painter_.rotate (-angle);
00957 painter_.drawRect(rect);
00958 painter_.drawPolyline(parL);
00959 painter_.drawPolyline(parR);
00960 painter_.drawPolyline(parT);
00961 painter_.drawPolyline(parB);
00962 painter_.fillRect(c, brush);
00963 painter_.restore ();
00964
00965 plotOnWindow();
00966 painter_.save ();
00967 painter_.setRasterOp (Qt::XorROP);
00968 painter_.setBrush(Qt::NoBrush);
00969 pen = QPen(QColor("green"));
00970 painter_.setPen(pen);
00971 painter_.translate (p.x()-o.x(), p.y()-o.y());
00972 painter_.rotate (-angle);
00973 painter_.drawRect(rect);
00974 painter_.drawPolyline(parL);
00975 painter_.drawPolyline(parR);
00976 painter_.drawPolyline(parT);
00977 painter_.drawPolyline(parB);
00978 painter_.fillRect(c, brush);
00979 painter_.restore ();
00980 }
00981 else
00982 {
00983 plotOnPixmap0();
00984 painter_.save ();
00985 painter_.setRasterOp (Qt::XorROP);
00986 painter_.setBrush(Qt::NoBrush);
00987 QPen pen(QColor("green"));
00988 painter_.setPen(pen);
00989 painter_.drawRect(rect);
00990 painter_.drawPolyline(parL);
00991 painter_.drawPolyline(parR);
00992 painter_.drawPolyline(parT);
00993 painter_.drawPolyline(parB);
00994 painter_.fillRect(c, brush);
00995 painter_.restore ();
00996
00997 plotOnWindow();
00998 painter_.save ();
00999 painter_.setRasterOp (Qt::XorROP);
01000 painter_.setBrush(Qt::NoBrush);
01001 pen = QPen(QColor("green"));
01002 painter_.setPen(pen);
01003 painter_.translate (-o.x(), -o.y());
01004 painter_.drawRect(rect);
01005 painter_.drawPolyline(parL);
01006 painter_.drawPolyline(parR);
01007 painter_.drawPolyline(parT);
01008 painter_.drawPolyline(parB);
01009 painter_.fillRect(c, brush);
01010 painter_.restore ();
01011 }
01012 plotOnPixmap0();
01013 }
01014
01015 void TeQtCanvas::setArcColor (int r, int g, int b)
01016 {
01017 arcColor_.setRgb(r,g,b);
01018 }
01019
01020 void TeQtCanvas::setArcStyle (int s, int w )
01021 {
01022 arcPen_.setStyle ((Qt::PenStyle)s);
01023 arcPen_.setWidth(w);
01024 }
01025
01026 void TeQtCanvas::setPointColor (int r, int g, int b)
01027 {
01028 pointColor_.setRgb(r,g,b);
01029 }
01030
01031 void TeQtCanvas::setPointStyle (int s, int w)
01032 {
01033 pointStyle_ = (TePtBasicType) s;
01034 pointSize_ = w;
01035 }
01036
01037 void TeQtCanvas::plotPoint (const TeCoord2D &pt)
01038 {
01039 pointPen_.setColor (pointColor_);
01040 painter_.setPen(pointPen_);
01041
01042 QPoint p = mapDWtoV (pt);
01043
01044 plotMark(p,pointStyle_, pointSize_);
01045 }
01046
01047 void TeQtCanvas::setNodeColor (int r, int g, int b)
01048 {
01049 nodeColor_.setRgb(r,g,b);
01050 }
01051
01052 void TeQtCanvas::setNodeStyle (int s, int w)
01053 {
01054 nodeStyle_ = s;
01055 nodeSize_ = w;
01056 }
01057
01058 void TeQtCanvas::plotNode (TeNode &pt)
01059 {
01060 nodePen_.setColor (nodeColor_);
01061 painter_.setPen(nodePen_);
01062
01063 QPoint p = mapDWtoV (pt.location());
01064 plotMark(p,nodeStyle_, nodeSize_);
01065 }
01066
01067
01068 void TeQtCanvas::plotMark(QPoint &p, int s, int w)
01069 {
01070 painter_.setPen(pointColor_);
01071 if (s == TePtTypePlus)
01072 {
01073 painter_.drawLine (p.x()-w/2,p.y(),p.x()+w/2,p.y());
01074 painter_.drawLine (p.x(),p.y()-w/2,p.x(),p.y()+w/2);
01075 }
01076 else if (s == TePtTypeStar)
01077 {
01078 painter_.save ();
01079 painter_.translate (p.x(),p.y());
01080 painter_.drawLine (0,-w/2,0,w/2);
01081 painter_.rotate (45);
01082 painter_.drawLine (0,-w/2,0,w/2);
01083 painter_.rotate (-90);
01084 painter_.drawLine (0,-w/2,0,w/2);
01085 painter_.restore ();
01086 }
01087 else if (s == TePtTypeCircle)
01088 {
01089 painter_.setBrush(pointColor_);
01090 painter_.drawChord (p.x()-w/2,p.y()-w/2,w,w,0,360*16);
01091 }
01092 else if (s == TePtTypeX)
01093 {
01094 painter_.drawLine (p.x()-w/2,p.y()-w/2,p.x()+w/2,p.y()+w/2);
01095 painter_.drawLine (p.x()-w/2,p.y()+w/2,p.x()+w/2,p.y()-w/2);
01096 }
01097 else if (s == TePtTypeBox)
01098 {
01099 painter_.fillRect (p.x()-w/2,p.y()-w/2,w,w,pointColor_);
01100 }
01101 else if (s == TePtTypeDiamond)
01102 {
01103 QPointArray pa(5);
01104 pa.setPoint(0, p.x()-w/2, p.y());
01105 pa.setPoint(1, p.x(), p.y()-w/2);
01106 pa.setPoint(2, p.x()+w/2, p.y());
01107 pa.setPoint(3, p.x(), p.y()+w/2);
01108 pa.setPoint(4, p.x()-w/2, p.y());
01109 painter_.setBrush(pointColor_);
01110 painter_.drawPolygon(pa);
01111 }
01112 else if (s == TePtTypeHollowCircle)
01113 {
01114 painter_.drawArc (p.x()-w/2,p.y()-w/2,w,w,0,360*16);
01115 }
01116 else if (s == TePtTypeHollowBox)
01117 {
01118 painter_.setBrush(Qt::NoBrush);
01119 painter_.drawRect (p.x()-w/2,p.y()-w/2,w,w);
01120 }
01121 else if (s == TePtTypeHollowDiamond)
01122 {
01123 painter_.drawLine (p.x()-w/2,p.y(),p.x(),p.y()-w/2);
01124 painter_.drawLine (p.x(),p.y()-w/2,p.x()+w/2,p.y());
01125 painter_.drawLine (p.x()+w/2,p.y(),p.x(),p.y()+w/2);
01126 painter_.drawLine (p.x(),p.y()+w/2,p.x()-w/2,p.y());
01127 }
01128 }
01129
01130
01131 void TeQtCanvas::plotCell (TeCell &cell, const bool& restoreBackground)
01132 {
01133 int w, h;
01134 TeBox b = getDataWorld ();
01135
01136 if (!TeIntersects (b, cell.box ()))
01137 return;
01138
01139 QPoint pfrom, pto;
01140
01141 pfrom = mapDWtoV (cell.box().lowerLeft());
01142 pto = mapDWtoV (cell.box().upperRight());
01143
01144 painter_.setBrush(polygonBrush_);
01145 painter_.setPen (polygonPen_);
01146
01147 if(!restoreBackground &&
01148 (polygonTransparency_ == 0 ||
01149 polygonTransparency_ == 100 && polygonBrush_.style() == Qt::NoBrush))
01150 {
01151 if(polygonTransparency_ == 100 && polygonBrush_.style() != Qt::NoBrush)
01152 painter_.setBrush(Qt::NoBrush);
01153
01154 if((w = pto.x() - pfrom.x()) <= 1)
01155 w = 2;
01156 if((h = pfrom.y() - pto.y()) <= 1)
01157 h = 2;
01158
01159 painter_.drawRect( pfrom.x(), pto.y(), w+1, h+1);
01160 }
01161 else if(polygonBrush_.style() == Qt::HorPattern ||
01162 polygonBrush_.style() == Qt::VerPattern ||
01163 polygonBrush_.style() == Qt::CrossPattern ||
01164 polygonBrush_.style() == Qt::BDiagPattern ||
01165 polygonBrush_.style() == Qt::FDiagPattern ||
01166 polygonBrush_.style() == Qt::DiagCrossPattern)
01167 {
01168 if((w = pto.x() - pfrom.x()) <= 1)
01169 w = 2;
01170 if((h = pfrom.y() - pto.y()) <= 1)
01171 h = 2;
01172
01173 painter_.drawRect( pfrom.x(), pto.y(), w+1, h+1);
01174 }
01175 else
01176 {
01177 QRect devRect;
01178 if(painter_.device() == viewport())
01179 devRect = viewport()->rect();
01180 else
01181 devRect = pixmap0_->rect();
01182
01183 TeBox box = cell.box();
01184 mapDWtoV(box);
01185 if((w = (int)box.width()) <= 3)
01186 w = 4;
01187 if((h = (int)box.height()) <= 3)
01188 h = 4;
01189
01190 QRect polyRect((int)box.x1_, (int)box.y1_, w+1, h+1);
01191 QRect interRect = devRect & polyRect;
01192 QPoint pOffset = interRect.topLeft();
01193
01194 int width = interRect.width();
01195 int height = interRect.height();
01196
01197 int r = width%8;
01198 if(r)
01199 width += (8-r);
01200 r = height%8;
01201 if(r)
01202 height += (8-r);
01203
01204 QBitmap bm;
01205 bm.resize(width, height);
01206
01207 bm.fill(Qt::color0);
01208 QPainter maskPainter(&bm);
01209
01210
01211 QBrush bs(Qt::color1);
01212 maskPainter.setBrush(bs);
01213 QPen pen(Qt::color1, polygonPen_.width());
01214 maskPainter.setPen(pen);
01215 maskPainter.translate(-pOffset.x(), -pOffset.y());
01216 maskPainter.drawRect( interRect );
01217 maskPainter.end();
01218
01219 QRegion clipRegion(bm);
01220 clipRegion.translate(pOffset.x(), pOffset.y());
01221
01222 int transp = 255 - (polygonTransparency_ * 255 / 100);
01223 painter_.setClipRegion(clipRegion);
01224 if(restoreBackground)
01225 {
01226 painter_.drawPixmap(pOffset.x(), pOffset.y(), *pixmap2_, pOffset.x(),
01227 pOffset.y(), interRect.width(), interRect.height());
01228 }
01229
01230
01231 QImage img(interRect.width(), interRect.height(), 32);
01232 unsigned int val = (transp << 24) | (polygonColor_.red() << 16) | (polygonColor_.green() << 8) | polygonColor_.blue();
01233 img.fill(val);
01234 img.setAlphaBuffer(true);
01235
01236
01237 painter_.drawPixmap(pOffset.x(), pOffset.y(), img);
01238
01239
01240
01241 painter_.setClipping(false);
01242 painter_.setBrush(Qt::NoBrush);
01243 painter_.drawRect( interRect );
01244 }
01245 }
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255
01256
01257
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278
01279
01280
01281
01282
01283
01284
01285
01286
01287
01288
01289
01290
01291
01292
01293
01294
01295
01296
01297
01298
01299
01300
01301
01302
01303
01304
01305
01306
01307
01308
01309
01310
01311
01312
01313
01314
01315
01316
01317
01318
01319
01320
01321
01322
01323
01324
01325
01326
01327
01328
01329
01330
01331
01332
01333
01334
01335
01336
01337
01338
01339
01340
01341
01342
01343
01344
01345 void TeQtCanvas::plotPolygon (const TePolygon &poly, const bool& restoreBackground)
01346 {
01347 if(canvasAndDataProjectionEqual_)
01348 {
01349 if (!TeIntersects (wc_, poly.box ()))
01350 return;
01351 }
01352 else
01353 {
01354 TeBox canvasBox = TeRemapBoxPC2Geodetic(wc_, canvasProjection_);
01355 TeBox pBox = TeRemapBoxPC2Geodetic(poly.box(), dataProjection_);
01356
01357 if (!TeIntersects(canvasBox, pBox))
01358 return;
01359 }
01360
01361 int i, k;
01362 QPoint p;
01363 painter_.setBrush(polygonBrush_);
01364 painter_.setPen (polygonPen_);
01365
01366 if(!restoreBackground && poly.size() == 1 &&
01367 (polygonTransparency_ == 0 ||
01368 polygonBrush_.style() == Qt::NoBrush))
01369
01370 {
01371 TeLinearRing ring = poly[0];
01372 QPointArray parray = mapDWtoV(ring);
01373 painter_.drawPolygon( parray );
01374 }
01375 else if(polygonBrush_.style() == Qt::HorPattern ||
01376 polygonBrush_.style() == Qt::VerPattern ||
01377 polygonBrush_.style() == Qt::CrossPattern ||
01378 polygonBrush_.style() == Qt::BDiagPattern ||
01379 polygonBrush_.style() == Qt::FDiagPattern ||
01380 polygonBrush_.style() == Qt::DiagCrossPattern)
01381 {
01382 TeLinearRing ring = poly[0];
01383 QPointArray parray = mapDWtoV(ring);
01384 painter_.drawPolygon( parray );
01385 }
01386 else
01387 {
01388 QRect devRect;
01389 if(painter_.device() == viewport())
01390 devRect = viewport()->rect();
01391 else
01392 devRect = pixmap0_->rect();
01393
01394 TeBox box = poly.box();
01395 mapDWtoV(box);
01396 if(box.width() <= 0 || box.height() <= 0)
01397 return;
01398 int w = (int)box.width();
01399 int h = (int)box.height();
01400 if(w < 4)
01401 w = 4;
01402 if(h < 4)
01403 h = 4;
01404
01405 QRect polyRect((int)box.x1_, (int)box.y1_, w, h);
01406 if(polyRect.intersects(devRect) == false)
01407 return;
01408 QRect interRect = devRect & polyRect;
01409
01410 if(painter_.hasClipping())
01411 {
01412 QRegion interRegion = QRegion(interRect);
01413 QRegion pclip = painter_.clipRegion();
01414 interRegion = interRegion.intersect(pclip);
01415 interRect = interRegion.boundingRect();
01416 }
01417
01418 QPoint pOffset = interRect.topLeft();
01419 int width = interRect.width();
01420 int height = interRect.height();
01421
01422 int r = width%8;
01423 if(r)
01424 width += (8-r);
01425 r = height%8;
01426 if(r)
01427 height += (8-r);
01428
01429 if(width == 0)
01430 width = 8;
01431 if(height == 0)
01432 height = 8;
01433
01434 QBitmap bm;
01435 bm.resize(width, height);
01436
01437 bm.fill(Qt::color0);
01438 QPainter maskPainter(&bm);
01439
01440 TeLinearRing ring = poly[0];
01441 QPointArray parray = mapDWtoV(ring);
01442
01443
01444 QBrush bs(Qt::color1);
01445 maskPainter.setBrush(bs);
01446 QPen pen(Qt::color1, polygonPen_.width());
01447 maskPainter.setPen(pen);
01448 maskPainter.translate(-pOffset.x(), -pOffset.y());
01449 maskPainter.drawPolygon( parray );
01450
01451 vector<QPointArray> holeVec;
01452 if(poly.size() > 1)
01453 {
01454
01455 maskPainter.setBrush(Qt::color0);
01456 pen.setColor(Qt::color0);
01457 maskPainter.setPen(pen);
01458 for ( k = 1; k < (int)poly.size(); k++ )
01459 {
01460 ring = poly[k];
01461 QPointArray hole = mapDWtoV(ring);
01462 holeVec.push_back(hole);
01463 maskPainter.drawPolygon( hole );
01464 }
01465 }
01466 maskPainter.end();
01467
01468 QRegion clipRegion(bm);
01469 clipRegion.translate(pOffset.x(), pOffset.y());
01470
01471 painter_.setClipRegion(clipRegion);
01472
01473 if(restoreBackground && pixmap0_->rect() == pixmap2_->rect())
01474 {
01475
01476 painter_.drawPixmap(pOffset.x(), pOffset.y(), *pixmap2_, pOffset.x(),
01477 pOffset.y(), interRect.width(), interRect.height());
01478 }
01479
01480 if(polygonBrush_.style() != Qt::CustomPattern)
01481 {
01482 if(polygonBrush_.style() == Qt::SolidPattern)
01483 {
01484 int transp = 255 - (polygonTransparency_ * 255 / 100);
01485
01486
01487 QImage img(interRect.width(), interRect.height(), 32);
01488 unsigned int val = (transp << 24) | (polygonColor_.red() << 16) | (polygonColor_.green() << 8) | polygonColor_.blue();
01489 img.fill(val);
01490 img.setAlphaBuffer(true);
01491
01492
01493 painter_.drawPixmap(pOffset.x(), pOffset.y(), img);
01494 }
01495 }
01496
01497
01498
01499
01500
01501
01502
01503
01504
01505
01506
01507
01508
01509
01510
01511
01512
01513
01514
01515
01516
01517
01518
01519
01520
01521
01522
01523
01524
01525
01526
01527
01528
01529
01530
01531
01532
01533
01534
01535
01536
01537 painter_.setClipping(false);
01538 painter_.drawPolyline( parray );
01539 for(i = 0; i< (int)holeVec.size(); i++)
01540 painter_.drawPolyline( holeVec[i] );
01541 }
01542 }
01543
01544
01545
01546
01547
01548
01549
01550
01551
01552
01553
01554
01555
01556
01557
01558
01559
01560
01561
01562
01563
01564
01565
01566
01567
01568
01569
01570
01571
01572
01573
01574
01575
01576
01577
01578
01579
01580
01581
01582
01583
01584
01585
01586
01587
01588
01589
01590
01591
01592
01593
01594
01595
01596
01597
01598
01599
01600
01601
01602
01603
01604
01605
01606
01607
01608
01609
01610
01611
01612
01613
01614
01615
01616
01617
01618
01619
01620
01621
01622
01623
01624
01625
01626
01627
01628
01629
01630
01631
01632
01633
01634
01635
01636
01637
01638
01639
01640
01641
01642
01643
01644
01645
01646
01647
01648
01649
01650
01651
01652
01653
01654
01655
01656
01657
01658
01659
01660
01661
01662
01663
01664
01665
01666
01667
01668
01669
01670
01671
01672
01673
01674
01675
01676
01677
01678
01679
01680
01681
01682
01683
01684
01685
01686
01687
01688
01689
01690
01691
01692
01693
01694
01695
01696
01697
01698
01699
01700
01701
01702
01703
01704
01705
01706
01707
01708
01709
01710
01711
01712
01713
01714
01715
01716
01717
01718
01719
01720
01721
01722
01723
01724
01725
01726
01727
01728
01729
01730
01731
01732
01733
01734
01735
01736
01737
01738
01739
01740
01741
01742
01743
01744
01745
01746
01747
01748
01749
01750
01751
01752
01753
01754
01755
01756 QRect TeQtCanvas::getLegendRect (QPoint p, const QPixmap* pix, string tx)
01757 {
01758 QRect rect;
01759 TeVisual visual;
01760 TeColor cor(0, 0, 0);
01761 visual.size(8);
01762 visual.bold(true);
01763 visual.color(cor);
01764 visual.fixedSize(true);
01765 setTextColor (cor.red_, cor.green_, cor.blue_);
01766 string fam(visual.family());
01767 setTextStyle (fam, visual.size(), visual.bold(), visual.italic());
01768
01769 if(pix)
01770 {
01771 int x = (int)(p.x()+pix->width()+3.*printerFactor_);
01772 int y = (int)(p.y()+13.*printerFactor_);
01773 QFontMetrics fm(textFont_);
01774 rect = fm.boundingRect(tx.c_str());
01775 rect.setRight(rect.right() + x);
01776 rect.setLeft(rect.left() + x);
01777 rect.setTop(rect.top() + y);
01778 rect.setBottom(rect.bottom() + y);
01779 QRect prect = pix->rect();
01780 prect.setRight(prect.right() + p.x());
01781 prect.setLeft(prect.left() + p.x());
01782 prect.setTop(prect.top() + p.y());
01783 prect.setBottom(prect.bottom() + p.y());
01784 rect |= prect;
01785 }
01786 else
01787 {
01788 int x = (int)(p.x()+1.*printerFactor_);
01789 int y = (int)(p.y()+13.*printerFactor_);
01790 QFontMetrics fm(textFont_);
01791 rect = fm.boundingRect(tx.c_str());
01792 rect = fm.boundingRect(tx.c_str());
01793 rect.setRight(rect.right() + x);
01794 rect.setLeft(rect.left() + x);
01795 rect.setTop(rect.top() + y);
01796 rect.setBottom(rect.bottom() + y);
01797 }
01798 return rect;
01799 }
01800
01801 void TeQtCanvas::plotLegend (QPoint p, const QPixmap* pix, string tx)
01802 {
01803 TeVisual visual;
01804 TeColor cor(0, 0, 0);
01805 visual.fixedSize(true);
01806 visual.size(8);
01807 visual.bold(true);
01808 visual.color(cor);
01809 setTextColor (cor.red_, cor.green_, cor.blue_);
01810 string fam = visual.family();
01811 setTextStyle (fam, visual.size(), visual.bold(), visual.italic());
01812 painter_.setFont(textFont_);
01813 painter_.setPen(textPen_);
01814
01815 if(pix)
01816 {
01817 int x = (int)(p.x()+pix->width()+3.*printerFactor_);
01818 int y = (int)(p.y()+13.*printerFactor_);
01819 bitBlt (painter_.device(), p.x(), p.y(), pix, 0, 0, pix->width(), pix->height(), Qt::CopyROP, true);
01820 painter_.drawText(x, y, tx.c_str());
01821 }
01822 else
01823 {
01824 int x = (int)(p.x()+1.*printerFactor_);
01825 int y = (int)(p.y()+13.*printerFactor_);
01826 painter_.drawText(x, y, tx.c_str());
01827 }
01828 }
01829
01830 bool TeQtCanvas::locateGraphicScale(const QPoint& p)
01831 {
01832 return graphicScaleRect_.contains(p);
01833 }
01834
01835 void TeQtCanvas::plotLegend (const QPoint& p, const TeColor& cor, const string& tx)
01836 {
01837 TeVisual v;
01838 TeColor c = cor;
01839 v.color(c);
01840 c.init(0, 0, 0);
01841 v.contourColor(c);
01842 int ww = (int)(21. * printerFactor_);
01843 int hh = (int)(16. * printerFactor_);
01844
01845 drawPolygonRep(p, ww, hh, v);
01846
01847 QPoint pos = p;
01848 pos.setX(pos.x() + ww);
01849 pos.setX((int)(pos.x() + 3.*printerFactor_));
01850 pos.setY((int)(pos.y()+13.*printerFactor_));
01851 painter_.setPen(textPen_);
01852 painter_.drawText(pos, tx.c_str());
01853 }
01854
01855 void TeQtCanvas::plotLegend (const QPoint& p, TeLegendEntry* leg, const string& tx)
01856 {
01857 TeVisual visual;
01858 TeColor cor(0, 0, 0);
01859 visual.fixedSize(true);
01860 visual.size(8);
01861 visual.bold(true);
01862 visual.color(cor);
01863 setTextColor (cor.red_, cor.green_, cor.blue_);
01864 string fam = visual.family();
01865 setTextStyle (fam, visual.size(), visual.bold(), visual.italic());
01866 painter_.setFont(textFont_);
01867 painter_.setPen(textPen_);
01868 QPoint pos = p;
01869
01870 int ww = (int)(21. * printerFactor_);
01871 int hh = (int)(16. * printerFactor_);
01872
01873 if(leg == 0)
01874 {
01875 pos.setX(pos.x() + ww);
01876 pos.setX((int)(pos.x() + 3.*printerFactor_));
01877 pos.setY((int)(p.y()+13.*printerFactor_));
01878 painter_.drawText(pos.x(), pos.y(), tx.c_str());
01879 return;
01880 }
01881
01882
01883 bool hasPolygons = true;
01884 bool hasCells = true;
01885 bool hasLines = true;
01886 bool hasPoints = true;
01887
01888 string s = leg->to();
01889 if(s.find("mean = ") == string::npos)
01890 {
01891 TeGeomRepVisualMap& vm = leg->getVisualMap();
01892 if(vm.find(TePOLYGONS) == vm.end())
01893 {
01894 hasPolygons = false;
01895 hasCells = false;
01896 }
01897 if(vm.find(TeLINES) == vm.end())
01898 hasLines = false;
01899 if(vm.find(TePOINTS) == vm.end())
01900 hasPoints = false;
01901
01902 if ((hasPolygons || hasCells) && (hasLines == false) && (hasPoints == false))
01903 drawPolygonRep(pos, ww, hh, *(vm[TePOLYGONS]));
01904 else if ((hasPolygons || hasCells) && (hasLines == true) && (hasPoints == false))
01905 {
01906 drawPolygonRep(pos, ww, hh, *(vm[TePOLYGONS]));
01907 pos.setX(pos.x() + ww);
01908 drawLineRep(pos, *(vm[TeLINES]));
01909 }
01910 else if ((hasPolygons || hasCells) && (hasLines == false) && (hasPoints == true))
01911 {
01912 drawPolygonRep(pos, ww, hh, *(vm[TePOLYGONS]));
01913 pos.setX(pos.x() + ww);
01914 drawPointRep(pos, *(vm[TePOINTS]));
01915 }
01916 else if ((hasPolygons || hasCells) && (hasLines == true) && (hasPoints == true))
01917 {
01918 drawPolygonRep(pos, ww, hh, *(vm[TePOLYGONS]));
01919 pos.setX(pos.x() + ww);
01920 drawLineRep(pos, *(vm[TeLINES]));
01921 pos.setX(pos.x() + ww);
01922 drawPointRep(pos, *(vm[TePOINTS]));
01923 }
01924 else if (hasPolygons == false && hasCells == false && hasLines == true && hasPoints == false)
01925 drawLineRep(pos, *(vm[TeLINES]));
01926 else if (hasPolygons == false && hasCells == false && hasLines == false && hasPoints == true)
01927 drawPointRep(pos, *(vm[TePOINTS]));
01928 else if (hasPolygons == false && hasCells == false && hasLines == true && hasPoints == true)
01929 {
01930 drawLineRep(pos, *(vm[TeLINES]));
01931 pos.setX(pos.x() + ww);
01932 drawPointRep(pos, *(vm[TePOINTS]));
01933 }
01934 }
01935
01936 pos.setX(pos.x() + ww);
01937 pos.setX((int)(pos.x() + 3.*printerFactor_));
01938 pos.setY((int)(p.y()+13.*printerFactor_));
01939 painter_.setPen(textPen_);
01940 painter_.drawText(pos, tx.c_str());
01941 }
01942
01943 void TeQtCanvas::drawPolygonRep (QPoint p, int w, int h, TeVisual& v)
01944 {
01945 QBrush brush;
01946 brush.setStyle(brushStyleMap_[(TePolyBasicType)v.style()]);
01947 QColor bcor(v.color().red_, v.color().green_, v.color().blue_);
01948 brush.setColor(bcor);
01949 painter_.setBrush(brush);
01950
01951 QPen pen;
01952 pen.setStyle(penStyleMap_[(TeLnBasicType)v.contourStyle()]);
01953 QColor pcor(v.contourColor().red_, v.contourColor().green_, v.contourColor().blue_);
01954 pen.setColor(pcor);
01955 int pwidth = (Qt::PenStyle) v.contourWidth();
01956 pen.setWidth (pwidth);
01957 painter_.setPen(pen);
01958
01959 QRect rect(p.x(), (int)(p.y()+2.*printerFactor_), w, (int)(h-2.*printerFactor_));
01960
01961
01962
01963 int transp = v.transparency();
01964 if( (transp !=0) && ((TePolyBasicType)v.style() == TePolyTypeFill) )
01965 {
01966 transp = (int)(2.55 * (double)(100 - transp));
01967 QImage img(rect.width(), rect.height(), 32);
01968 unsigned int val = (transp << 24) | (bcor.red() << 16) | (bcor.green() << 8) | bcor.blue();
01969 img.fill(val);
01970 img.setAlphaBuffer(true);
01971
01972 painter_.drawPixmap(rect.x(), rect.y(), img);
01973 }
01974 else painter_.fillRect(rect,brush);
01975 painter_.setBrush(Qt::NoBrush);
01976 painter_.drawRect(rect);
01977 }
01978
01979 void TeQtCanvas::drawLineRep (QPoint p, TeVisual& v)
01980 {
01981 QPen pen;
01982 QColor cor;
01983 TeColor tcor;
01984 uint width;
01985
01986 tcor = v.color();
01987 cor.setRgb(tcor.red_, tcor.green_, tcor.blue_);
01988 pen.setColor(cor);
01989 pen.setStyle(penStyleMap_[(TeLnBasicType)v.style()]);
01990 width = v.width();
01991 pen.setWidth (width);
01992 painter_.setPen(pen);
01993
01994 painter_.moveTo((int)(p.x()+1.*printerFactor_), (int)(p.y()+5.*printerFactor_));
01995 painter_.lineTo((int)(p.x()+3.*printerFactor_), (int)(p.y()+5.*printerFactor_));
01996 painter_.lineTo((int)(p.x()+6.*printerFactor_), (int)(p.y()+6.*printerFactor_));
01997 painter_.lineTo((int)(p.x()+8.*printerFactor_), (int)(p.y()+8.*printerFactor_));
01998 painter_.lineTo((int)(p.x()+10.*printerFactor_), (int)(p.y()+9.*printerFactor_));
01999 painter_.lineTo((int)(p.x()+14.*printerFactor_), (int)(p.y()+10.*printerFactor_));
02000 painter_.lineTo((int)(p.x()+16.*printerFactor_), (int)(p.y()+10.*printerFactor_));
02001 painter_.lineTo((int)(p.x()+18.*printerFactor_), (int)(p.y()+9.*printerFactor_));
02002 painter_.lineTo((int)(p.x()+19.*printerFactor_), (int)(p.y()+9.*printerFactor_));
02003 painter_.moveTo((int)(p.x()+2.*printerFactor_), (int)(p.y()+13.*printerFactor_));
02004 painter_.lineTo((int)(p.x()+3.*printerFactor_), (int)(p.y()+12.*printerFactor_));
02005 painter_.lineTo((int)(p.x()+5.*printerFactor_), (int)(p.y()+11.*printerFactor_));
02006 painter_.lineTo((int)(p.x()+6.*printerFactor_), (int)(p.y()+11.*printerFactor_));
02007 painter_.lineTo((int)(p.x()+9.*printerFactor_), (int)(p.y()+10.*printerFactor_));
02008 painter_.lineTo((int)(p.x()+10.*printerFactor_), (int)(p.y()+9.*printerFactor_));
02009 }
02010
02011 void TeQtCanvas::drawPointRep (QPoint pp, TeVisual& v)
02012 {
02013 QColor cor;
02014 TeColor tcor;
02015
02016 tcor = v.color();
02017 cor.setRgb(tcor.red_, tcor.green_, tcor.blue_);
02018 int s = v.style();
02019 double w = (double)v.size() * printerFactor_;
02020
02021 QPoint p = pp;
02022 QPoint offset((int)(10.*printerFactor_), (int)(7.*printerFactor_));
02023 p += offset;
02024
02025 painter_.setPen(cor);
02026 if (s == TePtTypePlus)
02027 {
02028 painter_.drawLine ((int)(p.x()-w/2),p.y(),(int)(p.x()+w/2.),p.y());
02029 painter_.drawLine (p.x(),(int)(p.y()-w/2.),p.x(),(int)(p.y()+w/2.));
02030 }
02031 else if (s == TePtTypeStar)
02032 {
02033 painter_.save ();
02034 painter_.translate (p.x(),p.y());
02035 painter_.drawLine (0,(int)(-w/2.),0,(int)(w/2.));
02036 painter_.rotate (45);
02037 painter_.drawLine (0,(int)(-w/2.),0,(int)(w/2.));
02038 painter_.rotate (-90);
02039 painter_.drawLine (0,(int)(-w/2.),0,(int)(w/2.));
02040 painter_.restore ();
02041 }
02042 else if (s == TePtTypeCircle)
02043 {
02044 painter_.setBrush(cor);
02045 painter_.drawChord ((int)(p.x()-w/2.),(int)(p.y()-w/2.),(int)w,(int)w,0,360*16);
02046 }
02047 else if (s == TePtTypeX)
02048 {
02049 painter_.drawLine ((int)(p.x()-w/2.),(int)(p.y()-w/2.),(int)(p.x()+w/2.),(int)(p.y()+w/2.));
02050 painter_.drawLine ((int)(p.x()-w/2.),(int)(p.y()+w/2.),(int)(p.x()+w/2.),(int)(p.y()-w/2.));
02051 }
02052 else if (s == TePtTypeBox)
02053 {
02054 painter_.fillRect ((int)(p.x()-w/2.),(int)(p.y()-w/2.),(int)w,(int)w,cor);
02055 }
02056 else if (s == TePtTypeDiamond)
02057 {
02058 QPointArray pa(5);
02059 pa.setPoint(0, (int)(p.x()-w/2.), p.y());
02060 pa.setPoint(1, p.x(), (int)(p.y()-w/2.));
02061 pa.setPoint(2, (int)(p.x()+w/2.), p.y());
02062 pa.setPoint(3, p.x(), (int)(p.y()+w/2.));
02063 pa.setPoint(4, (int)(p.x()-w/2.), p.y());
02064 painter_.setBrush(cor);
02065 painter_.drawPolygon(pa);
02066 }
02067 else if (s == TePtTypeHollowCircle)
02068 {
02069 painter_.drawArc ((int)(p.x()-w/2.),(int)(p.y()-w/2.),(int)w,(int)w,0,360*16);
02070 }
02071 else if (s == TePtTypeHollowBox)
02072 {
02073 painter_.setBrush(Qt::NoBrush);
02074 painter_.drawRect ((int)(p.x()-w/2.),(int)(p.y()-w/2.),(int)w,(int)w);
02075 }
02076 else if (s == TePtTypeHollowDiamond)
02077 {
02078 painter_.drawLine ((int)(p.x()-w/2.),p.y(),p.x(),(int)(p.y()-w/2.));
02079 painter_.drawLine (p.x(),(int)(p.y()-w/2.),(int)(p.x()+w/2.),p.y());
02080 painter_.drawLine ((int)(p.x()+w/2.),p.y(),p.x(),(int)(p.y()+w/2.));
02081 painter_.drawLine (p.x(),(int)(p.y()+w/2.),(int)(p.x()-w/2.),p.y());
02082 }
02083 }
02084
02085 void TeQtCanvas::plotLine (TeLine2D &line)
02086 {
02087 TeBox b = getDataWorld ();
02088 if (!TeIntersects (b, line.box ()))
02089 return;
02090
02091 linePen_.setColor (lineColor_);
02092 painter_.setPen(linePen_);
02093
02094 QPointArray a = mapDWtoV(line);
02095 painter_.drawPolyline( a );
02096 if(_penStyle == TeLnTypeArrow)
02097 {
02098 plotArrow(a);
02099 }else if(_penStyle == TeLnTypeMiddleArrow)
02100 {
02101 plotMiddleLineArrow(line,a);
02102 }
02103 }
02104
02105 void TeQtCanvas::plotArrow(QPointArray a)
02106 {
02107 QPoint first=a.point(0);
02108 QPoint init=a.point(a.size() - 2);
02109 QPoint end=a.point(a.size() - 1);
02110
02111 if(TeDistance(TeCoord2D(first.x(),first.y()),TeCoord2D(end.x(),end.y()))>10)
02112 {
02113 QPointArray a = getArrow(init,end,10);
02114 painter_.setBrush(Qt::SolidPattern);
02115 painter_.setBrush(lineColor_);
02116 painter_.drawPolygon( a );
02117 }
02118 }
02119
02120 void TeQtCanvas::plotMiddleLineArrow(const TeLine2D &lne, QPointArray a)
02121 {
02122 int seg;
02123 TeCoord2D center;
02124 TeCoord2D previousCoord;
02125 QPoint first=a.point(0);
02126 QPoint end=a.point(a.size() - 1);
02127 TeLine2D ln;
02128
02129 ln.copyElements(lne);
02130 TeFindCentroid(lne,center);
02131 TeLocateLineSegment(center,ln,seg,1.0);
02132 previousCoord=lne[seg];
02133 QPoint pCenter=mapDWtoV(center);
02134 QPoint pPrevious=mapDWtoV(previousCoord);
02135 if(TeDistance(TeCoord2D(first.x(),first.y()),TeCoord2D(end.x(),end.y()))>20)
02136 {
02137 plotMiddleLineArrow(pPrevious,pCenter);
02138 }
02139 }
02140
02141 void TeQtCanvas::plotMiddleLineArrow(QPoint ptBegin, QPoint ptEnd)
02142 {
02143 QPointArray a = getArrow(ptBegin,ptEnd,10);
02144 painter_.setBrush(Qt::SolidPattern);
02145 painter_.setBrush(lineColor_);
02146 painter_.drawPolygon( a );
02147 }
02148
02149
02150 QPointArray TeQtCanvas::getArrow(QPoint ptBegin, QPoint ptEnd, double size)
02151 {
02152 QPointArray points(4);
02153 double slopy , cosy , siny;
02154
02155
02156 slopy = atan2((double)( ptBegin.y() - ptEnd.y() ),(double)( ptBegin.x() - ptEnd.x() ) );
02157 cosy = cos( slopy );
02158 siny = sin( slopy );
02159
02160 points[0]=QPoint(ptEnd.x(),ptEnd.y());
02161 points[1]=QPoint(ptEnd.x() - int(-size*cosy-(size/2.0*siny)),ptEnd.y() - int(-size*siny+(size/2.0*cosy )));
02162 points[2]=QPoint(ptEnd.x() - int(-size*cosy+(size/2.0*siny)),ptEnd.y() + int(size/2.0*cosy+size*siny));
02163 points[3]=QPoint(ptEnd.x(),ptEnd.y());
02164 return points;
02165 }
02166
02167 void TeQtCanvas::plotArc (TeArc &arc)
02168 {
02169 TeBox b = getDataWorld ();
02170 if (!TeIntersects (b, arc.box ()))
02171 return;
02172
02173 arcPen_.setColor (arcColor_);
02174 painter_.setPen(arcPen_);
02175
02176 QPoint pfrom, pto;
02177
02178 pfrom = mapDWtoV (arc.fromNode().location());
02179 pto = mapDWtoV (arc.toNode().location());
02180
02181 painter_.drawLine( pfrom, pto );
02182
02183 double ang = atan2 (double(pfrom.y()-pto.y()), double (pfrom.x()-pto.x()));
02184 QPoint pm((int)((pto.x()+pfrom.x())/2.+0.5),(int)((pto.y()+pfrom.y())/2.+0.5));
02185
02186 double ang1 = ang + 25.*TeCDR;
02187 double ang2 = ang - 25.*TeCDR;
02188 QPoint p1((int)(10.*cos(ang1)+0.5),(int)(10.*sin(ang1)+.5)),
02189 p2((int)(10.*cos(ang2)+0.5),(int)(10.*sin(ang2)+.5));
02190 p1 += pm;
02191 p2 += pm;
02192 painter_.drawLine( pm, p1 );
02193 painter_.drawLine( pm, p2 );
02194 painter_.drawLine( p1, p2 );
02195
02196 }
02197
02198 void TeQtCanvas::plotPie (double x, double y, double w, double h, double a, double alen)
02199 {
02200 int dx, dy, dw, dh, da, df;
02201
02202 pieBrush_.setColor (pieColor_);
02203 painter_.setBrush(pieBrush_);
02204 painter_.setPen(linePen_);
02205
02206 TeCoord2D p(x, y);
02207 QPoint qp = mapDWtoV(p);
02208 dx = qp.x();
02209 dy = qp.y();
02210
02211 TeCoord2D pt(x+w, y+h);
02212 QPoint qpt = mapDWtoV(pt);
02213 dw = abs(qpt.x() - dx);
02214 dh = abs(qpt.y() - dy);
02215
02216 da = (int)(a * 16);
02217 df = (int)(alen * 16);
02218 painter_.drawPie(dx, dy-dh, dw, dh, da, df);
02219 }
02220
02221 void TeQtCanvas::setPieColor (int r, int g, int b)
02222 {
02223 pieColor_.setRgb(r, g, b);
02224 pieBrush_.setStyle(Qt::SolidPattern);
02225 }
02226
02227 void TeQtCanvas::plotRect (QRect& rect)
02228 {
02229 rectBrush_.setColor (rectColor_);
02230 painter_.setBrush(Qt::NoBrush);
02231 painter_.setPen(linePen_);
02232 painter_.drawRect(rect);
02233 }
02234
02235 void TeQtCanvas::plotRect (double x, double y, double w, double h, int transp, bool legend)
02236 {
02237 if(pixmap1_ == 0)
02238 return;
02239
02240 int dx, dy, dw, dh;
02241
02242 TeCoord2D p(x, y);
02243 QPoint qp;
02244 if(legend)
02245 qp = QPoint((int)p.x(), (int)p.y());
02246 else
02247 qp = mapDWtoV(p);
02248 dx = qp.x();
02249 dy = qp.y();
02250
02251 TeCoord2D pt(x+w, y+h);
02252 QPoint qpt;
02253 if(legend)
02254 {
02255 qpt = QPoint((int)pt.x(), (int)pt.y());
02256 dw = abs(qpt.x() - dx);
02257 dh = abs(qpt.y() - dy);
02258 }
02259 else
02260 {
02261
02262 TeBox b = wc_;
02263 mapCWtoDW(b);
02264 TeCoord2D center = b.center();
02265 TeCoord2D cc = center;
02266 cc.x_ += w;
02267 dw = abs(mapDWtoV(center).x() - mapDWtoV(cc).x());
02268 cc = center;
02269 cc.y_ += h;
02270 dh = abs(mapDWtoV(center).y() - mapDWtoV(cc).y());
02271 }
02272
02273 if(transp == 0)
02274 {
02275 rectBrush_.setColor (rectColor_);
02276 painter_.setBrush(rectBrush_);
02277 painter_.setPen(linePen_);
02278 painter_.drawRect(dx, dy-dh, dw, dh);
02279 }
02280 else
02281 {
02282 double alpha = transp / 100.;
02283 double beta = 1 - alpha;
02284 double red = rectColor_.red() * beta;
02285 double green = rectColor_.green() * beta;
02286 double blue = rectColor_.blue() * beta;
02287
02288 int r = dw%8;
02289 if(r)
02290 dw += (8-r);
02291 r = dh%8;
02292 if(r)
02293 dh += (8-r);
02294
02295 QImage ima = pixmap0_->convertToImage();
02296 QImage imap(dw, dh, 32);
02297 int i, j;
02298 int x = qp.x();
02299 int y = qp.y() - dh;
02300 for(i=x; i-x<dw && i<ima.width(); i++)
02301 {
02302 if(i < 0)
02303 continue;
02304 for(j=y; j-y<dh && j<ima.height(); j++)
02305 {
02306 if(j < 0)
02307 continue;
02308 QRgb v = ima.pixel(i, j);
02309 int r = (int)((double)qRed(v) * alpha + red);
02310 int g = (int)((double)qGreen(v) * alpha + green);
02311 int b = (int)((double)qBlue(v) * alpha + blue);
02312 QRgb t = qRgb(r, g, b);
02313 imap.setPixel(i-x, j-y, t);
02314 }
02315 }
02316
02317 QPixmap pm(dw, dh);
02318 pm.convertFromImage(imap);
02319 QRect rec = pm.rect();
02320 rec &= painter_.viewport();
02321 bitBlt (painter_.device(), x, y, &pm, 0, 0, rec.width(), rec.height(), Qt::CopyROP, true);
02322 }
02323 }
02324
02325 void TeQtCanvas::setRectColor (int r, int g, int b)
02326 {
02327 rectColor_.setRgb(r, g, b);
02328 rectBrush_.setStyle(Qt::SolidPattern);
02329 }
02330
02331 static inline int blendComponent( int back, int fore, int falpha )
02332 {
02333 int balpha = 255 - falpha;
02334 int a = falpha + balpha -(falpha*balpha)/255;
02335 return (falpha*fore + balpha*back -(balpha*falpha*fore)/255)/a;
02336 }
02337
02338 int d2dms(double v)
02339 {
02340 double av;
02341 int d, m, s;
02342 av = fabs(v);
02343 d = (int)av;
02344 av = av - d;
02345 av = av * 60;
02346 m = (int)av;
02347 av = av - m;
02348 av = av * 60;
02349 s = (int)av;
02350 int gms = d * 10000 + m * 100 + s ;
02351 return gms;
02352 }
02353
02354 double dms2d (int vs)
02355 {
02356 int v = abs(vs);
02357 int dd = v/10000;
02358 int dm = (v-dd*10000)/100;
02359 int ds = v - dd*10000 - dm*100;
02360 double d = dd + dm/60. + ds/3600.;
02361 if (vs < 0)
02362 d = -d;
02363 return d;
02364 }
02365
02366 string buildMosaicName (int x, int y, int delta)
02367 {
02368 int lad,lam,las,lod,lom,los,dd,dm,ds;
02369 char hemis,hemiss;
02370 int lx1,ly1;
02371
02372 hemis = 'S';
02373 if (y>=0)hemis = 'N';
02374 ly1 = abs(y);
02375 lad = ly1/3600;
02376 lam = (ly1-lad*3600)/60;
02377 las = ly1 - lad*3600 - lam*60;
02378
02379 hemiss = 'O';
02380 if (x>=0)hemis = 'E';
02381 lx1 = abs(x);
02382 lod = lx1/3600;
02383 lom = (lx1-lod*3600)/60;
02384 los = lx1 - lod*3600 - lom*60;
02385
02386 dd = delta/10000;
02387 dm = (delta-dd*10000)/100;
02388 ds = delta - dd*10000 - dm*100;
02389
02390 char name[128];
02391 sprintf(name,"%c%02d%02d%02d%c%02d%02d%02d%02d%02d%02d",
02392 hemis,lad,lam,las,hemiss,lod,lom,los,dd,dm,ds);
02393 return string(name);
02394 }
02395
02396 void TeQtCanvas::copyPixmap0ToPrinter()
02397 {
02398 if (pixmap0_)
02399 {
02400 QPrinter printer;
02401 if (printer.setup())
02402 {
02403 QPainter p(&printer);
02404
02405 QPaintDevice* dev = painter_.device();
02406 if(dev == pixmap0_)
02407 painter_.end();
02408
02409 p.drawPixmap(0, 0, *pixmap0_);
02410 p.flush();
02411 p.end();
02412
02413 if(dev && painter_.device() == 0)
02414 painter_.begin(dev);
02415 }
02416 }
02417 }
02418
02419 void TeQtCanvas::copyPixmapToWindow(QPixmap* p, int ulx, int uly, int w, int h)
02420 {
02421 bitBlt (viewport(),ulx,uly,p,ulx,uly,w,h,Qt::CopyROP,true);
02422 }
02423
02424 void TeQtCanvas::copyPixmap0To(QPaintDevice* dev)
02425 {
02426 if (pixmap0_)
02427 {
02428 bitBlt (dev,0,0,pixmap0_,0,0,width_,height_,Qt::CopyROP,true);
02429 }
02430 }
02431
02432 void TeQtCanvas::copyPixmap0ToWindow()
02433 {
02434 if (pixmap0_)
02435 {
02436 bitBlt (viewport(),0,0,pixmap0_,contentsX(),contentsY(),viewport()->rect().width(),viewport()->rect().height(),Qt::CopyROP,true);
02437 }
02438 }
02439
02440 void TeQtCanvas::copyPixmap1ToWindow()
02441 {
02442 if (pixmap1_)
02443 {
02444 bitBlt (viewport(),0,0,pixmap1_,contentsX(),contentsY(),viewport()->rect().width(),viewport()->rect().height(),Qt::CopyROP,true);
02445 }
02446 }
02447
02448 void TeQtCanvas::copyPixmap0ToWindow(int ulx, int uly, int w, int h)
02449 {
02450 if (pixmap0_)
02451 {
02452 bitBlt (viewport(),ulx,uly,pixmap0_,ulx,uly,w,h,Qt::CopyROP,true);
02453 }
02454 }
02455
02456 void TeQtCanvas::copyPanArea(int x, int y)
02457 {
02458 if (pixmap0_)
02459 {
02460 QPaintDevice* dev = painter_.device();
02461 if(dev)
02462 painter_.end();
02463 painter_.begin(viewport());
02464 QRect a, b;
02465 int vw = viewport()->width();
02466 int vh = viewport()->height();
02467
02468 int xi = horizontalScrollBar()->value();
02469 int yi = verticalScrollBar()->value();
02470 bitBlt (viewport(), 0, 0, pixmap1_, xi+x, yi+y, vw, vh, Qt::CopyROP, true);
02471
02472 if((xi + x + vw) > contentsWidth())
02473 {
02474 int ww = (xi + x + vw) - contentsWidth();
02475 int xii = vw - ww;
02476 QRect a(xii, 0, vw - xii, vh);
02477 painter_.fillRect(a, painter_.backgroundColor());
02478 }
02479 if((xi + x) < 0)
02480 {
02481 QRect a(0, 0, -(xi + x), vh);
02482 painter_.fillRect(a, painter_.backgroundColor());
02483 }
02484 if((yi + y + vh) > contentsHeight())
02485 {
02486 int hh = (yi + y + vh) - contentsHeight();
02487 int yii = vh - hh;
02488 QRect a(0, yii, vw, vh - yii);
02489 painter_.fillRect(a, painter_.backgroundColor());
02490 }
02491 if((yi + y) < 0)
02492 {
02493 QRect a(0, 0, vw, -(yi + y));
02494 painter_.fillRect(a, painter_.backgroundColor());
02495 }
02496
02497 painter_.end();
02498 if(dev)
02499 painter_.begin(dev);
02500 }
02501 }
02502
02503 void TeQtCanvas::copyPixmap0ToPixmap1()
02504 {
02505 if (pixmap1_ && pixmap0_)
02506 bitBlt (pixmap1_,0,0,pixmap0_,0,0,width_,height_,Qt::CopyROP,true);
02507 }
02508
02509 void TeQtCanvas::copyPixmap0ToPixmap1(int ulx, int uly, int w, int h)
02510 {
02511 if (pixmap1_ && pixmap0_)
02512 bitBlt (pixmap1_,ulx,uly,pixmap0_,ulx,uly,w,h,Qt::CopyROP,true);
02513 }
02514
02515 void TeQtCanvas::copyPixmap1ToPixmap0()
02516 {
02517 if (pixmap1_ && pixmap0_)
02518 bitBlt (pixmap0_,0,0,pixmap1_,0,0,width_,height_,Qt::CopyROP,true);
02519 }
02520
02521 void TeQtCanvas::copyPixmap1ToPixmap0(int ulx, int uly, int w, int h)
02522 {
02523 if (pixmap1_ && pixmap0_)
02524 bitBlt (pixmap0_,ulx,uly,pixmap1_,ulx,uly,w,h,Qt::CopyROP,true);
02525 }
02526
02527 void TeQtCanvas::copyPixmap1ToPixmap2()
02528 {
02529 if (pixmap1_ && pixmap2_)
02530 {
02531 bitBlt (pixmap2_,0,0,pixmap1_,0,0,width_,height_,Qt::CopyROP,true);
02532 qimage_.reset();
02533 qimage_ = pixmap2_->convertToImage();
02534 }
02535 }
02536
02537 void TeQtCanvas::copyPixmap1ToPixmap2(int ulx, int uly, int w, int h)
02538 {
02539 if (pixmap1_ && pixmap2_)
02540 {
02541 bitBlt (pixmap2_,ulx,uly,pixmap1_,ulx,uly,w,h,Qt::CopyROP,true);
02542 qimage_.reset();
02543 qimage_ = pixmap2_->convertToImage();
02544 }
02545 }
02546
02547 void TeQtCanvas::copyPixmap2ToPixmap1()
02548 {
02549 if (pixmap1_ && pixmap2_)
02550 bitBlt (pixmap1_,0,0,pixmap2_,0,0,width_,height_,Qt::CopyROP,true);
02551 }
02552
02553 void TeQtCanvas::copyPixmap2ToPixmap1(int ulx, int uly, int w, int h)
02554 {
02555 if (pixmap1_ && pixmap2_)
02556 bitBlt (pixmap1_,ulx,uly,pixmap2_,ulx,uly,w,h,Qt::CopyROP,true);
02557 }
02558
02559 void TeQtCanvas::plotRaster(TeRaster* raster, TeRasterTransform* transf, TeQtProgress *progress)
02560 {
02561 int dt = CLOCKS_PER_SEC/2;
02562 int dt2 = CLOCKS_PER_SEC;
02563 clock_t t0, t1, t2;
02564 params_.fileName_ = raster->params().fileName_;
02565
02566 if (buildRaster ())
02567 {
02568
02569 TeBox bboxBackRaster = backRaster_->params().boundingBox();
02570 TeBox bboxSearched = TeRemapBox(bboxBackRaster, backRaster_->projection(), raster->projection());
02571 TeBox bboxIntersection;
02572 if (!TeIntersection (raster->params().boundingBox(),bboxSearched,bboxIntersection))
02573 return ;
02574
02575
02576 TeDecoderQtImage* decqt = reinterpret_cast<TeDecoderQtImage*>(backRaster_->decoder());
02577 decqt->getImage()->setAlphaBuffer(false);
02578 decqt->setAlphaBufferToTransparent();
02579
02580
02581 TeRasterRemap remap;
02582 if (transf)
02583 {
02584 remap.setTransformer(transf);
02585
02586 decqt->setTransparency(transf->getTransparency());
02587 }
02588 remap.setOutput(backRaster_);
02589 TeBox b = raster->params().boundingBox();
02590 remap.setROI(b);
02591
02592
02593
02594 int res = raster->decoder()->bestResolution(bboxBackRaster, backRaster_->params().ncols_, backRaster_->params().nlines_, backRaster_->params().projection());
02595
02596
02597
02598
02599 TeRasterParams parBlock;
02600 if(
02601 raster->selectBlocks(bboxIntersection,res,parBlock))
02602 {
02603 if (progress)
02604 progress->setTotalSteps(raster->numberOfSelectedBlocks());
02605 t2 = clock();
02606 t0 = t1 = t2;
02607
02608
02609 TeRaster* block = new TeRaster;
02610 remap.setInput(block);
02611
02612 TeDecoderMemory* decMem = new TeDecoderMemory(parBlock);
02613 decMem->init();
02614
02615
02616 int numBlockProcessed=0;
02617 bool flag = true;
02618 do
02619 {
02620 flag = raster->fetchRasterBlock(decMem);
02621 block->setDecoder(decMem);
02622 remap.apply();
02623 numBlockProcessed++;
02624 t2 = clock();
02625 if (int(t2-t1) > dt)
02626 {
02627 t1 = t2;
02628 if((int)(t2-t0) > dt2)
02629 {
02630 if (progress)
02631 {
02632 if (progress->wasCancelled())
02633 break;
02634 else
02635 progress->setProgress(numBlockProcessed);
02636 }
02637 }
02638 }
02639 } while (flag);
02640 if (progress)
02641 progress->reset();
02642 decMem->clear();
02643 delete block;
02644 raster->clearBlockSelection();
02645 }
02646 else
02647 {
02648 remap.setInput(raster);
02649 remap.apply(true);
02650 }
02651 decqt->getImage()->setAlphaBuffer(true);
02652 painter_.drawPixmap(0, 0, *(decqt->getImage()));
02653 }
02654 }
02655
02656 bool TeQtCanvas::buildRaster ()
02657 {
02658 if (!backRaster_)
02659 {
02660 backRaster_ = new TeRaster();
02661 params_.mode_ = 'c';
02662 params_.useDummy_ = true;
02663 params_.setDummy(255);
02664 TeDecoderQtImage *dec = new TeDecoderQtImage(params_);
02665 backRaster_->setDecoder (dec);
02666 backRaster_->init();
02667 }
02668 return true;
02669 }
02670
02671 void TeQtCanvas::endPrinting()
02672 {
02673 QPaintDevice* dev = painter_.device();
02674 if(dev)
02675 painter_.end();
02676 if(pixmap0_)
02677 painter_.begin(pixmap0_);
02678 }
02679
02680 void TeQtCanvas::plotGraphicScale(TeVisual& visual, double offsetX, double offsetY, double unitConv, const string& dunit)
02681 {
02682 TeBox box = getWorld();
02683 if(box.isValid() == false)
02684 return;
02685
02686 string unit = dunit;
02687 if (dunit.empty())
02688 unit = canvasProjection_->units();
02689
02690 double w = box.width();
02691 double www = w / unitConv;
02692 double dx = www / 9.;
02693 long idx = (long)dx;
02694
02695 double f;
02696 double fa = 1.;
02697 int fw, fh;
02698
02699 int size = visual.size();
02700 if(pixmap0_ && pixmap1_ && (pixmap0_->rect() != pixmap1_->rect()))
02701 size = (int)((double)size * printerFactor_ + .5);
02702
02703
02704 int conta = 1000;
02705 if(idx > 0)
02706 {
02707 while(--conta)
02708 {
02709 dx /= 10.;
02710 fa *= 10.;
02711 idx = (long)dx;
02712
02713 if(idx == 0)
02714 {
02715 idx = (long)(dx * 10.);
02716 f = idx * fa / 10.;
02717
02718
02719 break;
02720 }
02721 }
02722 }
02723 else
02724 {
02725 while(--conta)
02726 {
02727 dx *= 10.;
02728 fa /= 10.;
02729 idx = (long)dx;
02730
02731 if(idx > 0)
02732 {
02733 f = idx * fa;
02734
02735 break;
02736 }
02737 }
02738 }
02739 if(conta == 0)
02740 return;
02741
02742 double fff = f * unitConv;
02743 double space = fff * 3.;
02744 double hini = box.x1_ + (w - space) / 2.;
02745
02746 TeColor cor = visual.color();
02747 string family = visual.family();
02748 bool bold = visual.bold();
02749 bool italic = visual.italic();
02750 QFont font(family.c_str(), size);
02751 font.setBold (bold);
02752 font.setItalic (italic);
02753 painter_.setFont(font);
02754
02755 QFontMetrics fm(font);
02756 QRect rect;
02757 rect = fm.boundingRect(unit.c_str());
02758 fh = rect.height();
02759 double vini = box.y1_ + mapVtoCW(fh+6);
02760
02761 TeCoord2D wp(hini, vini);
02762 int x = TeRound((wp.x() - xmin_)*f_) + x0_;
02763 int y = height_ - y0_ - TeRound((wp.y() - ymin_)*f_);
02764 QPoint p1(x, y);
02765 correctScrolling (p1);
02766
02767 wp.x(wp.x() + fff);
02768 x = TeRound((wp.x() - xmin_)*f_) + x0_;
02769 y = height_ - y0_ - TeRound((wp.y() - ymin_)*f_);
02770 QPoint p2(x, y);
02771 correctScrolling (p2);
02772
02773 wp.x(wp.x() + fff);
02774 x = TeRound((wp.x() - xmin_)*f_) + x0_;
02775 y = height_ - y0_ - TeRound((wp.y() - ymin_)*f_);
02776 QPoint p3(x, y);
02777 correctScrolling (p3);
02778
02779 wp.x(wp.x() + fff);
02780 x = TeRound((wp.x() - xmin_)*f_) + x0_;
02781 y = height_ - y0_ - TeRound((wp.y() - ymin_)*f_);
02782 QPoint p4(x, y);
02783 correctScrolling (p4);
02784
02785 rect = fm.boundingRect("0");
02786 fw = rect.width();
02787 QPoint pp(p1);
02788 bool setRect = false;
02789 if(graphicScaleRect_.isValid())
02790 {
02791 x = TeRound((double)graphicScaleRect_.left() * printerFactor_ + (double)fw/2.);
02792 y = TeRound((double)graphicScaleRect_.top() * printerFactor_ + (double)rect.height() + 8. * printerFactor_);
02793 pp.setX(x);
02794 pp.setY(y);
02795 }
02796 else
02797 {
02798 setRect = true;
02799 offsetX = 0.;
02800 offsetY = 0.;
02801 }
02802
02803 x = TeRound((double)pixmap0_->width() * offsetX);
02804 y = TeRound((double)pixmap0_->height() * offsetY);
02805 if(x!=0 || y!=0)
02806 {
02807 graphicScaleRect_.setLeft(graphicScaleRect_.left() + x);
02808 graphicScaleRect_.setRight(graphicScaleRect_.right() + x);
02809 graphicScaleRect_.setTop(graphicScaleRect_.top() + y);
02810 graphicScaleRect_.setBottom(graphicScaleRect_.bottom() + y);
02811 }
02812
02813 QPoint offset(x, y);
02814 pp += offset;
02815
02816 QPoint interval = p2 - p1;
02817
02818 p1 = pp;
02819 p2 = p1 + interval;
02820 p3 = p2 + interval;
02821 p4 = p3 + interval;
02822 if(setRect)
02823 {
02824 x = TeRound(((double)p1.x() - (double)fw/2.) / printerFactor_);
02825 graphicScaleRect_.setLeft(x);
02826 }
02827
02828 QPen pen(QColor(cor.red_, cor.green_, cor.blue_));
02829 painter_.setPen(pen);
02830
02831 if(bold == false)
02832 {
02833 QPoint pa = p2;
02834 QPoint pb = p3;
02835 painter_.drawLine(pa, pb);
02836
02837 pa = p1;
02838 pb = pa;
02839 y = TeRound((double)pa.y() - 5. * printerFactor_);
02840 pa.setY(y);
02841 y = TeRound((double)pb.y() + 4. * printerFactor_);
02842 pb.setY(y);
02843 painter_.drawLine(pa, pb);
02844
02845 pa = p2;
02846 pb = pa;
02847 y = TeRound((double)pa.y() - 5. * printerFactor_);
02848 pa.setY(y);
02849 y = TeRound((double)pb.y() + 4. * printerFactor_);
02850 pb.setY(y);
02851 painter_.drawLine(pa, pb);
02852
02853 pa = p3;
02854 pb = pa;
02855 y = TeRound((double)pa.y() - 5. * printerFactor_);
02856 pa.setY(y);
02857 y = TeRound((double)pb.y() + 4. * printerFactor_);
02858 pb.setY(y);
02859 painter_.drawLine(pa, pb);
02860
02861 pa = p4;
02862 pb = pa;
02863 y = TeRound((double)pa.y() - 5. * printerFactor_);
02864 pa.setY(y);
02865 y = TeRound((double)pb.y() + 4. * printerFactor_);
02866 pb.setY(y);
02867 painter_.drawLine(pa, pb);
02868
02869 pa = p1;
02870 pb = p4;
02871 y = TeRound((double)pa.y() - 1. * printerFactor_);
02872 pa.setY(y);
02873 y = TeRound((double)pb.y() - 1. * printerFactor_);
02874 pb.setY(y);
02875 painter_.drawLine(pa, pb);
02876 y = TeRound((double)pa.y() + 2. * printerFactor_);
02877 pa.setY(y);
02878 y = TeRound((double)pb.y() + 2. * printerFactor_);
02879 pb.setY(y);
02880 painter_.drawLine(pa, pb);
02881 }
02882 else
02883 {
02884 QPoint pa = p2;
02885 QPoint pb = p3;
02886 painter_.drawLine(pa, pb);
02887 y = TeRound((double)pa.y() - 1. * printerFactor_);
02888 pa.setY(y);
02889 y = TeRound((double)pb.y() - 1. * printerFactor_);
02890 pb.setY(y);
02891 painter_.drawLine(pa, pb);
02892
02893 pa = p1;
02894 pb = pa;
02895 y = TeRound((double)pa.y() - 5. * printerFactor_);
02896 pa.setY(y);
02897 y = TeRound((double)pb.y() + 4. * printerFactor_);
02898 pb.setY(y);
02899 painter_.drawLine(pa, pb);
02900 x = TeRound((double)pa.x() - 1. * printerFactor_);
02901 pa.setY(x);
02902 x = TeRound((double)pb.x() - 1. * printerFactor_);
02903 pb.setY(x);
02904 painter_.drawLine(pa, pb);
02905
02906 pa = p2;
02907 pb = pa;
02908 y = TeRound((double)pa.y() - 5. * printerFactor_);
02909 pa.setY(y);
02910 y = TeRound((double)pb.y() + 4. * printerFactor_);
02911 pb.setY(y);
02912 painter_.drawLine(pa, pb);
02913 x = TeRound((double)pa.x() - 1. * printerFactor_);
02914 pa.setY(x);
02915 x = TeRound((double)pb.x() - 1. * printerFactor_);
02916 pb.setY(x);
02917 painter_.drawLine(pa, pb);
02918
02919 pa = p3;
02920 pb = pa;
02921 y = TeRound((double)pa.y() - 5. * printerFactor_);
02922 pa.setY(y);
02923 y = TeRound((double)pb.y() + 4. * printerFactor_);
02924 pb.setY(y);
02925 painter_.drawLine(pa, pb);
02926 x = TeRound((double)pa.x() - 1. * printerFactor_);
02927 pa.setY(x);
02928 x = TeRound((double)pb.x() - 1. * printerFactor_);
02929 pb.setY(x);
02930 painter_.drawLine(pa, pb);
02931
02932 pa = p4;
02933 pb = pa;
02934 y = TeRound((double)pa.y() - 5. * printerFactor_);
02935 pa.setY(y);
02936 y = TeRound((double)pb.y() + 4. * printerFactor_);
02937 pb.setY(y);
02938 painter_.drawLine(pa, pb);
02939 x = TeRound((double)pa.x() - 1. * printerFactor_);
02940 pa.setY(x);
02941 x = TeRound((double)pb.x() - 1. * printerFactor_);
02942 pb.setY(x);
02943 painter_.drawLine(pa, pb);
02944
02945 pa = p1;
02946 pb = p4;
02947 y = TeRound((double)pa.y() - 2. * printerFactor_);
02948 pa.setY(y);
02949 y = TeRound((double)pb.y() - 2. * printerFactor_);
02950 pb.setY(y);
02951 painter_.drawLine(pa, pb);
02952 y = TeRound((double)pa.y() + 3. * printerFactor_);
02953 pa.setY(y);
02954 y = TeRound((double)pb.y() + 3. * printerFactor_);
02955 pb.setY(y);
02956 painter_.drawLine(pa, pb);
02957 }
02958
02959 x = TeRound((double)p1.x()-(double)fw/2.);
02960 y = TeRound((double)p1.y()-8.*printerFactor_);
02961 painter_.drawText(x, y, "0");
02962 if(setRect)
02963 {
02964 y = TeRound(((double)y - (double)rect.height()) / printerFactor_);
02965 graphicScaleRect_.setTop(y);
02966 }
02967
02968 char buf[50];
02969 long n = (long)f;
02970
02971 if(n > 0)
02972 {
02973 sprintf(buf, "%ld", n);
02974 QString s = buf;
02975 rect = fm.boundingRect(s);
02976 int fw1 = rect.width();
02977
02978 sprintf(buf, "%ld", n*2);
02979 s = buf;
02980 rect = fm.boundingRect(s);
02981 int fw2 = rect.width();
02982
02983 sprintf(buf, "%ld", n*3);
02984 s = buf;
02985 rect = fm.boundingRect(s);
02986 int fw3 = rect.width();
02987
02988 if((fw1 + fw2)/2 < p3.x()-p2.x() &&
02989 (fw2 + fw3)/2 < p3.x()-p2.x())
02990 {
02991 sprintf(buf, "%ld", n);
02992 QString s = buf;
02993 rect = fm.boundingRect(s);
02994 fw = rect.width();
02995 x = TeRound((double)p2.x()-(double)fw/2.);
02996 y = TeRound((double)p2.y()-8.*printerFactor_);
02997 painter_.drawText(x, y, s);
02998
02999 sprintf(buf, "%ld", n*2);
03000 s = buf;
03001 rect = fm.boundingRect(s);
03002 fw = rect.width();
03003 x = TeRound((double)p3.x()-(double)fw/2.);
03004 y = TeRound((double)p3.y()-8.*printerFactor_);
03005 painter_.drawText(x, y, s);
03006 }
03007
03008 sprintf(buf, "%ld", n*3);
03009 s = buf;
03010 rect = fm.boundingRect(s);
03011 fw = rect.width();
03012 x = TeRound((double)p4.x()-(double)fw/2.);
03013 y = TeRound((double)p4.y()-8.*printerFactor_);
03014 painter_.drawText(x, y, s);
03015 if(setRect)
03016 {
03017 x = TeRound(((double)x + (double)fw) / printerFactor_);
03018 graphicScaleRect_.setRight(x);
03019 }
03020 }
03021 else
03022 {
03023 int nn=0;
03024 int fn = (int)fa;
03025 while(fn == 0)
03026 {
03027 fa *= 10.;
03028 fn = TeRound(fa);
03029 nn++;
03030 }
03031 sprintf (buf, "%.*f", nn, f);
03032 QString s = buf;
03033 rect = fm.boundingRect(s);
03034 int fw1 = rect.width();
03035
03036 sprintf (buf, "%.*f", nn, f*2.);
03037 s = buf;
03038 rect = fm.boundingRect(s);
03039 int fw2 = rect.width();
03040
03041 sprintf (buf, "%.*f", nn, f*3.);
03042 s = buf;
03043 rect = fm.boundingRect(s);
03044 int fw3 = rect.width();
03045
03046 if((fw1 + fw2)/2 < p3.x()-p2.x() &&
03047 (fw2 + fw3)/2 < p3.x()-p2.x())
03048 {
03049 sprintf (buf, "%.*f", nn, f);
03050 QString s = buf;
03051 rect = fm.boundingRect(s);
03052 fw = rect.width();
03053 x = TeRound((double)p2.x()-(double)fw/2.);
03054 y = TeRound((double)p2.y()-8.*printerFactor_);
03055 painter_.drawText(x, y, s);
03056
03057 sprintf (buf, "%.*f", nn, f*2.);
03058 s = buf;
03059 rect = fm.boundingRect(s);
03060 fw = rect.width();
03061 x = TeRound((double)p3.x()-(double)fw/2.);
03062 y = TeRound((double)p3.y()-8.*printerFactor_);
03063 painter_.drawText(x, y, s);
03064 }
03065
03066 sprintf (buf, "%.*f", nn, f*3.);
03067 s = buf;
03068 rect = fm.boundingRect(s);
03069 fw = rect.width();
03070 x = TeRound((double)p4.x()-(double)fw/2.);
03071 y = TeRound((double)p4.y()-8.*printerFactor_);
03072 painter_.drawText(x, y, s);
03073 x = TeRound((double)x + printerFactor_);
03074 graphicScaleRect_.setRight(x);
03075 }
03076
03077 int sw = p4.x() - p1.x();
03078 rect = fm.boundingRect(unit.c_str());
03079 fw = rect.width();
03080 fh = rect.height();
03081 int suini = TeRound(((double)(sw - fw)) / 2. + (double)p1.x());
03082 y = TeRound((double)p1.y()+(double)fh+2.*printerFactor_);
03083 painter_.drawText (suini, y, unit.c_str());
03084 if(setRect)
03085 {
03086 y = TeRound((double)y / printerFactor_);
03087 graphicScaleRect_.setBottom(y);
03088 }
03089 }
03090
03091 void TeQtCanvas::setClipRegion(int x, int y, int w, int h)
03092 {
03093 QRegion region(x, y, w, h);
03094 if(painter_.device())
03095 painter_.setClipRegion(region);
03096 }
03097
03098 void TeQtCanvas::setClipRegion(QRegion region)
03099 {
03100 if(painter_.device())
03101 painter_.setClipRegion(region);
03102 }
03103
03104 void TeQtCanvas::setClipping(bool enable)
03105 {
03106 if(painter_.device())
03107 painter_.setClipping(enable);
03108 }
03109
03110 void TeQtCanvas::clearRaster()
03111 {
03112 if (backRaster_)
03113 delete backRaster_;
03114 backRaster_ = 0;
03115 }
03116
03117
03118 void TeQtCanvas::setMode (CursorMode m)
03119 {
03120 cursorMode_ = m;
03121 down_ = false;
03122 }
03123
03124 void TeQtCanvas::clear()
03125 {
03126 int ww, hh;
03127 ww = viewport()->width();
03128 hh = viewport()->height();
03129
03130
03131 QPaintDevice* dev = painter_.device();
03132 if(dev)
03133 painter_.end();
03134 painter_.begin(viewport());
03135 painter_.eraseRect(0, 0, ww, hh);
03136 painter_.end();
03137 if(dev)
03138 painter_.begin(dev);
03139 }
03140
03141 void TeQtCanvas::clear(TeBox box)
03142 {
03143 mapCWtoV(box);
03144
03145
03146 plotOnWindow();
03147 painter_.eraseRect((int)box.x1(), (int)box.y1(), (int)box.width(), (int)box.height());
03148 plotOnPixmap0();
03149 }
03150
03151 void TeQtCanvas::clearAll()
03152 {
03153
03154 clear();
03155
03156
03157 if(pixmap0_)
03158 pixmap0_->fill(paletteBackgroundColor());
03159 if(pixmap1_)
03160 pixmap1_->fill(paletteBackgroundColor());
03161 if(pixmap2_)
03162 pixmap2_->fill(paletteBackgroundColor());
03163
03164 if (backRaster_)
03165 delete backRaster_;
03166 backRaster_ = 0;
03167 }
03168
03169 void TeQtCanvas::clearAll(TeBox box)
03170 {
03171
03172 clear(box);
03173
03174
03175 mapCWtoV(box);
03176
03177 QPaintDevice* dev = painter_.device();
03178 if(dev)
03179 painter_.end();
03180
03181 if(pixmap0_)
03182 {
03183 painter_.begin(pixmap0_);
03184 painter_.fillRect((int)box.x1(), (int)box.y1(), (int)box.width(), (int)box.height(), backgroundColor());
03185 painter_.end();
03186 }
03187 if(pixmap1_)
03188 {
03189 painter_.begin(pixmap1_);
03190 painter_.fillRect((int)box.x1(), (int)box.y1(), (int)box.width(), (int)box.height(), backgroundColor());
03191 painter_.end();
03192 }
03193 if(pixmap2_)
03194 {
03195 painter_.begin(pixmap2_);
03196 painter_.fillRect((int)box.x1(), (int)box.y1(), (int)box.width(), (int)box.height(), backgroundColor());
03197 painter_.end();
03198 }
03199
03200 if(dev)
03201 painter_.begin(dev);
03202 }
03203
03204
03205 bool TeQtCanvas::setView(int w, int h, QPaintDevice *pd)
03206 {
03207 int dpix, dpiy, ncolors, wmm, hmm, depth, pdepth;
03208 int ww = w, hh = h;
03209
03210 x0_ = y0_ = 0;
03211
03212 if (pd == 0)
03213 {
03214 if (ww == 0)
03215 ww = viewport()->width();
03216 if (hh == 0)
03217 hh = viewport()->height();
03218 resizeContents (ww,hh);
03219
03220 QPaintDevice* dev = painter_.device();
03221 if(dev)
03222 painter_.end();
03223
03224
03225 if ((pixmap0_ == 0 || width_ != ww || height_ != hh) ||
03226 (pixmap0_ && (pixmap0_->width() != ww || pixmap0_->height() != hh)))
03227 {
03228 if (pixmap0_)
03229 delete pixmap0_;
03230 if(numberOfPixmaps_ > 0)
03231 pixmap0_ = new QPixmap (ww,hh);
03232 else
03233 pixmap0_ = new QPixmap (0,0);
03234
03235 if (pixmap1_)
03236 delete pixmap1_;
03237 if(numberOfPixmaps_ > 1)
03238 pixmap1_ = new QPixmap (ww,hh);
03239 else
03240 pixmap1_ = new QPixmap (0,0);
03241
03242 if (pixmap2_)
03243 delete pixmap2_;
03244 if(numberOfPixmaps_ > 2)
03245 pixmap2_ = new QPixmap (ww,hh);
03246 else
03247 pixmap2_ = new QPixmap (0,0);
03248
03249 pdepth = pixmap0_->depth ();
03250 }
03251 painter_.begin(pixmap0_);
03252 printerFactor_ = 1.;
03253 }
03254 else
03255 {
03256 QPaintDeviceMetrics pdm(pd);
03257 if (ww == 0)
03258 ww = pdm.width();
03259 if (hh == 0)
03260 hh = pdm.height ();
03261
03262 int pw = pixmap0_->rect().width();
03263 int ph = pixmap0_->rect().height();
03264 if((double)ww/(double)pw < (double)hh/(double)ph)
03265 hh = (int)((double)ph * (double)ww/(double)pw);
03266 else
03267 ww = (int)((double)pw * (double)hh/(double)ph);
03268
03269 dpix = pdm.logicalDpiX();
03270 dpiy = pdm.logicalDpiY();
03271 ncolors = pdm.numColors();
03272 wmm = pdm.widthMM ();
03273 hmm = pdm.heightMM ();
03274 depth = pdm.depth ();
03275 QPaintDevice* dev = painter_.device();
03276 if(dev)
03277 painter_.end();
03278
03279 if (pixmap0_)
03280 delete pixmap0_;
03281 if(numberOfPixmaps_ > 0)
03282 pixmap0_ = new QPixmap (ww,hh);
03283 else
03284 pixmap0_ = new QPixmap (0,0);
03285
03286
03287 painter_.begin(pixmap0_);
03288 painter_.setClipRect( x0_, y0_, ww, hh );
03289
03290 printerFactor_ = (double)ww / (double)widthRef2PrinterFactor_;
03291
03292 if (pixmap1_)
03293 delete pixmap1_;
03294 pixmap1_ = new QPixmap (0,0);
03295
03296 if (pixmap2_)
03297 delete pixmap2_;
03298 pixmap2_ = new QPixmap (0,0);
03299 }
03300
03301 if(numberOfPixmaps_ > 0 && (pixmap0_->width() == 0 || pixmap0_->height() == 0))
03302 return false;
03303 else if(numberOfPixmaps_ > 1 && (pixmap1_->width() == 0 || pixmap1_->height() == 0))
03304 return false;
03305 else if(numberOfPixmaps_ > 2 && (pixmap2_->width() == 0 || pixmap2_->height() == 0))
03306 return false;
03307
03308 width_ = ww;
03309 height_ = hh;
03310 params_.ncols_ = width_;
03311 params_.nlines_ = height_;
03312
03313 down_ = false;
03314 xul_ = xmin_;
03315 yul_ = ymax_;
03316 xlr_ = xmax_;
03317 ylr_ = ymin_;
03318
03319 if (pd == 0)
03320 clearAll();
03321 return true;
03322 }
03323
03324 void TeQtCanvas::correctScrolling (QPoint &p)
03325 {
03326 if(painter_.device() == viewport())
03327 {
03328 QPoint o (contentsX (), contentsY ());
03329 p -= o;
03330 }
03331 }
03332
03333 void TeQtCanvas::initCursorArea(QPoint p)
03334 {
03335 if (!pixmap0_)
03336 return;
03337
03338 down_ = true;
03339 TeCoord2D pw = mapVtoCW(p);
03340 xul_ = pw.x();
03341 yul_ = pw.y();
03342 ixul_ = ixlr_ = p.x();
03343 iyul_ = iylr_ = p.y();
03344 }
03345
03346 void TeQtCanvas::contentsMousePressEvent( QMouseEvent* e)
03347 {
03348 if (!pixmap0_)
03349 return;
03350
03351 QPoint m = e->pos();
03352 TeCoord2D p = mapVtoCW(m);
03353
03354 if(e->button() == LeftButton)
03355 {
03356 if (cursorMode_ == Area || cursorMode_ == Edit)
03357 {
03358 plotOnWindow();
03359 down_ = true;
03360 xul_ = p.x();
03361 yul_ = p.y();
03362 ixul_ = ixlr_ = e->pos().x();
03363 iyul_ = iylr_ = e->pos().y();
03364 plotOnPixmap0();
03365 emit mouseMoved (p, e->state(), m);
03366 }
03367 else
03368 emit mousePressed (p, e->state(), m);
03369 }
03370 else if(e->button() == RightButton)
03371 emit mouseRightButtonPressed (p, e->state(), m);
03372 }
03373
03374 void TeQtCanvas::contentsMouseMoveEvent ( QMouseEvent* e)
03375 {
03376 if (!pixmap0_)
03377 return;
03378 plotOnWindow();
03379 QPoint m = e->pos();
03380 TeCoord2D p = mapVtoCW(m);
03381 if (down_)
03382 {
03383 QPoint o = offset();
03384 painter_.setPen (green);
03385 painter_.setRasterOp (Qt::XorROP);
03386 painter_.drawLine(ixul_-o.x(),iyul_-o.y(),ixlr_-o.x()-1,iyul_-o.y());
03387 painter_.drawLine(ixlr_-o.x(),iyul_-o.y(),ixlr_-o.x(),iylr_-o.y() -1);
03388 painter_.drawLine(ixlr_-o.x(),iylr_-o.y(),ixul_-o.x()-1,iylr_-o.y() );
03389 painter_.drawLine(ixul_-o.x(),iylr_-o.y(),ixul_-o.x(),iyul_-o.y()-1 );
03390 ixlr_ = e->pos().x();
03391 iylr_ = e->pos().y();
03392 painter_.drawLine(ixul_-o.x(),iyul_-o.y(),ixlr_-o.x()-1,iyul_-o.y());
03393 painter_.drawLine(ixlr_-o.x(),iyul_-o.y(),ixlr_-o.x(),iylr_ -o.y()-1);
03394 painter_.drawLine(ixlr_-o.x(),iylr_-o.y(),ixul_-o.x()-1,iylr_-o.y() );
03395 painter_.drawLine(ixul_-o.x(),iylr_-o.y(),ixul_-o.x(),iyul_-o.y()-1 );
03396 painter_.setRasterOp (Qt::CopyROP);
03397 }
03398 plotOnPixmap0();
03399 emit mouseMoved (p, e->state(), m);
03400 }
03401
03402 void TeQtCanvas::contentsMouseReleaseEvent( QMouseEvent* e)
03403 {
03404 if (!pixmap0_)
03405 return;
03406 QPoint m = e->pos();
03407 TeCoord2D p = mapVtoCW(m);
03408 if (down_)
03409 {
03410 ixlr_ = e->pos().x();
03411 iylr_ = e->pos().y();
03412 xlr_ = p.x();
03413 ylr_ = p.y();
03414 if(xul_ > xlr_)
03415 {
03416 double a = xlr_;
03417 xlr_ = xul_;
03418 xul_ = a;
03419 }
03420 if(ylr_ > yul_)
03421 {
03422 double a = ylr_;
03423 ylr_ = yul_;
03424 yul_ = a;
03425 }
03426 down_ = false;
03427
03428 emit zoomArea();
03429 }
03430 emit mouseReleased (p, e->state(), m);
03431 }
03432
03433 void TeQtCanvas::contentsMouseDoubleClickEvent ( QMouseEvent* e)
03434 {
03435 if (!pixmap0_)
03436 return;
03437
03438 QPoint m = e->pos();
03439 TeCoord2D p = mapVtoCW(m);
03440
03441 if(e->button() == LeftButton)
03442 emit mouseDoublePressed (p, e->state(), m);
03443 }
03444
03445
03446 void TeQtCanvas::contentsContextMenuEvent( QContextMenuEvent* e)
03447 {
03448 QMouseEvent *m = (QMouseEvent *)e;
03449 emit popupCanvasSignal(m);
03450 }
03451
03452
03453 void TeQtCanvas::leaveEvent ( QEvent * )
03454 {
03455 emit mouseLeave();
03456 }
03457
03458 void TeQtCanvas::keyPressEvent (QKeyEvent* e)
03459 {
03460 emit keyPressed(e);
03461 }
03462
03463 void TeQtCanvas::keyReleaseEvent (QKeyEvent* e)
03464 {
03465 emit keyReleased(e);
03466 }
03467
03468 void TeQtCanvas::viewportPaintEvent (QPaintEvent*)
03469 {
03470 copyPixmapToWindow ();
03471 emit paintEvent ();
03472 }
03473
03474 void TeQtCanvas::resizeEvent ( QResizeEvent * e)
03475 {
03476 QScrollView::resizeEvent(e);
03477 }
03478
03479 void TeQtCanvas::copyPixmapToWindow()
03480 {
03481 if (pixmap0_)
03482 {
03483 int cx = contentsX();
03484 int cy = contentsY();
03485 bitBlt (viewport(),0,0,pixmap0_,cx,cy,viewport()->rect().width(),viewport()->rect().height(),CopyROP,true);
03486 }
03487 }
03488
03489 int TeQtCanvas::mapDWtoV(double a)
03490 {
03491 TeBox dbox = getDataWorld();
03492 double dwidth = dbox.width();
03493 int pwidth = viewport()->width();
03494
03495 int d = (int)((double)pwidth * a / (double)dwidth);
03496 return d;
03497 }
03498