/*************************************************************************** * Copyright (c) 2013 Luke Parry * * 2014 wandererfan * * * * This file is part of the FreeCAD CAx development system. * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Library General Public * * License as published by the Free Software Foundation; either * * version 2 of the License, or (at your option) any later version. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Library General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this library; see the file COPYING.LIB. If not, * * write to the Free Software Foundation, Inc., 59 Temple Place, * * Suite 330, Boston, MA 02111-1307, USA * * * ***************************************************************************/ #include "PreCompiled.h" #ifndef _PreComp_ #include #include #include #include #include #include #include #include #include #include #include #include #endif #include #include #include #include #include #include #include #include #include #include #include #include "QGIViewAnnotation.h" #include "QGCustomText.h" using namespace TechDrawGui; QGIViewAnnotation::QGIViewAnnotation() { setCacheMode(QGraphicsItem::NoCache); setFlag(QGraphicsItem::ItemIsSelectable, true); setFlag(QGraphicsItem::ItemIsMovable, true); setAcceptHoverEvents(true); m_textItem = new QGCustomText(); m_textItem->setTextInteractionFlags(Qt::NoTextInteraction); //To allow on screen editing of text: //m_textItem->setTextInteractionFlags(Qt::TextEditorInteraction); //this works //QObject::connect(QGraphicsTextItem::document(), SIGNAL(contentsChanged()),m_textItem, SLOT(updateText())); //not tested addToGroup(m_textItem); m_textItem->setPos(0.,0.); } QVariant QGIViewAnnotation::itemChange(GraphicsItemChange change, const QVariant &value) { return QGIView::itemChange(change, value); } void QGIViewAnnotation::setViewAnnoFeature(TechDraw::DrawViewAnnotation *obj) { // called from QGVPage. (once) setViewFeature(static_cast(obj)); } void QGIViewAnnotation::updateView(bool update) { if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewAnnotation::getClassTypeId())) return; TechDraw::DrawViewAnnotation *viewAnno = dynamic_cast(getViewObject()); if (update || viewAnno->isTouched() || viewAnno->Text.isTouched() || viewAnno->Font.isTouched() || viewAnno->TextColor.isTouched() || viewAnno->TextSize.isTouched() ) { draw(); } QGIView::updateView(update); } void QGIViewAnnotation::draw() { if (!isVisible()) { return; } drawAnnotation(); if (borderVisible) { drawBorder(); } } void QGIViewAnnotation::drawAnnotation() { if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewAnnotation::getClassTypeId())) return; TechDraw::DrawViewAnnotation *viewAnno = dynamic_cast(getViewObject()); const std::vector& annoText = viewAnno->Text.getValues(); //build HTML/CSS formating around Text lines std::stringstream ss; ss << "\n\n\n\n\n

"; for(std::vector::const_iterator it = annoText.begin(); it != annoText.end(); it++) { if (it == annoText.begin()) { ss << *it; } else { ss << "
" << *it ; } } ss << "

\n\n "; prepareGeometryChange(); m_textItem->setTextWidth(viewAnno->MaxWidth.getValue()); QString qs = QString::fromUtf8(ss.str().c_str()); m_textItem->setHtml(qs); m_textItem->setPos(0.,0.); }