37 #include <QtGui/QApplication>
38 #include <QtGui/QAction>
39 #include <QtGui/QMenu>
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>
51 #include <QtGui/QResizeEvent>
52 #include <QtGui/QBoxLayout>
53 #include <QtCore/QCoreApplication>
54 #include <QtCore/qmath.h>
57 te::qt::widgets::
Frame(me, f),
61 m_family(
"Linux Libertine G"),
63 m_align(Qt::AlignHCenter),
64 m_style(QFont::StyleNormal),
70 m_capitalization(QFont::MixedCase),
71 m_weight(QFont::Normal),
74 setWindowTitle(
"TextFrame");
75 setMouseTracking(
true);
98 te::qt::widgets::
Frame(rhs.m_layoutEditor, rhs.windowFlags()),
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),
114 m_pointSize(rhs.m_pointSize)
117 setWindowTitle(
"TextFrame");
118 setMouseTracking(
true);
144 delete m_setTextAction;
145 delete m_setFamilyAction;
146 delete m_setColorAction;
147 delete m_showTooTipAction;
148 delete m_hideTooTipAction;
157 setWindowTitle(
"TextFrame");
174 m_font =
new QFont(*rhs.
m_font);
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");
216 setPointSize(m_pointSize);
222 QPainter painter(&pix);
223 painter.setFont(*m_font);
226 rt = painter.boundingRect(QRect(0, 0, 100000, 100000), Qt::AlignLeft, m_text);
240 QMatrix matrix = m_layoutEditor->getMatrixPaperViewToVp();
243 calculateTextRect(br);
244 QRectF r = matrix.inverted().mapRect(br);
245 m_frameRect = QRectF(m_point.x(), m_point.y(), r.width(), r.height());
248 r = matrix.mapRect(m_frameRect);
251 m.translate(-r.center().x(), -r.center().y());
252 QPolygon poly = m.mapToPolygon(r.toRect());
254 m.translate(r.center().x(), r.center().y());
256 QRect widgetRec = poly.boundingRect();
259 m_pixmap = QPixmap(widgetRec.width() + 1, widgetRec.height() + 2);
260 m_pixmap.fill(Qt::transparent);
262 QWidget::resize(widgetRec.width(), widgetRec.height());
263 QWidget::move(widgetRec.left(), widgetRec.top());
266 QRectF rec = matrix.mapRect(m_frameRect);
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.);
284 int iw2 = qRound(w/2.);
285 int ih2 = qRound(h/2.);
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);
310 m_font->setFamily(m_family);
320 m_pointSize = pointSize;
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);
329 m_font->setPixelSize(ps);
340 m_font->setStretch(m_stretch);
361 m_font->setStyle(m_style);
372 m_font->setWeight(m_weight);
377 return m_capitalization;
382 m_capitalization = cap;
383 m_font->setCapitalization(m_capitalization);
394 m_font->setOverline(m_overline);
405 m_font->setStrikeOut(m_strikeOut);
416 m_font->setUnderline(m_underline);
421 return m_letterSpacing;
426 m_letterSpacing = spacing;
427 m_font->setLetterSpacing(QFont::PercentageSpacing, m_letterSpacing);
432 return m_wordSpacing;
437 m_wordSpacing = spacing;
438 m_font->setWordSpacing(m_wordSpacing);
443 QRectF rec = m_layoutEditor->getMatrix().mapRect(m_frameRect);
445 QPainter painter(&m_pixmap);
446 painter.setPen(m_cor);
448 painter.setFont(*m_font);
450 double rad = fabs(m_angle * 3.141593 / 180);
451 QRect br(0, 0, qRound(rec.width()), qRound(rec.height()));
453 QMatrix matrix = getAuxMatrix();
454 painter.setMatrix(matrix);
455 painter.drawText(br, m_align, m_text);
465 QPixmap* pixmap = m_layoutEditor->getDraftPixmap();
466 QPainter painter(pixmap);
467 painter.setBrush(Qt::NoBrush);
468 painter.setPen(Qt::red);
471 if(m_copyAuxFrameRect.isValid())
473 QRectF rec = m_copyAuxFrameRect;
474 rec.moveCenter(QPointF(0, 0));
476 painter.setCompositionMode(QPainter::CompositionMode_DestinationOut);
478 matrix.translate(m_copyAuxFrameRect.center().x(), m_copyAuxFrameRect.center().y());
479 matrix.rotate(m_auxAngle);
480 painter.setMatrix(matrix);
481 painter.drawRect(rec);
485 QRectF rec = m_auxFrameRect;
486 rec.moveCenter(QPointF(0, 0));
488 painter.setCompositionMode(QPainter::CompositionMode_DestinationOver);
490 matrix.translate(m_auxFrameRect.center().x(), m_auxFrameRect.center().y());
491 matrix.rotate(m_angle);
492 painter.setMatrix(matrix);
493 painter.drawRect(rec);
496 m_auxAngle = m_angle;
497 m_copyAuxFrameRect = m_auxFrameRect;
499 m_layoutEditor->update();
504 QPainter painter(
this);
505 painter.drawPixmap(0, 0, m_pixmap);
510 m_pixmap.fill(Qt::transparent);
513 QPainter painter(&m_pixmap);
514 QMatrix matrix = getAuxMatrix();
515 painter.setMatrix(matrix);
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));
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);
528 painter.drawRect(m_recSel2);
529 painter.drawRect(m_recSel6);
531 painter.drawRect(m_recSel4);
532 painter.drawRect(m_recSel8);
534 if(!(fabs(m_angle) == 0 || fabs(m_angle) == 90 || fabs(m_angle) == 180) || (fabs(m_angle) == 270 || fabs(m_angle) == 360))
536 painter.resetMatrix();
537 painter.setBrush(QColor(0, 0, 255, 24));
538 painter.drawRect(QRect(0, 0, width()-1, height()-1));
547 m_pixmap.fill(Qt::transparent);
556 QMatrix matrix = getAuxMatrix();
558 if(matrix.mapToPolygon(m_recSel1).containsPoint(p, Qt::OddEvenFill))
560 else if(matrix.mapToPolygon(m_recSel2).containsPoint(p, Qt::OddEvenFill))
562 else if(matrix.mapToPolygon(m_recSel3).containsPoint(p, Qt::OddEvenFill))
564 else if(matrix.mapToPolygon(m_recSel4).containsPoint(p, Qt::OddEvenFill))
566 else if(matrix.mapToPolygon(m_recSel5).containsPoint(p, Qt::OddEvenFill))
568 else if(matrix.mapToPolygon(m_recSel6).containsPoint(p, Qt::OddEvenFill))
570 else if(matrix.mapToPolygon(m_recSel7).containsPoint(p, Qt::OddEvenFill))
572 else if(matrix.mapToPolygon(m_recSel8).containsPoint(p, Qt::OddEvenFill))
574 else if(matrix.mapToPolygon(m_recSel10).containsPoint(p, Qt::OddEvenFill))
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;
586 if(m_angle >= 0 && m_angle <= 90)
588 double w = rec.height() * sin(rad);
589 matrix.translate(w, 0);
591 else if(m_angle >= 90 && m_angle <= 180)
593 double h = rec.height() * cos(rad);
594 matrix.translate(widWidth, -h);
596 else if(m_angle >= 180 && m_angle <= 270)
598 double w = rec.height() * sin(rad);
599 matrix.translate(widWidth + w, widHeight);
603 double h = rec.height() * cos(rad);
604 matrix.translate(0, widHeight - h);
606 matrix.rotate(m_angle);
612 QMatrix matrix = getAuxMatrix();
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());
675 QMatrix matrix = m_layoutEditor->getMatrixPaperViewToVp();
676 QRect rec = matrix.mapRect(m_frameRect).toRect();
677 QPoint center = rec.center();
678 return mapToGlobal(center);
690 QPoint ref = rect().center();
695 angle = atan((
double)da.y() / (double)da.x()) * 180 / 3.141593;
701 else if(da.x() > 0 && da.y() < 0)
720 if(m_showToolTip ==
false)
722 QToolTip::hideText();
726 QString rotation, stretch, pointSize, letterSpacing, wordSpacing, align, weight, style, capitalization, overline, underline, strikeOut;
733 rotation.setNum(angle);
734 rotation =
"Rotation = " + rotation +
" degrees";
736 stretch.setNum(m_stretch);
737 stretch =
"Stretch = " + stretch +
"%";
739 pointSize.setNum(m_pointSize);
740 pointSize =
"Point Size = " + pointSize;
742 letterSpacing.setNum(qRound(m_letterSpacing));
743 letterSpacing =
"Letter Spacing = " + letterSpacing +
"%";
745 wordSpacing.setNum(qRound(m_wordSpacing));
746 wordSpacing =
"Word Spacing = " + wordSpacing;
748 if(m_align == Qt::AlignLeft)
749 align =
"Align = Left";
750 else if(m_align == Qt::AlignHCenter)
751 align =
"Align = Center";
753 align =
"Align = Right";
756 weight =
"Weight = Weight Light";
757 else if(m_weight == QFont::Normal)
758 weight =
"Weight = Normal Light";
760 weight =
"Weight = DemiBold Light";
762 weight =
"Weight = Bold Light";
764 weight =
"Weight = Black Light";
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";
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";
785 overline =
"Overline = ON";
787 overline =
"Overline = OFF";
790 underline =
"Underline = ON";
792 underline =
"Underline = OFF";
795 strikeOut =
"Strike Out = ON";
797 strikeOut =
"Strike Out = OFF";
799 if(type ==
"Selection")
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);
810 QToolTip::hideText();
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);
840 QMatrix matrix = m_layoutEditor->getMatrixPaperViewToVp();
842 if(mouseEvent->buttons() == Qt::LeftButton)
845 QPoint p = mouseEvent->pos();
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);
858 m_layoutEditor->raiseDraftLayoutEditor();
860 else if(mouseEvent->buttons() == Qt::RightButton)
862 QPoint gp = mouseEvent->globalPos();
865 QAction* action = m_menu->exec(gp);
866 if(action == m_setFamilyAction)
868 else if(action == m_setColorAction)
870 else if(action == m_setTextAction)
872 else if(action == m_showTooTipAction)
874 else if(action == m_hideTooTipAction)
882 QMatrix matrix = m_layoutEditor->getMatrixPaperViewToVp();
883 QPoint p = mouseEvent->pos();
884 QPoint gp = mouseEvent->globalPos();
886 if(mouseEvent->buttons() == Qt::NoButton)
891 getSelectionPoint(p);
893 toolTip(gp,
"Selection");
897 m_layoutEditor->setFrameSelected(0);
898 if(!(fabs(m_angle) == 0 || fabs(m_angle) == 90 || fabs(m_angle) == 180))
904 if(m_layoutEditor->getFrameSelected() !=
this)
905 m_layoutEditor->setFrameSelected(
this);
909 else if(mouseEvent->buttons() == Qt::LeftButton)
914 QPoint p = mouseEvent->pos();
915 QPoint gp = mouseEvent->globalPos();
916 QPoint d = m_pressPoint - p;
917 int pointSize = m_pointSize;
923 m_layoutEditor->insertCopy2Undo(
this);
926 if(m_selected == 1 || m_selected == 3 || m_selected == 5 || m_selected == 7)
928 double beta = getAngle(p);
929 double ang = beta - m_refAngle;
930 adjustAngleRange(ang);
932 m_angle = m_iniAngle + ang;
933 adjustAngleRange(m_angle);
936 m_angle = qRound(m_angle);
937 toolTip(gp,
"Rotate");
939 else if(m_selected == 2 || m_selected == 6)
941 QPoint dif = p - QPoint(width()/2, height()/2);
942 double height = 2 * qSqrt(dif.x() * dif.x() + dif.y() * dif.y());
944 int ps = qRound(m_auxPointSize * height / m_auxHeight);
946 QPointF center = m_auxFrameRect.center();
947 calculateTextRect(m_auxFrameRect);
948 m_auxFrameRect.moveCenter(center);
949 toolTip(gp,
"PointSize");
951 else if(m_selected == 4 || m_selected == 8)
953 QPoint dif = p - QPoint(width()/2, height()/2);
954 double width = 2 * qSqrt(dif.x() * dif.x() + dif.y() * dif.y());
956 int stretch = qRound(m_auxStretch * width / m_auxWidth);
958 QPointF center = m_auxFrameRect.center();
959 calculateTextRect(m_auxFrameRect);
960 m_auxFrameRect.moveCenter(center);
961 toolTip(gp,
"Stretch");
965 m_auxFrameRect.moveCenter(m_auxFrameRect.center() - d);
980 QMatrix matrix = m_layoutEditor->getMatrixPaperViewToVp();
981 QPixmap* pixmap = m_layoutEditor->getDraftPixmap();
982 pixmap->fill(Qt::transparent);
984 QPointF pp = matrix.inverted().map(m_auxFrameRect.bottomLeft());
987 showSelectionPoints();
988 m_layoutEditor->lowerDraftLayoutEditor();
989 m_layoutEditor->update();
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);
1002 if(QApplication::overrideCursor() || m_dragging)
1005 m_layoutEditor->setFrameSelected(
this);
1020 m_layoutEditor->setFrameSelected(0);
1029 if(m_selected >= 1 && m_selected <= 8)
1030 cursor.setShape(Qt::PointingHandCursor);
1031 else if(m_selected == 10)
1032 cursor.setShape(Qt::SizeAllCursor);
1034 if(QApplication::overrideCursor())
1036 if(QApplication::overrideCursor()->shape() != cursor.shape())
1038 while(QApplication::overrideCursor())
1039 QApplication::restoreOverrideCursor();
1040 if(cursor.shape() != Qt::ArrowCursor)
1041 QApplication::setOverrideCursor(cursor);
1044 else if(cursor.shape() != Qt::ArrowCursor)
1045 QApplication::setOverrideCursor(cursor);
1051 QFont auxFont(*m_font);
1052 auxFont.setPointSize(m_pointSize);
1056 QFont font = QFontDialog::getFont(&ok, auxFont,
this);
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());
1071 QColor color = QColorDialog::getColor(m_cor,
this,
"Set Text Color", QColorDialog::ShowAlphaChannel);
1082 QString text = QInputDialog::getText(
this,
"Change Text",
"New Text", QLineEdit::Normal, m_text, &ok);
1083 if(text.isEmpty() ==
false && ok)
void calculateTextRect(QRectF &)
void mousePressEvent(QMouseEvent *)
QPoint getGlobalPositionCenter()
void getSelectionPoint(const QPoint &p)
This file contains include headers for the Vector Geometry model of TerraLib.
TextFrame & operator=(const TextFrame &rhs)
void paintEvent(QPaintEvent *event)
QFont::Capitalization getCapitalization()
QFont::Weight getWeight()
TextFrame(const QPointF &p, const QString &s, const int &pointSize, te::qt::widgets::LayoutEditor *me, Qt::WindowFlags f=Qt::Widget)
void setWeight(QFont::Weight)
This file contains include headers for the Layout module.
void setPointSize(int ps)
A canvas built on top of Qt.
QPoint getCenterSelected()
void adjustAngleRange(double &)
void adjustSize(QPointF &p)
double getAngle(QPoint &)
void mouseMoveEvent(QMouseEvent *)
void setLetterSpacing(double)
void leaveEvent(QEvent *)
Frame & operator=(const Frame &rhs)
void setStyle(QFont::Style)
void showSelectionPoints()
void enterEvent(QEvent *)
void mouseReleaseEvent(QMouseEvent *)
void setWordSpacing(double)
void hideSelectionPoints()
void setCapitalization(QFont::Capitalization)
void toolTip(const QPoint &, const QString &)
double getLetterSpacing()
QFont::Capitalization m_capitalization
void setText(const QString &t)