1
/***************************************************************************
2
* Copyright (c) 2015 Ian Rees <ian.rees@gmail.com> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
23
#include "PreCompiled.h"
26
#include <QGraphicsSceneMouseEvent>
27
#include <QInputDialog>
29
#include <QTextDocument>
30
#endif // #ifndef _PreCmp_
32
#include <Base/Console.h>
33
#include <Mod/TechDraw/App/DrawTemplate.h>
35
#include "DlgTemplateField.h"
36
#include "TemplateTextField.h"
38
using namespace TechDrawGui;
40
TemplateTextField::TemplateTextField(QGraphicsItem *parent,
41
TechDraw::DrawTemplate *myTmplte,
42
const std::string &myFieldName)
43
: QGraphicsItemGroup(parent),
45
fieldNameStr(myFieldName)
47
setToolTip(QObject::tr("Click to update text"));
48
m_rect = new QGraphicsRectItem();
50
QPen rectPen(Qt::transparent);
51
QBrush rectBrush(Qt::NoBrush);
52
m_rect->setPen(rectPen);
53
m_rect->setBrush(rectBrush);
55
m_line = new QGraphicsPathItem();
59
void TemplateTextField::mousePressEvent(QGraphicsSceneMouseEvent *event)
61
if ( tmplte && m_rect->rect().contains(event->pos()) ) {
64
QGraphicsItemGroup::mousePressEvent(event);
68
void TemplateTextField::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
70
if ( tmplte && m_rect->rect().contains(event->pos()) ) {
75
ui.setFieldName(fieldNameStr);
76
ui.setFieldContent(tmplte->EditableTexts[fieldNameStr]);
78
if (ui.exec() == QDialog::Accepted) {
79
//WF: why is this escaped?
80
// "<" is converted elsewhere and no other characters cause problems.
81
// escaping causes "&" to appear as "&" etc
82
// QString qsClean = ui.getFieldContent().toHtmlEscaped();
83
QString qsClean = ui.getFieldContent();
84
std::string utf8Content = qsClean.toUtf8().constData();
85
tmplte->EditableTexts.setValue(fieldNameStr, utf8Content);
89
QGraphicsItemGroup::mouseReleaseEvent(event);
93
void TemplateTextField::setRectangle(QRectF rect)
95
m_rect->setRect(rect);
98
void TemplateTextField::setLine(QPointF from, QPointF to)
100
QPainterPath path(from);
102
m_line->setPath(path);
105
void TemplateTextField::setLineColor(QColor color)