FreeCAD

Форк
0
/
TaskBalloon.cpp 
268 строк · 9.5 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2016 WandererFan <wandererfan@gmail.com>                *
3
 *   Copyright (c) 2019 Franck Jullien <franck.jullien@gmail.com>          *
4
 *                                                                         *
5
 *   This file is part of the FreeCAD CAx development system.              *
6
 *                                                                         *
7
 *   This library is free software; you can redistribute it and/or         *
8
 *   modify it under the terms of the GNU Library General Public           *
9
 *   License as published by the Free Software Foundation; either          *
10
 *   version 2 of the License, or (at your option) any later version.      *
11
 *                                                                         *
12
 *   This library  is distributed in the hope that it will be useful,      *
13
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
14
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
15
 *   GNU Library General Public License for more details.                  *
16
 *                                                                         *
17
 *   You should have received a copy of the GNU Library General Public     *
18
 *   License along with this library; see the file COPYING.LIB. If not,    *
19
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
20
 *   Suite 330, Boston, MA  02111-1307, USA                                *
21
 *                                                                         *
22
 ***************************************************************************/
23

24
#include "PreCompiled.h"
25
#ifndef _PreComp_
26
# include <cmath>
27
#endif // #ifndef _PreComp_
28

29
#include <App/Document.h>
30
#include <Base/Console.h>
31
#include <Gui/BitmapFactory.h>
32
#include <Gui/Command.h>
33
#include <Gui/Document.h>
34
#include <Gui/Control.h>
35

36
#include "TaskBalloon.h"
37
#include "ui_TaskBalloon.h"
38
#include "DrawGuiUtil.h"
39
#include "QGIViewBalloon.h"
40
#include "ViewProviderBalloon.h"
41

42

43
using namespace Gui;
44
using namespace TechDraw;
45
using namespace TechDrawGui;
46

47
TaskBalloon::TaskBalloon(QGIViewBalloon *parent, ViewProviderBalloon *balloonVP) :
48
    ui(new Ui_TaskBalloon)
