1
/***************************************************************************
2
* Copyright (c) 2004 Jürgen Riegel <juergen.riegel@web.de> *
3
* Copyright (c) 2012 Luke Parry <l.parry@warwick.ac.uk> *
4
* Copyright (c) 2019 Franck Jullien <franck.jullien@gmail.com> *
6
* This file is part of the FreeCAD CAx development system. *
8
* This library is free software; you can redistribute it and/or *
9
* modify it under the terms of the GNU Library General Public *
10
* License as published by the Free Software Foundation; either *
11
* version 2 of the License, or (at your option) any later version. *
13
* This library is distributed in the hope that it will be useful, *
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16
* GNU Library General Public License for more details. *
18
* You should have received a copy of the GNU Library General Public *
19
* License along with this library; see the file COPYING.LIB. If not, *
20
* write to the Free Software Foundation, Inc., 59 Temple Place, *
21
* Suite 330, Boston, MA 02111-1307, USA *
23
***************************************************************************/
26
#include "PreCompiled.h"
35
#include <App/DocumentObject.h>
36
#include <Gui/ActionFunction.h>
37
#include <Gui/Control.h>
38
#include <Gui/MainWindow.h>
39
#include <Gui/Selection.h>
40
#include <Gui/ViewProviderDocumentObject.h>
42
#include <Mod/TechDraw/App/LineGroup.h>
44
#include "PreferencesGui.h"
46
#include "QGIViewBalloon.h"
47
#include "TaskBalloon.h"
48
#include "ViewProviderBalloon.h"
50
using namespace TechDrawGui;
51
using namespace TechDraw;
53
PROPERTY_SOURCE(TechDrawGui::ViewProviderBalloon, TechDrawGui::ViewProviderDrawingView)
55
//**************************************************************************
56
// Construction/Destruction
58
ViewProviderBalloon::ViewProviderBalloon()
60
sPixmap = "TechDraw_Balloon";
62
static const char *group = "Balloon Format";
64
ADD_PROPERTY_TYPE(Font, (Preferences::labelFont().c_str()), group, App::Prop_None, "The name of the font to use");
65
ADD_PROPERTY_TYPE(Fontsize, (Preferences::dimFontSizeMM()),
66
group, (App::PropertyType)(App::Prop_None), "Balloon text size in units");
67
double weight = TechDraw::LineGroup::getDefaultWidth("Thin");
68
ADD_PROPERTY_TYPE(LineWidth, (weight), group, (App::PropertyType)(App::Prop_None), "Leader line width");
69
ADD_PROPERTY_TYPE(LineVisible, (true), group, (App::PropertyType)(App::Prop_None), "Balloon line visible or hidden");
70
ADD_PROPERTY_TYPE(Color, (PreferencesGui::dimColor()), group, App::Prop_None, "Color of the balloon");
72
StackOrder.setValue(ZVALUE::DIMENSION);
75
ViewProviderBalloon::~ViewProviderBalloon()
79
bool ViewProviderBalloon::doubleClicked()
81
startDefaultEditMode();
85
void ViewProviderBalloon::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
87
Gui::ActionFunction* func = new Gui::ActionFunction(menu);
88
QAction* act = menu->addAction(QObject::tr("Edit %1").arg(QString::fromUtf8(getObject()->Label.getValue())));
89
act->setData(QVariant((int)ViewProvider::Default));
90
func->trigger(act, [this]() {
91
this->startDefaultEditMode();
94
ViewProviderDrawingView::setupContextMenu(menu, receiver, member);
97
bool ViewProviderBalloon::setEdit(int ModNum)
99
if (ModNum != ViewProvider::Default ) {
100
return ViewProviderDrawingView::setEdit(ModNum);
102
if (Gui::Control().activeDialog()) {
105
// clear the selection (convenience)
106
Gui::Selection().clearSelection();
107
auto qgivBalloon(dynamic_cast<QGIViewBalloon*>(getQView()));
109
Gui::Control().showDialog(new TaskDlgBalloon(qgivBalloon, this));
114
void ViewProviderBalloon::updateData(const App::Property* p)
116
//Balloon handles X, Y updates differently that other QGIView
117
//call QGIViewBalloon::updateView
118
if (p == &(getViewObject()->X) ||
119
p == &(getViewObject()->Y) ){
120
QGIView* qgiv = getQView();
122
qgiv->updateView(true);
126
//Skip QGIView X, Y processing - do not call ViewProviderDrawingView
127
Gui::ViewProviderDocumentObject::updateData(p);
130
void ViewProviderBalloon::onChanged(const App::Property* p)
136
(p == &LineVisible)) {
137
QGIView* qgiv = getQView();
139
qgiv->updateView(true);
142
Gui::ViewProviderDocumentObject::onChanged(p);
145
TechDraw::DrawViewBalloon* ViewProviderBalloon::getViewObject() const
147
return dynamic_cast<TechDraw::DrawViewBalloon*>(pcObject);
150
void ViewProviderBalloon::handleChangedPropertyType(Base::XMLReader &reader, const char *TypeName, App::Property *prop)
151
// transforms properties that had been changed
153
// property LineWidth had the App::PropertyFloat and was changed to App::PropertyLength
154
if (prop == &LineWidth && strcmp(TypeName, "App::PropertyFloat") == 0) {
155
App::PropertyFloat LineWidthProperty;
156
// restore the PropertyFloat to be able to set its value
157
LineWidthProperty.Restore(reader);
158
LineWidth.setValue(LineWidthProperty.getValue());
161
ViewProviderDrawingView::handleChangedPropertyType(reader, TypeName, prop);
165
bool ViewProviderBalloon::canDelete(App::DocumentObject *obj) const
167
// deletions of a balloon object doesn't destroy anything
168
// thus we can pass this action
173
bool ViewProviderBalloon::onDelete(const std::vector<std::string> & parms)
176
// Base::Console().Message("VPB::onDelete() - parms: %d\n", parms.size());
177
if (Gui::Control().activeDialog()) {
178
// TODO: make this selective so only a dialog involving this vp's
179
// feature is blocked. As is, this will prevent deletion during any
182
QTextStream bodyMessageStream(&bodyMessage);
183
bodyMessageStream << qApp->translate("TaskBalloon",
184
"You cannot delete this balloon now because\nthere is an open task dialog.");
185
QMessageBox::warning(Gui::getMainWindow(),
186
qApp->translate("TaskBalloon", "Can Not Delete"), bodyMessage,