1
/***************************************************************************
2
* Copyright (c) 2004 Jürgen Riegel <juergen.riegel@web.de> *
3
* Copyright (c) 2019 Wanderer Fan <wandererfan@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"
26
#include <App/DocumentObject.h>
27
#include <Gui/Control.h>
28
#include <Gui/Selection.h>
30
#include <Mod/TechDraw/App/DrawRichAnno.h>
31
#include <Mod/TechDraw/App/LineGroup.h>
33
#include "PreferencesGui.h"
36
#include "TaskRichAnno.h"
38
#include "ViewProviderPage.h"
39
#include "ViewProviderRichAnno.h"
41
using namespace TechDrawGui;
42
using namespace TechDraw;
44
PROPERTY_SOURCE(TechDrawGui::ViewProviderRichAnno, TechDrawGui::ViewProviderDrawingView)
46
const char* ViewProviderRichAnno::LineStyleEnums[] = { "NoLine",
54
//**************************************************************************
55
// Construction/Destruction
57
ViewProviderRichAnno::ViewProviderRichAnno()
59
sPixmap = "actions/TechDraw_RichTextAnnotation";
61
static const char *group = "Frame Format";
63
ADD_PROPERTY_TYPE(LineWidth, (getDefLineWeight()), group, (App::PropertyType)(App::Prop_None), "Frame line width");
64
LineStyle.setEnums(LineStyleEnums);
65
ADD_PROPERTY_TYPE(LineStyle, (1), group, (App::PropertyType)(App::Prop_None), "Frame line style");
66
ADD_PROPERTY_TYPE(LineColor, (getDefLineColor()), group, App::Prop_None, "The color of the frame");
68
StackOrder.setValue(ZVALUE::DIMENSION);
71
ViewProviderRichAnno::~ViewProviderRichAnno()
75
bool ViewProviderRichAnno::doubleClicked()
77
// Base::Console().Message("VPRA::doubleClicked()\n");
78
setEdit(ViewProvider::Default);
82
void ViewProviderRichAnno::updateData(const App::Property* p)
84
// only if there is a frame we can enable the frame line parameters
85
if (getViewObject()) {
86
if (getViewObject()->ShowFrame.getValue()) {
87
LineWidth.setStatus(App::Property::ReadOnly, false);
88
LineStyle.setStatus(App::Property::ReadOnly, false);
89
LineColor.setStatus(App::Property::ReadOnly, false);
92
LineWidth.setStatus(App::Property::ReadOnly, true);
93
LineStyle.setStatus(App::Property::ReadOnly, true);
94
LineColor.setStatus(App::Property::ReadOnly, true);
98
ViewProviderDrawingView::updateData(p);
101
void ViewProviderRichAnno::onChanged(const App::Property* p)
103
if ((p == &LineColor) ||
106
QGIView* qgiv = getQView();
108
qgiv->updateView(true);
112
ViewProviderDrawingView::onChanged(p);
115
TechDraw::DrawRichAnno* ViewProviderRichAnno::getViewObject() const
117
return dynamic_cast<TechDraw::DrawRichAnno*>(pcObject);
120
TechDraw::DrawRichAnno* ViewProviderRichAnno::getFeature() const
122
return dynamic_cast<TechDraw::DrawRichAnno*>(pcObject);
125
App::Color ViewProviderRichAnno::getDefLineColor()
127
return PreferencesGui::leaderColor();
130
std::string ViewProviderRichAnno::getDefFont()
132
return Preferences::labelFont();
135
double ViewProviderRichAnno::getDefFontSize()
137
return Preferences::dimFontSizeMM();
140
double ViewProviderRichAnno::getDefLineWeight()
142
return TechDraw::LineGroup::getDefaultWidth("Graphics");
145
void ViewProviderRichAnno::handleChangedPropertyType(Base::XMLReader &reader, const char *TypeName, App::Property *prop)
146
// transforms properties that had been changed
148
// property LineWidth had App::PropertyFloat and was changed to App::PropertyLength
149
if (prop == &LineWidth && strcmp(TypeName, "App::PropertyFloat") == 0) {
150
App::PropertyFloat LineWidthProperty;
151
// restore the PropertyFloat to be able to set its value
152
LineWidthProperty.Restore(reader);
153
LineWidth.setValue(LineWidthProperty.getValue());
156
// property LineStyle had App::PropertyInteger and was changed to App::PropertyIntegerConstraint
157
else if (prop == &LineStyle && strcmp(TypeName, "App::PropertyInteger") == 0) {
158
App::PropertyInteger LineStyleProperty;
159
// restore the PropertyInteger to be able to set its value
160
LineStyleProperty.Restore(reader);
161
LineStyle.setValue(LineStyleProperty.getValue());
164
// property LineStyle had App::PropertyIntegerConstraint and was changed to App::PropertyEnumeration
165
else if (prop == &LineStyle && strcmp(TypeName, "App::PropertyIntegerConstraint") == 0) {
166
App::PropertyIntegerConstraint LineStyleProperty;
167
// restore the PropertyIntegerConstraint to be able to set its value
168
LineStyleProperty.Restore(reader);
169
LineStyle.setValue(LineStyleProperty.getValue());
173
ViewProviderDrawingView::handleChangedPropertyType(reader, TypeName, prop);
177
bool ViewProviderRichAnno::canDelete(App::DocumentObject *obj) const
179
// deletions of RichAnno objects don't destroy anything
180
// thus we can pass this action
181
// only for information: RichAnnos that have a parent
182
// view will get the page as new parent if the view is deleted