49
{
50
    int i = 0;
51
    m_parent = parent;
52
    m_balloonVP = balloonVP;
53
    m_guiDocument = balloonVP->getDocument();
54
    m_appDocument = parent->getBalloonFeat()->getDocument();
55
    m_balloonName = parent->getBalloonFeat()->getNameInDocument();
56

57
    ui->setupUi(this);
58

59
    ui->qsbShapeScale->setValue(parent->getBalloonFeat()->ShapeScale.getValue());
60
    connect(ui->qsbShapeScale, qOverload<double>(&QuantitySpinBox::valueChanged), this, &TaskBalloon::onShapeScaleChanged);
61

62
    ui->qsbSymbolScale->setValue(parent->getBalloonFeat()->EndTypeScale.getValue());
63
    connect(ui->qsbSymbolScale, qOverload<double>(&QuantitySpinBox::valueChanged), this, &TaskBalloon::onEndSymbolScaleChanged);
64

65
    std::string value = parent->getBalloonFeat()->Text.getValue();
66
    QString qs = QString::fromUtf8(value.data(), value.size());
67
    ui->leText->setText(qs);
68
    ui->leText->selectAll();
69
    connect(ui->leText, &QLineEdit::textChanged, this, &TaskBalloon::onTextChanged);
70
    QTimer::singleShot(0, ui->leText, qOverload<>(&QLineEdit::setFocus));
71

72
    DrawGuiUtil::loadArrowBox(ui->comboEndSymbol);
73
    i = parent->getBalloonFeat()->EndType.getValue();
74
    ui->comboEndSymbol->setCurrentIndex(i);
75
    connect(ui->comboEndSymbol, qOverload<int>(&QComboBox::currentIndexChanged), this, &TaskBalloon::onEndSymbolChanged);
76

77
    i = parent->getBalloonFeat()->BubbleShape.getValue();
78
    ui->comboBubbleShape->setCurrentIndex(i);
79
    connect(ui->comboBubbleShape, qOverload<int>(&QComboBox::currentIndexChanged), this, &TaskBalloon::onBubbleShapeChanged);
80

81
    ui->qsbFontSize->setUnit(Base::Unit::Length);
82
    ui->qsbFontSize->setMinimum(0);
83

84
    ui->qsbLineWidth->setUnit(Base::Unit::Length);
85
    ui->qsbLineWidth->setSingleStep(0.100);
86
    ui->qsbLineWidth->setMinimum(0);
87

88
    // negative kink length is allowed, thus no minimum
89
    ui->qsbKinkLength->setUnit(Base::Unit::Length);
90

91
    if (balloonVP) {
92
        ui->textColor->setColor(balloonVP->Color.getValue().asValue<QColor>());
93
        connect(ui->textColor, &ColorButton::changed, this, &TaskBalloon::onColorChanged);
94
        ui->qsbFontSize->setValue(balloonVP->Fontsize.getValue());
95
        ui->comboLineVisible->setCurrentIndex(balloonVP->LineVisible.getValue());
96
        ui->qsbLineWidth->setValue(balloonVP->LineWidth.getValue());
97
    }
98
    // new balloons have already the preferences BalloonKink length
99
    ui->qsbKinkLength->setValue(parent->getBalloonFeat()->KinkLength.getValue());
100

101
    connect(ui->qsbFontSize, qOverload<double>(&QuantitySpinBox::valueChanged), this, &TaskBalloon::onFontsizeChanged);
102
    connect(ui->comboLineVisible, qOverload<int>(&QComboBox::currentIndexChanged), this, &TaskBalloon::onLineVisibleChanged);
103
    connect(ui->qsbLineWidth, qOverload<double>(&QuantitySpinBox::valueChanged), this, &TaskBalloon::onLineWidthChanged);
104
    connect(ui->qsbKinkLength, qOverload<double>(&QuantitySpinBox::valueChanged), this, &TaskBalloon::onKinkLengthChanged);
105

106
}
107

108
TaskBalloon::~TaskBalloon()
109
{
110
}
111

112
bool TaskBalloon::accept()
113
{
114
    // re issue #9626 if the balloon is deleted while the task dialog is in progress we will fail
115
    // trying to access the feature object or the viewprovider.  This should be prevented by
116
    // change to ViewProviderBalloon
117
    // see also reject()
118
    App::DocumentObject* balloonFeature = m_appDocument->getObject(m_balloonName.c_str());
119
    if(balloonFeature) {
120
        // an object with our name still exists in the document
121
        balloonFeature->purgeTouched();
122
        m_guiDocument->commitCommand();
123
    } else {
124
        // see comment in reject(). this may not do what we want.
125
        Gui::Command::abortCommand();
126
    }
127

128
    m_guiDocument->resetEdit();
129

130
    return true;
131
}
132

133
bool TaskBalloon::reject()
134
{
135
    // re issue #9626 - if the balloon is deleted while the dialog is in progress
136
    // the delete transaction is still active and ?locked? so our "abortCommand"
137
    // doesn't work properly and a pending transaction is still in place.  This
138
    // causes a warning message from App::AutoTransaction (??) that can't be
139
    // cleared.  Even closing the document will not clear the warning.
140
    // A change to ViewProviderBalloon::onDelete should prevent this from
141
    // happening from the Gui.  It is possible(?) that the balloon could be
142
    // deleted by a script.
143
    m_guiDocument->abortCommand();
144
    App::DocumentObject* balloonFeature = m_appDocument->getObject(m_balloonName.c_str());
145
    if(balloonFeature) {
146
        // an object with our name still exists in the document
147
        balloonFeature->recomputeFeature();
148
        balloonFeature->purgeTouched();
149
    }
150
    m_guiDocument->resetEdit();
151
    Gui::Command::updateActive();
152

153
    return true;
154
}
155

