All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Canvas.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/qt/widgets/canvas/Canvas.cpp
22 
23  \brief A canvas built on top of Qt.
24 */
25 
26 // TerraLib
27 #include "../../../annotationtext/Attributes.h"
28 #include "../../../annotationtext/Element.h"
29 #include "../../../annotationtext/Text.h"
30 #include "../../../color/RGBAColor.h"
31 #include "../../../common/StringUtils.h"
32 #include "../../../geometry.h"
33 #include "../../../maptools/PtMarker.h"
34 #include "../../../raster.h"
35 #include "../Utils.h"
36 #include "Canvas.h"
37 
38 // Qt
39 #include <QBitmap>
40 #include <QBuffer>
41 #include <QImage>
42 #include <QPaintEngine>
43 #include <QPixmap>
44 #include <QPrinter>
45 #include <QResizeEvent>
46 
47 // STL
48 #include <cassert>
49 #include <algorithm>
50 
51 te::qt::widgets::Canvas::Canvas(int w, int h, int devType)
52  : m_isDeviceOwner(true),
53  m_bgColor(Qt::transparent),
54  m_erase(false),
55  m_ptWidth(1),
56  m_ptColor(Qt::black),
57  m_ptColorFrom(m_ptColor),
58  m_ptImg(0),
59  m_ptImgRotated(0),
60  m_ptSelectionPatternImg(0),
61  m_ptClearPatternImg(0),
62  m_ptRotation(0),
63  m_ptVOffset(0),
64  m_ptHOffset(0),
65  m_lnColor(Qt::transparent),
66  m_lnPen(Qt::blue),
67  m_polyContourColor(Qt::transparent),
68  m_polyContourPen(Qt::gray),
69  m_polyColor(Qt::red),
70  m_polyBrush(Qt::magenta),
71  m_polyImage(0),
72  m_polyRotatedImage(0),
73  m_polyPatternWidth(16),
74  m_txtContourPen(Qt::black),
75  m_txtContourEnabled(false),
76  m_txtBrush(Qt::black),
77  m_txtLetterSpacing(1),
78  m_txtWordSpacing(1),
79  m_txtLineSpacing(1)
80 {
81  if(devType == QInternal::Pixmap)
82  {
83  QPixmap* p = new QPixmap(w, h);
84  p->fill(m_bgColor);
85  m_painter.begin(p);
86  }
87  else
88  {
89  //QImage* i = new QImage(w, h, QImage::Format_ARGB32);
90  QImage* i = new QImage(w, h, QImage::Format_ARGB32_Premultiplied);
91  i->fill(m_bgColor.rgba());
92  m_painter.begin(i);
93  }
94 
95  m_ptPen.setColor(m_ptColor);
96 }
97 
98 te::qt::widgets::Canvas::Canvas(QPaintDevice* device)
99  : m_isDeviceOwner(false),
100  m_bgColor(Qt::transparent),
101  m_erase(false),
102  m_ptWidth(1),
103  m_ptColor(Qt::black),
104  m_ptColorFrom(m_ptColor),
105  m_ptImg(0),
106  m_ptImgRotated(0),
107  m_ptSelectionPatternImg(0),
108  m_ptClearPatternImg(0),
109  m_ptRotation(0),
110  m_ptVOffset(0),
111  m_ptHOffset(0),
112  m_lnColor(Qt::transparent),
113  m_lnPen(Qt::blue),
114  m_polyContourColor(Qt::transparent),
115  m_polyContourPen(Qt::gray),
116  m_polyColor(Qt::red),
117  m_polyBrush(Qt::magenta),
118  m_polyImage(0),
119  m_polyRotatedImage(0),
120  m_polyPatternWidth(16),
121  m_txtContourPen(Qt::black),
122  m_txtContourEnabled(false),
123  m_txtBrush(Qt::black),
124  m_txtLetterSpacing(1),
125  m_txtWordSpacing(1),
126  m_txtLineSpacing(1)
127 {
128  m_painter.begin(device);
129 }
130 
132 {
133  if(m_isDeviceOwner)
134  {
135  QPaintDevice* device = m_painter.device();
136  m_painter.end();
137  delete device;
138  }
139 
140  delete m_ptImg;
141  delete m_ptImgRotated;
142  delete m_ptClearPatternImg;
143  delete m_ptSelectionPatternImg;
144 
145 }
146 
147 void te::qt::widgets::Canvas::setWindow(const double& llx, const double& lly,
148  const double& urx, const double& ury)
149 {
150  double xScale = static_cast<double>(getWidth()) / (urx - llx);
151  double yScale = static_cast<double>(getHeight()) / (ury - lly);
152 
153  m_matrix.reset();
154  m_matrix.scale(xScale, -yScale);
155  m_matrix.translate(-llx, -ury);
156 
157  m_painter.setMatrix(m_matrix);
158 }
159 
160 void te::qt::widgets::Canvas::calcAspectRatio(double& llx, double& lly, double& urx, double& ury,
161  const te::map::AlignType hAlign, const te::map::AlignType vAlign)
162 {
163  double ww = urx - llx;
164  double wh = ury - lly;
165 
166  double widthByHeight = static_cast<double>(getWidth()) / static_cast<double>(getHeight());
167 
168  if(widthByHeight > ww / wh)
169  {
170  double v = ww;
171 
172  ww = wh * widthByHeight;
173 
174  if(hAlign == te::map::Left)
175  urx = llx + ww;
176  else if(hAlign == te::map::Right)
177  llx = urx - ww;
178  else // it is center
179  {
180  llx = llx - (ww - v) / 2.0;
181  urx = llx + ww;
182  }
183  }
184  else
185  {
186  double v = wh;
187 
188  wh = ww / widthByHeight;
189 
190  if(vAlign == te::map::Top)
191  lly = ury - wh;
192  else if(vAlign == te::map::Bottom)
193  ury = lly + wh;
194  else // it is center
195  {
196  lly = lly - (wh - v) / 2.0;
197  ury = lly + wh;
198  }
199  }
200 }
201 
203 {
204  calcAspectRatio(envelope->m_llx, envelope->m_lly, envelope->m_urx, envelope->m_ury, hAlign, vAlign);
205 }
206 
208 {
209  m_bgColor = QColor(color.getRgba());
210  m_bgColor.setAlpha(qAlpha(color.getRgba()));
211 
212  m_painter.setWorldMatrixEnabled(false);
213  m_painter.fillRect(m_painter.viewport(), m_bgColor);
214  m_painter.setWorldMatrixEnabled(true);
215 }
216 
218 {
219  return te::color::RGBAColor(m_bgColor.red(), m_bgColor.green(), m_bgColor.blue(), m_bgColor.alpha());
220 }
221 
223 {
224  int devType = m_painter.device()->devType();
225 
226  if(devType != QInternal::Image && devType != QInternal::Pixmap)
227  return;
228 
229  QPaintDevice* device = m_painter.device();
230 
231  if(device)
232  {
233  m_painter.end();
234  if(devType == QInternal::Image)
235  static_cast<QImage*>(device)->fill(m_bgColor.rgba());
236  else
237  static_cast<QPixmap*>(device)->fill(m_bgColor);
238  m_painter.begin(device);
239  }
240  //QPixmap* pix = getPixmap();
241  //if(pix)
242  //{
243  // m_painter.end();
244  // pix->fill(m_bgColor);
245  // m_painter.begin(pix);
246  //}
247  m_painter.setMatrix(m_matrix);
248 
249  m_ptPen.setColor(m_ptColor);
250  QRectF rec(QPoint(0., 0.), QPoint(m_ptWidth, m_ptWidth));
251  rec = m_matrix.inverted().mapRect(rec);
252  m_ptPen.setWidthF(rec.width());
253 }
254 
256 {
257  int devType = m_painter.device()->devType();
258 
259  if(devType != QInternal::Image && devType != QInternal::Pixmap)
260  return;
261 
262  if(!m_isDeviceOwner)
263  return;
264 
265  if(devType == QInternal :: Pixmap)
266  {
267  QPixmap* pixmap = static_cast<QPixmap*>(m_painter.device());
268  m_painter.end();
269  delete pixmap;
270  pixmap = new QPixmap(w, h);
271  pixmap->fill(m_bgColor);
272  m_painter.begin(pixmap);
273  }
274  else
275  {
276  QImage* image = static_cast<QImage*>(m_painter.device());
277  m_painter.end();
278  delete image;
279  //image = new QImage(w, h, QImage::Format_ARGB32);
280  image = new QImage(w, h, QImage::Format_ARGB32_Premultiplied);
281  image->fill(m_bgColor.rgba());
282  m_painter.begin(image);
283  }
284 }
285 
287 {
288  return m_painter.device()->width();
289 }
290 
292 {
293  return m_painter.device()->height();
294 }
295 
297 {
298  switch(geom->getGeomTypeId())
299  {
304  draw(static_cast<const te::gm::MultiPolygon*>(geom));
305  break;
306 
307  case te::gm::PointType:
308  case te::gm::PointZType:
309  case te::gm::PointMType:
310  case te::gm::PointZMType:
311  draw(static_cast<const te::gm::Point*>(geom));
312  break;
313 
318  draw(static_cast<const te::gm::LineString*>(geom));
319  break;
320 
321  case te::gm::PolygonType:
325  draw(static_cast<const te::gm::Polygon*>(geom));
326  break;
327 
332  draw(static_cast<const te::gm::MultiLineString*>(geom));
333  break;
334 
339  draw(static_cast<const te::gm::MultiPoint*>(geom));
340  break;
341 
346  draw(static_cast<const te::gm::GeometryCollection*>(geom));
347  break;
348  default:
349  break;
350  }
351 }
352 
354 {
355  m_pt.setX(point->getX());
356  m_pt.setY(point->getY());
357 
358  if(m_ptImg != 0)
359  {
360  QRectF rectf(0, 0, m_ptImg->width(), m_ptImg->height());
361  QPointF pc = m_matrix.map(m_pt);
362  pc.setX(pc.x() + m_ptHOffset);
363  pc.setY(pc.y() + m_ptVOffset);
364  rectf.moveCenter(pc);
365 
366  m_painter.setWorldMatrixEnabled(false);
367  if(m_erase && m_ptClearPatternImg)
368  m_painter.drawImage(rectf, *m_ptClearPatternImg);
369  else if(!m_erase && m_ptSelectionPatternImg)
370  m_painter.drawImage(rectf, *m_ptSelectionPatternImg);
371  m_painter.setWorldMatrixEnabled(true);
372  }
373  else
374  {
375  if(m_erase)
376  {
377  QPen p(m_ptPen);
378  p.setColor(Qt::black);
379  m_painter.setPen(p);
380  }
381  else
382  m_painter.setPen(m_ptPen);
383  m_painter.drawPoint(m_pt);
384  }
385 }
386 
388 {
389  std::size_t size = mpoint->getNumGeometries();
390 
391  for(std::size_t i = 0; i < size; ++i)
392  draw(static_cast<const te::gm::Point*>(mpoint->getGeometryN(i)));
393 }
394 
396 {
397  if(m_lnPen.brush().style() != Qt::TexturePattern)
398  {
399  const std::size_t nPoints = line->getNPoints();
400  QPolygonF qpol(nPoints);
401  memcpy(&(qpol[0]), (double*)(line->getCoordinates()), 16 * nPoints);
402  QPen pen(m_lnPen);
403  pen.setColor(m_lnColor);
404  m_painter.setPen(pen);
405  m_painter.setBrush(Qt::NoBrush);
406  m_painter.drawPolyline(qpol);
407  return;
408  }
409 
410  QPointF p1;
411  QPointF p2;
412  bool drawed = false;
413 
414  te::gm::Coord2D* coords = line->getCoordinates();
415  std::size_t size = line->getNPoints();
416 
417  p1.setX(coords[0].x);
418  p1.setY(coords[0].y);
419 
420  for(register std::size_t i = 1; i != size; ++i)
421  {
422  p2.setX(coords[i].x);
423  p2.setY(coords[i].y);
424 
425  if(m_erase)
426  {
427  QPen pen(m_lnPen);
428  pen.setColor(Qt::red);
429  if(m_lnPen.brush().style() == Qt::TexturePattern)
430  pen.setCapStyle(Qt::FlatCap); // Qt::RoundCap Qt::FlatCap Qt::SquareCap
431  m_painter.setPen(pen);
432  m_painter.setBrush(Qt::NoBrush);
433  m_painter.drawLine(p1, p2);
434  drawed = true;
435  }
436  //else if(m_lnPen.brush().style() != Qt::TexturePattern)
437  //{
438  // QPen pen(m_lnPen);
439  // pen.setColor(m_lnColor);
440  // m_painter.setPen(pen);
441  // m_painter.drawLine(p1, p2);
442  // drawed = true;
443  //}
444  //else
445  if(m_lnPen.brush().style() == Qt::TexturePattern)
446  {
447  int minPixels = 20; // dx and dy is greater than minPixels, then, draw the segment using pattern
448  double alfa;
449  QPoint dp1 = m_matrix.map(p1).toPoint();
450  QPoint dp2 = m_matrix.map(p2).toPoint();
451  int ddx = dp2.x() - dp1.x();
452  int ddy = dp2.y() - dp1.y();
453  if(abs(ddx) <= minPixels && abs(ddy) <= minPixels)
454  {
455  drawed = false;
456  continue;
457  }
458 
459  drawed = true;
460  double dx = p2.x() - p1.x();
461  double dy = p2.y() - p1.y();
462  double distance = sqrt((dx * dx) + (dy * dy));
463  double scale = m_lnPen.widthF() / m_lnPen.brush().textureImage().height();
464 
465  if(ddx == 0.)
466  {
467  if(p2.y() >= p1.y())
468  alfa = 90.;
469  else
470  alfa = 270.;
471  }
472  else if(ddy == 0.)
473  {
474  if(p2.x() >= p1.x())
475  alfa = 0.;
476  else
477  alfa = 180.;
478  }
479  else
480  {
481  alfa = atan(dy/dx) * 180. / 3.14159265;
482  if(dx < 0.)
483  alfa += 180.;
484  else if(alfa < 0 && dy < 0.)
485  alfa += 360.;
486  if(alfa == 360.)
487  alfa = 0.;
488  }
489 
490  QBrush brush(m_lnPen.brush());
491  QPen pen(m_lnPen);
492 // pen.setJoinStyle(Qt::RoundJoin); // Qt::BevelJoin Qt::MiterJoin Qt::RoundJoin
493  pen.setCapStyle(Qt::FlatCap); // Qt::RoundCap Qt::FlatCap Qt::SquareCap
494  QMatrix matrix;
495  matrix.scale(scale, scale);
496  matrix.translate(m_lnPen.brush().textureImage().width()/2, -m_lnPen.brush().textureImage().height()/2.);
497  brush.setMatrix(matrix);
498  pen.setBrush(brush);
499  m_painter.setPen(pen);
500 
501  m_painter.save();
502  m_painter.translate(p1);
503  m_painter.rotate(alfa);
504  m_painter.drawLine(0., 0., distance, 0.);
505  if(m_lnColor.alpha() != 0)
506  {
507  pen.setBrush(Qt::NoBrush);
508  pen.setColor(m_lnColor);
509  m_painter.setPen(pen);
510  m_painter.drawLine(0., 0., distance, 0.);
511  }
512  m_painter.restore();
513  }
514  p1 = p2;
515  }
516  if(drawed == false)
517  {
518  double alfa;
519  QPoint dp1 = m_matrix.map(p1).toPoint();
520  QPoint dp2 = m_matrix.map(p2).toPoint();
521  int ddx = dp2.x() - dp1.x();
522  int ddy = dp2.y() - dp1.y();
523  double dx = p2.x() - p1.x();
524  double dy = p2.y() - p1.y();
525  double distance = sqrt((dx * dx) + (dy * dy));
526  double scale = m_lnPen.widthF() / m_lnPen.brush().textureImage().height();
527 
528  if(ddx == 0.)
529  {
530  if(p2.y() >= p1.y())
531  alfa = 90.;
532  else
533  alfa = 270.;
534  }
535  else if(ddy == 0.)
536  {
537  if(p2.x() >= p1.x())
538  alfa = 0.;
539  else
540  alfa = 180.;
541  }
542  else
543  {
544  alfa = atan(dy/dx) * 180. / 3.14159265;
545  if(dx < 0.)
546  alfa += 180.;
547  else if(alfa < 0 && dy < 0.)
548  alfa += 360.;
549  if(alfa == 360.)
550  alfa = 0.;
551  }
552 
553  QBrush brush(m_lnPen.brush());
554  QPen pen(m_lnPen);
555 // pen.setJoinStyle(Qt::RoundJoin); // Qt::BevelJoin Qt::MiterJoin Qt::RoundJoin
556  pen.setCapStyle(Qt::FlatCap); // Qt::RoundCap Qt::FlatCap Qt::SquareCap
557  QMatrix matrix;
558  matrix.scale(scale, scale);
559  matrix.translate(m_lnPen.brush().textureImage().width()/2, -m_lnPen.brush().textureImage().height()/2.);
560  brush.setMatrix(matrix);
561  pen.setBrush(brush);
562  m_painter.setPen(pen);
563 
564  m_painter.save();
565  m_painter.translate(p1);
566  m_painter.rotate(alfa);
567  m_painter.drawLine(0., 0., distance, 0.);
568  if(m_lnColor.alpha() != 0)
569  {
570  pen.setBrush(Qt::NoBrush);
571  pen.setColor(m_lnColor);
572  m_painter.setPen(pen);
573  m_painter.drawLine(0., 0., distance, 0.);
574  }
575  m_painter.restore();
576  }
577 }
578 
580 {
581  std::size_t size = mline->getNumGeometries();
582 
583  for(size_t i = 0; i < size; ++i)
584  draw(static_cast<const te::gm::LineString*>(mline->getGeometryN(i)));
585 }
586 
588 {
589  const std::size_t nRings = poly->getNumRings();
590 
591  assert(nRings > 0);
592 
593  QPainterPath path;
594 
595  std::vector<te::gm::LinearRing*> rings;
596 
597  for(register std::size_t i = 0; i != nRings; ++i)
598  {
599  te::gm::LinearRing* ring = static_cast<te::gm::LinearRing*>(poly->getRingN(i));
600  rings.push_back(ring);
601 
602  const std::size_t nPoints = ring->getNPoints();
603 
604  assert(nPoints > 3);
605 
606  QPolygonF qpol(nPoints);
607 
608  memcpy(&(qpol[0]), (double*)(ring->getCoordinates()), 16 * nPoints);
609  path.addPolygon(qpol);
610  //te::gm::LinearRing* ring = static_cast<te::gm::LinearRing*>(poly->getRingN(i));
611  //const std::size_t nPoints = ring->getNPoints();
612  //assert(nPoints > 3);
613  //rings.push_back(ring);
614 
615  //te::gm::Coord2D* coords = ring->getCoordinates();
616  //std::size_t size = ring->getNPoints();
617  //if(size <= 1)
618  // continue;
619 
620  //QPolygonF qpol;
621  //QPointF p1(coords[0].x, coords[0].y);
622  //qpol.append(p1);
623 
624  //double xMax = p1.x();
625  //double yMax = p1.y();
626  //double xMin = p1.x();
627  //double yMin = p1.y();
628  //QPointF p2;
629  //for(register std::size_t i = 1; i != size; ++i)
630  //{
631  // p2.setX(coords[i].x);
632  // p2.setY(coords[i].y);
633 
634  // xMax = qMax(xMax, p2.x());
635  // yMax = qMax(yMax, p2.y());
636  // xMin = qMin(xMin, p2.x());
637  // yMin = qMin(yMin, p2.y());
638 
639  // if(m_matrix.map(p1).toPoint() == m_matrix.map(p2).toPoint())
640  // continue;
641  // qpol.append(p2);
642  // p1 = p2;
643  //}
644 
645  //if(qpol.size() < 3)
646  //{
647  // qpol.clear();
648  // qpol.append(QPointF(xMin, yMin));
649  // qpol.append(QPointF(xMax, yMin));
650  // qpol.append(QPointF(xMax, yMax));
651  // qpol.append(QPointF(xMin, yMax));
652  // qpol.append(QPointF(xMin, yMin));
653  //}
654  //path.addPolygon(qpol);
655  }
656 
657  if(m_erase)
658  {
659  m_painter.setPen(Qt::NoPen);
660  m_painter.setBrush(Qt::red);
661  m_painter.drawPath(path);
662  }
663  else
664  {
665  // fill polygon
666  m_painter.setPen(Qt::NoPen);
667  if(m_polyImage && m_polyColor.alpha() != 255)
668  {
669  const te::gm::Envelope* envelope = poly->getMBR();
670  QRectF recf(envelope->m_llx, envelope->m_lly, envelope->getWidth(), envelope->getHeight());
671  QPointF pc = m_matrix.map(recf.center());
672  int transx = pc.toPoint().x();
673  int transy = pc.toPoint().y();
674 
675  QMatrix matrix = m_matrix.inverted();
676  double scale = static_cast<double>(m_polyPatternWidth) / static_cast<double>(m_polyImage->width());
677  matrix.scale(scale, scale);
678  if(m_polyRotatedImage)
679  {
680  transx = transx % m_polyRotatedImage->width();
681  transy = transy % m_polyRotatedImage->height();
682  matrix.translate(transx, transy);
683  m_polyBrush.setMatrix(matrix);
684  m_polyBrush.setTextureImage(*m_polyRotatedImage);
685  }
686  else
687  {
688  transx = transx % m_polyImage->width();
689  transy = transy % m_polyImage->height();
690  matrix.translate(transx, transy);
691  m_polyBrush.setMatrix(matrix);
692  m_polyBrush.setTextureImage(*m_polyImage);
693  }
694 
695  m_painter.setBrush(m_polyBrush);
696 
697  if(m_polyContourPen.brush().style() == Qt::TexturePattern)
698  m_painter.setPen(Qt::NoPen);
699  else
700  m_painter.setPen(m_polyContourPen);
701 
702  m_painter.drawPath(path);
703  }
704  // if(m_polyColor.alpha() != 0)
705  // {
706  QBrush brush(m_polyColor);
707  m_painter.setBrush(brush);
708 
709  if(m_polyContourPen.brush().style() == Qt::TexturePattern)
710  m_painter.setPen(Qt::NoPen);
711  else
712  m_painter.setPen(m_polyContourPen);
713 
714  m_painter.drawPath(path);
715  // }
716 
717  // draw contour
718  if(m_polyContourPen.brush().style() == Qt::TexturePattern)
719  {
720  std::vector<te::gm::LinearRing*>::iterator it;
721  for(it = rings.begin(); it != rings.end(); ++it)
722  drawContour(*it);
723  }
724  }
725 }
726 
728 {
729  te::gm::Coord2D* coords = line->getCoordinates();
730  std::size_t size = line->getNPoints();
731  if(size <= 1)
732  return;
733 
734  bool drawed = false;
735 
736  m_polyContourPen.setColor(m_polyContourColor);
737  m_painter.setPen(m_polyContourPen);
738  m_painter.setBrush(Qt::NoBrush);
739 
740  QPointF p1(coords[0].x, coords[0].y);
741  QPointF p2;
742 
743  for(register std::size_t i = 1; i != size; ++i)
744  {
745  p2.setX(coords[i].x);
746  p2.setY(coords[i].y);
747 
748  if(m_polyContourPen.brush().style() != Qt::TexturePattern)
749  {
750  drawed = true;
751  m_painter.drawLine(p1, p2);
752  }
753  else
754  {
755  double alfa, beta;
756  QPointF pf1, pf2;
757  QPoint dp1 = m_matrix.map(p1).toPoint();
758  QPoint dp2 = m_matrix.map(p2).toPoint();
759  int ddx = dp2.x() - dp1.x();
760  int ddy = dp2.y() - dp1.y();
761  if(ddx == 0 && ddy == 0)
762  {
763  drawed = false;
764  continue;
765  }
766 
767  drawed = true;
768  double dx = p2.x() - p1.x();
769  double dy = p2.y() - p1.y();
770  double distance = sqrt((dx * dx) + (dy * dy));
771  double scale = m_polyContourPen.widthF() / m_polyContourPen.brush().textureImage().height();
772 
773  if(ddx == 0.)
774  {
775  if(p2.y() >= p1.y())
776  alfa = 90.;
777  else
778  alfa = 270.;
779  }
780  else if(ddy == 0.)
781  {
782  if(p2.x() >= p1.x())
783  alfa = 0.;
784  else
785  alfa = 180.;
786  }
787  else
788  {
789  alfa = atan(dy/dx) * 180. / 3.14159265;
790  if(dx < 0.)
791  alfa += 180.;
792  else if(alfa < 0 && dy < 0.)
793  alfa += 360.;
794  if(alfa == 360.)
795  alfa = 0.;
796  }
797 
798  if(alfa > 90. && alfa <= 270.)
799  {
800  pf1 = p2;
801  pf2 = p1;
802  beta = alfa + 180.;
803  if(beta > 360.)
804  beta -= 360.;
805  if(beta == 360.)
806  beta = 0.;
807  }
808  else
809  {
810  pf1 = p1;
811  pf2 = p2;
812  beta = alfa;
813  }
814 
815  QBrush brush(m_polyContourPen.brush());
816  QPen pen(m_polyContourPen);
817 // pen.setJoinStyle(Qt::RoundJoin); // Qt::BevelJoin Qt::MiterJoin Qt::RoundJoin
818  pen.setCapStyle(Qt::FlatCap); // Qt::RoundCap Qt::FlatCap Qt::SquareCap
819  QMatrix matrix;
820  matrix.scale(scale, scale);
821  matrix.translate(m_polyContourPen.brush().textureImage().width()/2, -m_polyContourPen.brush().textureImage().height()/2.);
822  brush.setMatrix(matrix);
823  pen.setBrush(brush);
824  m_painter.setPen(pen);
825 
826  m_painter.save();
827  m_painter.translate(pf1);
828  m_painter.rotate(beta);
829  m_painter.drawLine(0., 0., distance, 0.);
830  if(m_polyContourColor.alpha() != 0)
831  {
832  pen.setBrush(Qt::NoBrush);
833  pen.setColor(m_polyContourColor);
834  m_painter.setPen(pen);
835  m_painter.drawLine(0., 0., distance, 0.);
836  }
837  m_painter.restore();
838  }
839  p1 = p2;
840  }
841  if(drawed == false)
842  {
843  double alfa, beta;
844  QPointF pf1, pf2;
845  QPoint dp1 = m_matrix.map(p1).toPoint();
846  QPoint dp2 = m_matrix.map(p2).toPoint();
847  int ddx = dp2.x() - dp1.x();
848  int ddy = dp2.y() - dp1.y();
849  double dx = p2.x() - p1.x();
850  double dy = p2.y() - p1.y();
851  double distance = sqrt((dx * dx) + (dy * dy));
852  double scale = m_polyContourPen.widthF() / m_polyContourPen.brush().textureImage().height();
853 
854  if(ddx == 0.)
855  {
856  if(p2.y() >= p1.y())
857  alfa = 90.;
858  else
859  alfa = 270.;
860  }
861  else if(ddy == 0.)
862  {
863  if(p2.x() >= p1.x())
864  alfa = 0.;
865  else
866  alfa = 180.;
867  }
868  else
869  {
870  alfa = atan(dy/dx) * 180. / 3.14159265;
871  if(dx < 0.)
872  alfa += 180.;
873  else if(alfa < 0 && dy < 0.)
874  alfa += 360.;
875  if(alfa == 360.)
876  alfa = 0.;
877  }
878 
879  if(alfa > 90. && alfa <= 270.)
880  {
881  pf1 = p2;
882  pf2 = p1;
883  beta = alfa + 180.;
884  if(beta > 360.)
885  beta -= 360.;
886  if(beta == 360.)
887  beta = 0.;
888  }
889  else
890  {
891  pf1 = p1;
892  pf2 = p2;
893  beta = alfa;
894  }
895 
896  QBrush brush(m_polyContourPen.brush());
897  QPen pen(m_polyContourPen);
898 // pen.setJoinStyle(Qt::RoundJoin); // Qt::BevelJoin Qt::MiterJoin Qt::RoundJoin
899  pen.setCapStyle(Qt::FlatCap); // Qt::RoundCap Qt::FlatCap Qt::SquareCap
900  QMatrix matrix;
901  matrix.scale(scale, scale);
902  matrix.translate(m_polyContourPen.brush().textureImage().width()/2, -m_polyContourPen.brush().textureImage().height()/2.);
903  brush.setMatrix(matrix);
904  pen.setBrush(brush);
905  m_painter.setPen(pen);
906 
907  m_painter.save();
908  m_painter.translate(pf1);
909  m_painter.rotate(beta);
910  m_painter.drawLine(0., 0., distance, 0.);
911  if(m_polyContourColor.alpha() != 0)
912  {
913  pen.setBrush(Qt::NoBrush);
914  pen.setColor(m_polyContourColor);
915  m_painter.setPen(pen);
916  m_painter.drawLine(0., 0., distance, 0.);
917  }
918  m_painter.restore();
919  }
920 }
921 
923 {
924  const std::size_t size = mpoly->getNumGeometries();
925  for(std::size_t i = 0; i < size; ++i)
926  draw(static_cast<te::gm::Polygon*>(mpoly->getGeometryN(i)));
927 }
928 
930 {
931  const std::size_t size = g->getNumGeometries();
932  for(size_t i = 0; i < size; ++i)
933  draw(g->getGeometryN(i));
934 }
935 
936 void te::qt::widgets::Canvas::save(const char* fileName, te::map::ImageType t, int quality, int /*fg*/) const
937 {
938  int devType = m_painter.device()->devType();
939 
940  if(devType != QInternal::Image && devType != QInternal::Pixmap)
941  return;
942 
943  static_cast<QPixmap*>(m_painter.device())->save(fileName, GetFormat(t), quality);
944 }
945 
946 char* te::qt::widgets::Canvas::getImage(te::map::ImageType t, std::size_t& size, int quality, int /*fg*/) const
947 {
948  int devType = m_painter.device()->devType();
949 
950  if(devType != QInternal::Image && devType != QInternal::Pixmap)
951  return 0;
952 
953  QByteArray bytes;
954  QBuffer buffer(&bytes);
955  buffer.open(QIODevice::WriteOnly);
956 
957  switch(t)
958  {
959  case te::map::PNG:
960  static_cast<QPixmap*>(m_painter.device())->save(&buffer, Globals::sm_pngFmt);
961  break;
962 
963  case te::map::JPEG:
964  static_cast<QPixmap*>(m_painter.device())->save(&buffer, Globals::sm_jpegFmt, quality);
965  break;
966 
967  case te::map::GIF:
968  static_cast<QPixmap*>(m_painter.device())->save(&buffer, Globals::sm_gifFmt);
969  break;
970 
971  case te::map::BMP:
972  static_cast<QPixmap*>(m_painter.device())->save(&buffer, Globals::sm_bmpFmt);
973  break;
974 
975  case te::map::XPM:
976  static_cast<QPixmap*>(m_painter.device())->save(&buffer, Globals::sm_xpmFmt);
977  break;
978 
979  case te::map::XBM:
980  static_cast<QPixmap*>(m_painter.device())->save(&buffer, Globals::sm_xbmFmt);
981  break;
982 
983  default:
984  return 0;
985  }
986 
987  int nbytes = bytes.size();
988 
989  char* result = new char[nbytes];
990 
991  memcpy(result, bytes.data(), nbytes);
992 
993  size = nbytes;
994 
995  return result;
996 }
997 
998 te::color::RGBAColor** te::qt::widgets::Canvas::getImage(const int x, const int y, const int w, const int h) const
999 {
1000  int devType = m_painter.device()->devType();
1001 
1002  if(devType != QInternal::Image && devType != QInternal::Pixmap)
1003  return 0;
1004 
1005  te::color::RGBAColor** colors = 0;
1006  QImage img;
1007  if(devType == QInternal::Pixmap)
1008  img = static_cast<QPixmap*>(m_painter.device())->toImage();
1009  else
1010  img = *(static_cast<QImage*>(m_painter.device()));
1011 
1012  if(x == 0 && y == 0 && w == 0 && y == 0)
1013  {
1014  int width = img.width();
1015  int height = img.height();
1016 
1017  colors = new te::color::RGBAColor*[height];
1018  for(int i = 0; i < height; ++i)
1019  {
1020  colors[i] = new te::color::RGBAColor[width];
1021 
1022  unsigned char* u = img.scanLine(i);
1023 
1024  for(int j = 0; j < width; ++j)
1025  {
1026  QRgb* qrgb = (QRgb*)(u + (j << 2));
1027  QRgb value = *qrgb;
1028  te::color::RGBAColor rgba(qRed(value), qGreen(value), qBlue(value), qAlpha(value));
1029  colors[i][j] = rgba;
1030  }
1031  }
1032  }
1033  else
1034  {
1035  img = img.copy(x, y, w, h);
1036 
1037  colors = new te::color::RGBAColor*[h];
1038  for(int i = 0; i < h; ++i)
1039  {
1040  colors[i] = new te::color::RGBAColor[w];
1041 
1042  unsigned char* u = img.scanLine(i);
1043 
1044  for(int j = 0; j < w; ++j)
1045  {
1046  QRgb* qrgba = (QRgb*)(u+(j<<2));
1047  QRgb value = *qrgba;
1048  te::color::RGBAColor rgba(qRed(value), qGreen(value), qBlue(value), qAlpha(value));
1049  colors[i][j] = rgba;
1050  }
1051  }
1052  }
1053 
1054  return colors;
1055 }
1056 
1058 {
1059  delete [] img;
1060 }
1061 
1062 void te::qt::widgets::Canvas::drawImage(char* src, std::size_t size, te::map::ImageType t)
1063 {
1064  drawImage(0, 0, src, size, t);
1065 }
1066 
1068 {
1069  drawImage(0, 0, src, w, h);
1070 }
1071 
1072 void te::qt::widgets::Canvas::drawImage(int x, int y, char* src, std::size_t size, te::map::ImageType t)
1073 {
1074  QPixmap pix;
1075 
1076  const char* f = GetFormat(t);
1077  pix.loadFromData((unsigned char*)src, size, f);
1078 
1079  m_painter.setWorldMatrixEnabled(false);
1080  m_painter.drawPixmap(x, y, pix);
1081  m_painter.setWorldMatrixEnabled(true);
1082 }
1083 
1084 void te::qt::widgets::Canvas::drawImage(int x, int y, te::color::RGBAColor** src, int w, int h)
1085 {
1086  QImage img(w, h, QImage::Format_ARGB32);
1087 
1088  for(int l = 0; l < h; ++l)
1089  {
1090  for(int c = 0; c < w; ++c)
1091  {
1092  QRgb val = qRgba(src[l][c].getRed(), src[l][c].getGreen(), src[l][c].getBlue(), src[l][c].getAlpha());
1093 
1094  img.setPixel(c, l, val);
1095  }
1096  }
1097 
1098  m_painter.setWorldMatrixEnabled(false);
1099  m_painter.drawImage(x, y, img);
1100  m_painter.setWorldMatrixEnabled(true);
1101 }
1102 
1103 void te::qt::widgets::Canvas::drawImage(int x, int y, int w, int h, char* src, std::size_t size, te::map::ImageType t)
1104 {
1105  QPixmap pix;
1106 
1107  const char* f = GetFormat(t);
1108  pix.loadFromData((unsigned char*)src, size, f);
1109 
1110  m_painter.setWorldMatrixEnabled(false);
1111  m_painter.drawPixmap(x, y, w, h, pix);
1112  m_painter.setWorldMatrixEnabled(true);
1113 }
1114 
1115 void te::qt::widgets::Canvas::drawImage(int x, int y, int w, int h, te::color::RGBAColor** src, int srcw, int srch)
1116 {
1117  QImage img(srcw, srch, QImage::Format_RGB32);
1118 
1119  for(int l = 0; l < srch; ++l)
1120  for(int c = 0; c < srcw; ++c)
1121  img.setPixel(c, l, src[l][c].getRgba());
1122 
1123  m_painter.setWorldMatrixEnabled(false);
1124  m_painter.drawImage(QRect(x, y, w, h), img, QRect(0, 0, srcw, srch));
1125  m_painter.setWorldMatrixEnabled(true);
1126 }
1127 
1128 void te::qt::widgets::Canvas::drawImage(int x, int y, int w, int h, char* src, std::size_t size, te::map::ImageType t, int sx, int sy, int sw, int sh)
1129 {
1130  QPixmap pix;
1131 
1132  const char* f = GetFormat(t);
1133  pix.loadFromData((unsigned char*)src, size, f);
1134 
1135  m_painter.setWorldMatrixEnabled(false);
1136  m_painter.drawPixmap(x, y, w, h, pix, sx, sy, sw, sh);
1137  m_painter.setWorldMatrixEnabled(true);
1138 }
1139 
1140 void te::qt::widgets::Canvas::drawImage(int x, int y, int w, int h, te::color::RGBAColor** src, int sx, int sy, int sw, int sh)
1141 {
1142  QImage img(sw, sh, QImage::Format_RGB32);
1143 
1144  int ssh = sy + sh;
1145  int ssw = sx + sw;
1146 
1147  for(int l = sy, li = 0; l < ssh; ++l, ++li)
1148  for(int c = sx, ci = 0; c < ssw; ++c, ++ci)
1149  img.setPixel(ci, li, src[l][c].getRgba());
1150 
1151  m_painter.setWorldMatrixEnabled(false);
1152  m_painter.drawImage(QRect(x, y, w, h), img, QRect(0, 0, sw, sh));
1153  m_painter.setWorldMatrixEnabled(true);
1154 }
1155 
1156 void te::qt::widgets::Canvas::drawImage(int x, int y, te::rst::Raster* src, int opacity)
1157 {
1158  int sw = src->getNumberOfColumns();
1159  int sh = src->getNumberOfRows();
1160 
1161  drawImage(x, y, sw, sh, src, 0, 0, sw, sh, opacity);
1162 }
1163 
1164 void te::qt::widgets::Canvas::drawImage(int x, int y, int w, int h, te::rst::Raster* src, int sx, int sy, int sw, int sh, int opacity)
1165 {
1166  // Defines QImage size
1167  int iw = std::min(sw, w);
1168  int ih = std::min(sh, h);
1169 
1170  QImage img(iw, ih, QImage::Format_ARGB32);
1171  double pr, pg, pb;
1172  te::color::RGBAColor* pixel;
1173 
1174  // Checks if undersampling is needed
1175  double sl = std::max(1.0, sh/(double)h);
1176  double sr = std::max(1.0, sw/(double)w);
1177 
1178  int l, r;
1179  double dl = sy;
1180  for(int li = 0; li < ih; dl+=sl, ++li)
1181  {
1182  double dr = sx;
1183  for(int ri = 0; ri < iw; dr+=sr, ++ri)
1184  {
1185  r = static_cast<int> (dr);
1186  l = static_cast<int> (dl);
1187  src->getValue(r, l, pr, 0);
1188  src->getValue(r, l, pg, 1);
1189  src->getValue(r, l, pb, 2);
1190 
1191  pixel = new te::color::RGBAColor((int)pr, (int)pg, (int)pb, opacity);
1192  QRgb val = qRgba(pixel->getRed(), pixel->getGreen(), pixel->getBlue(), pixel->getAlpha());
1193 
1194  img.setPixel(ri, li, val);
1195 
1196  delete pixel;
1197  }
1198  }
1199 
1200  m_painter.setWorldMatrixEnabled(false);
1201  m_painter.drawImage(QRect(x, y, w, h), img, QRect(0, 0, iw, ih));
1202  m_painter.setWorldMatrixEnabled(true);
1203 }
1204 
1206 {
1207  m_painter.setWorldMatrixEnabled(false);
1208  m_painter.drawPoint(x, y);
1209  m_painter.setWorldMatrixEnabled(true);
1210 }
1211 
1213 {
1214  QColor c(color.getRgba());
1215  c.setAlpha(qAlpha(color.getRgba()));
1216 
1217  m_painter.setPen(c);
1218 
1219  m_painter.setWorldMatrixEnabled(false);
1220  m_painter.drawPoint(x, y);
1221  m_painter.setWorldMatrixEnabled(true);
1222 }
1223 
1225  const std::string& txt,
1226  float angle,
1229 {
1230  QPoint p(x, y);
1231  drawText(p, txt, angle, hAlign, vAlign);
1232 }
1233 
1235  const std::string& txt,
1236  float angle,
1239 {
1240  drawText(p->getX(), p->getY(), txt, angle, hAlign, vAlign);
1241 }
1242 
1243 void te::qt::widgets::Canvas::drawText(const double& x, const double& y,
1244  const std::string& txt,
1245  float angle,
1248 {
1249  QPointF pf(x, y);
1250  pf = m_matrix.map(pf);
1251  QPoint p = pf.toPoint();
1252  drawText(p, txt, angle, hAlign, vAlign);
1253 }
1254 
1256 {
1257  std::size_t size = txt->getElements().size();
1258 
1259  if(size == 0)
1260  return;
1261 
1262  std::size_t i = 0;
1263 
1264  while(txt->getElements()[i]->getAttributes() == 0 && i < size)
1265  ++i;
1266 
1269 
1270  while(i < size)
1271  {
1272  // set attributes
1273  te::at::Element* element = txt->getElements()[i];
1275  if(atr)
1276  {
1277  // get font family
1278  std::string family = ((te::at::Attributes*)atr)->getFamily();
1279  m_font.setFamily(family.c_str());
1280 
1281  // get font point size
1282  const double& pointSize = atr->getPointSize();
1283  setTextPointSize(pointSize);
1284 
1285  // get font weight
1286  const te::at::FontWeight& weight = atr->getWeight();
1287  if(weight == te::at::Light)
1288  m_font.setWeight(QFont::Light);
1289  else if(weight == te::at::NormalWeight)
1290  m_font.setWeight(QFont::Normal);
1291  else if(weight == te::at::DemiBold)
1292  m_font.setWeight(QFont::DemiBold);
1293  else if(weight == te::at::Bold)
1294  m_font.setWeight(QFont::Bold);
1295  else
1296  m_font.setWeight(QFont::Black);
1297 
1298  // get font style
1299  const te::at::FontStyle& style = atr->getStyle();
1300  if(style == te::at::NormalStyle)
1301  m_font.setStyle(QFont::StyleNormal);
1302  else if(style == te::at::Oblique)
1303  m_font.setStyle(QFont::StyleOblique);
1304  else
1305  m_font.setStyle(QFont::StyleItalic);
1306 
1307  // get font decoration
1308  const te::at::TextDecoration& decoration = atr->getDecoration();
1309  if(decoration == te::at::None)
1310  {
1311  m_font.setOverline(false);
1312  m_font.setUnderline(false);
1313  m_font.setStrikeOut(false);
1314  }
1315  else if(decoration == te::at::Overline)
1316  m_font.setOverline(true);
1317  else if(decoration == te::at::Underline)
1318  m_font.setUnderline(true);
1319  else
1320  m_font.setStrikeOut(true);
1321 
1322  m_painter.setFont(m_font);
1323 
1324  // get letter spacing
1325  m_txtLetterSpacing = atr->getLetterSpacing();
1326  // nao sei o que fazer ????????????
1327 
1328  // get word spacing
1329  m_txtWordSpacing = atr->getLetterSpacing();
1330  // nao sei o que fazer ????????????
1331 
1332  // get text color and opacity
1333  const std::string& cor = atr->getTextColor();
1334  QColor qcor(cor.c_str());
1335  int opacity = atr->getTextOpacity() * 255.;
1336  qcor.setAlpha(opacity);
1337  m_txtBrush = QBrush(qcor);
1338 
1339  // get stroke color and opacity
1340  const std::string& sCor = atr->getTextStrokeColor();
1341  QColor qscor(sCor.c_str());
1342  int sOpacity = atr->getTextStrokeOpacity() * 255.;
1343  qscor.setAlpha(sOpacity);
1344  m_txtContourPen = QPen(qscor);
1345 
1346  // get stroke width
1347  m_txtContourPen.setWidth(10. * atr->getTextStrokeWidth() * (double)getResolution() / 72.);
1348 
1349  // get horizontal alignment
1350  hAlign = atr->getHorizontalAlignment();
1351 
1352  // get vertical alignment
1353  vAlign = atr->getVerticalAlignment();
1354 
1355  // get multi line justification
1356  //m_txtLineJustification = atr->getLineJustification();
1357  // parece haver confusao entre horizontal alignment e line justification ????????????
1358  // por enquanto estou usando somente horizontal aligment.
1359 
1360  // get multi line spacing
1361  m_txtLineSpacing = atr->getLineSpacing();
1362  // como usar isto (0...1) ????????????
1363  }
1364 
1365  if(element->getLeaderLine() == 0) // without leaderLine
1366  {
1367  // supondo que location e' do tipo ponto
1368  const te::gm::Point* pt = static_cast<const te::gm::Point*>(element->getLocation());
1369  std::string text = element->getValue();
1370  size_t p = text.find("\n");
1371  double hline = 0;
1372  te::gm::Point* pclone = 0;
1373  if(p != std::string::npos)
1374  {
1375  QFontMetrics fm = QFontMetrics(m_font);
1376  QRectF rec(fm.boundingRect("A"));
1377  hline = QRectF(m_matrix.inverted().mapRect(rec)).height();
1378  hline = hline + hline * m_txtLineSpacing; // no chute ????????
1379  pclone = (te::gm::Point*)pt->clone();
1380  }
1381  while(p != std::string::npos) // multiline text
1382  {
1383  std::string t = text.substr(0, p);
1384  drawText(pclone, t, 0., hAlign, vAlign);
1385  text = text.substr(p+1);
1386  p = text.find("\n");
1387  pclone->setY(pclone->getY() - hline); // next line
1388  }
1389  if(pclone) // multiline
1390  drawText(pclone, text, 0., hAlign, vAlign);
1391  else
1392  drawText(pt, text, 0., hAlign, vAlign);
1393 
1394  delete pclone;
1395  }
1396  else // with leaderLine
1397  {
1398  }
1399 
1400  ++i;
1401  }
1402 }
1403 
1405 {
1406  QPoint p(x, y);
1407  return getTextBoundary(p, txt, angle, hAlign, vAlign);
1408 }
1409 
1411 {
1412  return getTextBoundary(p->getX(), p->getY(), txt, angle, hAlign, vAlign);
1413 }
1414 
1415 te::gm::Polygon* te::qt::widgets::Canvas::getTextBoundary(const double& x, const double& y, const std::string& txt, float angle, te::at::HorizontalAlignment hAlign, te::at::VerticalAlignment vAlign)
1416 {
1417  QPointF pf(x, y);
1418  pf = m_matrix.map(pf);
1419  QPoint p = pf.toPoint();
1420  return getTextBoundary(p, txt, angle, hAlign, vAlign);
1421 }
1422 
1424 {
1425  m_txtBrush.setStyle(Qt::SolidPattern);
1426  QColor cor(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
1427  m_txtBrush.setColor(cor);
1428 }
1429 
1431 {
1432  QColor cor(m_txtBrush.color().red(), m_txtBrush.color().green(), m_txtBrush.color().blue(), opacity);
1433  m_txtBrush.setColor(cor);
1434 }
1435 
1436 void te::qt::widgets::Canvas::setFontFamily(const std::string& family)
1437 {
1438  m_font.setFamily(family.c_str());
1439 }
1440 
1442 {
1443  double resolution = 0.0;
1444 
1445  if(m_painter.device()->devType() == QInternal::Printer)
1446  resolution = static_cast<QPrinter*>(m_painter.device())->resolution();
1447  else
1448  resolution = m_painter.device()->logicalDpiY();
1449 
1450  double PointSize = psize * resolution / 72.0;
1451 
1452  m_font.setPointSizeF(PointSize);
1453 }
1454 
1456 {
1457  m_font.setStyle((QFont::Style)style);
1458 }
1459 
1461 {
1462  int wg = weight;
1463 
1464  if(wg > 99)
1465  wg = 99;
1466 
1467  m_font.setWeight((QFont::Weight)wg);
1468 }
1469 
1471 {
1472  m_font.setStretch(stretch);
1473 }
1474 
1476 {
1477  m_font.setUnderline(b);
1478 }
1479 
1481 {
1482  m_font.setOverline(b);
1483 }
1484 
1486 {
1487  m_font.setStrikeOut(b);
1488 }
1489 
1491 {
1492 }
1493 
1495 {
1496 }
1497 
1499 {
1500  QColor cor(color.getRgba());
1501  cor.setAlpha(qAlpha(color.getRgba()));
1502  m_txtContourPen.setColor(cor);
1503 }
1504 
1506 {
1507  m_txtContourEnabled = b;
1508 }
1509 
1511 {
1512  QColor cor(m_txtContourPen.color().red(), m_txtContourPen.color().green(), m_txtContourPen.color().blue(), opacity);
1513  m_txtContourPen.setColor(cor);
1514 }
1515 
1517 {
1518  m_txtContourPen.setWidth(width);
1519 }
1520 
1522 {
1523 }
1524 
1526 {
1527  m_txtLineSpacing = spacing;
1528 }
1529 
1531 {
1532  QColor cor(color.getRgba());
1533  cor.setAlpha(qAlpha(color.getRgba()));
1534  if(m_ptColor == cor)
1535  return;
1536 
1537  m_ptColor = cor;
1538  m_ptPen.setColor(m_ptColor);
1539 
1540  if(m_ptColorFrom != m_ptColor && m_ptImg)
1541  createPointPatterns();
1542 }
1543 
1545 {
1546  if(w == m_ptWidth)
1547  return;
1548 
1549  m_ptWidth = w;
1550  QRectF rec(QPoint(0., 0.), QPoint(m_ptWidth, m_ptWidth));
1551  rec = m_matrix.inverted().mapRect(rec);
1552  m_ptPen.setWidthF(rec.width());
1553 
1554  if(m_ptImg)
1555  {
1556  double scale = (double)m_ptWidth / (double)m_ptImg->width();
1557  int h = m_ptImg->height() * scale;
1558  QImage* ima = new QImage(m_ptImg->scaled(m_ptWidth, h));
1559  delete m_ptImg;
1560  m_ptImg = ima;
1561  }
1562  createPointPatterns();
1563 }
1564 
1566 {
1567  delete m_ptImg;
1568  m_ptImg = 0;
1569 
1570  if(pattern == 0 || ncols == 0 || nrows == 0)
1571  return;
1572 
1573  m_ptImg = GetImage(pattern, ncols, nrows);
1574  int width = m_ptImg->width();
1575  m_ptWidth = width;
1576 
1577  createPointPatterns();
1578 }
1579 
1580 void te::qt::widgets::Canvas::setPointPattern(char* pattern, std::size_t size, te::map::ImageType t)
1581 {
1582  delete m_ptImg;
1583  m_ptImg = 0;
1584 
1585  if(pattern == 0 || size == 0)
1586  return;
1587 
1588  m_ptImg = new QImage();
1589 
1590  const char* format = te::qt::widgets::GetFormat(t);
1591 
1592  if(m_ptImg->loadFromData((const uchar*)pattern, size, format) == false)
1593  {
1594  delete m_ptImg;
1595  m_ptImg = 0;
1596  return;
1597  }
1598 
1599  int width = m_ptImg->width();
1600  m_ptWidth = width;
1601 
1602  createPointPatterns();
1603 }
1604 
1606 {
1607  m_ptRotation = angle;
1608  createPointPatterns();
1609 }
1610 
1612 {
1613  if(m_ptImg == 0)
1614  return;
1615 
1616  updateAlpha(*m_ptImg, opacity);
1617  createPointPatterns();
1618 }
1619 
1621 {
1622  QColor cor(color.getRgba());
1623  cor.setAlpha(qAlpha(color.getRgba()));
1624 
1625  //if(cor.alpha() == 255)
1626  //{
1627  // m_lnPen.setColor(cor);
1628  // m_lnColor = QColor(0, 0, 0, 0);
1629  //}
1630  //else
1631  m_lnColor = cor;
1632 }
1633 
1635 {
1636  if(pattern == 0)
1637  {
1638  m_lnPen.setBrush(Qt::NoBrush);
1639  return;
1640  }
1641 
1642  QImage* img = GetImage(pattern, ncols, nrows);
1643 
1644  if(img->isNull() == false)
1645  {
1646  QBrush brush;
1647  brush.setTextureImage(*img);
1648  m_lnPen.setBrush(brush);
1649  }
1650  delete img;
1651 }
1652 
1653 void te::qt::widgets::Canvas::setLinePattern(char* pattern, std::size_t size, te::map::ImageType t)
1654 {
1655  if(pattern == 0)
1656  {
1657  m_lnPen.setBrush(Qt::NoBrush);
1658  return;
1659  }
1660 
1661  QImage img;
1662 
1663  const char* format = te::qt::widgets::GetFormat(t);
1664 
1665  bool result = img.loadFromData((const uchar*)pattern, size, format);
1666 
1667  if(result && img.isNull() == false)
1668  {
1669  QBrush brush;
1670  brush.setTextureImage(img);
1671  m_lnPen.setBrush(brush);
1672  }
1673 }
1674 
1676 {
1677  QBrush brush = m_lnPen.brush();
1678  QImage img = brush.textureImage();
1679  if(img.isNull())
1680  return;
1681 
1682  QMatrix matrix;
1683  matrix.translate(img.width()/2, img.height()/2);
1684  matrix.rotate(angle);
1685  QImage imgRot = img.transformed(matrix);
1686 
1687  brush.setTextureImage(imgRot);
1688  m_lnPen.setBrush(brush);
1689 }
1690 
1692 {
1693  QBrush brush = m_lnPen.brush();
1694  QImage img = brush.textureImage();
1695  if(img.isNull())
1696  return;
1697 
1698  // Updates the alpha channel
1699  updateAlpha(img, opacity);
1700 
1701  brush.setTextureImage(img);
1702  m_lnPen.setBrush(brush);
1703 }
1704 
1706 {
1707  m_lnPen.setStyle((Qt::PenStyle)style);
1708 }
1709 
1710 void te::qt::widgets::Canvas::setLineDashStyle(const std::vector<double>& style)
1711 {
1712  setLineDashStyle(m_lnPen, style);
1713 }
1714 
1716 {
1717  m_lnPen.setCapStyle((Qt::PenCapStyle)style);
1718 }
1719 
1721 {
1722  m_lnPen.setJoinStyle((Qt::PenJoinStyle)style);
1723 }
1724 
1726 {
1727  QRectF rec(QPoint(0., 0.), QPoint(w, w));
1728  rec = m_matrix.inverted().mapRect(rec);
1729  m_lnPen.setWidthF(rec.width());
1730 }
1731 
1733 {
1734  QColor cor(color.getRgba());
1735  cor.setAlpha(qAlpha(color.getRgba()));
1736  m_polyColor = cor;
1737 }
1738 
1740 {
1741  if(pattern == 0)
1742  {
1743  m_polyBrush.setStyle(Qt::NoBrush);
1744  delete m_polyImage;
1745  delete m_polyRotatedImage;
1746  m_polyImage = 0;
1747  m_polyRotatedImage = 0;
1748  return;
1749  }
1750 
1751  if(m_polyImage)
1752  delete m_polyImage;
1753 
1754  m_polyImage = GetImage(pattern, ncols, nrows);
1755  if(m_polyImage->isNull())
1756  {
1757  delete m_polyImage;
1758  m_polyImage = 0;
1759  }
1760  m_polyPatternWidth = m_polyImage->width();
1761 
1762  //QImage* img = GetImage(pattern, ncols, nrows);
1763 
1764  //if(img->isNull() == false)
1765  //{
1766  // //QMatrix matrix = m_matrix.inverted();
1767  // //double scale = static_cast<double>(m_polyPatternWidth) / static_cast<double>(img->width());
1768  // //matrix.scale(scale, scale);
1769  // //m_polyBrush.setStyle(Qt::TexturePattern);
1770  // //m_polyBrush.setMatrix(matrix);
1771  // //m_polyBrush.setTextureImage(*img);
1772  //}
1773  //delete img;
1774 }
1775 
1777 {
1778  if(pattern == 0)
1779  {
1780  m_polyBrush.setStyle(Qt::NoBrush);
1781  delete m_polyImage;
1782  delete m_polyRotatedImage;
1783  m_polyImage = 0;
1784  m_polyRotatedImage = 0;
1785  return;
1786  }
1787  delete m_polyImage;
1788 
1789  m_polyImage = new QImage();
1790  const char* format = te::qt::widgets::GetFormat(t);
1791  bool result = m_polyImage->loadFromData((const uchar*)pattern, size, format);
1792  if(result == false)
1793  {
1794  delete m_polyImage;
1795  m_polyImage = 0;
1796  }
1797 
1798  //QImage img;
1799 
1800  //const char* format = te::qt::widgets::GetFormat(t);
1801 
1802  //bool result = img.loadFromData((const uchar*)pattern, size, format);
1803 
1804  //if(result && img.isNull() == false)
1805  //{
1806  // QMatrix matrix = m_matrix.inverted();
1807  // double scale = static_cast<double>(m_polyPatternWidth) / static_cast<double>(img.width());
1808  // matrix.scale(scale, scale);
1809  // m_polyBrush.setStyle(Qt::TexturePattern);
1810  // m_polyBrush.setMatrix(matrix);
1811  // m_polyBrush.setTextureImage(img);
1812  //}
1813 }
1814 
1816 {
1817  m_polyPatternWidth = w;
1818 
1819  if(m_polyPatternWidth == 0.)
1820  m_polyPatternWidth = 1.;
1821 
1822  //QImage img = m_polyBrush.textureImage();
1823 
1824  //if(img.isNull() == false)
1825  //{
1826  // QMatrix matrix = m_matrix.inverted();
1827  // double scale = static_cast<double>(m_polyPatternWidth) / static_cast<double>(img.width());
1828  // matrix.scale(scale, scale);
1829  // m_polyBrush.setMatrix(matrix);
1830  //}
1831 }
1832 
1834 {
1835  if(m_polyImage)
1836  {
1837  QMatrix matrix;
1838  matrix.translate((double)m_polyImage->width()/2., (double)m_polyImage->height()/2.);
1839  matrix.rotate(angle);
1840 
1841  if(m_polyRotatedImage == 0)
1842  m_polyRotatedImage = new QImage();
1843  *m_polyRotatedImage = m_polyImage->transformed(matrix);
1844  }
1845 }
1846 
1848 {
1849  QImage img = m_polyBrush.textureImage();
1850  if(img.isNull())
1851  return;
1852 
1853  // Updates the alpha channel
1854  if(m_polyImage)
1855  updateAlpha(*m_polyImage, opacity);
1856  if(m_polyRotatedImage)
1857  updateAlpha(*m_polyRotatedImage, opacity);
1858 
1859  //m_polyBrush.setTextureImage(img);
1860 }
1861 
1863 {
1864  QColor cor(color.getRgba());
1865  cor.setAlpha(qAlpha(color.getRgba()));
1866 
1867  //if(cor.alpha() == 255)
1868  //{
1869  // m_polyContourPen.setColor(cor);
1870  // m_polyContourColor = QColor(0, 0, 0, 0);
1871  //}
1872  //else
1873  // m_polyContourColor = cor;
1874  m_polyContourPen.setColor(cor);
1875  m_polyContourColor = cor;
1876 }
1877 
1879 {
1880  if(pattern == 0)
1881  {
1882  m_polyContourPen.setBrush(Qt::NoBrush);
1883  return;
1884  }
1885 
1886  QImage* img = GetImage(pattern, ncols, nrows);
1887 
1888  if(img->isNull() == false)
1889  {
1890  QBrush brush;
1891  brush.setTextureImage(*img);
1892  m_polyContourPen.setBrush(brush);
1893  }
1894  delete img;
1895 }
1896 
1898 {
1899  if(pattern == 0)
1900  {
1901  m_polyContourPen.setBrush(Qt::NoBrush);
1902  return;
1903  }
1904 
1905  QImage img;
1906 
1907  const char* format = te::qt::widgets::GetFormat(t);
1908 
1909  bool result = img.loadFromData((const uchar*)pattern, size, format);
1910 
1911  if(result && img.isNull() == false)
1912  {
1913  QBrush brush;
1914  brush.setTextureImage(img);
1915  m_polyContourPen.setBrush(brush);
1916  }
1917 }
1918 
1920 {
1921  QRectF rec(QPoint(0., 0.), QPoint(w, w));
1922  rec = m_matrix.inverted().mapRect(rec);
1923  m_polyContourPen.setWidthF(rec.width());
1924 }
1925 
1927 {
1928  QBrush brush = m_polyContourPen.brush();
1929  QImage img = brush.textureImage();
1930  if(img.isNull())
1931  return;
1932 
1933  QMatrix matrix;
1934  matrix.translate(img.width()/2, img.height()/2);
1935  matrix.rotate(angle);
1936  QImage imgRot = img.transformed(matrix);
1937 
1938  brush.setTextureImage(imgRot);
1939  m_polyContourPen.setBrush(brush);
1940 }
1941 
1943 {
1944  QBrush brush = m_polyContourPen.brush();
1945  QImage img = brush.textureImage();
1946  if(img.isNull())
1947  return;
1948 
1949  // Updates the alpha channel
1950  updateAlpha(img, opacity);
1951 
1952  brush.setTextureImage(img);
1953  m_polyContourPen.setBrush(brush);
1954 }
1955 
1957 {
1958  m_polyContourPen.setStyle((Qt::PenStyle)style);
1959 }
1960 
1961 void te::qt::widgets::Canvas::setPolygonContourDashStyle(const std::vector<double>& style)
1962 {
1963  setLineDashStyle(m_polyContourPen, style);
1964 }
1965 
1967 {
1968  m_polyContourPen.setCapStyle((Qt::PenCapStyle)style);
1969 }
1970 
1972 {
1973  m_polyContourPen.setJoinStyle((Qt::PenJoinStyle)style);
1974 }
1975 
1977  const std::string& txt,
1978  float angle,
1981 {
1982  if(txt.empty())
1983  return;
1984 
1985  double ax, ay; // alignment position
1986  QString qtx(txt.c_str());
1987  QPainterPath path;
1988  QFontMetrics fm(m_font);
1989  QRectF rec(fm.boundingRect(qtx));
1990 
1991  if(hAlign == te::at::Start)
1992  ax = rec.left();
1993  else if(hAlign == te::at::CenterH)
1994  ax = rec.center().x();
1995  else
1996  ax = rec.right();
1997 
1998  if(vAlign == te::at::Bottom)
1999  ay = rec.bottom();
2000  else if(vAlign == te::at::CenterV)
2001  ay = rec.center().y();
2002  else if(vAlign == te::at::Top)
2003  ay = rec.top();
2004  else
2005  ay = 0.;
2006 
2007  path.addText(-ax, -ay, m_font, qtx);
2008 
2009  m_painter.resetMatrix();
2010  m_painter.translate(p);
2011  if(angle != 0.)
2012  m_painter.rotate(angle);
2013 
2014  if(m_txtContourEnabled)
2015  {
2016  m_painter.setBrush(Qt::NoBrush);
2017  m_painter.setPen(m_txtContourPen);
2018  m_painter.drawPath(path);
2019  }
2020 
2021  m_painter.setPen(Qt::NoPen);
2022  m_painter.fillPath(path, m_txtBrush);
2023 
2024  m_painter.drawPath(path);
2025 
2026  m_painter.setMatrix(m_matrix);
2027 }
2028 
2029 te::gm::Polygon* te::qt::widgets::Canvas::getTextBoundary(const QPoint& p, const std::string& txt, float angle,
2032 {
2033  if(txt.empty())
2034  return 0;
2035 
2036  double ax, ay; // alignment position
2037  QString qtx(txt.c_str());
2038  QPainterPath path;
2039  QFontMetrics fm(m_font);
2040  QRectF rec(fm.boundingRect(qtx));
2041  QRectF wrec(m_matrix.inverted().mapRect(rec));
2042 
2043  if(hAlign == te::at::Start)
2044  ax = wrec.left();
2045  else if(hAlign == te::at::CenterH)
2046  ax = wrec.center().x();
2047  else
2048  ax = wrec.right();
2049 
2050 // reverse top-bottom
2051  if(vAlign == te::at::Bottom)
2052  ay = wrec.top();
2053  else if(vAlign == te::at::CenterV)
2054  ay = wrec.center().y();
2055  else if(vAlign == te::at::Top)
2056  ay = wrec.bottom();
2057  else // Baseline
2058  ay = m_matrix.inverted().map(QPoint(0, 0)).y();
2059 
2060  wrec.translate(-ax, -ay); // rotation point on text alignment
2061  QPolygonF polf(wrec);
2062 
2063  if(angle != 0.)
2064  {
2065  QMatrix m;
2066  m.rotate(-angle);
2067  polf = m.map(polf);
2068  }
2069  QPointF wp = m_matrix.inverted().map(QPointF(p));
2070  polf.translate(wp.x(), wp.y()); // translate to entry point
2071 
2072 //converter QPolygon para te::gm::Polygon. Como fazer isso?
2075  poly->setRingN(0, lr);
2076  lr->setPoint(0, polf.at(0).x(), polf.at(0).y());
2077  lr->setPoint(1, polf.at(1).x(), polf.at(1).y());
2078  lr->setPoint(2, polf.at(2).x(), polf.at(2).y());
2079  lr->setPoint(3, polf.at(3).x(), polf.at(3).y());
2080  return poly;
2081 }
2082 
2084 {
2085  if(m_painter.device()->devType() == QInternal::Pixmap)
2086  return static_cast<QPixmap*>(m_painter.device());
2087  else
2088  return 0;
2089 }
2090 
2092 {
2093  if(m_painter.device()->devType() == QInternal::Image)
2094  return static_cast<QImage*>(m_painter.device());
2095  else
2096  return 0;
2097 }
2098 
2100 {
2101  return m_painter.device();
2102 }
2103 
2104 void te::qt::widgets::Canvas::setDevice(QPaintDevice* device, bool takeOwnerShip)
2105 {
2106  m_painter.end();
2107 
2108  if(m_isDeviceOwner)
2109  delete m_painter.device();
2110 
2111  m_isDeviceOwner = takeOwnerShip;
2112  m_painter.begin(device);
2113 }
2114 
2116 {
2117  if(m_painter.device()->devType() == QInternal::Printer)
2118  return static_cast<QPrinter*>(m_painter.device())->resolution();
2119  else
2120  return m_painter.device()->logicalDpiX();
2121 }
2122 
2124 {
2125  return m_matrix;
2126 }
2127 
2128 void te::qt::widgets::Canvas::setRenderHint(QPainter::RenderHint hint, bool on)
2129 {
2130  m_painter.setRenderHint(hint, on);
2131 }
2132 
2133 void te::qt::widgets::Canvas::setLineDashStyle(QPen& pen, const std::vector<double>& style)
2134 {
2135  assert(style.size() % 2 == 0);
2136  QVector<qreal> pattern;
2137  for(std::size_t i = 0; i < style.size(); ++i)
2138  pattern << style[i];
2139  pen.setDashPattern(pattern);
2140 }
2141 
2142 void te::qt::widgets::Canvas::updateAlpha(QImage& img, const int& opacity)
2143 {
2144  int o = opacity << 24;
2145  for(int i = 0; i < img.height(); ++i)
2146  {
2147  unsigned char* u = img.scanLine(i);
2148  for(int j = 0; j < img.width(); ++j)
2149  {
2150  QRgb* v = (QRgb*)(u + (j << 2));
2151  if(qAlpha(*v) <= opacity)
2152  continue;
2153  *v = *v & 0x00ffffff;
2154  *v = o | *v;
2155  }
2156  }
2157 }
2158 
2160 {
2161  delete m_ptSelectionPatternImg;
2162  delete m_ptClearPatternImg;
2163  delete m_ptImgRotated;
2164  m_ptSelectionPatternImg = 0;
2165  m_ptClearPatternImg = 0;
2166  m_ptImgRotated = 0;
2167 
2168  if(m_ptImg == 0)
2169  return;
2170 
2171  QMatrix m;
2172  m.rotate(m_ptRotation);
2173  m_ptImgRotated = new QImage(m_ptImg->transformed(m));
2174 
2175  m_ptColorFrom = m_ptColor;
2176 
2177  double a = (double)m_ptColor.alpha() / (double)255;
2178  double b = (double)(255 - m_ptColor.alpha()) / (double)255;
2179  int width = m_ptImgRotated->width();
2180  int height = m_ptImgRotated->height();
2181  m_ptSelectionPatternImg = new QImage(width, height, QImage::Format_ARGB32);
2182  m_ptClearPatternImg = new QImage(width, height, QImage::Format_ARGB32);
2183  for(int i = 0; i < height; ++i)
2184  {
2185  unsigned char* u = m_ptImgRotated->scanLine(i);
2186  unsigned char* uu = m_ptSelectionPatternImg->scanLine(i);
2187  unsigned char* uuu = m_ptClearPatternImg->scanLine(i);
2188  for(int j = 0; j < width; ++j)
2189  {
2190  QRgb* v = (QRgb*)(u + (j << 2));
2191  QRgb* vv = (QRgb*)(uu + (j << 2));
2192  QRgb* vvv = (QRgb*)(uuu + (j << 2));
2193  if(qAlpha(*v) == 0)
2194  {
2195  *vv = qRgba(0, 0, 0, 0);
2196  *vvv = qRgba(0, 0, 0, 0);
2197  }
2198  else
2199  {
2200  int red = (int)((double)m_ptColor.red() * a + (double)qRed(*v) * b);
2201  int green = (int)((double)m_ptColor.green() * a + (double)qGreen(*v) * b);
2202  int blue = (int)((double)m_ptColor.blue() * a + (double)qBlue(*v) * b);
2203  *vv = qRgba(red, green, blue, qAlpha(*v));
2204  *vvv = qRgba(255, 255, 255, 255);
2205  }
2206  }
2207  }
2208 }
2209 
2211 {
2212  m_painter.setCompositionMode(QPainter::CompositionMode_DestinationOut);
2213  m_erase = true;
2214 }
2215 
2217 {
2218  m_painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
2219  m_erase = false;
2220 }
2221 
2222 void te::qt::widgets::Canvas::setMatrix(const QMatrix& matrix )
2223 {
2224  m_matrix = matrix;
2225 
2226  m_painter.setMatrix(m_matrix);
2227 }
void freeImage(char *img) const
This is the method that you should use to release an image generated by the canvas.
Definition: Canvas.cpp:1057
void getRgba(int *r, int *g, int *b, int *a=0) const
It gets the color value.
Definition: RGBAColor.h:315
std::size_t getNumRings() const
It returns the number of rings in this CurvePolygon.
Definition: CurvePolygon.h:153
std::size_t getNumGeometries() const
It returns the number of geometries in this GeometryCollection.
ImageType
This enum specifies the possible input and output image formats supported by the canvas API...
Definition: Enums.h:38
void setPolygonContourDashStyle(te::map::LineDashStyle style)
It sets the polygon contour dash style.
Definition: Canvas.cpp:1956
void updateAlpha(QImage &img, const int &opacity)
It updates the alpha channel of the given image using the given opacity value.
Definition: Canvas.cpp:2142
void setTextStrikeOut(bool b)
It sets the text strike out flag.
Definition: Canvas.cpp:1485
void clear()
It clears the canvas content and fills with the background color.
Definition: Canvas.cpp:222
MultiPolygon is a MultiSurface whose elements are Polygons.
Definition: MultiPolygon.h:50
Canvas()
Constructor.
Definition: Canvas.h:101
TextDecoration getDecoration() const
It returns the font decoration.
Definition: Attributes.cpp:164
void setPointPatternOpacity(int opacity)
It sets the point pattern opacity.
Definition: Canvas.cpp:1611
A canvas built on top of Qt.
const double & getLetterSpacing() const
It returns the letter spacing.
Definition: Attributes.cpp:174
void setDevice(QPaintDevice *device, bool takeOwnerShip)
It sets new device as QPrinter.
Definition: Canvas.cpp:2104
FontWeight
Font weight for drawing text.
Definition: Enums.h:50
te::color::RGBAColor getBackgroundColor() const
It returns the canvas background color.
Definition: Canvas.cpp:217
void setPolygonFillPattern(te::color::RGBAColor **pattern, int ncols, int nrows)
It sets the polygon fill pattern.
Definition: Canvas.cpp:1739
const double & getTextOpacity() const
It returns the text opacity.
Definition: Attributes.cpp:204
void setPolygonPatternWidth(int w)
It sets the polygon pattern width.
Definition: Canvas.cpp:1815
int getRed() const
It returns the red component color value (a value from 0 to 255).
Definition: RGBAColor.h:295
void drawImage(char *src, std::size_t size, te::map::ImageType t)
It draws the src image over the canvas.
Definition: Canvas.cpp:1062
void drawPixel(int x, int y)
It sets a pixel using the point pen.
Definition: Canvas.cpp:1205
Coord2D * getCoordinates() const
It returns a pointer to the internal array of coordinates.
Definition: LineString.h:456
static const char * sm_xpmFmt
Definition: Globals.h:56
QColor m_bgColor
Canvas background color. Defaults: white fully transparent.
Definition: Canvas.h:478
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
Definition: Raster.cpp:213
const std::string & getFamily() const
It returns the font family.
Definition: Attributes.cpp:124
LineJustification
Line justification for drawing multi line text.
Definition: Enums.h:106
FontStyle
Font style for drawing text.
Definition: Enums.h:38
static const char * sm_jpegFmt
Definition: Globals.h:53
void setTextWeight(te::at::FontWeight weight)
It sets the text weight.
Definition: Canvas.cpp:1460
void setTextContourOpacity(int opacity)
It sets the text contour opacity.
Definition: Canvas.cpp:1510
const std::string & getTextColor() const
It returns the text color.
Definition: Attributes.cpp:194
const double & getPointSize() const
It returns the font point size.
Definition: Attributes.cpp:134
int getBlue() const
It returns the blue component color value (a value from 0 to 255).
Definition: RGBAColor.h:305
double m_urx
Upper right corner x-coordinate.
Definition: Envelope.h:346
void setPolygonFillColor(const te::color::RGBAColor &color)
It sets the color used to fill the draw of polygon geometries.
Definition: Canvas.cpp:1732
int getGreen() const
It returns the green component color value (a value from 0 to 255).
Definition: RGBAColor.h:300
const std::string & getTextStrokeColor() const
It returns the text stroke color.
Definition: Attributes.cpp:214
double getWidth() const
It returns the envelope width.
Definition: Envelope.h:443
void setTextDecorationColor(const te::color::RGBAColor &color)
It sets the text color for drawing text decoration.
Definition: Canvas.cpp:1490
void setLinePattern(te::color::RGBAColor **pattern, int ncols, int nrows)
It sets the line pattern.
Definition: Canvas.cpp:1634
A Text may contain 1 or more Text Elements.
Definition: Text.h:51
void setPolygonContourColor(const te::color::RGBAColor &color)
It sets the pen color used to draw the boundary of polygon geometries.
Definition: Canvas.cpp:1862
void setNormalMode()
It sets the painter to normal copy source to destination mode.
Definition: Canvas.cpp:2216
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
void setTextOpacity(int opacity)
It sets the text opacity.
Definition: Canvas.cpp:1430
void setTextContourWidth(int width)
It sets the text contour width.
Definition: Canvas.cpp:1516
HorizontalAlignment getHorizontalAlignment() const
It returns the horizontal text alignment.
Definition: Attributes.cpp:244
void setEraseMode()
It sets the painter to erase mode.
Definition: Canvas.cpp:2210
void createPointPatterns()
It creates two patterns. A pattern used to draw selected objects and the other used to erase this pat...
Definition: Canvas.cpp:2159
void setPointPatternRotation(const double &angle)
It sets the point pattern rotation. Rotation is made ​​from the center of the pattern.
Definition: Canvas.cpp:1605
void draw(const te::gm::Geometry *geom)
It draws the geometry on canvas.
Definition: Canvas.cpp:296
const Attributes * getAttributes() const
it returns the text attributes.
Definition: Element.cpp:102
const te::gm::Geometry * getLeaderLine() const
it returns the text leader line.
Definition: Element.cpp:91
~Canvas()
Destructor.
Definition: Canvas.cpp:131
FontStyle getStyle() const
It returns the font style.
Definition: Attributes.cpp:144
void setTextJustification(te::at::LineJustification just)
It sets the text justification for multi line text.
Definition: Canvas.cpp:1521
QMatrix getMatrix()
It returns the matrix.
Definition: Canvas.cpp:2123
AlignType
This enum contains values to control the alignment of components (like Canvas and MapDisplay)...
Definition: Enums.h:124
TextDecoration
Text decoration for drawing text.
Definition: Enums.h:68
LineCapStyle
This enum encodes enumerated values telling how line strings should be capped (at the two ends of the...
Definition: Enums.h:71
QPainter m_painter
The painter used to draw geometric objects.
Definition: Canvas.h:474
A LinearRing is a LineString that is both closed and simple.
Definition: LinearRing.h:53
void setFontFamily(const std::string &family)
It sets the text font family.
Definition: Canvas.cpp:1436
void setTextStretch(std::size_t stretch)
It sets the text stretch.
Definition: Canvas.cpp:1470
const char * GetFormat(te::map::ImageType t)
It returns the file format as a NULL terminated string.
Definition: Utils.h:75
void setPointWidth(int w)
It sets the point width. If point has a patterns, this pattern is scaled to width.
Definition: Canvas.cpp:1544
static const char * sm_xbmFmt
Definition: Globals.h:57
void setPolygonContourPatternRotation(const double &angle)
It sets the polygon contour pattern rotation.
Definition: Canvas.cpp:1926
void setRenderHint(QPainter::RenderHint hint, bool on=true)
Sets the given render hint on the canvas painter if on is true; otherwise clears the render hint...
Definition: Canvas.cpp:2128
void setWindow(const double &llx, const double &lly, const double &urx, const double &ury)
It sets the world (or window) coordinates area (supposing a cartesian reference system).
Definition: Canvas.cpp:147
MultiPoint is a GeometryCollection whose elements are restricted to points.
Definition: MultiPoint.h:50
double m_llx
Lower left corner x-coordinate.
Definition: Envelope.h:344
QImage * getImage() const
It returns the internal image used to draw geographical objects.
Definition: Canvas.cpp:2091
LineString is a curve with linear interpolation between points.
Definition: LineString.h:62
QPaintDevice * getDevice() const
It returns the internal device used to draw geographical objects.
Definition: Canvas.cpp:2099
HorizontalAlignment
Horizontal alignment for drawing text.
Definition: Enums.h:81
static const char * sm_pngFmt
Definition: Globals.h:52
const double & getY() const
It returns the Point y-coordinate value.
Definition: Point.h:150
A point with x and y coordinate values.
Definition: Point.h:50
void setPoint(std::size_t i, const double &x, const double &y)
It sets the value of the specified point.
Definition: LineString.cpp:353
VerticalAlignment getVerticalAlignment() const
It returns the vertical text alignment.
Definition: Attributes.cpp:254
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
void setLineWidth(int w)
It sets the line width.
Definition: Canvas.cpp:1725
void setPointColor(const te::color::RGBAColor &color)
It sets the point drawing color.
Definition: Canvas.cpp:1530
An abstract class for raster data strucutures.
Definition: Raster.h:71
virtual te::dt::AbstractData * clone() const
It clones the point.
Definition: Point.cpp:71
void calcAspectRatio(double &llx, double &lly, double &urx, double &ury, const te::map::AlignType hAlign=te::map::Center, const te::map::AlignType vAlign=te::map::Center)
It calculates the best aspect ratio for world (or window) coordinates area (supposing a cartesian ref...
Definition: Canvas.cpp:160
unsigned int getNumberOfRows() const
Returns the raster number of rows.
Definition: Raster.cpp:208
void setMatrix(const QMatrix &matrix)
Definition: Canvas.cpp:2222
void setLineColor(const te::color::RGBAColor &color)
It sets the pen color used to draw line geometries.
Definition: Canvas.cpp:1620
const std::vector< Element * > & getElements() const
It returns the elements.
Definition: Text.cpp:85
const double & getLineSpacing() const
It returns the multi line spacing.
Definition: Attributes.cpp:274
void resize(int w, int h)
It adjusts the canvas size (width and height).
Definition: Canvas.cpp:255
void setTextContourColor(const te::color::RGBAColor &color)
It sets the text contour (outline) drawing color.
Definition: Canvas.cpp:1498
int getAlpha() const
It returns the alpha component color value (a value from 0 to 255).
Definition: RGBAColor.h:310
void setPolygonContourWidth(int w)
It sets the polygon contour width.
Definition: Canvas.cpp:1919
void drawText(int x, int y, const std::string &txt, float angle=0.0, te::at::HorizontalAlignment hAlign=te::at::Start, te::at::VerticalAlignment vAlign=te::at::Baseline)
It draws a text.
Definition: Canvas.cpp:1224
void setTextDecorationWidth(int width)
It sets the width for drawing text decoration.
Definition: Canvas.cpp:1494
std::size_t getNPoints() const
It returns the number of points (vertexes) in the linestring.
Definition: LineString.h:193
void setTextStyle(te::at::FontStyle style)
It sets the text style.
Definition: Canvas.cpp:1455
const double & getTextStrokeOpacity() const
It returns the text stroke opacity.
Definition: Attributes.cpp:234
te::gm::Polygon * getTextBoundary(int x, int y, const std::string &txt, float angle=0.0, te::at::HorizontalAlignment hAlign=te::at::Start, te::at::VerticalAlignment vAlign=te::at::Baseline)
It returns the text boundary (its enclose rectangle).
Definition: Canvas.cpp:1404
void setTextUnderline(bool b)
It sets the text underline flag.
Definition: Canvas.cpp:1475
const std::string & getValue() const
it returns the text string.
Definition: Element.cpp:69
GeomType getGeomTypeId() const
It returns the geometry subclass type identifier.
Definition: Geometry.h:178
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
FontWeight getWeight() const
It returns the font weight.
Definition: Attributes.cpp:154
void setLinePatternRotation(const double &angle)
It sets the line pattern rotation. Rotation is made ​​from the center of the pattern.
Definition: Canvas.cpp:1675
virtual void getValue(unsigned int c, unsigned int r, double &value, std::size_t b=0) const
Returns the attribute value of a band of a cell.
Definition: Raster.cpp:228
double m_lly
Lower left corner y-coordinate.
Definition: Envelope.h:345
Geometry * getGeometryN(std::size_t i) const
It returns the n-th geometry in this GeometryCollection.
int getWidth() const
It returns the canvas width.
Definition: Canvas.cpp:286
void setLineCapStyle(te::map::LineCapStyle style)
It sets the line cap style.
Definition: Canvas.cpp:1715
MultiLineString is a MultiCurve whose elements are LineStrings.
void setTextOverline(bool b)
It sets the text overline flag.
Definition: Canvas.cpp:1480
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:50
LineDashStyle
This enum encodes enumerated values telling how lines should be drawn. e.g. as a plain line or dash l...
Definition: Enums.h:55
LineJoinStyle
This enum encodes enumerated values telling how line strings should be joined (between line segments)...
Definition: Enums.h:83
QPixmap * getPixmap() const
It returns the internal pixmap used to draw geographical objects.
Definition: Canvas.cpp:2083
void setPolygonContourCapStyle(te::map::LineCapStyle style)
It sets the polygon contour cap style.
Definition: Canvas.cpp:1966
VerticalAlignment
Vertical alignment for drawing text.
Definition: Enums.h:93
void setTextMultiLineSpacing(int spacing)
It sets the multi line text spacing.
Definition: Canvas.cpp:1525
TEQTWIDGETSEXPORT QImage * GetImage(te::color::RGBAColor **img, int width, int height)
It creates a QImage from an RGBA color array.
Definition: Utils.cpp:69
double m_ury
Upper right corner y-coordinate.
Definition: Envelope.h:347
QPen m_ptPen
The pen used to draw points.
Definition: Canvas.h:481
const te::gm::Geometry * getLocation() const
it returns the text location.
Definition: Element.cpp:80
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
void setLinePatternOpacity(int opacity)
It sets the line pattern opacity.
Definition: Canvas.cpp:1691
void setPointPattern(te::color::RGBAColor **pattern, int ncols, int nrows)
It sets the point pattern.
Definition: Canvas.cpp:1565
int getHeight() const
It returns the canvas height.
Definition: Canvas.cpp:291
void setPolygonContourPattern(te::color::RGBAColor **pattern, int ncols, int nrows)
It sets the pen pattern used to draw the boundary of polygon geometries.
Definition: Canvas.cpp:1878
void setTextContourEnabled(bool b)
It controls the display of the text outline.
Definition: Canvas.cpp:1505
void setPolygonContourJoinStyle(te::map::LineJoinStyle style)
It sets the polygon contour join style.
Definition: Canvas.cpp:1971
void setPolygonPatternRotation(const double &angle)
It sets the polygon pattern rotation.
Definition: Canvas.cpp:1833
static const char * sm_bmpFmt
Definition: Globals.h:55
void setY(const double &y)
It sets the Point y-coordinate value.
Definition: Point.h:157
void save(const char *fileName, te::map::ImageType t, int quality=75, int fg=0) const
It saves the canvas content to a file image in the specified format type.
Definition: Canvas.cpp:936
It is a collection of other geometric objects.
void setLineJoinStyle(te::map::LineJoinStyle style)
It sets the line join style.
Definition: Canvas.cpp:1720
void drawContour(const te::gm::LineString *line)
It draw the polygon contour.
Definition: Canvas.cpp:727
void setLineDashStyle(te::map::LineDashStyle style)
It sets the line dash style.
Definition: Canvas.cpp:1705
void setTextColor(const te::color::RGBAColor &color)
It sets the text drawing color.
Definition: Canvas.cpp:1423
double getHeight() const
It returns the envelope height.
Definition: Envelope.h:448
const Envelope * getMBR() const
It returns the minimum bounding rectangle for the geometry in an internal representation.
Definition: Geometry.cpp:104
const double & getTextStrokeWidth() const
It returns the text stroke width.
Definition: Attributes.cpp:224
const double & getX() const
It returns the Point x-coordinate value.
Definition: Point.h:136
void setTextPointSize(double psize)
It sets the text point Size.
Definition: Canvas.cpp:1441
void setBackgroundColor(const te::color::RGBAColor &color)
It sets the canvas background color.
Definition: Canvas.cpp:207
void setPolygonPatternOpacity(int opacity)
It sets the polygon pattern opacity.
Definition: Canvas.cpp:1847
Curve * getRingN(std::size_t i) const
It returns the n-th ring for this curve polygon as a curve.
Definition: CurvePolygon.h:193
void setRingN(std::size_t i, Curve *r)
It sets the informed position ring to the new one.
void setPolygonContourPatternOpacity(int opacity)
It sets the polygon contour pattern opacity.
Definition: Canvas.cpp:1942
QColor m_ptColor
The color used to draw point (pixel) or marker.
Definition: Canvas.h:484
static const char * sm_gifFmt
Definition: Globals.h:54
int getResolution()
It returns the device resolution.
Definition: Canvas.cpp:2115