1
/***************************************************************************
2
* Copyright (c) 2016 WandererFan <wandererfan@gmail.com> *
3
* Copyright (c) 2019 Franck Jullien <franck.jullien@gmail.com> *
5
* This file is part of the FreeCAD CAx development system. *
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. *
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. *
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 *
22
***************************************************************************/
24
#include "PreCompiled.h"
27
#endif // #ifndef _PreComp_
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>
36
#include "TaskBalloon.h"
37
#include "ui_TaskBalloon.h"
38
#include "DrawGuiUtil.h"
39
#include "QGIViewBalloon.h"
40
#include "ViewProviderBalloon.h"
44
using namespace TechDraw;
45
using namespace TechDrawGui;
47
TaskBalloon::TaskBalloon(QGIViewBalloon *parent, ViewProviderBalloon *balloonVP) :
48
ui(new Ui_TaskBalloon)
52
m_balloonVP = balloonVP;
53
m_guiDocument = balloonVP->getDocument();
54
m_appDocument = parent->getBalloonFeat()->getDocument();
55
m_balloonName = parent->getBalloonFeat()->getNameInDocument();
59
ui->qsbShapeScale->setValue(parent->getBalloonFeat()->ShapeScale.getValue());
60
connect(ui->qsbShapeScale, qOverload<double>(&QuantitySpinBox::valueChanged), this, &TaskBalloon::onShapeScaleChanged);
62
ui->qsbSymbolScale->setValue(parent->getBalloonFeat()->EndTypeScale.getValue());
63
connect(ui->qsbSymbolScale, qOverload<double>(&QuantitySpinBox::valueChanged), this, &TaskBalloon::onEndSymbolScaleChanged);
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));
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);
77
i = parent->getBalloonFeat()->BubbleShape.getValue();
78
ui->comboBubbleShape->setCurrentIndex(i);
79
connect(ui->comboBubbleShape, qOverload<int>(&QComboBox::currentIndexChanged), this, &TaskBalloon::onBubbleShapeChanged);
81
ui->qsbFontSize->setUnit(Base::Unit::Length);
82
ui->qsbFontSize->setMinimum(0);
84
ui->qsbLineWidth->setUnit(Base::Unit::Length);
85
ui->qsbLineWidth->setSingleStep(0.100);
86
ui->qsbLineWidth->setMinimum(0);
88
// negative kink length is allowed, thus no minimum
89
ui->qsbKinkLength->setUnit(Base::Unit::Length);
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());
98
// new balloons have already the preferences BalloonKink length
99
ui->qsbKinkLength->setValue(parent->getBalloonFeat()->KinkLength.getValue());
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);
108
TaskBalloon::~TaskBalloon()
112
bool TaskBalloon::accept()
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
118
App::DocumentObject* balloonFeature = m_appDocument->getObject(m_balloonName.c_str());
120
// an object with our name still exists in the document
121
balloonFeature->purgeTouched();
122
m_guiDocument->commitCommand();
124
// see comment in reject(). this may not do what we want.
125
Gui::Command::abortCommand();
128
m_guiDocument->resetEdit();
133
bool TaskBalloon::reject()
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());
146
// an object with our name still exists in the document
147
balloonFeature->recomputeFeature();
148
balloonFeature->purgeTouched();
150
m_guiDocument->resetEdit();
151
Gui::Command::updateActive();
156
void TaskBalloon::recomputeFeature()
158
App::DocumentObject* objVP = m_balloonVP->getObject();
160
objVP->getDocument()->recomputeFeature(objVP);
163
void TaskBalloon::onTextChanged()
165
m_parent->getBalloonFeat()->Text.setValue(ui->leText->text().toUtf8().constData());
169
void TaskBalloon::onColorChanged()
172
ac.setValue<QColor>(ui->textColor->color());
173
m_balloonVP->Color.setValue(ac);
177
void TaskBalloon::onFontsizeChanged()
179
m_balloonVP->Fontsize.setValue(ui->qsbFontSize->value().getValue());
183
void TaskBalloon::onBubbleShapeChanged()
185
m_parent->getBalloonFeat()->BubbleShape.setValue(ui->comboBubbleShape->currentIndex());
189
void TaskBalloon::onShapeScaleChanged()
191
m_parent->getBalloonFeat()->ShapeScale.setValue(ui->qsbShapeScale->value().getValue());
195
void TaskBalloon::onEndSymbolChanged()
197
m_parent->getBalloonFeat()->EndType.setValue(ui->comboEndSymbol->currentIndex());
201
void TaskBalloon::onEndSymbolScaleChanged()
203
m_parent->getBalloonFeat()->EndTypeScale.setValue(ui->qsbSymbolScale->value().getValue());
207
void TaskBalloon::onLineVisibleChanged()
209
m_balloonVP->LineVisible.setValue(ui->comboLineVisible->currentIndex());
213
void TaskBalloon::onLineWidthChanged()
215
m_balloonVP->LineWidth.setValue(ui->qsbLineWidth->value().getValue());
219
void TaskBalloon::onKinkLengthChanged()
221
m_parent->getBalloonFeat()->KinkLength.setValue(ui->qsbKinkLength->value().getValue());
226
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
227
TaskDlgBalloon::TaskDlgBalloon(QGIViewBalloon *parent, ViewProviderBalloon *balloonVP) :
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);
237
TaskDlgBalloon::~TaskDlgBalloon()
241
void TaskDlgBalloon::update()
243
//widget->updateTask();
246
//==== calls from the TaskView ===============================================================
247
void TaskDlgBalloon::open()
251
void TaskDlgBalloon::clicked(int i)
256
bool TaskDlgBalloon::accept()
262
bool TaskDlgBalloon::reject()
268
#include <Mod/TechDraw/Gui/moc_TaskBalloon.cpp>