156
void TaskBalloon::recomputeFeature()
157
{
158
    App::DocumentObject* objVP = m_balloonVP->getObject();
159
    assert(objVP);
160
    objVP->getDocument()->recomputeFeature(objVP);
161
}
162

163
void TaskBalloon::onTextChanged()
164
{
165
    m_parent->getBalloonFeat()->Text.setValue(ui->leText->text().toUtf8().constData());
166
    recomputeFeature();
167
}
168

169
void TaskBalloon::onColorChanged()
170
{
171
    App::Color ac;
172
    ac.setValue<QColor>(ui->textColor->color());
173
    m_balloonVP->Color.setValue(ac);
174
    recomputeFeature();
175
}
176

177
void TaskBalloon::onFontsizeChanged()
178
{
179
    m_balloonVP->Fontsize.setValue(ui->qsbFontSize->value().getValue());
180
    recomputeFeature();
181
}
182

183
void TaskBalloon::onBubbleShapeChanged()
184
{
185
    m_parent->getBalloonFeat()->BubbleShape.setValue(ui->comboBubbleShape->currentIndex());
186
    recomputeFeature();
187
}
188

189
void TaskBalloon::onShapeScaleChanged()
190
{
191
    m_parent->getBalloonFeat()->ShapeScale.setValue(ui->qsbShapeScale->value().getValue());
192
    recomputeFeature();
193
}
194

195
void TaskBalloon::onEndSymbolChanged()
196
{
197
    m_parent->getBalloonFeat()->EndType.setValue(ui->comboEndSymbol->currentIndex());
198
    recomputeFeature();
199
}
200

201
void TaskBalloon::onEndSymbolScaleChanged()
202
{
203
    m_parent->getBalloonFeat()->EndTypeScale.setValue(ui->qsbSymbolScale->value().getValue());
204
    recomputeFeature();
205
}
206

207
void TaskBalloon::onLineVisibleChanged()
208
{
209
    m_balloonVP->LineVisible.setValue(ui->comboLineVisible->currentIndex());
210
    recomputeFeature();
211
}
212

213
void TaskBalloon::onLineWidthChanged()
214
{
215
    m_balloonVP->LineWidth.setValue(ui->qsbLineWidth->value().getValue());
216
    recomputeFeature();
217
}
218

219
void TaskBalloon::onKinkLengthChanged()
220
{
221
    m_parent->getBalloonFeat()->KinkLength.setValue(ui->qsbKinkLength->value().getValue());
222
    recomputeFeature();
223
}
224

225

226
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
227
TaskDlgBalloon::TaskDlgBalloon(QGIViewBalloon *parent, ViewProviderBalloon *balloonVP) :
228
    TaskDialog()
229
{
230
    widget  = new TaskBalloon(parent, balloonVP);
231
    taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("TechDraw_Balloon"), widget->windowTitle(), true, nullptr);
232
    taskbox->groupLayout()->addWidget(widget);
233
    Content.push_back(taskbox);
234
    setAutoCloseOnTransactionChange(true);
235
}
236

237
TaskDlgBalloon::~TaskDlgBalloon()
238
{
239
}
240

241
void TaskDlgBalloon::update()
242
{
243
    //widget->updateTask();
244
}
245

246
//==== calls from the TaskView ===============================================================
247
void TaskDlgBalloon::open()
248
{
249
}
250

251
void TaskDlgBalloon::clicked(int i)
252
{
253
    Q_UNUSED(i);
254
}
255

256
bool TaskDlgBalloon::accept()
257
{
258
    widget->accept();
259
    return true;
260
}
261

262
bool TaskDlgBalloon::reject()
263
{
264
    widget->reject();
265
    return true;
266
}
267

268
#include <Mod/TechDraw/Gui/moc_TaskBalloon.cpp>
269

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

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

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

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