FreeCAD

Форк
0
/
TemplateTextField.cpp 
110 строк · 3.9 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2015 Ian Rees <ian.rees@gmail.com>                      *
3
 *                                                                         *
4
 *   This file is part of the FreeCAD CAx development system.              *
5
 *                                                                         *
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.      *
10
 *                                                                         *
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.                  *
15
 *                                                                         *
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                                *
20
 *                                                                         *
21
 ***************************************************************************/
22

23
#include "PreCompiled.h"
24

25
#ifndef _PreComp_
26
  #include <QGraphicsSceneMouseEvent>
27
  #include <QInputDialog>
28
  #include <QLineEdit>
29
  #include <QTextDocument>
30
#endif // #ifndef _PreCmp_
31

32
#include <Base/Console.h>
33
#include <Mod/TechDraw/App/DrawTemplate.h>
34

35
#include "DlgTemplateField.h"
36
#include "TemplateTextField.h"
37

38
using namespace TechDrawGui;
39

40
TemplateTextField::TemplateTextField(QGraphicsItem *parent,
41
                                     TechDraw::DrawTemplate *myTmplte,
42
                                     const std::string &myFieldName)
43
    : QGraphicsItemGroup(parent),
44
      tmplte(myTmplte),
45
      fieldNameStr(myFieldName)
46
{
47
    setToolTip(QObject::tr("Click to update text"));
48
    m_rect = new QGraphicsRectItem();
49
    addToGroup(m_rect);
50
    QPen rectPen(Qt::transparent);
51
    QBrush rectBrush(Qt::NoBrush);
52
    m_rect->setPen(rectPen);
53
    m_rect->setBrush(rectBrush);
54

55
    m_line = new QGraphicsPathItem();
56
    addToGroup(m_line);
57
 }
58

59
void TemplateTextField::mousePressEvent(QGraphicsSceneMouseEvent *event)
60
{
61
    if ( tmplte && m_rect->rect().contains(event->pos()) ) {
62
        event->accept();
63
    } else {
64
        QGraphicsItemGroup::mousePressEvent(event);
65
    }
66
}
67

68
void TemplateTextField::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
69
{
70
    if ( tmplte && m_rect->rect().contains(event->pos()) ) {
71
        event->accept();
72

73
        DlgTemplateField ui;
74

75
        ui.setFieldName(fieldNameStr);
76
        ui.setFieldContent(tmplte->EditableTexts[fieldNameStr]);
77

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 "&amp;" 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);
86
        }
87

88
    } else {
89
        QGraphicsItemGroup::mouseReleaseEvent(event);
90
    }
91
}
92

93
void TemplateTextField::setRectangle(QRectF rect)
94
{
95
    m_rect->setRect(rect);
96
}
97

98
void TemplateTextField::setLine(QPointF from, QPointF to)
99
{
100
    QPainterPath path(from);
101
    path.lineTo(to);
102
    m_line->setPath(path);
103
}
104

105
void TemplateTextField::setLineColor(QColor color)
106
{
107
    QPen pen(color);
108
    pen.setWidth(5);
109
    m_line->setPen(pen);
110
}
111

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.