All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TextFrame.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2001-2009 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/TextFrame.h
22 
23  \brief The frame data....
24 */
25 
26 // TerraLib
27 #include "TextFrame.h"
28 #include "LayoutEditor.h"
29 
30 #include <terralib/geometry.h>
31 //#include <terralib/postgis.h>
32 //#include <terralib/dataaccess.h>
33 #include <terralib/srs.h>
35 
36 // Qt
37 #include <QtGui/QApplication>
38 #include <QtGui/QAction>
39 #include <QtGui/QMenu>
40 
41 #include <QtGui/QPainter>
42 #include <QtGui/QColor>
43 #include <QtCore/QRect>
44 #include <QtGui/QWidget>
45 #include <QtGui/QColorDialog>
46 #include <QtGui/QFontDialog>
47 #include <QtGui/QInputDialog>
48 #include <QtGui/QMenu>
49 #include <QtGui/QAction>
50 #include <QToolTip>
51 #include <QtGui/QResizeEvent>
52 #include <QtGui/QBoxLayout>
53 #include <QtCore/QCoreApplication>
54 #include <QtCore/qmath.h>
55 
56 te::qt::widgets::TextFrame::TextFrame(const QPointF& p, const QString& txt, const int& pointSize, te::qt::widgets::LayoutEditor* me, Qt::WindowFlags f) :
57  te::qt::widgets::Frame(me, f),
58  m_cor(Qt::magenta),
59  m_point(p),
60  m_angle(0),
61  m_family("Linux Libertine G"),
62  m_stretch(100),
63  m_align(Qt::AlignHCenter),
64  m_style(QFont::StyleNormal),
65  m_overline(false),
66  m_strikeOut(false),
67  m_underline(false),
68  m_letterSpacing(100),
69  m_wordSpacing(0),
70  m_capitalization(QFont::MixedCase),
71  m_weight(QFont::Normal),
72  m_text(txt)
73 {
74  setWindowTitle("TextFrame");
75  setMouseTracking(true);
76  //m_layoutEditor = (te::qt::widgets::LayoutEditor*)(parent->parent());
77  //QMatrix matrix = m_layoutEditor->getMatrixPaperViewToVp();
78  //QRectF pRect = matrix.mapRect(m_layoutEditor->getPaperViewRect());
79  m_font = new QFont(m_family);
80  m_font->setStretch(m_stretch);
81  m_font->setStyle(m_style);
82  m_font->setOverline(m_overline);
83  m_font->setStrikeOut(m_strikeOut);
84  m_font->setUnderline(m_underline);
85  m_font->setLetterSpacing(QFont::PercentageSpacing, m_letterSpacing);
86  m_font->setWordSpacing(m_wordSpacing);
87  m_font->setCapitalization(m_capitalization);
88  m_font->setWeight(m_weight);
89 
90  setPointSize(pointSize);
91  adjust();
92 
93  show();
94  createMenu();
95 }
96 
98  te::qt::widgets::Frame(rhs.m_layoutEditor, rhs.windowFlags()),
99  m_cor(rhs.m_cor),
100  m_point(rhs.m_point + QPointF(20, 20)),
101  m_angle(rhs.m_angle),
102  m_family(rhs.m_family),
103  m_stretch(rhs.m_stretch),
104  m_align(rhs.m_align),
105  m_style(rhs.m_style),
106  m_overline(rhs.m_overline),
107  m_strikeOut(rhs.m_strikeOut),
108  m_underline(rhs.m_underline),
109  m_letterSpacing(rhs.m_letterSpacing),
110  m_wordSpacing(rhs.m_wordSpacing),
111  m_capitalization(rhs.m_capitalization),
112  m_weight(rhs.m_weight),
113  m_text(rhs.m_text),
114  m_pointSize(rhs.m_pointSize)
115 {
117  setWindowTitle("TextFrame");
118  setMouseTracking(true);
119 
120  //m_layoutEditor = rhs.m_layoutEditor,
121 
122  m_font = new QFont(*rhs.m_font);
123  m_font->setStretch(m_stretch);
124  m_font->setStyle(m_style);
125  m_font->setOverline(m_overline);
126  m_font->setStrikeOut(m_strikeOut);
127  m_font->setUnderline(m_underline);
128  m_font->setLetterSpacing(QFont::PercentageSpacing, m_letterSpacing);
129  m_font->setWordSpacing(m_wordSpacing);
130  m_font->setCapitalization(m_capitalization);
131  m_font->setWeight(m_weight);
132  m_font->setFamily(m_family);
133 
134  adjust();
135 
136  show();
137  createMenu();
138 }
139 
141 {
142  hide();
143  delete m_font;
144  delete m_setTextAction;
145  delete m_setFamilyAction;
146  delete m_setColorAction;
147  delete m_showTooTipAction;
148  delete m_hideTooTipAction;
149  delete m_menu;
150 }
151 
153 {
154  if(this != &rhs)
155  {
157  setWindowTitle("TextFrame");
158  m_cor = rhs.m_cor;
159  m_point = rhs.m_point;
160  m_angle = rhs.m_angle;
161  m_family = rhs.m_family;
162  m_stretch = rhs.m_stretch;
163  m_align = rhs.m_align;
164  m_style = rhs.m_style;
165  m_overline = rhs.m_overline;
166  m_strikeOut = rhs.m_strikeOut;
167  m_underline = rhs.m_underline;
168  m_letterSpacing = rhs.m_letterSpacing;
169  m_wordSpacing = rhs.m_wordSpacing;
170  m_capitalization = rhs.m_capitalization;
171  m_weight = rhs.m_weight;
172  m_text = rhs.m_text;
173  m_pointSize = rhs.m_pointSize;
174  m_font = new QFont(*rhs.m_font);
175  adjust();
176 
177  show();
178  createMenu();
179  }
180 
181  return *this;
182 }
183 
185 {
186  m_menu = new QMenu(this);
187  m_setFamilyAction = m_menu->addAction("Font Family...");
188  m_setColorAction = m_menu->addAction("Text Color...");
189  m_setTextAction = m_menu->addAction("Change Text...");
190  m_showTooTipAction = m_menu->addAction("Show Tool Tip");
191  m_hideTooTipAction = m_menu->addAction("Hide Tool Tip");
192 }
193 
195 {
196  m_text = t;
197 }
198 
200 {
201  return m_text;
202 }
203 
205 {
206  return m_frameRect;
207 }
208 
210 {
211  return &m_pixmap;
212 }
213 
215 {
216  setPointSize(m_pointSize);
217 
218  if(m_text.isEmpty())
219  m_text = " ";
220 
221  QPixmap pix(10, 10);
222  QPainter painter(&pix);
223  painter.setFont(*m_font);
224 
225  // nao mude nada na linha abaixo
226  rt = painter.boundingRect(QRect(0, 0, 100000, 100000), Qt::AlignLeft, m_text); // nao mude nada aqui!!!
227  // nao mude nada na linha acima
228 
229  painter.end();
230 }
231 
233 {
234  adjustSize(m_point);
235 }
236 
238 {
239  m_point = p;
240  QMatrix matrix = m_layoutEditor->getMatrixPaperViewToVp();
241 
242  QRectF br;
243  calculateTextRect(br);
244  QRectF r = matrix.inverted().mapRect(br);
245  m_frameRect = QRectF(m_point.x(), m_point.y(), r.width(), r.height());
246 
247  // calcular o tamanho do widget
248  r = matrix.mapRect(m_frameRect);
249  QMatrix m;
250  m.rotate(m_angle);
251  m.translate(-r.center().x(), -r.center().y());
252  QPolygon poly = m.mapToPolygon(r.toRect());
253  m.reset();
254  m.translate(r.center().x(), r.center().y());
255  poly = m.map(poly);
256  QRect widgetRec = poly.boundingRect();
257 
258  // aumente o tamanho do pixmap para se casar com o widget
259  m_pixmap = QPixmap(widgetRec.width() + 1, widgetRec.height() + 2);
260  m_pixmap.fill(Qt::transparent);
261 
262  QWidget::resize(widgetRec.width(), widgetRec.height());
263  QWidget::move(widgetRec.left(), widgetRec.top());
264 
265  // calculate selection points
266  QRectF rec = matrix.mapRect(m_frameRect);
267 
268  double pw = rec.width();
269  double ph = rec.height();
270  int ipw = qRound(pw);
271  int iph = qRound(ph);
272  int ipw2 = qRound(pw/2.);
273  int iph2 = qRound(ph/2.);
274  double w = 5;
275  double h = 5;
276 
277  if(pw < w*5)
278  w = pw / 5.;
279  if(ph < h*5)
280  h = ph / 5.;
281 
282  int iw = qRound(w);
283  int ih = qRound(h);
284  int iw2 = qRound(w/2.);
285  int ih2 = qRound(h/2.);
286 
287  m_recSel1 = QRect(0, 0, iw, ih);
288  m_recSel2 = QRect(ipw2 - iw2, 0, iw, ih);
289  m_recSel3 = QRect(ipw - iw, 0, iw, ih);
290  m_recSel4 = QRect(ipw - iw, iph2 - ih2, iw, ih);
291  m_recSel5 = QRect(ipw - iw, iph - ih, iw, ih);
292  m_recSel6 = QRect(ipw2 - iw2, iph - ih, iw, ih);
293  m_recSel7 = QRect(0, iph - ih, iw, ih);
294  m_recSel8 = QRect(0, iph2 - ih2, iw, ih);
295  m_recSel10 = QRect(0, 0, ipw, iph);
296 
297  draw();
298 }
299 
300 // NOTA: apos setar qualquer propriedade chame o metodo adjustSize() para desenhar o texto
301 
303 {
304  return m_family;
305 }
306 
308 {
309  m_family = family;
310  m_font->setFamily(m_family);
311 }
312 
314 {
315  return m_pointSize;
316 }
317 
319 {
320  m_pointSize = pointSize;
321 
322  QMatrix matrix = m_layoutEditor->getMatrixPaperViewToVp();
323  double h = m_pointSize * 25.4 / 72.;
324  double vtam = h * matrix.m11();
325  int ps = qRound(vtam);
326  if(ps < 1)
327  ps = 1;
328 
329  m_font->setPixelSize(ps);
330 }
331 
333 {
334  return m_stretch;
335 }
336 
338 {
339  m_stretch = s;
340  m_font->setStretch(m_stretch);
341 }
342 
344 {
345  return m_align;
346 }
347 
349 {
350  m_align = align;
351 }
352 
354 {
355  return m_style;
356 }
357 
358 void te::qt::widgets::TextFrame::setStyle(QFont::Style style)
359 {
360  m_style = style;
361  m_font->setStyle(m_style);
362 }
363 
365 {
366  return m_weight;
367 }
368 
369 void te::qt::widgets::TextFrame::setWeight(QFont::Weight weight)
370 {
371  m_weight = weight;
372  m_font->setWeight(m_weight);
373 }
374 
376 {
377  return m_capitalization;
378 }
379 
380 void te::qt::widgets::TextFrame::setCapitalization(QFont::Capitalization cap)
381 {
382  m_capitalization = cap;
383  m_font->setCapitalization(m_capitalization);
384 }
385 
387 {
388  return m_overline;
389 }
390 
392 {
393  m_overline = b;
394  m_font->setOverline(m_overline);
395 }
396 
398 {
399  return m_strikeOut;
400 }
401 
403 {
404  m_strikeOut = b;
405  m_font->setStrikeOut(m_strikeOut);
406 }
407 
409 {
410  return m_underline;
411 }
412 
414 {
415  m_underline = b;
416  m_font->setUnderline(m_underline);
417 }
418 
420 {
421  return m_letterSpacing;
422 }
423 
425 {
426  m_letterSpacing = spacing;
427  m_font->setLetterSpacing(QFont::PercentageSpacing, m_letterSpacing);
428 }
429 
431 {
432  return m_wordSpacing;
433 }
434 
436 {
437  m_wordSpacing = spacing;
438  m_font->setWordSpacing(m_wordSpacing);
439 }
440 
442 {
443  QRectF rec = m_layoutEditor->getMatrix().mapRect(m_frameRect);
444 
445  QPainter painter(&m_pixmap);
446  painter.setPen(m_cor);
447 // painter.setBrush(Qt::cyan);
448  painter.setFont(*m_font);
449 
450  double rad = fabs(m_angle * 3.141593 / 180);
451  QRect br(0, 0, qRound(rec.width()), qRound(rec.height()));
452 
453  QMatrix matrix = getAuxMatrix();
454  painter.setMatrix(matrix);
455  painter.drawText(br, m_align, m_text);
456  painter.end();
457 
458  update();
459 }
460 
462 {
463  // faz tudo em coordenadas do dispositivo
464 
465  QPixmap* pixmap = m_layoutEditor->getDraftPixmap();
466  QPainter painter(pixmap);
467  painter.setBrush(Qt::NoBrush);
468  painter.setPen(Qt::red);
469 
470  // erase old
471  if(m_copyAuxFrameRect.isValid())
472  {
473  QRectF rec = m_copyAuxFrameRect;
474  rec.moveCenter(QPointF(0, 0));
475 
476  painter.setCompositionMode(QPainter::CompositionMode_DestinationOut);
477  QMatrix matrix;
478  matrix.translate(m_copyAuxFrameRect.center().x(), m_copyAuxFrameRect.center().y());
479  matrix.rotate(m_auxAngle);
480  painter.setMatrix(matrix);
481  painter.drawRect(rec);
482  }
483 
484  // show new
485  QRectF rec = m_auxFrameRect;
486  rec.moveCenter(QPointF(0, 0));
487 
488  painter.setCompositionMode(QPainter::CompositionMode_DestinationOver);
489  QMatrix matrix;
490  matrix.translate(m_auxFrameRect.center().x(), m_auxFrameRect.center().y());
491  matrix.rotate(m_angle);
492  painter.setMatrix(matrix);
493  painter.drawRect(rec);
494  painter.end();
495 
496  m_auxAngle = m_angle;
497  m_copyAuxFrameRect = m_auxFrameRect;
498 
499  m_layoutEditor->update();
500 }
501 
503 {
504  QPainter painter(this);
505  painter.drawPixmap(0, 0, m_pixmap);
506 }
507 
509 {
510  m_pixmap.fill(Qt::transparent);
511  draw();
512 
513  QPainter painter(&m_pixmap);
514  QMatrix matrix = getAuxMatrix();
515  painter.setMatrix(matrix);
516 
517  painter.setPen(Qt::blue);
518  painter.setBrush(QColor(0, 0, 255, 24));
519  painter.drawRect(QRect(m_recSel10.left(), m_recSel10.top(), m_recSel10.width(), m_recSel10.height()-1));
520 
521  // draw selection points
522  painter.setBrush(QColor(0, 0, 255, 150));
523  painter.drawRect(m_recSel1);
524  painter.drawRect(m_recSel3);
525  painter.drawRect(m_recSel5);
526  painter.drawRect(m_recSel7);
527 
528  painter.drawRect(m_recSel2);
529  painter.drawRect(m_recSel6);
530 
531  painter.drawRect(m_recSel4);
532  painter.drawRect(m_recSel8);
533 
534  if(!(fabs(m_angle) == 0 || fabs(m_angle) == 90 || fabs(m_angle) == 180) || (fabs(m_angle) == 270 || fabs(m_angle) == 360))
535  {
536  painter.resetMatrix();
537  painter.setBrush(QColor(0, 0, 255, 24));
538  painter.drawRect(QRect(0, 0, width()-1, height()-1));
539  }
540 
541  painter.end();
542  update();
543 }
544 
546 {
547  m_pixmap.fill(Qt::transparent);
548  draw();
549  update();
550 }
551 
553 {
554  m_selected = 0;
555 
556  QMatrix matrix = getAuxMatrix();
557 
558  if(matrix.mapToPolygon(m_recSel1).containsPoint(p, Qt::OddEvenFill))
559  m_selected = 1;
560  else if(matrix.mapToPolygon(m_recSel2).containsPoint(p, Qt::OddEvenFill))
561  m_selected = 2;
562  else if(matrix.mapToPolygon(m_recSel3).containsPoint(p, Qt::OddEvenFill))
563  m_selected = 3;
564  else if(matrix.mapToPolygon(m_recSel4).containsPoint(p, Qt::OddEvenFill))
565  m_selected = 4;
566  else if(matrix.mapToPolygon(m_recSel5).containsPoint(p, Qt::OddEvenFill))
567  m_selected = 5;
568  else if(matrix.mapToPolygon(m_recSel6).containsPoint(p, Qt::OddEvenFill))
569  m_selected = 6;
570  else if(matrix.mapToPolygon(m_recSel7).containsPoint(p, Qt::OddEvenFill))
571  m_selected = 7;
572  else if(matrix.mapToPolygon(m_recSel8).containsPoint(p, Qt::OddEvenFill))
573  m_selected = 8;
574  else if(matrix.mapToPolygon(m_recSel10).containsPoint(p, Qt::OddEvenFill))
575  m_selected = 10;
576 }
577 
579 {
580  QRectF rec = m_layoutEditor->getMatrix().mapRect(m_frameRect);
581  double widHeight = height();
582  double widWidth = width();
583  double rad = m_angle * 3.141593 / 180;
584  QMatrix matrix;
585 
586  if(m_angle >= 0 && m_angle <= 90)
587  {
588  double w = rec.height() * sin(rad);
589  matrix.translate(w, 0);
590  }
591  else if(m_angle >= 90 && m_angle <= 180)
592  {
593  double h = rec.height() * cos(rad);
594  matrix.translate(widWidth, -h);
595  }
596  else if(m_angle >= 180 && m_angle <= 270)
597  {
598  double w = rec.height() * sin(rad);
599  matrix.translate(widWidth + w, widHeight);
600  }
601  else
602  {
603  double h = rec.height() * cos(rad);
604  matrix.translate(0, widHeight - h);
605  }
606  matrix.rotate(m_angle);
607  return matrix;
608 }
609 
611 {
612  QMatrix matrix = getAuxMatrix();
613  QPolygon pol;
614  QPoint c;
615 
616  if(m_selected == 1)
617  c = matrix.map(m_recSel1.center());
618  else if(m_selected == 2)
619  c = matrix.map(m_recSel2.center());
620  else if(m_selected == 3)
621  c = matrix.map(m_recSel3.center());
622  else if(m_selected == 4)
623  c = matrix.map(m_recSel4.center());
624  else if(m_selected == 5)
625  c = matrix.map(m_recSel5.center());
626  else if(m_selected == 6)
627  c = matrix.map(m_recSel6.center());
628  else if(m_selected == 7)
629  c = matrix.map(m_recSel7.center());
630  else if(m_selected == 8)
631  c = matrix.map(m_recSel8.center());
632  else if(m_selected == 10)
633  c = matrix.map(m_recSel10.center());
634 
635  return c;
636 }
637 
639 {
640  //QSize size = m_layoutEditor->getPaperSize();
641  //QRectF page(0, 0, size.width(), size.height());
642  //QMatrix matrix = m_layoutEditor->getMatrixPaperViewToVp();
643  //QRectF r = matrix.inverted().mapRect(m_auxFrameRect);
644  //
645  //if(page.contains(r) == false)
646  //{
647  // if(m_selected == 10)
648  // {
649  // if(r.top() < page.top())
650  // r = QRectF(r.left(), page.top(), r.width(), r.height());
651  // if(r.bottom() > page.bottom())
652  // r = QRectF(r.left(), page.bottom() - r.height(), r.width(), r.height());
653  // if(r.left() < page.left())
654  // r = QRectF(page.left(), r.top(), r.width(), r.height());
655  // if(r.right() > page.right())
656  // r = QRectF(page.right() - r.width(), r.top(), r.width(), r.height());
657  // }
658  // else
659  // {
660  // if(r.top() < page.top())
661  // r.setTop(page.top());
662  // if(r.bottom() > page.bottom())
663  // r.setBottom(page.bottom());
664  // if(r.left() < page.left())
665  // r.setLeft(page.left());
666  // if(r.right() > page.right())
667  // r.setRight(page.right());
668  // }
669  // m_auxFrameRect = matrix.mapRect(r);
670  //}
671 }
672 
674 {
675  QMatrix matrix = m_layoutEditor->getMatrixPaperViewToVp();
676  QRect rec = matrix.mapRect(m_frameRect).toRect();
677  QPoint center = rec.center();
678  return mapToGlobal(center);
679  //QWidget* parent = static_cast<QWidget*>(m_layoutEditor);
680  //while(parent)
681  //{
682  // center += QPoint(parent->x(), parent->y());
683  // parent = static_cast<QWidget*>(parent->parent());
684  //}
685  //return center;
686 }
687 
689 {
690  QPoint ref = rect().center();
691 
692  QPoint da = p - ref;
693  double angle = 90;
694  if(da.x() != 0)
695  angle = atan((double)da.y() / (double)da.x()) * 180 / 3.141593;
696  else if(da.y() < 0)
697  angle = 270;
698 
699  if(da.x() < 0)
700  angle = 180 + angle;
701  else if(da.x() > 0 && da.y() < 0)
702  angle = 360 + angle;
703 
704  return angle;
705 }
706 
708 {
709  if(ang < 0)
710  ang += 360;
711  else if(ang > 360)
712  ang -= 360;
713 
714  if(fabs(ang) == 360)
715  ang = 0;
716 }
717 
718 void te::qt::widgets::TextFrame::toolTip(const QPoint& p, const QString& type)
719 {
720  if(m_showToolTip == false)
721  {
722  QToolTip::hideText();
723  return;
724  }
725 
726  QString rotation, stretch, pointSize, letterSpacing, wordSpacing, align, weight, style, capitalization, overline, underline, strikeOut;
727 
728  int angle = m_angle;
729  if(angle == 360)
730  angle = 0;
731  else if(angle > 180)
732  angle -= 360;
733  rotation.setNum(angle);
734  rotation = "Rotation = " + rotation + " degrees";
735 
736  stretch.setNum(m_stretch);
737  stretch = "Stretch = " + stretch + "%";
738 
739  pointSize.setNum(m_pointSize);
740  pointSize = "Point Size = " + pointSize;
741 
742  letterSpacing.setNum(qRound(m_letterSpacing));
743  letterSpacing = "Letter Spacing = " + letterSpacing + "%";
744 
745  wordSpacing.setNum(qRound(m_wordSpacing));
746  wordSpacing = "Word Spacing = " + wordSpacing;
747 
748  if(m_align == Qt::AlignLeft)
749  align = "Align = Left";
750  else if(m_align == Qt::AlignHCenter)
751  align = "Align = Center";
752  else
753  align = "Align = Right";
754 
755  if(m_weight == QFont::Light)
756  weight = "Weight = Weight Light";
757  else if(m_weight == QFont::Normal)
758  weight = "Weight = Normal Light";
759  else if(m_weight == QFont::DemiBold)
760  weight = "Weight = DemiBold Light";
761  else if(m_weight == QFont::Bold)
762  weight = "Weight = Bold Light";
763  else if(m_weight == QFont::Black)
764  weight = "Weight = Black Light";
765 
766  if(m_style == QFont::StyleNormal)
767  style = "Style = Normal";
768  else if(m_style == QFont::StyleItalic)
769  style = "Style = Italic";
770  else if(m_style == QFont::StyleOblique)
771  style = "Style = Oblique";
772 
773  if(m_capitalization == QFont::MixedCase)
774  capitalization = "Case = Mixed Case";
775  else if(m_capitalization == QFont::AllUppercase)
776  capitalization = "Case = All Uppercase";
777  else if(m_capitalization == QFont::AllLowercase)
778  capitalization = "Case = All Lowercase";
779  else if(m_capitalization == QFont::SmallCaps)
780  capitalization = "Case = Small Caps";
781  else if(m_capitalization == QFont::Capitalize)
782  capitalization = "Case = Capitalize";
783 
784  if(m_overline)
785  overline = "Overline = ON";
786  else
787  overline = "Overline = OFF";
788 
789  if(m_underline)
790  underline = "Underline = ON";
791  else
792  underline = "Underline = OFF";
793 
794  if(m_strikeOut)
795  strikeOut = "Strike Out = ON";
796  else
797  strikeOut = "Strike Out = OFF";
798 
799  if(type == "Selection")
800  {
801  if(m_selected == 1 || m_selected == 3 || m_selected == 5 || m_selected == 7)
802  QToolTip::showText(p, rotation, this);
803  else if(m_selected == 2 || m_selected == 6)
804  QToolTip::showText(p, pointSize, this);
805  else if(m_selected == 4 || m_selected == 8)
806  QToolTip::showText(p, stretch, this);
807  else if(m_selected == 10)
808  QToolTip::showText(p, "Drag to Move", this);
809  else
810  QToolTip::hideText();
811  }
812  else if(type == "Rotate")
813  QToolTip::showText(p, rotation, this);
814  else if(type == "Stretch")
815  QToolTip::showText(p, stretch, this);
816  else if(type == "PointSize")
817  QToolTip::showText(p, pointSize, this);
818  else if(type == "LetterSpacing")
819  QToolTip::showText(p, letterSpacing, this);
820  else if(type == "WordSpacing")
821  QToolTip::showText(p, wordSpacing, this);
822  else if(type == "Align")
823  QToolTip::showText(p, align, this);
824  else if(type == "Weight")
825  QToolTip::showText(p, weight, this);
826  else if(type == "Style")
827  QToolTip::showText(p, style, this);
828  else if(type == "Capitalization")
829  QToolTip::showText(p, capitalization, this);
830  else if(type == "Overline")
831  QToolTip::showText(p, overline, this);
832  else if(type == "Underline")
833  QToolTip::showText(p, underline, this);
834  else if(type == "StrikeOut")
835  QToolTip::showText(p, strikeOut, this);
836 }
837 
838 void te::qt::widgets::TextFrame::mousePressEvent(QMouseEvent* mouseEvent)
839 {
840  QMatrix matrix = m_layoutEditor->getMatrixPaperViewToVp();
841 
842  if(mouseEvent->buttons() == Qt::LeftButton)
843  {
844  // start edition
845  QPoint p = mouseEvent->pos();
846  m_pressPoint = p;
847  m_auxFrameRect = matrix.mapRect(m_frameRect);
848  m_copyAuxFrameRect = m_auxFrameRect;
849  m_auxStretch = m_stretch;
850  m_auxPointSize = m_pointSize;
851  m_auxWidth = m_auxFrameRect.width();
852  m_auxHeight = m_auxFrameRect.height();
853  m_iniAngle = m_angle;
854  m_auxAngle = m_angle;
855  m_refAngle = getAngle(p);
856  m_undo = false;
857 
858  m_layoutEditor->raiseDraftLayoutEditor();
859  }
860  else if(mouseEvent->buttons() == Qt::RightButton)
861  {
862  QPoint gp = mouseEvent->globalPos();
863  if(m_selected == 10)
864  {
865  QAction* action = m_menu->exec(gp);
866  if(action == m_setFamilyAction)
867  changeFontFamily();
868  else if(action == m_setColorAction)
869  changeTextColor();
870  else if(action == m_setTextAction)
871  changeText();
872  else if(action == m_showTooTipAction)
873  showToolTip(true);
874  else if(action == m_hideTooTipAction)
875  showToolTip(false);
876  }
877  }
878 }
879 
880 void te::qt::widgets::TextFrame::mouseMoveEvent(QMouseEvent* mouseEvent)
881 {
882  QMatrix matrix = m_layoutEditor->getMatrixPaperViewToVp();
883  QPoint p = mouseEvent->pos();
884  QPoint gp = mouseEvent->globalPos();
885 
886  if(mouseEvent->buttons() == Qt::NoButton)
887  {
888  // only moving the mouse (without press any button)
889  // search selection point
890  m_dragging = false;
891  getSelectionPoint(p);
892  setCursor();
893  toolTip(gp, "Selection");
894 
895  if(m_selected == 0)
896  {
897  m_layoutEditor->setFrameSelected(0);
898  if(!(fabs(m_angle) == 0 || fabs(m_angle) == 90 || fabs(m_angle) == 180))
899  lower(); // teste
900  return;
901  }
902  else
903  {
904  if(m_layoutEditor->getFrameSelected() != this)
905  m_layoutEditor->setFrameSelected(this);
906  }
907 
908  }
909  else if(mouseEvent->buttons() == Qt::LeftButton)
910  {
911  // mouse drag with left buttom
912  // edit from selection point
913  m_dragging = true;
914  QPoint p = mouseEvent->pos();
915  QPoint gp = mouseEvent->globalPos();
916  QPoint d = m_pressPoint - p;
917  int pointSize = m_pointSize;
918 
919  if(m_selected != 0)
920  {
921  if(m_undo == false)
922  {
923  m_layoutEditor->insertCopy2Undo(this);
924  m_undo = true;
925  }
926  if(m_selected == 1 || m_selected == 3 || m_selected == 5 || m_selected == 7) // rotate using corners
927  {
928  double beta = getAngle(p);
929  double ang = beta - m_refAngle;
930  adjustAngleRange(ang);
931 
932  m_angle = m_iniAngle + ang;
933  adjustAngleRange(m_angle);
934 
935  // resolucao angular = 1 grau
936  m_angle = qRound(m_angle);
937  toolTip(gp, "Rotate");
938  }
939  else if(m_selected == 2 || m_selected == 6) // change pointSize
940  {
941  QPoint dif = p - QPoint(width()/2, height()/2);
942  double height = 2 * qSqrt(dif.x() * dif.x() + dif.y() * dif.y());
943 
944  int ps = qRound(m_auxPointSize * height / m_auxHeight);
945  setPointSize(ps);
946  QPointF center = m_auxFrameRect.center();
947  calculateTextRect(m_auxFrameRect);
948  m_auxFrameRect.moveCenter(center);
949  toolTip(gp, "PointSize");
950  }
951  else if(m_selected == 4 || m_selected == 8) // stretch
952  {
953  QPoint dif = p - QPoint(width()/2, height()/2);
954  double width = 2 * qSqrt(dif.x() * dif.x() + dif.y() * dif.y());
955 
956  int stretch = qRound(m_auxStretch * width / m_auxWidth);
957  setStretch(stretch);
958  QPointF center = m_auxFrameRect.center();
959  calculateTextRect(m_auxFrameRect);
960  m_auxFrameRect.moveCenter(center);
961  toolTip(gp, "Stretch");
962  }
963  else // move frame text
964  {
965  m_auxFrameRect.moveCenter(m_auxFrameRect.center() - d);
966  m_pressPoint = p;
967  }
968 
969  rubberBand();
970  }
971  }
972 }
973 
975 {
976  // end edition
977  if(m_selected == 0)
978  return;
979 
980  QMatrix matrix = m_layoutEditor->getMatrixPaperViewToVp();
981  QPixmap* pixmap = m_layoutEditor->getDraftPixmap();
982  pixmap->fill(Qt::transparent);
983  verifyConstraints();
984  QPointF pp = matrix.inverted().map(m_auxFrameRect.bottomLeft());
985  adjustSize(pp);
986 
987  showSelectionPoints();
988  m_layoutEditor->lowerDraftLayoutEditor();
989  m_layoutEditor->update();
990 
991  if(m_selected != 10)
992  {
993  QPoint c = getCenterSelected();
994  cursor().setPos(mapToGlobal(c));
995  QMouseEvent e1(QEvent::MouseButtonPress, c, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
996  QApplication::sendEvent(this, &e1);
997  }
998 }
999 
1001 {
1002  if(QApplication::overrideCursor() || m_dragging)
1003  return;
1004 
1005  m_layoutEditor->setFrameSelected(this);
1006  raise();
1007  m_selected = 0;
1008 }
1009 
1011 {
1012  if(m_dragging)
1013  {
1014  if(m_selected != 0)
1015  raise();
1016  return;
1017  }
1018 
1019  m_selected = 0;
1020  m_layoutEditor->setFrameSelected(0);
1021  lower();
1022  setCursor();
1023 }
1024 
1026 {
1027  QCursor cursor;
1028 
1029  if(m_selected >= 1 && m_selected <= 8)
1030  cursor.setShape(Qt::PointingHandCursor);
1031  else if(m_selected == 10)
1032  cursor.setShape(Qt::SizeAllCursor);
1033 
1034  if(QApplication::overrideCursor())
1035  {
1036  if(QApplication::overrideCursor()->shape() != cursor.shape())
1037  {
1038  while(QApplication::overrideCursor())
1039  QApplication::restoreOverrideCursor();
1040  if(cursor.shape() != Qt::ArrowCursor)
1041  QApplication::setOverrideCursor(cursor);
1042  }
1043  }
1044  else if(cursor.shape() != Qt::ArrowCursor)
1045  QApplication::setOverrideCursor(cursor);
1046 }
1047 
1049 {
1050  bool ok;
1051  QFont auxFont(*m_font);
1052  auxFont.setPointSize(m_pointSize); // use point size original
1053  // nota: point size = 72 é o maximo da lista na interface do QT,
1054  // mas, o LineEdit é do tipo write, então voce pode mudar.
1055 
1056  QFont font = QFontDialog::getFont(&ok, auxFont, this);
1057  if (ok)
1058  {
1059  setFamily(font.family());
1060  setPointSize(font.pointSize());
1061  setStyle(font.style());
1062  setWeight((QFont::Weight)font.weight());
1063  setStrikeOut(font.strikeOut());
1064  setUnderline(font.underline());
1065  adjust();
1066  }
1067 }
1068 
1070 {
1071  QColor color = QColorDialog::getColor(m_cor, this, "Set Text Color", QColorDialog::ShowAlphaChannel);
1072  if(color.isValid())
1073  {
1074  m_cor = color;
1075  adjust();
1076  }
1077 }
1078 
1080 {
1081  bool ok;
1082  QString text = QInputDialog::getText(this, "Change Text", "New Text", QLineEdit::Normal, m_text, &ok);
1083  if(text.isEmpty() == false && ok)
1084  {
1085  //char c;
1086  //int i = 0;
1087  //while(i < text.length())
1088  //{
1089  // c = text[i].toAscii();
1090  // i++;
1091  //}
1092  m_text = text;
1093  adjust();
1094  }
1095 }
void calculateTextRect(QRectF &)
Definition: TextFrame.cpp:214
void mousePressEvent(QMouseEvent *)
Definition: TextFrame.cpp:838
void getSelectionPoint(const QPoint &p)
Definition: TextFrame.cpp:552
This file contains include headers for the Vector Geometry model of TerraLib.
TextFrame & operator=(const TextFrame &rhs)
Definition: TextFrame.cpp:152
void paintEvent(QPaintEvent *event)
Definition: TextFrame.cpp:502
QFont::Capitalization getCapitalization()
Definition: TextFrame.cpp:375
QFont::Weight getWeight()
Definition: TextFrame.cpp:364
TextFrame(const QPointF &p, const QString &s, const int &pointSize, te::qt::widgets::LayoutEditor *me, Qt::WindowFlags f=Qt::Widget)
Definition: TextFrame.cpp:56
void setWeight(QFont::Weight)
Definition: TextFrame.cpp:369
This file contains include headers for the Layout module.
A TextFrame ....
Definition: TextFrame.h:56
A canvas built on top of Qt.
void adjustAngleRange(double &)
Definition: TextFrame.cpp:707
void adjustSize(QPointF &p)
Definition: TextFrame.cpp:237
double getAngle(QPoint &)
Definition: TextFrame.cpp:688
QFont::Weight m_weight
Definition: TextFrame.h:141
void mouseMoveEvent(QMouseEvent *)
Definition: TextFrame.cpp:880
void setLetterSpacing(double)
Definition: TextFrame.cpp:424
Frame & operator=(const Frame &rhs)
Definition: Frame.cpp:70
void setStyle(QFont::Style)
Definition: TextFrame.cpp:358
void mouseReleaseEvent(QMouseEvent *)
Definition: TextFrame.cpp:974
void setCapitalization(QFont::Capitalization)
Definition: TextFrame.cpp:380
void toolTip(const QPoint &, const QString &)
Definition: TextFrame.cpp:718
QFont::Capitalization m_capitalization
Definition: TextFrame.h:140
void setText(const QString &t)
Definition: TextFrame.cpp:194