[TD]add light text on dark page mode

- some visually impaired users need white graphics on
  dark page.

- revise Annotation dialog to respect dark style
This commit is contained in:
wandererfan
2022-12-17 07:41:37 -05:00
committed by WandererFan
parent ed8e45ac9b
commit d63ac0f7f6
34 changed files with 3257 additions and 2160 deletions

View File

@@ -23,9 +23,9 @@
#include "PreCompiled.h" #include "PreCompiled.h"
#ifndef _PreComp_ #ifndef _PreComp_
#include <Precision.hxx>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
# include <Precision.hxx>
#endif #endif
#include <App/Application.h> #include <App/Application.h>
@@ -50,15 +50,12 @@ using namespace TechDraw;
// DrawPage // DrawPage
//=========================================================================== //===========================================================================
App::PropertyFloatConstraint::Constraints DrawPage::scaleRange = {Precision::Confusion(), App::PropertyFloatConstraint::Constraints DrawPage::scaleRange = {
std::numeric_limits<double>::max(), Precision::Confusion(), std::numeric_limits<double>::max(), (0.1)};// increment by 0.1
(0.1)}; // increment by 0.1
PROPERTY_SOURCE(TechDraw::DrawPage, App::DocumentObject) PROPERTY_SOURCE(TechDraw::DrawPage, App::DocumentObject)
const char* DrawPage::ProjectionTypeEnums[] = { "First Angle", const char* DrawPage::ProjectionTypeEnums[] = {"First Angle", "Third Angle", nullptr};
"Third Angle",
nullptr };
DrawPage::DrawPage(void) DrawPage::DrawPage(void)
{ {
@@ -66,24 +63,38 @@ DrawPage::DrawPage(void)
nowUnsetting = false; nowUnsetting = false;
forceRedraw(false); forceRedraw(false);
ADD_PROPERTY_TYPE(KeepUpdated, (Preferences::keepPagesUpToDate()), ADD_PROPERTY_TYPE(KeepUpdated,
group, (App::PropertyType)(App::Prop_Output), "Keep page in sync with model"); (Preferences::keepPagesUpToDate()),
ADD_PROPERTY_TYPE(Template, (nullptr), group, (App::PropertyType)(App::Prop_None), "Attached Template"); group,
(App::PropertyType)(App::Prop_Output),
"Keep page in sync with model");
ADD_PROPERTY_TYPE(
Template, (nullptr), group, (App::PropertyType)(App::Prop_None), "Attached Template");
Template.setScope(App::LinkScope::Global); Template.setScope(App::LinkScope::Global);
ADD_PROPERTY_TYPE(Views, (nullptr), group, (App::PropertyType)(App::Prop_None), "Attached Views"); ADD_PROPERTY_TYPE(
Views, (nullptr), group, (App::PropertyType)(App::Prop_None), "Attached Views");
Views.setScope(App::LinkScope::Global); Views.setScope(App::LinkScope::Global);
// Projection Properties // Projection Properties
ProjectionType.setEnums(ProjectionTypeEnums); ProjectionType.setEnums(ProjectionTypeEnums);
ADD_PROPERTY(ProjectionType, ((long)Preferences::projectionAngle())); ADD_PROPERTY(ProjectionType, ((long)Preferences::projectionAngle()));
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter(). Base::Reference<ParameterGrp> hGrp = App::GetApplication()
GetGroup("BaseApp")->GetGroup("Preferences")-> .GetUserParameter()
GetGroup("Mod/TechDraw/General"); .GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/General");
double defScale = hGrp->GetFloat("DefaultScale", 1.0); double defScale = hGrp->GetFloat("DefaultScale", 1.0);
ADD_PROPERTY_TYPE(Scale, (defScale), group, (App::PropertyType)(App::Prop_None), "Scale factor for this Page"); ADD_PROPERTY_TYPE(Scale,
(defScale),
group,
(App::PropertyType)(App::Prop_None),
"Scale factor for this Page");
ADD_PROPERTY_TYPE(NextBalloonIndex, (1), group, (App::PropertyType)(App::Prop_None), ADD_PROPERTY_TYPE(NextBalloonIndex,
(1),
group,
(App::PropertyType)(App::Prop_None),
"Auto-numbering for Balloons"); "Auto-numbering for Balloons");
Scale.setConstraints(&scaleRange); Scale.setConstraints(&scaleRange);
@@ -91,8 +102,7 @@ DrawPage::DrawPage(void)
} }
DrawPage::~DrawPage() DrawPage::~DrawPage()
{ {}
}
void DrawPage::onBeforeChange(const App::Property* prop) void DrawPage::onBeforeChange(const App::Property* prop)
{ {
@@ -101,27 +111,29 @@ void DrawPage::onBeforeChange(const App::Property* prop)
void DrawPage::onChanged(const App::Property* prop) void DrawPage::onChanged(const App::Property* prop)
{ {
if ((prop == &KeepUpdated) && if ((prop == &KeepUpdated) && KeepUpdated.getValue()) {
KeepUpdated.getValue()) { if (!isRestoring() && !isUnsetting()) {
if (!isRestoring() &&
!isUnsetting()) {
//would be nice if this message was displayed immediately instead of after the recomputeFeature //would be nice if this message was displayed immediately instead of after the recomputeFeature
Base::Console().Message("Rebuilding Views for: %s/%s\n", getNameInDocument(), Label.getValue()); Base::Console().Message(
"Rebuilding Views for: %s/%s\n", getNameInDocument(), Label.getValue());
updateAllViews(); updateAllViews();
purgeTouched(); purgeTouched();
} }
} else if (prop == &Template) { }
if (!isRestoring() && else if (prop == &Template) {
!isUnsetting()) { if (!isRestoring() && !isUnsetting()) {
//nothing to page to do?? //nothing to page to do??
} }
} else if(prop == &Scale) { }
else if (prop == &Scale) {
// touch all views in the Page as they may be dependent on this scale // touch all views in the Page as they may be dependent on this scale
// WF: not sure this loop is required. Views figure out their scale as required. but maybe // WF: not sure this loop is required. Views figure out their scale as required. but maybe
// this is needed just to mark the Views to recompute?? // this is needed just to mark the Views to recompute??
if (!isRestoring()) { if (!isRestoring()) {
const std::vector<App::DocumentObject*>& vals = Views.getValues(); const std::vector<App::DocumentObject*>& vals = Views.getValues();
for(std::vector<App::DocumentObject *>::const_iterator it = vals.begin(); it < vals.end(); ++it) { for (std::vector<App::DocumentObject*>::const_iterator it = vals.begin();
it < vals.end();
++it) {
TechDraw::DrawView* view = dynamic_cast<TechDraw::DrawView*>(*it); TechDraw::DrawView* view = dynamic_cast<TechDraw::DrawView*>(*it);
if (view && view->ScaleType.isValue("Page")) { if (view && view->ScaleType.isValue("Page")) {
if (std::abs(view->Scale.getValue() - Scale.getValue()) > FLT_EPSILON) { if (std::abs(view->Scale.getValue() - Scale.getValue()) > FLT_EPSILON) {
@@ -130,10 +142,12 @@ void DrawPage::onChanged(const App::Property* prop)
} }
} }
} }
} else if (prop == &ProjectionType) { }
else if (prop == &ProjectionType) {
// touch all ortho views in the Page as they may be dependent on Projection Type //(is this true?) // touch all ortho views in the Page as they may be dependent on Projection Type //(is this true?)
const std::vector<App::DocumentObject*>& vals = Views.getValues(); const std::vector<App::DocumentObject*>& vals = Views.getValues();
for(std::vector<App::DocumentObject *>::const_iterator it = vals.begin(); it < vals.end(); ++it) { for (std::vector<App::DocumentObject*>::const_iterator it = vals.begin(); it < vals.end();
++it) {
TechDraw::DrawProjGroup* view = dynamic_cast<TechDraw::DrawProjGroup*>(*it); TechDraw::DrawProjGroup* view = dynamic_cast<TechDraw::DrawProjGroup*>(*it);
if (view && view->ProjectionType.isValue("Default")) { if (view && view->ProjectionType.isValue("Default")) {
view->ProjectionType.touch(); view->ProjectionType.touch();
@@ -141,7 +155,6 @@ void DrawPage::onChanged(const App::Property* prop)
} }
// TODO: Also update Template graphic. // TODO: Also update Template graphic.
} }
App::DocumentObject::onChanged(prop); App::DocumentObject::onChanged(prop);
} }
@@ -157,10 +170,8 @@ short DrawPage::mustExecute() const
{ {
short result = 0; short result = 0;
if (!isRestoring()) { if (!isRestoring()) {
result = (Views.isTouched() || result = (Views.isTouched() || Scale.isTouched() || ProjectionType.isTouched()
Scale.isTouched() || || Template.isTouched());
ProjectionType.isTouched() ||
Template.isTouched());
if (result) { if (result) {
return result; return result;
} }
@@ -185,8 +196,7 @@ bool DrawPage::hasValidTemplate() const
if (obj && obj->isDerivedFrom(TechDraw::DrawTemplate::getClassTypeId())) { if (obj && obj->isDerivedFrom(TechDraw::DrawTemplate::getClassTypeId())) {
TechDraw::DrawTemplate* templ = static_cast<TechDraw::DrawTemplate*>(obj); TechDraw::DrawTemplate* templ = static_cast<TechDraw::DrawTemplate*>(obj);
if (templ->getWidth() > 0. && if (templ->getWidth() > 0. && templ->getHeight() > 0.) {
templ->getHeight() > 0.) {
return true; return true;
} }
} }
@@ -256,13 +266,14 @@ int DrawPage::getOrientation() const
int DrawPage::addView(App::DocumentObject* docObj) int DrawPage::addView(App::DocumentObject* docObj)
{ {
if(!docObj->isDerivedFrom(TechDraw::DrawView::getClassTypeId())) if (!docObj->isDerivedFrom(TechDraw::DrawView::getClassTypeId())) {
return -1; return -1;
}
DrawView* view = static_cast<DrawView*>(docObj); DrawView* view = static_cast<DrawView*>(docObj);
//position all new views in center of Page (exceptDVDimension) //position all new views in center of Page (exceptDVDimension)
if (!docObj->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId()) && if (!docObj->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId())
!docObj->isDerivedFrom(TechDraw::DrawViewBalloon::getClassTypeId())) { && !docObj->isDerivedFrom(TechDraw::DrawViewBalloon::getClassTypeId())) {
view->X.setValue(getPageWidth() / 2.0); view->X.setValue(getPageWidth() / 2.0);
view->Y.setValue(getPageHeight() / 2.0); view->Y.setValue(getPageHeight() / 2.0);
} }
@@ -275,7 +286,8 @@ int DrawPage::addView(App::DocumentObject *docObj)
//check if View fits on Page //check if View fits on Page
if (!view->checkFit(this)) { if (!view->checkFit(this)) {
Base::Console().Warning("%s is larger than page. Will be scaled.\n", view->getNameInDocument()); Base::Console().Warning("%s is larger than page. Will be scaled.\n",
view->getNameInDocument());
view->ScaleType.setValue("Automatic"); view->ScaleType.setValue("Automatic");
} }
@@ -287,8 +299,9 @@ int DrawPage::addView(App::DocumentObject *docObj)
//Note Views might be removed from document elsewhere so need to check if a View is still in Document here //Note Views might be removed from document elsewhere so need to check if a View is still in Document here
int DrawPage::removeView(App::DocumentObject* docObj) int DrawPage::removeView(App::DocumentObject* docObj)
{ {
if(!docObj->isDerivedFrom(TechDraw::DrawView::getClassTypeId())) if (!docObj->isDerivedFrom(TechDraw::DrawView::getClassTypeId())) {
return -1; return -1;
}
App::Document* doc = docObj->getDocument(); App::Document* doc = docObj->getDocument();
if (!doc) { if (!doc) {
@@ -343,7 +356,8 @@ void DrawPage::redrawCommand()
void DrawPage::updateAllViews() void DrawPage::updateAllViews()
{ {
// Base::Console().Message("DP::updateAllViews()\n"); // Base::Console().Message("DP::updateAllViews()\n");
std::vector<App::DocumentObject*> featViews = getAllViews(); //unordered list of views within page std::vector<App::DocumentObject*> featViews =
getAllViews();//unordered list of views within page
//first, make sure all the Parts have been executed so GeometryObjects exist //first, make sure all the Parts have been executed so GeometryObjects exist
for (auto& v : featViews) { for (auto& v : featViews) {
@@ -404,24 +418,27 @@ void DrawPage::unsetupObject()
if (v->isAttachedToDocument()) { if (v->isAttachedToDocument()) {
std::string viewName = v->getNameInDocument(); std::string viewName = v->getNameInDocument();
Base::Interpreter().runStringArg("App.getDocument(\"%s\").removeObject(\"%s\")", Base::Interpreter().runStringArg("App.getDocument(\"%s\").removeObject(\"%s\")",
docName.c_str(), viewName.c_str()); docName.c_str(),
} else { viewName.c_str());
Base::Console().Log("DP::unsetupObject - v(%s) is not in document. skipping\n", pageName.c_str()); }
else {
Base::Console().Log("DP::unsetupObject - v(%s) is not in document. skipping\n",
pageName.c_str());
} }
} }
std::vector<App::DocumentObject*> emptyViews;//probably superfluous std::vector<App::DocumentObject*> emptyViews;//probably superfluous
Views.setValues(emptyViews); Views.setValues(emptyViews);
} }
catch (...) { catch (...) {
Base::Console().Warning("DP::unsetupObject - %s - error while deleting children\n", getNameInDocument()); Base::Console().Warning("DP::unsetupObject - %s - error while deleting children\n",
getNameInDocument());
} }
App::DocumentObject* tmp = Template.getValue(); App::DocumentObject* tmp = Template.getValue();
if (tmp) { if (tmp) {
std::string templateName = Template.getValue()->getNameInDocument(); std::string templateName = Template.getValue()->getNameInDocument();
Base::Interpreter().runStringArg("App.getDocument(\"%s\").removeObject(\"%s\")", Base::Interpreter().runStringArg(
docName.c_str(), templateName.c_str()); "App.getDocument(\"%s\").removeObject(\"%s\")", docName.c_str(), templateName.c_str());
} }
Template.setValue(nullptr); Template.setValue(nullptr);
} }
@@ -434,8 +451,8 @@ int DrawPage::getNextBalloonIndex(void)
return result; return result;
} }
void DrawPage::handleChangedPropertyType( void DrawPage::handleChangedPropertyType(Base::XMLReader& reader, const char* TypeName,
Base::XMLReader &reader, const char * TypeName, App::Property * prop) App::Property* prop)
{ {
if (prop == &Scale) { if (prop == &Scale) {
App::PropertyFloat tmp; App::PropertyFloat tmp;
@@ -445,10 +462,12 @@ void DrawPage::handleChangedPropertyType(
double tmpValue = tmp.getValue(); double tmpValue = tmp.getValue();
if (tmpValue > 0.0) { if (tmpValue > 0.0) {
Scale.setValue(tmpValue); Scale.setValue(tmpValue);
} else { }
else {
Scale.setValue(1.0); Scale.setValue(1.0);
} }
} else { }
else {
// has Scale prop that isn't Float! // has Scale prop that isn't Float!
Base::Console().Log("DrawPage::Restore - old Document Scale is Not Float!\n"); Base::Console().Log("DrawPage::Restore - old Document Scale is Not Float!\n");
// no idea // no idea
@@ -459,12 +478,10 @@ void DrawPage::handleChangedPropertyType(
bool DrawPage::canUpdate() const bool DrawPage::canUpdate() const
{ {
bool result = false; bool result = false;
if (GlobalUpdateDrawings() && if (GlobalUpdateDrawings() && KeepUpdated.getValue()) {
KeepUpdated.getValue()) {
result = true; result = true;
} else if (!GlobalUpdateDrawings() && }
AllowPageOverride() && else if (!GlobalUpdateDrawings() && AllowPageOverride() && KeepUpdated.getValue()) {
KeepUpdated.getValue()) {
result = true; result = true;
} }
return result; return result;
@@ -486,8 +503,11 @@ bool DrawPage::hasObject(App::DocumentObject* obj)
//allow/prevent drawing updates for all Pages //allow/prevent drawing updates for all Pages
bool DrawPage::GlobalUpdateDrawings(void) bool DrawPage::GlobalUpdateDrawings(void)
{ {
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter() Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/General"); .GetUserParameter()
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/General");
bool result = hGrp->GetBool("GlobalUpdateDrawings", true); bool result = hGrp->GetBool("GlobalUpdateDrawings", true);
return result; return result;
} }
@@ -495,8 +515,11 @@ bool DrawPage::GlobalUpdateDrawings(void)
//allow/prevent a single page to update despite GlobalUpdateDrawings setting //allow/prevent a single page to update despite GlobalUpdateDrawings setting
bool DrawPage::AllowPageOverride(void) bool DrawPage::AllowPageOverride(void)
{ {
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter() Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/General"); .GetUserParameter()
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/General");
bool result = hGrp->GetBool("AllowPageOverride", true); bool result = hGrp->GetBool("AllowPageOverride", true);
return result; return result;
} }
@@ -504,14 +527,16 @@ bool DrawPage::AllowPageOverride(void)
// Python Drawing feature --------------------------------------------------------- // Python Drawing feature ---------------------------------------------------------
namespace App { namespace App
{
/// @cond DOXERR /// @cond DOXERR
PROPERTY_SOURCE_TEMPLATE(TechDraw::DrawPagePython, TechDraw::DrawPage) PROPERTY_SOURCE_TEMPLATE(TechDraw::DrawPagePython, TechDraw::DrawPage)
template<> const char* TechDraw::DrawPagePython::getViewProviderName(void) const { template<> const char* TechDraw::DrawPagePython::getViewProviderName(void) const
{
return "TechDrawGui::ViewProviderPage"; return "TechDrawGui::ViewProviderPage";
} }
/// @endcond /// @endcond
// explicit template instantiation // explicit template instantiation
template class TechDrawExport FeaturePythonT<TechDraw::DrawPage>; template class TechDrawExport FeaturePythonT<TechDraw::DrawPage>;
} }// namespace App

View File

@@ -53,7 +53,7 @@ DrawViewAnnotation::DrawViewAnnotation()
ADD_PROPERTY_TYPE(Text ,("Default Text"), vgroup, App::Prop_None, "Annotation text"); ADD_PROPERTY_TYPE(Text ,("Default Text"), vgroup, App::Prop_None, "Annotation text");
ADD_PROPERTY_TYPE(Font ,(Preferences::labelFont().c_str()), ADD_PROPERTY_TYPE(Font ,(Preferences::labelFont().c_str()),
vgroup, App::Prop_None, "Font name"); vgroup, App::Prop_None, "Font name");
ADD_PROPERTY_TYPE(TextColor, (0.0f, 0.0f, 0.0f), vgroup, App::Prop_None, "Text color"); ADD_PROPERTY_TYPE(TextColor, (Preferences::normalColor()), vgroup, App::Prop_None, "Text color");
ADD_PROPERTY_TYPE(TextSize, (Preferences::labelFontSizeMM()), ADD_PROPERTY_TYPE(TextSize, (Preferences::labelFontSizeMM()),
vgroup, App::Prop_None, "Text size"); vgroup, App::Prop_None, "Text size");
ADD_PROPERTY_TYPE(MaxWidth, (-1.0), vgroup, App::Prop_None, "Maximum width of the annotation block.\n -1 means no maximum width."); ADD_PROPERTY_TYPE(MaxWidth, (-1.0), vgroup, App::Prop_None, "Maximum width of the annotation block.\n -1 means no maximum width.");

View File

@@ -23,19 +23,19 @@
#include "PreCompiled.h" #include "PreCompiled.h"
#ifndef _PreComp_ #ifndef _PreComp_
# include <sstream>
# include <QDomDocument>
#include "QDomNodeModel.h" #include "QDomNodeModel.h"
#include <QDomDocument>
#include <QXmlQuery> #include <QXmlQuery>
#include <QXmlResultItems> #include <QXmlResultItems>
#include <sstream>
#endif #endif
#include <Base/Console.h> #include <Base/Console.h>
#include "DrawViewSymbol.h"
#include "DrawViewSymbolPy.h" // generated from DrawViewSymbolPy.xml
#include "DrawPage.h" #include "DrawPage.h"
#include "DrawUtil.h" #include "DrawUtil.h"
#include "DrawViewSymbol.h"
#include "DrawViewSymbolPy.h"// generated from DrawViewSymbolPy.xml
using namespace TechDraw; using namespace TechDraw;
@@ -52,15 +52,14 @@ DrawViewSymbol::DrawViewSymbol()
static const char* vgroup = "Drawing view"; static const char* vgroup = "Drawing view";
ADD_PROPERTY_TYPE(Symbol, (""), vgroup, App::Prop_None, "The SVG code defining this symbol"); ADD_PROPERTY_TYPE(Symbol, (""), vgroup, App::Prop_None, "The SVG code defining this symbol");
ADD_PROPERTY_TYPE(EditableTexts, (""), vgroup, App::Prop_None, "Substitution values for the editable strings in this symbol"); ADD_PROPERTY_TYPE(EditableTexts, (""), vgroup, App::Prop_None,
"Substitution values for the editable strings in this symbol");
ScaleType.setValue("Custom"); ScaleType.setValue("Custom");
Scale.setStatus(App::Property::ReadOnly, false); Scale.setStatus(App::Property::ReadOnly, false);
Symbol.setStatus(App::Property::Hidden, true); Symbol.setStatus(App::Property::Hidden, true);
} }
DrawViewSymbol::~DrawViewSymbol() DrawViewSymbol::~DrawViewSymbol() {}
{
}
void DrawViewSymbol::onChanged(const App::Property* prop) void DrawViewSymbol::onChanged(const App::Property* prop)
{ {
@@ -69,7 +68,8 @@ void DrawViewSymbol::onChanged(const App::Property* prop)
std::vector<std::string> editables = getEditableFields(); std::vector<std::string> editables = getEditableFields();
EditableTexts.setValues(editables); EditableTexts.setValues(editables);
} }
} else if (prop == &EditableTexts) { }
else if (prop == &EditableTexts) {
//this will change Symbol, which will call onChanged(Symbol), //this will change Symbol, which will call onChanged(Symbol),
//which will change EditableTexts, but the loop stops after //which will change EditableTexts, but the loop stops after
//1 cycle //1 cycle
@@ -117,15 +117,15 @@ std::vector<std::string> DrawViewSymbol::getEditableFields()
// XPath query to select all <tspan> nodes whose <text> parent // XPath query to select all <tspan> nodes whose <text> parent
// has "freecad:editable" attribute // has "freecad:editable" attribute
query.setQuery(QString::fromUtf8( query.setQuery(QString::fromUtf8("declare default element namespace \"" SVG_NS_URI "\"; "
"declare default element namespace \"" SVG_NS_URI "\"; "
"declare namespace freecad=\"" FREECAD_SVG_NS_URI "\"; " "declare namespace freecad=\"" FREECAD_SVG_NS_URI "\"; "
"//text[@freecad:editable]/tspan")); "//text[@freecad:editable]/tspan"));
query.evaluateTo(&queryResult); query.evaluateTo(&queryResult);
while (!queryResult.next().isNull()) { while (!queryResult.next().isNull()) {
QDomElement tspan = model.toDomNode(queryResult.current().toNodeModelIndex()).toElement(); QDomElement tspan =
model.toDomNode(queryResult.current().toNodeModelIndex()).toElement();
QString editableValue = tspan.firstChild().nodeValue(); QString editableValue = tspan.firstChild().nodeValue();
editables.emplace_back(editableValue.toUtf8().constData()); editables.emplace_back(editableValue.toUtf8().constData());
} }
@@ -153,19 +153,19 @@ void DrawViewSymbol::updateFieldsInSymbol()
// XPath query to select all <tspan> nodes whose <text> parent // XPath query to select all <tspan> nodes whose <text> parent
// has "freecad:editable" attribute // has "freecad:editable" attribute
query.setQuery(QString::fromUtf8( query.setQuery(QString::fromUtf8("declare default element namespace \"" SVG_NS_URI "\"; "
"declare default element namespace \"" SVG_NS_URI "\"; "
"declare namespace freecad=\"" FREECAD_SVG_NS_URI "\"; " "declare namespace freecad=\"" FREECAD_SVG_NS_URI "\"; "
"//text[@freecad:editable]/tspan")); "//text[@freecad:editable]/tspan"));
query.evaluateTo(&queryResult); query.evaluateTo(&queryResult);
unsigned int count = 0; unsigned int count = 0;
while (!queryResult.next().isNull()) while (!queryResult.next().isNull()) {
{ QDomElement tspanElement =
QDomElement tspanElement = model.toDomNode(queryResult.current().toNodeModelIndex()).toElement(); model.toDomNode(queryResult.current().toNodeModelIndex()).toElement();
// Keep all spaces in the text node // Keep all spaces in the text node
tspanElement.setAttribute(QString::fromUtf8("xml:space"), QString::fromUtf8("preserve")); tspanElement.setAttribute(QString::fromUtf8("xml:space"),
QString::fromUtf8("preserve"));
// Remove all child nodes (if any) // Remove all child nodes (if any)
while (!tspanElement.lastChild().isNull()) { while (!tspanElement.lastChild().isNull()) {
@@ -173,8 +173,8 @@ void DrawViewSymbol::updateFieldsInSymbol()
} }
// Finally append text node with editable replacement as the only <tspan> descendant // Finally append text node with editable replacement as the only <tspan> descendant
tspanElement.appendChild(symbolDocument.createTextNode( tspanElement.appendChild(
QString::fromUtf8(editText[count].c_str()))); symbolDocument.createTextNode(QString::fromUtf8(editText[count].c_str())));
++count; ++count;
} }
Symbol.setValue(symbolDocument.toString(1).toStdString()); Symbol.setValue(symbolDocument.toString(1).toStdString());
@@ -186,6 +186,9 @@ bool DrawViewSymbol::loadQDomDocument(QDomDocument& symbolDocument)
{ {
const char* symbol = Symbol.getValue(); const char* symbol = Symbol.getValue();
QByteArray qba(symbol); QByteArray qba(symbol);
if (qba.isEmpty()) {
return false;
}
QString errorMsg; QString errorMsg;
int errorLine; int errorLine;
int errorCol; int errorCol;
@@ -193,10 +196,11 @@ bool DrawViewSymbol::loadQDomDocument(QDomDocument& symbolDocument)
bool rc = symbolDocument.setContent(qba, nsProcess, &errorMsg, &errorLine, &errorCol); bool rc = symbolDocument.setContent(qba, nsProcess, &errorMsg, &errorLine, &errorCol);
if (!rc) { if (!rc) {
//invalid SVG message //invalid SVG message
Base::Console().Warning("DrawViewSymbol - %s - SVG for Symbol is not valid. See log.\n"); Base::Console().Warning("DrawViewSymbol - %s - SVG for Symbol is not valid. See log.\n",
getNameInDocument());
Base::Console().Log("DrawViewSymbol - %s - len: %d rc: %d error: %s line: %d col: %d\n", Base::Console().Log("DrawViewSymbol - %s - len: %d rc: %d error: %s line: %d col: %d\n",
getNameInDocument(), strlen(symbol), rc, getNameInDocument(), strlen(symbol), rc, qPrintable(errorMsg),
qPrintable(errorMsg), errorLine, errorCol); errorLine, errorCol);
} }
return rc; return rc;
} }
@@ -212,14 +216,16 @@ PyObject *DrawViewSymbol::getPyObject()
// Python Drawing feature --------------------------------------------------------- // Python Drawing feature ---------------------------------------------------------
namespace App { namespace App
{
/// @cond DOXERR /// @cond DOXERR
PROPERTY_SOURCE_TEMPLATE(TechDraw::DrawViewSymbolPython, TechDraw::DrawViewSymbol) PROPERTY_SOURCE_TEMPLATE(TechDraw::DrawViewSymbolPython, TechDraw::DrawViewSymbol)
template<> const char* TechDraw::DrawViewSymbolPython::getViewProviderName() const { template<> const char* TechDraw::DrawViewSymbolPython::getViewProviderName() const
{
return "TechDrawGui::ViewProviderSymbol"; return "TechDrawGui::ViewProviderSymbol";
} }
/// @endcond /// @endcond
// explicit template instantiation // explicit template instantiation
template class TechDrawExport FeaturePythonT<TechDraw::DrawViewSymbol>; template class TechDrawExport FeaturePythonT<TechDraw::DrawViewSymbol>;
} }// namespace App

View File

@@ -23,8 +23,8 @@
#include "PreCompiled.h" #include "PreCompiled.h"
#ifndef _PreComp_ #ifndef _PreComp_
#include <string>
#include <QString> #include <QString>
#include <string>
#endif #endif
#include <App/Application.h> #include <App/Application.h>
@@ -45,9 +45,11 @@ const double Preferences::DefaultFontSizeInMM = 5.0;
std::string Preferences::labelFont() std::string Preferences::labelFont()
{ {
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter(). Base::Reference<ParameterGrp> hGrp = App::GetApplication()
GetGroup("BaseApp")->GetGroup("Preferences")-> .GetUserParameter()
GetGroup("Mod/TechDraw/Labels"); .GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/Labels");
std::string fontName = hGrp->GetASCII("LabelFont", "osifont"); std::string fontName = hGrp->GetASCII("LabelFont", "osifont");
return fontName; return fontName;
} }
@@ -60,25 +62,31 @@ QString Preferences::labelFontQString()
double Preferences::labelFontSizeMM() double Preferences::labelFontSizeMM()
{ {
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter(). Base::Reference<ParameterGrp> hGrp = App::GetApplication()
GetGroup("BaseApp")->GetGroup("Preferences")-> .GetUserParameter()
GetGroup("Mod/TechDraw/Labels"); .GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/Labels");
return hGrp->GetFloat("LabelSize", DefaultFontSizeInMM); return hGrp->GetFloat("LabelSize", DefaultFontSizeInMM);
} }
double Preferences::dimFontSizeMM() double Preferences::dimFontSizeMM()
{ {
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter(). Base::Reference<ParameterGrp> hGrp = App::GetApplication()
GetGroup("BaseApp")->GetGroup("Preferences")-> .GetUserParameter()
GetGroup("Mod/TechDraw/Dimensions"); .GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/Dimensions");
return hGrp->GetFloat("FontSize", DefaultFontSizeInMM); return hGrp->GetFloat("FontSize", DefaultFontSizeInMM);
} }
App::Color Preferences::normalColor() App::Color Preferences::normalColor()
{ {
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter(). Base::Reference<ParameterGrp> hGrp = App::GetApplication()
GetGroup("BaseApp")->GetGroup("Preferences")-> .GetUserParameter()
GetGroup("Mod/TechDraw/Colors"); .GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/Colors");
App::Color fcColor; App::Color fcColor;
fcColor.setPackedValue(hGrp->GetUnsigned("NormalColor", 0x000000FF));//#000000 black fcColor.setPackedValue(hGrp->GetUnsigned("NormalColor", 0x000000FF));//#000000 black
return fcColor; return fcColor;
@@ -86,14 +94,18 @@ App::Color Preferences::normalColor()
App::Color Preferences::selectColor() App::Color Preferences::selectColor()
{ {
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter(). Base::Reference<ParameterGrp> hGrp = App::GetApplication()
GetGroup("BaseApp")->GetGroup("Preferences")-> .GetUserParameter()
GetGroup("View"); .GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("View");
unsigned int defColor = hGrp->GetUnsigned("SelectionColor", 0x00FF00FF);//#00FF00 lime unsigned int defColor = hGrp->GetUnsigned("SelectionColor", 0x00FF00FF);//#00FF00 lime
hGrp = App::GetApplication().GetUserParameter(). hGrp = App::GetApplication()
GetGroup("BaseApp")->GetGroup("Preferences")-> .GetUserParameter()
GetGroup("Mod/TechDraw/Colors"); .GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/Colors");
App::Color fcColor; App::Color fcColor;
fcColor.setPackedValue(hGrp->GetUnsigned("SelectColor", defColor)); fcColor.setPackedValue(hGrp->GetUnsigned("SelectColor", defColor));
return fcColor; return fcColor;
@@ -101,14 +113,18 @@ App::Color Preferences::selectColor()
App::Color Preferences::preselectColor() App::Color Preferences::preselectColor()
{ {
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter(). Base::Reference<ParameterGrp> hGrp = App::GetApplication()
GetGroup("BaseApp")->GetGroup("Preferences")-> .GetUserParameter()
GetGroup("View"); .GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("View");
unsigned int defColor = hGrp->GetUnsigned("HighlightColor", 0xFFFF00FF);//#FFFF00 yellow unsigned int defColor = hGrp->GetUnsigned("HighlightColor", 0xFFFF00FF);//#FFFF00 yellow
hGrp = App::GetApplication().GetUserParameter(). hGrp = App::GetApplication()
GetGroup("BaseApp")->GetGroup("Preferences")-> .GetUserParameter()
GetGroup("Mod/TechDraw/Colors"); .GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/Colors");
App::Color fcColor; App::Color fcColor;
fcColor.setPackedValue(hGrp->GetUnsigned("PreSelectColor", defColor)); fcColor.setPackedValue(hGrp->GetUnsigned("PreSelectColor", defColor));
return fcColor; return fcColor;
@@ -116,9 +132,11 @@ App::Color Preferences::preselectColor()
App::Color Preferences::vertexColor() App::Color Preferences::vertexColor()
{ {
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter(). Base::Reference<ParameterGrp> hGrp = App::GetApplication()
GetGroup("BaseApp")->GetGroup("Preferences")-> .GetUserParameter()
GetGroup("Mod/TechDraw/Decorations"); .GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/Decorations");
App::Color fcColor; App::Color fcColor;
fcColor.setPackedValue(hGrp->GetUnsigned("VertexColor", 0x000000FF));//#000000 black fcColor.setPackedValue(hGrp->GetUnsigned("VertexColor", 0x000000FF));//#000000 black
return fcColor; return fcColor;
@@ -126,16 +144,22 @@ App::Color Preferences::vertexColor()
double Preferences::vertexScale() double Preferences::vertexScale()
{ {
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")-> Base::Reference<ParameterGrp> hGrp = App::GetApplication()
GetGroup("Preferences")->GetGroup("Mod/TechDraw/General"); .GetUserParameter()
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/General");
double result = hGrp->GetFloat("VertexScale", 3.0); double result = hGrp->GetFloat("VertexScale", 3.0);
return result; return result;
} }
int Preferences::scaleType() int Preferences::scaleType()
{ {
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter() Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/General"); .GetUserParameter()
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/General");
int result = hGrp->GetInt("DefaultScaleType", 0); int result = hGrp->GetInt("DefaultScaleType", 0);
return result; return result;
} }
@@ -144,24 +168,31 @@ double Preferences::scale()
{ {
int prefScaleType = scaleType(); int prefScaleType = scaleType();
if (prefScaleType == 0) {//page scale if (prefScaleType == 0) {//page scale
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter() Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/General"); .GetUserParameter()
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/General");
return hGrp->GetFloat("DefaultPageScale", 1.0); return hGrp->GetFloat("DefaultPageScale", 1.0);
} else if (prefScaleType == 1) { //custom scale }
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter() else if (prefScaleType == 1) {//custom scale
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/General"); Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetUserParameter()
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/General");
return hGrp->GetFloat("DefaultViewScale", 1.0); return hGrp->GetFloat("DefaultViewScale", 1.0);
} }
return 1.0; return 1.0;
} }
//lightgray #D3D3D3
bool Preferences::keepPagesUpToDate() bool Preferences::keepPagesUpToDate()
{ {
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter(). Base::Reference<ParameterGrp> hGrp = App::GetApplication()
GetGroup("BaseApp")->GetGroup("Preferences")-> .GetUserParameter()
GetGroup("Mod/TechDraw/General"); .GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/General");
bool autoUpdate = hGrp->GetBool("KeepPagesUpToDate", true); bool autoUpdate = hGrp->GetBool("KeepPagesUpToDate", true);
return autoUpdate; return autoUpdate;
} }
@@ -169,45 +200,55 @@ bool Preferences::keepPagesUpToDate()
bool Preferences::useGlobalDecimals() bool Preferences::useGlobalDecimals()
{ {
bool result = false; bool result = false;
Base::Reference<ParameterGrp> hGrp = App::GetApplication(). Base::Reference<ParameterGrp> hGrp = App::GetApplication()
GetUserParameter().GetGroup("BaseApp")-> .GetUserParameter()
GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions"); .GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/Dimensions");
result = hGrp->GetBool("UseGlobalDecimals", true); result = hGrp->GetBool("UseGlobalDecimals", true);
return result; return result;
} }
int Preferences::projectionAngle() int Preferences::projectionAngle()
{ {
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter(). Base::Reference<ParameterGrp> hGrp = App::GetApplication()
GetGroup("BaseApp")->GetGroup("Preferences")-> .GetUserParameter()
GetGroup("Mod/TechDraw/General"); .GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/General");
int projType = hGrp->GetInt("ProjectionAngle", 0);//First Angle int projType = hGrp->GetInt("ProjectionAngle", 0);//First Angle
return projType; return projType;
} }
int Preferences::lineGroup() int Preferences::lineGroup()
{ {
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter(). Base::Reference<ParameterGrp> hGrp = App::GetApplication()
GetGroup("BaseApp")->GetGroup("Preferences")-> .GetUserParameter()
GetGroup("Mod/TechDraw/Decorations"); .GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/Decorations");
int lgInt = hGrp->GetInt("LineGroup", 3);// FC 0.70mm int lgInt = hGrp->GetInt("LineGroup", 3);// FC 0.70mm
return lgInt; return lgInt;
} }
int Preferences::balloonArrow() int Preferences::balloonArrow()
{ {
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter(). Base::Reference<ParameterGrp> hGrp = App::GetApplication()
GetGroup("BaseApp")->GetGroup("Preferences")-> .GetUserParameter()
GetGroup("Mod/TechDraw/Decorations"); .GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/Decorations");
int end = hGrp->GetInt("BalloonArrow", 0); int end = hGrp->GetInt("BalloonArrow", 0);
return end; return end;
} }
QString Preferences::defaultTemplate() QString Preferences::defaultTemplate()
{ {
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter(). Base::Reference<ParameterGrp> hGrp = App::GetApplication()
GetGroup("BaseApp")->GetGroup("Preferences")-> .GetUserParameter()
GetGroup("Mod/TechDraw/Files"); .GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/Files");
std::string defaultDir = App::Application::getResourceDir() + "Mod/TechDraw/Templates/"; std::string defaultDir = App::Application::getResourceDir() + "Mod/TechDraw/Templates/";
std::string defaultFileName = defaultDir + "A4_LandscapeTD.svg"; std::string defaultFileName = defaultDir + "A4_LandscapeTD.svg";
std::string prefFileName = hGrp->GetASCII("TemplateFile", defaultFileName.c_str()); std::string prefFileName = hGrp->GetASCII("TemplateFile", defaultFileName.c_str());
@@ -225,8 +266,11 @@ QString Preferences::defaultTemplate()
QString Preferences::defaultTemplateDir() QString Preferences::defaultTemplateDir()
{ {
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter() Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Files"); .GetUserParameter()
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/Files");
std::string defaultDir = App::Application::getResourceDir() + "Mod/TechDraw/Templates"; std::string defaultDir = App::Application::getResourceDir() + "Mod/TechDraw/Templates";
std::string prefTemplateDir = hGrp->GetASCII("TemplateDir", defaultDir.c_str()); std::string prefTemplateDir = hGrp->GetASCII("TemplateDir", defaultDir.c_str());
@@ -236,7 +280,8 @@ QString Preferences::defaultTemplateDir()
QString templateDir = QString::fromStdString(prefTemplateDir); QString templateDir = QString::fromStdString(prefTemplateDir);
Base::FileInfo fi(prefTemplateDir); Base::FileInfo fi(prefTemplateDir);
if (!fi.isReadable()) { if (!fi.isReadable()) {
Base::Console().Warning("Template Directory: %s is not readable\n", prefTemplateDir.c_str()); Base::Console().Warning("Template Directory: %s is not readable\n",
prefTemplateDir.c_str());
templateDir = QString::fromStdString(defaultDir); templateDir = QString::fromStdString(defaultDir);
} }
return templateDir; return templateDir;
@@ -244,9 +289,11 @@ QString Preferences::defaultTemplateDir()
std::string Preferences::lineGroupFile() std::string Preferences::lineGroupFile()
{ {
Base::Reference<ParameterGrp> hGrp = App::GetApplication(). Base::Reference<ParameterGrp> hGrp = App::GetApplication()
GetUserParameter().GetGroup("BaseApp")-> .GetUserParameter()
GetGroup("Preferences")->GetGroup("Mod/TechDraw/Files"); .GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/Files");
std::string defaultDir = App::Application::getResourceDir() + "Mod/TechDraw/LineGroup/"; std::string defaultDir = App::Application::getResourceDir() + "Mod/TechDraw/LineGroup/";
std::string defaultFileName = defaultDir + "LineGroup.csv"; std::string defaultFileName = defaultDir + "LineGroup.csv";
std::string lgFileName = hGrp->GetASCII("LineGroupFile", defaultFileName.c_str()); std::string lgFileName = hGrp->GetASCII("LineGroupFile", defaultFileName.c_str());
@@ -263,31 +310,42 @@ std::string Preferences::lineGroupFile()
std::string Preferences::formatSpec() std::string Preferences::formatSpec()
{ {
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter() Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions"); .GetUserParameter()
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/Dimensions");
return hGrp->GetASCII("formatSpec", "%.2w"); return hGrp->GetASCII("formatSpec", "%.2w");
} }
int Preferences::altDecimals() int Preferences::altDecimals()
{ {
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter() Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions"); .GetUserParameter()
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/Dimensions");
return hGrp->GetInt("AltDecimals", 2); return hGrp->GetInt("AltDecimals", 2);
} }
int Preferences::mattingStyle() int Preferences::mattingStyle()
{ {
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter(). Base::Reference<ParameterGrp> hGrp = App::GetApplication()
GetGroup("BaseApp")->GetGroup("Preferences")-> .GetUserParameter()
GetGroup("Mod/TechDraw/Decorations"); .GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/Decorations");
int style = hGrp->GetInt("MattingStyle", 0); int style = hGrp->GetInt("MattingStyle", 0);
return style; return style;
} }
std::string Preferences::svgFile() std::string Preferences::svgFile()
{ {
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter() Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Files"); .GetUserParameter()
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/Files");
std::string defaultDir = App::Application::getResourceDir() + "Mod/TechDraw/Patterns/"; std::string defaultDir = App::Application::getResourceDir() + "Mod/TechDraw/Patterns/";
std::string defaultFileName = defaultDir + "simple.svg"; std::string defaultFileName = defaultDir + "simple.svg";
@@ -305,8 +363,11 @@ std::string Preferences::svgFile()
std::string Preferences::patFile() std::string Preferences::patFile()
{ {
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter() Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/PAT"); .GetUserParameter()
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/PAT");
std::string defaultDir = App::Application::getResourceDir() + "Mod/TechDraw/PAT/"; std::string defaultDir = App::Application::getResourceDir() + "Mod/TechDraw/PAT/";
std::string defaultFileName = defaultDir + "FCPAT.pat"; std::string defaultFileName = defaultDir + "FCPAT.pat";
@@ -325,8 +386,11 @@ std::string Preferences::patFile()
std::string Preferences::bitmapFill() std::string Preferences::bitmapFill()
{ {
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter() Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Files"); .GetUserParameter()
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/Files");
std::string defaultDir = App::Application::getResourceDir() + "Mod/TechDraw/Patterns/"; std::string defaultDir = App::Application::getResourceDir() + "Mod/TechDraw/Patterns/";
std::string defaultFileName = defaultDir + "default.png"; std::string defaultFileName = defaultDir + "default.png";
@@ -344,27 +408,130 @@ std::string Preferences::bitmapFill()
double Preferences::GapISO() double Preferences::GapISO()
{ {
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter() Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetGroup("BaseApp")->GetGroup("Preferences")-> .GetUserParameter()
GetGroup("Mod/TechDraw/Dimensions"); .GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/Dimensions");
double factor = hGrp->GetFloat("GapISO", 8.0); double factor = hGrp->GetFloat("GapISO", 8.0);
return factor; return factor;
} }
double Preferences::GapASME() double Preferences::GapASME()
{ {
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter() Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetGroup("BaseApp")->GetGroup("Preferences")-> .GetUserParameter()
GetGroup("Mod/TechDraw/Dimensions"); .GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/Dimensions");
double factor = hGrp->GetFloat("GapASME", 6.0); double factor = hGrp->GetFloat("GapASME", 6.0);
return factor; return factor;
} }
bool Preferences::reportProgress() bool Preferences::reportProgress()
{ {
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter(). Base::Reference<ParameterGrp> hGrp = App::GetApplication()
GetGroup("BaseApp")->GetGroup("Preferences")-> .GetUserParameter()
GetGroup("Mod/TechDraw/General"); .GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/General");
bool report = hGrp->GetBool("ReportProgress", false); bool report = hGrp->GetBool("ReportProgress", false);
return report; return report;
} }
bool Preferences::lightOnDark()
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetUserParameter()
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/Colors");
bool light = hGrp->GetBool("LightOnDark", false);
return light;
}
void Preferences::lightOnDark(bool state)
{
Base::Console().Message("Pref::useLightText - set to %d\n", state);
Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetUserParameter()
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/Colors");
hGrp->SetBool("LightOnDark", state);
}
bool Preferences::monochrome()
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetUserParameter()
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/Colors");
bool mono = hGrp->GetBool("Monochrome", false);
return mono;
}
void Preferences::monochrome(bool state)
{
Base::Console().Message("Pref::useLightText - set to %d\n", state);
Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetUserParameter()
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/Colors");
hGrp->SetBool("Monochrome", state);
}
App::Color Preferences::lightTextColor()
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetUserParameter()
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/Colors");
App::Color result;
result.setPackedValue(hGrp->GetUnsigned("LightTextColor", 0xFFFFFFFF));//#FFFFFFFF white
return result;
}
App::Color Preferences::lightenColor(App::Color orig)
{
// get component colours on [0, 255]
uchar red = orig.r * 255;
uchar blue = orig.b * 255;
uchar green = orig.g * 255;
// uchar alpha = orig.a * 255;
// shift color values
uchar m = std::min({red, blue, green});
red -= m;
blue -= m;
green -= m;
// calculate chroma (colour range)
uchar chroma = std::max({red, blue, green});
// calculate lightened colour value
uchar newm = 255 - chroma - m;
red += newm;
green += newm;
blue += newm;
double redF = (float)red / 255.0;
double greenF = (float)green / 255.0;
double blueF = (float)blue / 255.0;
return App::Color(redF, greenF, blueF, orig.a);
}
App::Color Preferences::getAccessibleColor(App::Color orig)
{
if (Preferences::lightOnDark() && Preferences::monochrome()) {
return lightTextColor();
}
if (Preferences::lightOnDark()) {
return lightenColor(orig);
}
return orig;
}

View File

@@ -29,6 +29,7 @@
class QString; class QString;
class QColor;
namespace App namespace App
{ {
@@ -39,7 +40,8 @@ namespace TechDraw
{ {
//getters for parameters used in multiple places. //getters for parameters used in multiple places.
class TechDrawExport Preferences { class TechDrawExport Preferences
{
public: public:
static std::string labelFont(); static std::string labelFont();
@@ -82,6 +84,14 @@ static double GapISO();
static double GapASME(); static double GapASME();
static bool reportProgress(); static bool reportProgress();
static bool lightOnDark();
static void lightOnDark(bool state);
static bool monochrome();
static void monochrome(bool state);
static App::Color lightTextColor();
static App::Color lightenColor(App::Color orig);
static App::Color getAccessibleColor(App::Color orig);
}; };
}//end namespace TechDraw }//end namespace TechDraw

View File

@@ -49,6 +49,7 @@ set(TechDrawGui_LIBS
qt_add_resources(TechDrawGui_SRCS Resources/TechDraw.qrc) qt_add_resources(TechDrawGui_SRCS Resources/TechDraw.qrc)
set(TechDrawGui_UIC_SRCS set(TechDrawGui_UIC_SRCS
DlgStringListEditor.ui
DlgPageChooser.ui DlgPageChooser.ui
DlgPrefsTechDrawAdvanced.ui DlgPrefsTechDrawAdvanced.ui
DlgPrefsTechDrawAnnotation.ui DlgPrefsTechDrawAnnotation.ui
@@ -115,6 +116,9 @@ SET(TechDrawGui_SRCS
TaskProjGroup.ui TaskProjGroup.ui
TaskProjGroup.cpp TaskProjGroup.cpp
TaskProjGroup.h TaskProjGroup.h
DlgStringListEditor.ui
DlgStringListEditor.cpp
DlgStringListEditor.h
DlgPageChooser.ui DlgPageChooser.ui
DlgPageChooser.cpp DlgPageChooser.cpp
DlgPageChooser.h DlgPageChooser.h

View File

@@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>440</width> <width>440</width>
<height>368</height> <height>400</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@@ -49,63 +49,19 @@
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="0" column="0"> <item row="10" column="1">
<widget class="QLabel" name="lbl_Normal"> <widget class="Gui::PrefColorButton" name="pcbLightTextColor">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Normal</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Gui::PrefColorButton" name="pcb_Normal">
<property name="toolTip"> <property name="toolTip">
<string>Normal line color</string> <string>Monochrome text color</string>
</property>
<property name="color">
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</property> </property>
<property name="prefEntry" stdset="0"> <property name="prefEntry" stdset="0">
<cstring>NormalColor</cstring> <cstring>LightTextColor</cstring>
</property> </property>
<property name="prefPath" stdset="0"> <property name="prefPath" stdset="0">
<cstring>Mod/TechDraw/Colors</cstring> <cstring>Mod/TechDraw/Colors</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="2">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="3">
<widget class="QLabel" name="lbl_Hidden">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Hidden Line</string>
</property>
</widget>
</item>
<item row="0" column="4"> <item row="0" column="4">
<widget class="Gui::PrefColorButton" name="pcb_Hidden"> <widget class="Gui::PrefColorButton" name="pcb_Hidden">
<property name="toolTip"> <property name="toolTip">
@@ -126,114 +82,8 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="6" column="1">
<widget class="QLabel" name="lbl_PreSelect"> <widget class="Gui::PrefColorButton" name="pcbHighlight">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Preselected</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="Gui::PrefColorButton" name="pcb_PreSelect">
<property name="toolTip">
<string>Preselection color</string>
</property>
<property name="color">
<color>
<red>255</red>
<green>255</green>
<blue>0</blue>
</color>
</property>
<property name="prefEntry" stdset="0">
<cstring>PreSelectColor</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/TechDraw/Colors</cstring>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QLabel" name="label_3">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Section Face</string>
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="Gui::PrefColorButton" name="pcb_Surface">
<property name="toolTip">
<string>Section face color</string>
</property>
<property name="color">
<color>
<red>211</red>
<green>211</green>
<blue>211</blue>
</color>
</property>
<property name="prefEntry" stdset="0">
<cstring>CutSurfaceColor</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/TechDraw/Colors</cstring>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="lbl_Select">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Selected</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="Gui::PrefColorButton" name="pcb_Select">
<property name="toolTip">
<string>Selected item color</string>
</property>
<property name="color">
<color>
<red>0</red>
<green>255</green>
<blue>0</blue>
</color>
</property>
<property name="prefEntry" stdset="0">
<cstring>SelectColor</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/TechDraw/Colors</cstring>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QLabel" name="label_14">
<property name="text">
<string>Section Line</string>
</property>
</widget>
</item>
<item row="2" column="4">
<widget class="Gui::PrefColorButton" name="pcbSectionLine">
<property name="toolTip">
<string>Section line color</string>
</property>
<property name="color"> <property name="color">
<color> <color>
<red>0</red> <red>0</red>
@@ -242,84 +92,13 @@
</color> </color>
</property> </property>
<property name="prefEntry" stdset="0"> <property name="prefEntry" stdset="0">
<cstring>SectionColor</cstring> <cstring>HighlightColor</cstring>
</property> </property>
<property name="prefPath" stdset="0"> <property name="prefPath" stdset="0">
<cstring>/Mod/TechDraw/Decorations</cstring> <cstring>/Mod/TechDraw/Decorations</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Background</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="Gui::PrefColorButton" name="pcb_Background">
<property name="toolTip">
<string>Background color around pages</string>
</property>
<property name="color">
<color>
<red>211</red>
<green>211</green>
<blue>211</blue>
</color>
</property>
<property name="prefEntry" stdset="0">
<cstring>Background</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>/Mod/TechDraw/Colors</cstring>
</property>
</widget>
</item>
<item row="3" column="3">
<widget class="QLabel" name="label_5">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Hatch</string>
</property>
</widget>
</item>
<item row="3" column="4">
<widget class="Gui::PrefColorButton" name="pcb_Hatch">
<property name="toolTip">
<string>Hatch image color</string>
</property>
<property name="color">
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</property>
<property name="prefEntry" stdset="0">
<cstring>Hatch</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>/Mod/TechDraw/Colors</cstring>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_13">
<property name="text">
<string>Dimension</string>
</property>
</widget>
</item>
<item row="4" column="1"> <item row="4" column="1">
<widget class="Gui::PrefColorButton" name="pcbDimColor"> <widget class="Gui::PrefColorButton" name="pcbDimColor">
<property name="toolTip"> <property name="toolTip">
@@ -340,6 +119,200 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Background</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lbl_PreSelect">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Preselected</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Grid Color</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_18">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Detail Highlight</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="lbl_Select">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Selected</string>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="Gui::PrefCheckBox" name="pcbLightOnDark">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Check this to use light text and lines on dark backgrounds. Set Page Color to a dark color. Transparent or light color faces are recommended with this option.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Light on dark</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>LightOnDark</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>/Mod/TechDraw/Colors</cstring>
</property>
</widget>
</item>
<item row="3" column="4">
<widget class="Gui::PrefColorButton" name="pcb_Hatch">
<property name="toolTip">
<string>Hatch image color</string>
</property>
<property name="color">
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</property>
<property name="prefEntry" stdset="0">
<cstring>Hatch</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>/Mod/TechDraw/Colors</cstring>
</property>
</widget>
</item>
<item row="6" column="4">
<widget class="Gui::PrefColorButton" name="pcbMarkup">
<property name="toolTip">
<string>Default color for leader lines</string>
</property>
<property name="color">
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</property>
<property name="prefEntry" stdset="0">
<cstring>Color</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/TechDraw/Markups</cstring>
</property>
</widget>
</item>
<item row="10" column="3">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Page Color</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="Gui::PrefColorButton" name="pcb_Background">
<property name="toolTip">
<string>Background color around pages</string>
</property>
<property name="color">
<color>
<red>211</red>
<green>211</green>
<blue>211</blue>
</color>
</property>
<property name="prefEntry" stdset="0">
<cstring>Background</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>/Mod/TechDraw/Colors</cstring>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QLabel" name="label_3">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Section Face</string>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QLabel" name="label_14">
<property name="text">
<string>Section Line</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_15">
<property name="text">
<string>Centerline</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="Gui::PrefColorButton" name="pcb_Grid">
<property name="color">
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</property>
<property name="prefEntry" stdset="0">
<cstring>gridColor</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>/Mod/TechDraw/Colors</cstring>
</property>
</widget>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="3"> <item row="4" column="3">
<widget class="QLabel" name="label_7"> <widget class="QLabel" name="label_7">
<property name="font"> <property name="font">
@@ -352,10 +325,34 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="4"> <item row="6" column="3">
<widget class="Gui::PrefColorButton" name="pcb_GeomHatch"> <widget class="QLabel" name="label_17">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Leaderline</string>
</property>
</widget>
</item>
<item row="3" column="3">
<widget class="QLabel" name="label_5">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Hatch</string>
</property>
</widget>
</item>
<item row="2" column="4">
<widget class="Gui::PrefColorButton" name="pcbSectionLine">
<property name="toolTip"> <property name="toolTip">
<string>Geometric hatch pattern color</string> <string>Section line color</string>
</property> </property>
<property name="color"> <property name="color">
<color> <color>
@@ -365,17 +362,102 @@
</color> </color>
</property> </property>
<property name="prefEntry" stdset="0"> <property name="prefEntry" stdset="0">
<cstring>GeomHatch</cstring> <cstring>SectionColor</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>/Mod/TechDraw/Decorations</cstring>
</property>
</widget>
</item>
<item row="7" column="4">
<widget class="Gui::PrefColorButton" name="pcb_Face">
<property name="toolTip">
<string>Face color (if not transparent)</string>
</property>
<property name="color">
<color>
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</property>
<property name="prefEntry" stdset="0">
<cstring>FaceColor</cstring>
</property> </property>
<property name="prefPath" stdset="0"> <property name="prefPath" stdset="0">
<cstring>/Mod/TechDraw/Colors</cstring> <cstring>/Mod/TechDraw/Colors</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="5" column="0"> <item row="1" column="1">
<widget class="QLabel" name="label_15"> <widget class="Gui::PrefColorButton" name="pcb_PreSelect">
<property name="toolTip">
<string>Preselection color</string>
</property>
<property name="color">
<color>
<red>255</red>
<green>255</green>
<blue>0</blue>
</color>
</property>
<property name="prefEntry" stdset="0">
<cstring>PreSelectColor</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/TechDraw/Colors</cstring>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLabel" name="lbl_Hidden">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text"> <property name="text">
<string>Centerline</string> <string>Hidden Line</string>
</property>
</widget>
</item>
<item row="10" column="4">
<widget class="Gui::PrefColorButton" name="pcbPageColor">
<property name="toolTip">
<string>Use a light color for dark text and dark color for light text.</string>
</property>
<property name="color">
<color>
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</property>
<property name="prefEntry" stdset="0">
<cstring>PageColor</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/TechDraw/Colors</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="Gui::PrefColorButton" name="pcb_Select">
<property name="toolTip">
<string>Selected item color</string>
</property>
<property name="color">
<color>
<red>0</red>
<green>255</green>
<blue>0</blue>
</color>
</property>
<property name="prefEntry" stdset="0">
<cstring>SelectColor</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/TechDraw/Colors</cstring>
</property> </property>
</widget> </widget>
</item> </item>
@@ -406,6 +488,46 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1">
<widget class="Gui::PrefColorButton" name="pcb_Normal">
<property name="toolTip">
<string>Normal line color</string>
</property>
<property name="color">
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</property>
<property name="prefEntry" stdset="0">
<cstring>NormalColor</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/TechDraw/Colors</cstring>
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="Gui::PrefColorButton" name="pcb_Surface">
<property name="toolTip">
<string>Section face color</string>
</property>
<property name="color">
<color>
<red>211</red>
<green>211</green>
<blue>211</blue>
</color>
</property>
<property name="prefEntry" stdset="0">
<cstring>CutSurfaceColor</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/TechDraw/Colors</cstring>
</property>
</widget>
</item>
<item row="5" column="4"> <item row="5" column="4">
<widget class="Gui::PrefColorButton" name="pcbVertexColor"> <widget class="Gui::PrefColorButton" name="pcbVertexColor">
<property name="toolTip"> <property name="toolTip">
@@ -426,92 +548,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="6" column="0"> <item row="7" column="3">
<widget class="QLabel" name="label_18">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Detail Highlight</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="Gui::PrefColorButton" name="pcbHighlight">
<property name="color">
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</property>
<property name="prefEntry" stdset="0">
<cstring>HighlightColor</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>/Mod/TechDraw/Decorations</cstring>
</property>
</widget>
</item>
<item row="6" column="3">
<widget class="QLabel" name="label_17">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Leaderline</string>
</property>
</widget>
</item>
<item row="6" column="4">
<widget class="Gui::PrefColorButton" name="pcbMarkup">
<property name="toolTip">
<string>Default color for leader lines</string>
</property>
<property name="color">
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</property>
<property name="prefEntry" stdset="0">
<cstring>Color</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/TechDraw/Markups</cstring>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Grid Color</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="Gui::PrefColorButton" name="pcb_Grid">
<property name="color">
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</property>
<property name="prefEntry" stdset="0">
<cstring>gridColor</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>/Mod/TechDraw/Colors</cstring>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="Gui::PrefCheckBox" name="pcb_PaintFaces"> <widget class="Gui::PrefCheckBox" name="pcb_PaintFaces">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
@@ -538,26 +575,68 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="8" column="1"> <item row="4" column="4">
<widget class="Gui::PrefColorButton" name="pcb_Face"> <widget class="Gui::PrefColorButton" name="pcb_GeomHatch">
<property name="toolTip"> <property name="toolTip">
<string>Face color (if not transparent)</string> <string>Geometric hatch pattern color</string>
</property> </property>
<property name="color"> <property name="color">
<color> <color>
<red>255</red> <red>0</red>
<green>255</green> <green>0</green>
<blue>255</blue> <blue>0</blue>
</color> </color>
</property> </property>
<property name="prefEntry" stdset="0"> <property name="prefEntry" stdset="0">
<cstring>FaceColor</cstring> <cstring>GeomHatch</cstring>
</property> </property>
<property name="prefPath" stdset="0"> <property name="prefPath" stdset="0">
<cstring>/Mod/TechDraw/Colors</cstring> <cstring>/Mod/TechDraw/Colors</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="0">
<widget class="QLabel" name="lbl_Normal">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Normal</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_13">
<property name="text">
<string>Dimension</string>
</property>
</widget>
</item>
<item row="10" column="0">
<widget class="Gui::PrefCheckBox" name="pcbMonochrome">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;If checked FreeCAD will use a single colour for all text and lines. If unchecked FreeCAD will attempt to use lighter versions of preferred colours.&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Monochrome</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>Monochrome</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>/Mod/TechDraw/Colors</cstring>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>
@@ -572,7 +651,7 @@
</font> </font>
</property> </property>
<property name="text"> <property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=" font-weight:600;"&gt;Note:&lt;/span&gt; Items in &lt;span style=" font-style:italic;"&gt;italics&lt;/span&gt; are default values for new objects. They have no effect on existing objects.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Note:&lt;/span&gt; Items in &lt;span style=&quot; font-style:italic;&quot;&gt;italics&lt;/span&gt; are default values for new objects. They have no effect on existing objects.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property> </property>
<property name="wordWrap"> <property name="wordWrap">
<bool>true</bool> <bool>true</bool>

View File

@@ -61,6 +61,10 @@ void DlgPrefsTechDrawColorsImp::saveSettings()
ui->pcbMarkup->onSave(); ui->pcbMarkup->onSave();
ui->pcbHighlight->onSave(); ui->pcbHighlight->onSave();
ui->pcb_Grid->onSave(); ui->pcb_Grid->onSave();
ui->pcbPageColor->onSave();
ui->pcbLightOnDark->onSave();
ui->pcbMonochrome->onSave();
ui->pcbLightTextColor->onSave();
} }
void DlgPrefsTechDrawColorsImp::loadSettings() void DlgPrefsTechDrawColorsImp::loadSettings()
@@ -82,6 +86,10 @@ void DlgPrefsTechDrawColorsImp::loadSettings()
ui->pcbMarkup->onRestore(); ui->pcbMarkup->onRestore();
ui->pcbHighlight->onRestore(); ui->pcbHighlight->onRestore();
ui->pcb_Grid->onRestore(); ui->pcb_Grid->onRestore();
ui->pcbPageColor->onRestore();
ui->pcbLightOnDark->onRestore();
ui->pcbMonochrome->onRestore();
ui->pcbLightTextColor->onRestore();
} }
/** /**

View File

@@ -0,0 +1,140 @@
/****************************************************************************
* Copyright (c) 2022 Wanderer Fan <wandererfan@gmail.com> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
****************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#include <QList>
#include <QListWidgetItem>
#endif
#include <Base/Console.h>// for FC_LOG_LEVEL_INIT
#include <Base/Tools.h>
#include "DlgStringListEditor.h"
#include "ui_DlgStringListEditor.h"
using namespace TechDrawGui;
/* TRANSLATOR Gui::DlgStringListEditor */
DlgStringListEditor::DlgStringListEditor(const std::vector<std::string> texts, QWidget* parent,
Qt::WindowFlags fl)
: QDialog(parent, fl),
ui(new Ui_DlgStringListEditor)
{
ui->setupUi(this);
ui->lwTexts->setSortingEnabled(false);
fillList(texts);
connect(ui->lwTexts,
SIGNAL(itemActivated(QListWidgetItem*)),
this,
SLOT(slotItemActivated(QListWidgetItem*)));
connect(ui->pbAdd, SIGNAL(clicked()), this, SLOT(slotAddItem()));
connect(ui->pbRemove, SIGNAL(clicked()), this, SLOT(slotRemoveItem()));
connect(ui->bbButtons, SIGNAL(accepted()), this, SLOT(accept()));
connect(ui->bbButtons, SIGNAL(rejected()), this, SLOT(reject()));
}
/**
* Destroys the object and frees any allocated resources
*/
DlgStringListEditor::~DlgStringListEditor()
{
// no need to delete child widgets, Qt does it all for us
delete ui;
}
void DlgStringListEditor::fillList(std::vector<std::string> texts)
{
QString qText;
int textCount = texts.size();
int i = 0;
for (; i < textCount; i++) {
qText = Base::Tools::fromStdString(texts[i]);
QListWidgetItem* item = new QListWidgetItem(qText);
item->setFlags(item->flags() | Qt::ItemIsEditable);
ui->lwTexts->addItem(item);
}
//add a blank line at the end to allow extending the list
QListWidgetItem* item = new QListWidgetItem(QString::fromUtf8(""));
item->setFlags(item->flags() | Qt::ItemIsEditable);
ui->lwTexts->addItem(item);
}
void DlgStringListEditor::slotItemActivated(QListWidgetItem* item)
{
ui->lwTexts->editItem(item);
}
void DlgStringListEditor::slotAddItem()
{
QString newText = ui->leNewItem->text();
QListWidgetItem* item = new QListWidgetItem(newText);
item->setFlags(item->flags() | Qt::ItemIsEditable);
int row = ui->lwTexts->currentRow();
if (row < 0) {
//no location set yet, add to end of list
ui->lwTexts->addItem(item);
}
else {
//insert item at current row and push the rest down 1 position
ui->lwTexts->insertItem(row, item);
}
ui->leNewItem->clear();
//TODO: how to append to end of list?
}
void DlgStringListEditor::slotRemoveItem()
{
int row = ui->lwTexts->currentRow();
if (row >= 0) {
auto item = ui->lwTexts->takeItem(row);
delete item;
}
}
std::vector<std::string> DlgStringListEditor::getTexts() const
{
std::vector<std::string> outTexts;
for (int iRow = 0; iRow < ui->lwTexts->count(); iRow++) {
QString itemText = ui->lwTexts->item(iRow)->text();
outTexts.push_back(Base::Tools::toStdString(itemText));
}
if (outTexts.back().empty()) {
outTexts.pop_back();
}
return outTexts;
}
void DlgStringListEditor::accept()
{
QDialog::accept();
}
void DlgStringListEditor::reject()
{
QDialog::reject();
}
#include "moc_DlgStringListEditor.cpp"

View File

@@ -0,0 +1,62 @@
/****************************************************************************
* Copyright (c) 2022 Wanderer Fan <wandererfan@gmail.com> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
****************************************************************************/
#ifndef GUI_DLGEDITABLETEXT_H
#define GUI_DLGEDITABLETEXT_H
#include <Mod/TechDraw/TechDrawGlobal.h>
#include <QDialog>
class QListWidgetItem;
namespace TechDrawGui {
class Ui_DlgStringListEditor;
class TechDrawGuiExport DlgStringListEditor : public QDialog
{
Q_OBJECT
public:
DlgStringListEditor(const std::vector<std::string> texts,
QWidget* parent = nullptr, Qt::WindowFlags fl = Qt::WindowFlags());
~DlgStringListEditor();
std::vector<std::string> getTexts() const;
void accept();
void reject();
public Q_SLOTS:
void slotItemActivated(QListWidgetItem* item);
void slotAddItem();
void slotRemoveItem();
private:
void fillList(std::vector<std::string> texts);
Ui_DlgStringListEditor* ui;
};
} // namespace Gui
#endif // GUI_DLGEDITABLETEXT_H

View File

@@ -0,0 +1,140 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TechDrawGui::DlgStringListEditor</class>
<widget class="QDialog" name="TechDrawGui::DlgStringListEditor">
<property name="windowModality">
<enum>Qt::WindowModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>360</width>
<height>331</height>
</rect>
</property>
<property name="windowTitle">
<string>String List Editor</string>
</property>
<property name="toolTip">
<string/>
</property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QListWidget" name="lwTexts">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Double click to edit a line. New lines are added at the current location in the list.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="editTriggers">
<set>QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked</set>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="pbAdd">
<property name="icon">
<iconset>
<normalon>:/icons/list-add.svg</normalon>
</iconset>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="leNewItem"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="pbRemove">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../../Gui/Icons/resource.qrc">
<normaloff>:/icons/list-remove.svg</normaloff>:/icons/list-remove.svg</iconset>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="bbButtons">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
<property name="centerButtons">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="Resources/TechDraw.qrc"/>
<include location="../../../Gui/Icons/resource.qrc"/>
</resources>
<connections>
<connection>
<sender>bbButtons</sender>
<signal>accepted()</signal>
<receiver>TechDrawGui::DlgStringListEditor</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>179</x>
<y>228</y>
</hint>
<hint type="destinationlabel">
<x>179</x>
<y>139</y>
</hint>
</hints>
</connection>
<connection>
<sender>bbButtons</sender>
<signal>rejected()</signal>
<receiver>TechDrawGui::DlgStringListEditor</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>179</x>
<y>228</y>
</hint>
<hint type="destinationlabel">
<x>179</x>
<y>139</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -24,7 +24,6 @@
#include "PreCompiled.h" #include "PreCompiled.h"
#ifndef _PreComp_ #ifndef _PreComp_
# include <cmath>
#include <QAction> #include <QAction>
#include <QApplication> #include <QApplication>
#include <QContextMenuEvent> #include <QContextMenuEvent>
@@ -35,10 +34,11 @@
#include <QPaintEngine> #include <QPaintEngine>
#include <QPainter> #include <QPainter>
#include <QPdfWriter> #include <QPdfWriter>
# include <QPrinter>
#include <QPrintDialog> #include <QPrintDialog>
#include <QPrintPreviewDialog> #include <QPrintPreviewDialog>
#include <QPrinter>
#include <boost_signals2.hpp> #include <boost_signals2.hpp>
#include <cmath>
#endif #endif
#include <App/Application.h> #include <App/Application.h>
@@ -65,6 +65,7 @@
#include "MDIViewPage.h" #include "MDIViewPage.h"
#include "QGIEdge.h" #include "QGIEdge.h"
#include "QGIFace.h" #include "QGIFace.h"
#include "QGITemplate.h"
#include "QGIVertex.h" #include "QGIVertex.h"
#include "QGIView.h" #include "QGIView.h"
#include "QGIViewBalloon.h" #include "QGIViewBalloon.h"
@@ -85,12 +86,8 @@ namespace bp = boost::placeholders;
TYPESYSTEM_SOURCE_ABSTRACT(TechDrawGui::MDIViewPage, Gui::MDIView) TYPESYSTEM_SOURCE_ABSTRACT(TechDrawGui::MDIViewPage, Gui::MDIView)
MDIViewPage::MDIViewPage(ViewProviderPage* pageVp, Gui::Document* doc, QWidget* parent) MDIViewPage::MDIViewPage(ViewProviderPage* pageVp, Gui::Document* doc, QWidget* parent)
: Gui::MDIView(doc, parent), : Gui::MDIView(doc, parent), m_vpPage(pageVp), m_orientation(QPageLayout::Landscape),
m_vpPage(pageVp), m_paperSize(QPageSize::A4), m_pagewidth(0.0), m_pageheight(0.0)
m_orientation(QPageLayout::Landscape),
m_paperSize(QPageSize::A4),
m_pagewidth(0.0),
m_pageheight(0.0)
{ {
setMouseTracking(true); setMouseTracking(true);
@@ -124,17 +121,13 @@ MDIViewPage::MDIViewPage(ViewProviderPage *pageVp, Gui::Document* doc, QWidget*
connectDeletedObject = appDoc->signalDeletedObject.connect(bnd); connectDeletedObject = appDoc->signalDeletedObject.connect(bnd);
} }
MDIViewPage::~MDIViewPage() MDIViewPage::~MDIViewPage() { connectDeletedObject.disconnect(); }
{
connectDeletedObject.disconnect();
}
void MDIViewPage::setScene(QGSPage* scene, QGVPage* viewWidget) void MDIViewPage::setScene(QGSPage* scene, QGVPage* viewWidget)
{ {
m_scene = scene; m_scene = scene;
setCentralWidget(viewWidget);//this makes viewWidget a Qt child of MDIViewPage setCentralWidget(viewWidget);//this makes viewWidget a Qt child of MDIViewPage
QObject::connect(m_scene, SIGNAL(selectionChanged()), QObject::connect(m_scene, SIGNAL(selectionChanged()), this, SLOT(sceneSelectionChanged()));
this, SLOT (sceneSelectionChanged()));
} }
void MDIViewPage::setDocumentObject(const std::string& name) void MDIViewPage::setDocumentObject(const std::string& name)
@@ -143,17 +136,15 @@ void MDIViewPage::setDocumentObject(const std::string& name)
setObjectName(Base::Tools::fromStdString(name)); setObjectName(Base::Tools::fromStdString(name));
} }
void MDIViewPage::setDocumentName(const std::string& name) void MDIViewPage::setDocumentName(const std::string& name) { m_documentName = name; }
{
m_documentName = name;
}
void MDIViewPage::closeEvent(QCloseEvent* event) void MDIViewPage::closeEvent(QCloseEvent* event)
{ {
// Base::Console().Message("MDIVP::closeEvent()\n"); // Base::Console().Message("MDIVP::closeEvent()\n");
MDIView::closeEvent(event); MDIView::closeEvent(event);
if (!event->isAccepted()) if (!event->isAccepted()) {
return; return;
}
detachSelection(); detachSelection();
blockSceneSelection(true); blockSceneSelection(true);
@@ -163,10 +154,11 @@ void MDIViewPage::closeEvent(QCloseEvent* event)
if (doc) { if (doc) {
App::DocumentObject* obj = doc->getObject(m_objectName.c_str()); App::DocumentObject* obj = doc->getObject(m_objectName.c_str());
Gui::ViewProvider* vp = _pcDocument->getViewProvider(obj); Gui::ViewProvider* vp = _pcDocument->getViewProvider(obj);
if (vp) if (vp) {
vp->hide(); vp->hide();
} }
} }
}
blockSceneSelection(false); blockSceneSelection(false);
} }
@@ -186,20 +178,25 @@ bool MDIViewPage::onMsg(const char *pMsg, const char **)
if (!doc) { if (!doc) {
return false; return false;
} else if (strcmp("ViewFit", pMsg) == 0) { }
else if (strcmp("ViewFit", pMsg) == 0) {
viewAll(); viewAll();
return true; return true;
} else if (strcmp("Save", pMsg) == 0 ) { }
else if (strcmp("Save", pMsg) == 0) {
doc->save(); doc->save();
return true; return true;
} else if (strcmp("SaveAs", pMsg) == 0 ) { }
else if (strcmp("SaveAs", pMsg) == 0) {
doc->saveAs(); doc->saveAs();
return true; return true;
} else if (strcmp("Undo", pMsg) == 0 ) { }
else if (strcmp("Undo", pMsg) == 0) {
doc->undo(1); doc->undo(1);
Gui::Command::updateActive(); Gui::Command::updateActive();
return true; return true;
} else if (strcmp("Redo", pMsg) == 0 ) { }
else if (strcmp("Redo", pMsg) == 0) {
doc->redo(1); doc->redo(1);
Gui::Command::updateActive(); Gui::Command::updateActive();
return true; return true;
@@ -210,24 +207,33 @@ bool MDIViewPage::onMsg(const char *pMsg, const char **)
bool MDIViewPage::onHasMsg(const char* pMsg) const bool MDIViewPage::onHasMsg(const char* pMsg) const
{ {
if (strcmp("ViewFit", pMsg) == 0) if (strcmp("ViewFit", pMsg) == 0) {
return true; return true;
else if(strcmp("Redo", pMsg) == 0 && getAppDocument()->getAvailableRedos() > 0) }
else if (strcmp("Redo", pMsg) == 0 && getAppDocument()->getAvailableRedos() > 0) {
return true; return true;
else if(strcmp("Undo", pMsg) == 0 && getAppDocument()->getAvailableUndos() > 0) }
else if (strcmp("Undo", pMsg) == 0 && getAppDocument()->getAvailableUndos() > 0) {
return true; return true;
else if (strcmp("Print", pMsg) == 0) }
else if (strcmp("Print", pMsg) == 0) {
return true; return true;
else if (strcmp("Save", pMsg) == 0) }
else if (strcmp("Save", pMsg) == 0) {
return true; return true;
else if (strcmp("SaveAs", pMsg) == 0) }
else if (strcmp("SaveAs", pMsg) == 0) {
return true; return true;
else if (strcmp("PrintPreview", pMsg) == 0) }
else if (strcmp("PrintPreview", pMsg) == 0) {
return true; return true;
else if (strcmp("PrintPdf",pMsg) == 0) }
else if (strcmp("PrintPdf", pMsg) == 0) {
return true; return true;
else if (strcmp("PrintAll",pMsg) == 0) }
else if (strcmp("PrintAll", pMsg) == 0) {
return true; return true;
}
return false; return false;
} }
@@ -235,8 +241,7 @@ bool MDIViewPage::onHasMsg(const char* pMsg) const
void MDIViewPage::setTabText(std::string tabText) void MDIViewPage::setTabText(std::string tabText)
{ {
if (!isPassive() && !tabText.empty()) { if (!isPassive() && !tabText.empty()) {
QString cap = QString::fromLatin1("%1 [*]") QString cap = QString::fromLatin1("%1 [*]").arg(QString::fromUtf8(tabText.c_str()));
.arg(QString::fromUtf8(tabText.c_str()));
setWindowTitle(cap); setWindowTitle(cap);
} }
} }
@@ -251,10 +256,12 @@ void MDIViewPage::getPaperAttributes()
m_pagewidth = pageTemplate->Width.getValue(); m_pagewidth = pageTemplate->Width.getValue();
m_pageheight = pageTemplate->Height.getValue(); m_pageheight = pageTemplate->Height.getValue();
} }
m_paperSize = QPageSize::id(QSizeF(m_pagewidth, m_pageheight), QPageSize::Millimeter, QPageSize::FuzzyOrientationMatch); m_paperSize = QPageSize::id(QSizeF(m_pagewidth, m_pageheight), QPageSize::Millimeter,
QPageSize::FuzzyOrientationMatch);
if (m_pagewidth > m_pageheight) { if (m_pagewidth > m_pageheight) {
m_orientation = QPageLayout::Landscape; m_orientation = QPageLayout::Landscape;
} else { }
else {
m_orientation = QPageLayout::Portrait; m_orientation = QPageLayout::Portrait;
} }
} }
@@ -264,7 +271,8 @@ void MDIViewPage::printPdf()
QStringList filter; QStringList filter;
filter << QObject::tr("PDF (*.pdf)"); filter << QObject::tr("PDF (*.pdf)");
filter << QObject::tr("All Files (*.*)"); filter << QObject::tr("All Files (*.*)");
QString fn = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(), QObject::tr("Export Page As PDF"), QString fn =
Gui::FileDialog::getSaveFileName(Gui::getMainWindow(), QObject::tr("Export Page As PDF"),
QString(), filter.join(QLatin1String(";;"))); QString(), filter.join(QLatin1String(";;")));
if (fn.isEmpty()) { if (fn.isEmpty()) {
return; return;
@@ -290,12 +298,14 @@ void MDIViewPage::printPdf(std::string file)
if (m_paperSize == QPageSize::Ledger) { if (m_paperSize == QPageSize::Ledger) {
printer.setPageOrientation((QPageLayout::Orientation)(1 - m_orientation));//reverse 0/1 printer.setPageOrientation((QPageLayout::Orientation)(1 - m_orientation));//reverse 0/1
} else { }
else {
printer.setPageOrientation(m_orientation); printer.setPageOrientation(m_orientation);
} }
if (m_paperSize == QPageSize::Custom) { if (m_paperSize == QPageSize::Custom) {
printer.setPageSize(QPageSize(QSizeF(m_pagewidth, m_pageheight), QPageSize::Millimeter)); printer.setPageSize(QPageSize(QSizeF(m_pagewidth, m_pageheight), QPageSize::Millimeter));
} else { }
else {
printer.setPageSize(QPageSize(m_paperSize)); printer.setPageSize(QPageSize(m_paperSize));
} }
print(&printer); print(&printer);
@@ -310,7 +320,8 @@ void MDIViewPage::print()
printer.setFullPage(true); printer.setFullPage(true);
if (m_paperSize == QPageSize::Custom) { if (m_paperSize == QPageSize::Custom) {
printer.setPageSize(QPageSize(QSizeF(m_pagewidth, m_pageheight), QPageSize::Millimeter)); printer.setPageSize(QPageSize(QSizeF(m_pagewidth, m_pageheight), QPageSize::Millimeter));
} else { }
else {
printer.setPageSize(QPageSize(m_paperSize)); printer.setPageSize(QPageSize(m_paperSize));
} }
printer.setPageOrientation(m_orientation); printer.setPageOrientation(m_orientation);
@@ -329,14 +340,14 @@ void MDIViewPage::printPreview()
printer.setFullPage(true); printer.setFullPage(true);
if (m_paperSize == QPageSize::Custom) { if (m_paperSize == QPageSize::Custom) {
printer.setPageSize(QPageSize(QSizeF(m_pagewidth, m_pageheight), QPageSize::Millimeter)); printer.setPageSize(QPageSize(QSizeF(m_pagewidth, m_pageheight), QPageSize::Millimeter));
} else { }
else {
printer.setPageSize(QPageSize(m_paperSize)); printer.setPageSize(QPageSize(m_paperSize));
} }
printer.setPageOrientation(m_orientation); printer.setPageOrientation(m_orientation);
QPrintPreviewDialog dlg(&printer, this); QPrintPreviewDialog dlg(&printer, this);
connect(&dlg, SIGNAL(paintRequested(QPrinter*)), connect(&dlg, SIGNAL(paintRequested(QPrinter*)), this, SLOT(print(QPrinter*)));
this, SLOT(print(QPrinter*)));
dlg.exec(); dlg.exec();
} }
@@ -366,27 +377,32 @@ void MDIViewPage::print(QPrinter* printer)
bool doPrint = paintType != QPaintEngine::Picture; bool doPrint = paintType != QPaintEngine::Picture;
if (doPrint && printer->pageLayout().orientation() != m_orientation) { if (doPrint && printer->pageLayout().orientation() != m_orientation) {
int ret = QMessageBox::warning(this, tr("Different orientation"), int ret = QMessageBox::warning(
this, tr("Different orientation"),
tr("The printer uses a different orientation than the drawing.\n" tr("The printer uses a different orientation than the drawing.\n"
"Do you want to continue?"), "Do you want to continue?"),
QMessageBox::Yes | QMessageBox::No); QMessageBox::Yes | QMessageBox::No);
if (ret != QMessageBox::Yes) if (ret != QMessageBox::Yes) {
return; return;
} }
}
if (doPrint && psPrtSetting != m_paperSize) { if (doPrint && psPrtSetting != m_paperSize) {
int ret = QMessageBox::warning(this, tr("Different paper size"), int ret = QMessageBox::warning(
this, tr("Different paper size"),
tr("The printer uses a different paper size than the drawing.\n" tr("The printer uses a different paper size than the drawing.\n"
"Do you want to continue?"), "Do you want to continue?"),
QMessageBox::Yes | QMessageBox::No); QMessageBox::Yes | QMessageBox::No);
if (ret != QMessageBox::Yes) if (ret != QMessageBox::Yes) {
return; return;
} }
} }
}
QPainter p(printer); QPainter p(printer);
if (!p.isActive() && !printer->outputFileName().isEmpty()) { if (!p.isActive() && !printer->outputFileName().isEmpty()) {
qApp->setOverrideCursor(Qt::ArrowCursor); qApp->setOverrideCursor(Qt::ArrowCursor);
QMessageBox::critical(this, tr("Opening file failed"), QMessageBox::critical(
this, tr("Opening file failed"),
tr("Can not open file %1 for writing.").arg(printer->outputFileName())); tr("Can not open file %1 for writing.").arg(printer->outputFileName()));
qApp->restoreOverrideCursor(); qApp->restoreOverrideCursor();
return; return;
@@ -397,8 +413,9 @@ void MDIViewPage::print(QPrinter* printer)
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
// On Windows the preview looks broken when using paperRect as render area. // On Windows the preview looks broken when using paperRect as render area.
// Although the picture is scaled when using pageRect, it looks just fine. // Although the picture is scaled when using pageRect, it looks just fine.
if (paintType == QPaintEngine::Picture) if (paintType == QPaintEngine::Picture) {
targetRect = printer->pageLayout().paintRectPixels(printer->resolution()); targetRect = printer->pageLayout().paintRectPixels(printer->resolution());
}
#endif #endif
//bool block = //bool block =
@@ -422,25 +439,34 @@ void MDIViewPage::print(QPrinter* printer)
} }
QRectF sourceRect(0.0, -height, width, height); QRectF sourceRect(0.0, -height, width, height);
//scene might be drawn in light text. we need to redraw in normal text.
bool saveLightOnDark = Preferences::lightOnDark();
if (Preferences::lightOnDark()) {
Preferences::lightOnDark(false);
m_vpPage->getQGSPage()->redrawAllViews();
m_vpPage->getQTemplate()->updateView();
}
m_scene->render(&p, targetRect, sourceRect); m_scene->render(&p, targetRect, sourceRect);
// Reset // Reset
m_vpPage->setFrameState(saveState); m_vpPage->setFrameState(saveState);
m_vpPage->setTemplateMarkers(saveState); m_vpPage->setTemplateMarkers(saveState);
Preferences::lightOnDark(saveLightOnDark);
m_scene->refreshViews(); m_scene->refreshViews();
m_vpPage->getQTemplate()->updateView();
//bool block = //bool block =
static_cast<void>(blockSelection(false)); static_cast<void>(blockSelection(false));
} }
//static routine to print all pages in a document //static routine to print all pages in a document
void MDIViewPage::printAll(QPrinter* printer, void MDIViewPage::printAll(QPrinter* printer, App::Document* doc)
App::Document* doc)
{ {
// Base::Console().Message("MDIVP::printAll()\n"); // Base::Console().Message("MDIVP::printAll()\n");
QPainter painter(printer); QPainter painter(printer);
QPageLayout pageLayout = printer->pageLayout(); QPageLayout pageLayout = printer->pageLayout();
bool firstTime = true; bool firstTime = true;
std::vector<App::DocumentObject*> docObjs = doc->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); std::vector<App::DocumentObject*> docObjs =
doc->getObjectsOfType(TechDraw::DrawPage::getClassTypeId());
for (auto& obj : docObjs) { for (auto& obj : docObjs) {
Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider(obj); Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider(obj);
if (!vp) { if (!vp) {
@@ -475,8 +501,7 @@ void MDIViewPage::printAll(QPrinter* printer,
} }
//static routine to print all pages in a document to pdf //static routine to print all pages in a document to pdf
void MDIViewPage::printAllPdf(QPrinter* printer, void MDIViewPage::printAllPdf(QPrinter* printer, App::Document* doc)
App::Document* doc)
{ {
// Base::Console().Message("MDIVP::printAllPdf()\n"); // Base::Console().Message("MDIVP::printAllPdf()\n");
QString outputFile = printer->outputFileName(); QString outputFile = printer->outputFileName();
@@ -489,7 +514,8 @@ void MDIViewPage::printAllPdf(QPrinter* printer,
double dpmm = printer->resolution() / 25.4; double dpmm = printer->resolution() / 25.4;
bool firstTime = true; bool firstTime = true;
std::vector<App::DocumentObject*> docObjs = doc->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); std::vector<App::DocumentObject*> docObjs =
doc->getObjectsOfType(TechDraw::DrawPage::getClassTypeId());
for (auto& obj : docObjs) { for (auto& obj : docObjs) {
Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider(obj); Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider(obj);
if (!vp) { if (!vp) {
@@ -524,10 +550,8 @@ void MDIViewPage::printAllPdf(QPrinter* printer,
} }
//static //static
void MDIViewPage::printBannerPage(QPrinter* printer, QPainter& painter, void MDIViewPage::printBannerPage(QPrinter* printer, QPainter& painter, QPageLayout& pageLayout,
QPageLayout& pageLayout, App::Document* doc, std::vector<App::DocumentObject*>& docObjs)
App::Document* doc,
std::vector<App::DocumentObject*>& docObjs)
{ {
QFont savePainterFont = painter.font(); QFont savePainterFont = painter.font();
QFont painterFont; QFont painterFont;
@@ -549,9 +573,8 @@ void MDIViewPage::printBannerPage(QPrinter* printer, QPainter& painter,
verticalPos += 2 * verticalSpacing * fontSizePx; verticalPos += 2 * verticalSpacing * fontSizePx;
for (auto& obj : docObjs) { for (auto& obj : docObjs) {
//print a line for each page //print a line for each page
QString pageLine = QString::fromUtf8(obj->getNameInDocument()) + QString pageLine = QString::fromUtf8(obj->getNameInDocument()) + QString::fromUtf8(" / ")
QString::fromUtf8(" / ") + + QString::fromUtf8(obj->Label.getValue());
QString::fromUtf8(obj->Label.getValue());
painter.drawText(leftMargin, verticalPos, pageLine); painter.drawText(leftMargin, verticalPos, pageLine);
verticalPos += verticalSpacing * fontSizePx; verticalPos += verticalSpacing * fontSizePx;
} }
@@ -559,27 +582,35 @@ void MDIViewPage::printBannerPage(QPrinter* printer, QPainter& painter,
} }
//static //static
void MDIViewPage::renderPage(ViewProviderPage* vpp, void MDIViewPage::renderPage(ViewProviderPage* vpp, QPainter& painter, QRectF& sourceRect,
QPainter& painter,
QRectF& sourceRect,
QRect& targetRect) QRect& targetRect)
{ {
bool saveState = vpp->getFrameState();
//turn off view frames for print //turn off view frames for print
bool saveState = vpp->getFrameState();
vpp->setFrameState(false); vpp->setFrameState(false);
vpp->setTemplateMarkers(false); vpp->setTemplateMarkers(false);
//scene might be drawn in light text. we need to redraw in normal text.
bool saveLightOnDark = Preferences::lightOnDark();
if (Preferences::lightOnDark()) {
Preferences::lightOnDark(false);
vpp->getQGSPage()->redrawAllViews();
}
vpp->getQGSPage()->refreshViews(); vpp->getQGSPage()->refreshViews();
vpp->getQGSPage()->render(&painter, targetRect, sourceRect); vpp->getQGSPage()->render(&painter, targetRect, sourceRect);
// Reset // Reset
vpp->setFrameState(saveState); vpp->setFrameState(saveState);
vpp->setTemplateMarkers(saveState); vpp->setTemplateMarkers(saveState);
Preferences::lightOnDark(saveLightOnDark);
vpp->getQGSPage()->refreshViews(); vpp->getQGSPage()->refreshViews();
} }
//static //static
void MDIViewPage::setPageLayout(QPageLayout& pageLayout, void MDIViewPage::setPageLayout(QPageLayout& pageLayout, TechDraw::DrawPage* dPage, double& width,
TechDraw::DrawPage* dPage, double& height)
double& width, double& height)
{ {
auto pageTemplate(dynamic_cast<TechDraw::DrawTemplate*>(dPage->Template.getValue())); auto pageTemplate(dynamic_cast<TechDraw::DrawTemplate*>(dPage->Template.getValue()));
if (pageTemplate) { if (pageTemplate) {
@@ -590,12 +621,12 @@ void MDIViewPage::setPageLayout(QPageLayout& pageLayout,
//we need to ask in the proper form. //we need to ask in the proper form.
QPageSize::PageSizeId paperSizeID = QPageSize::PageSizeId paperSizeID =
QPageSize::id(QSizeF(std::min(width, height), std::max(width, height)), QPageSize::id(QSizeF(std::min(width, height), std::max(width, height)),
QPageSize::Millimeter, QPageSize::Millimeter, QPageSize::FuzzyOrientationMatch);
QPageSize::FuzzyOrientationMatch);
if (paperSizeID == QPageSize::Custom) { if (paperSizeID == QPageSize::Custom) {
pageLayout.setPageSize(QPageSize(QSizeF(std::min(width, height), std::max(width, height)), pageLayout.setPageSize(QPageSize(QSizeF(std::min(width, height), std::max(width, height)),
QPageSize::Millimeter)); QPageSize::Millimeter));
} else { }
else {
pageLayout.setPageSize(QPageSize(paperSizeID)); pageLayout.setPageSize(QPageSize(paperSizeID));
} }
pageLayout.setOrientation((QPageLayout::Orientation)dPage->getOrientation()); pageLayout.setOrientation((QPageLayout::Orientation)dPage->getOrientation());
@@ -603,8 +634,9 @@ void MDIViewPage::setPageLayout(QPageLayout& pageLayout,
PyObject* MDIViewPage::getPyObject() PyObject* MDIViewPage::getPyObject()
{ {
if (!pythonObject) if (!pythonObject) {
pythonObject = new MDIViewPagePy(this); pythonObject = new MDIViewPagePy(this);
}
Py_INCREF(pythonObject); Py_INCREF(pythonObject);
return pythonObject; return pythonObject;
@@ -623,10 +655,7 @@ void MDIViewPage::contextMenuEvent(QContextMenuEvent *event)
menu.exec(event->globalPos()); menu.exec(event->globalPos());
} }
void MDIViewPage::toggleFrame() void MDIViewPage::toggleFrame() { m_vpPage->toggleFrameState(); }
{
m_vpPage->toggleFrameState();
}
void MDIViewPage::toggleKeepUpdated() void MDIViewPage::toggleKeepUpdated()
{ {
@@ -644,7 +673,8 @@ void MDIViewPage::saveSVG()
QStringList filter; QStringList filter;
filter << QObject::tr("SVG (*.svg)"); filter << QObject::tr("SVG (*.svg)");
filter << QObject::tr("All Files (*.*)"); filter << QObject::tr("All Files (*.*)");
QString fn = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(), QObject::tr("Export page as SVG"), QString fn =
Gui::FileDialog::getSaveFileName(Gui::getMainWindow(), QObject::tr("Export page as SVG"),
QString(), filter.join(QLatin1String(";;"))); QString(), filter.join(QLatin1String(";;")));
if (fn.isEmpty()) { if (fn.isEmpty()) {
return; return;
@@ -667,9 +697,8 @@ void MDIViewPage::saveSVG(std::string file)
void MDIViewPage::saveDXF() void MDIViewPage::saveDXF()
{ {
QString defaultDir; QString defaultDir;
QString fileName = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(), QString fileName = Gui::FileDialog::getSaveFileName(
QString::fromUtf8(QT_TR_NOOP("Save DXF file")), Gui::getMainWindow(), QString::fromUtf8(QT_TR_NOOP("Save DXF file")), defaultDir,
defaultDir,
QString::fromUtf8(QT_TR_NOOP("DXF (*.dxf)"))); QString::fromUtf8(QT_TR_NOOP("DXF (*.dxf)")));
if (fileName.isEmpty()) { if (fileName.isEmpty()) {
return; return;
@@ -686,20 +715,15 @@ void MDIViewPage::saveDXF(std::string fileName)
fileName = Base::Tools::escapeEncodeFilename(fileName); fileName = Base::Tools::escapeEncodeFilename(fileName);
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Save page to dxf")); Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Save page to dxf"));
Gui::Command::doCommand(Gui::Command::Doc, "import TechDraw"); Gui::Command::doCommand(Gui::Command::Doc, "import TechDraw");
Gui::Command::doCommand(Gui::Command::Doc, "TechDraw.writeDXFPage(App.activeDocument().%s, u\"%s\")", Gui::Command::doCommand(Gui::Command::Doc,
"TechDraw.writeDXFPage(App.activeDocument().%s, u\"%s\")",
PageName.c_str(), (const char*)fileName.c_str()); PageName.c_str(), (const char*)fileName.c_str());
Gui::Command::commitCommand(); Gui::Command::commitCommand();
} }
void MDIViewPage::savePDF() void MDIViewPage::savePDF() { printPdf(); }
{
printPdf();
}
void MDIViewPage::savePDF(std::string file) void MDIViewPage::savePDF(std::string file) { printPdf(file); }
{
printPdf(file);
}
//mdiviewpage method for printAll action //mdiviewpage method for printAll action
void MDIViewPage::printAll() void MDIViewPage::printAll()
@@ -722,7 +746,8 @@ void MDIViewPage::printAllPages()
} }
if (printer.outputFileName().isEmpty()) { if (printer.outputFileName().isEmpty()) {
printAll(&printer, doc); printAll(&printer, doc);
} else { }
else {
printAllPdf(&printer, doc); printAllPdf(&printer, doc);
} }
} }
@@ -736,16 +761,19 @@ void MDIViewPage::preSelectionChanged(const QPoint &pos)
{ {
QObject* obj = QObject::sender(); QObject* obj = QObject::sender();
if(!obj) if (!obj) {
return; return;
}
auto view(dynamic_cast<QGIView*>(obj)); auto view(dynamic_cast<QGIView*>(obj));
if(!view) if (!view) {
return; return;
}
QGraphicsItem* parent = view->parentItem(); QGraphicsItem* parent = view->parentItem();
if(!parent) if (!parent) {
return; return;
}
TechDraw::DrawView* viewObj = view->getViewObject(); TechDraw::DrawView* viewObj = view->getViewObject();
std::stringstream ss; std::stringstream ss;
@@ -756,46 +784,35 @@ void MDIViewPage::preSelectionChanged(const QPoint &pos)
if (edge) { if (edge) {
ss << "Edge" << edge->getProjIndex(); ss << "Edge" << edge->getProjIndex();
//bool accepted = //bool accepted =
static_cast<void> (Gui::Selection().setPreselect(viewObj->getDocument()->getName() static_cast<void>(Gui::Selection().setPreselect(viewObj->getDocument()->getName(),
,viewObj->getNameInDocument() viewObj->getNameInDocument(),
,ss.str().c_str() ss.str().c_str(), pos.x(), pos.y(), 0));
,pos.x() }
,pos.y() else if (vert) {
,0));
} else if(vert) {
ss << "Vertex" << vert->getProjIndex(); ss << "Vertex" << vert->getProjIndex();
//bool accepted = //bool accepted =
static_cast<void> (Gui::Selection().setPreselect(viewObj->getDocument()->getName() static_cast<void>(Gui::Selection().setPreselect(viewObj->getDocument()->getName(),
,viewObj->getNameInDocument() viewObj->getNameInDocument(),
,ss.str().c_str() ss.str().c_str(), pos.x(), pos.y(), 0));
,pos.x() }
,pos.y() else if (face) {
,0)); ss << "Face"
} else if(face) { << face->getProjIndex();//TODO: SectionFaces have ProjIndex = -1. (but aren't selectable?) Problem?
ss << "Face" << face->getProjIndex(); //TODO: SectionFaces have ProjIndex = -1. (but aren't selectable?) Problem?
//bool accepted = //bool accepted =
static_cast<void> (Gui::Selection().setPreselect(viewObj->getDocument()->getName() static_cast<void>(Gui::Selection().setPreselect(viewObj->getDocument()->getName(),
,viewObj->getNameInDocument() viewObj->getNameInDocument(),
,ss.str().c_str() ss.str().c_str(), pos.x(), pos.y(), 0));
,pos.x() }
,pos.y() else {
,0));
} else {
ss << ""; ss << "";
Gui::Selection().setPreselect(viewObj->getDocument()->getName() Gui::Selection().setPreselect(viewObj->getDocument()->getName(),
,viewObj->getNameInDocument() viewObj->getNameInDocument(), ss.str().c_str(), pos.x(),
,ss.str().c_str() pos.y(), 0);
,pos.x()
,pos.y()
,0);
} }
} }
//flag to prevent selection activity within mdivp //flag to prevent selection activity within mdivp
void MDIViewPage::blockSceneSelection(const bool isBlocked) void MDIViewPage::blockSceneSelection(const bool isBlocked) { isSelectionBlocked = isBlocked; }
{
isSelectionBlocked = isBlocked;
}
//Set all QGIViews to unselected state //Set all QGIViews to unselected state
@@ -816,7 +833,8 @@ void MDIViewPage::clearSceneSelection()
QGIViewDimension* dim = dynamic_cast<QGIViewDimension*>(*it); QGIViewDimension* dim = dynamic_cast<QGIViewDimension*>(*it);
if (dim) { if (dim) {
state = dim->getDatumLabel()->isSelected(); state = dim->getDatumLabel()->isSelected();
} else { }
else {
QGIViewBalloon* bal = dynamic_cast<QGIViewBalloon*>(*it); QGIViewBalloon* bal = dynamic_cast<QGIViewBalloon*>(*it);
if (bal) { if (bal) {
state = bal->getBalloonLabel()->isSelected(); state = bal->getBalloonLabel()->isSelected();
@@ -850,10 +868,12 @@ void MDIViewPage::selectQGIView(App::DocumentObject *obj, const bool isSelected)
void MDIViewPage::onSelectionChanged(const Gui::SelectionChanges& msg) void MDIViewPage::onSelectionChanged(const Gui::SelectionChanges& msg)
{ {
// Base::Console().Message("MDIVP::onSelectionChanged()\n"); // Base::Console().Message("MDIVP::onSelectionChanged()\n");
std::vector<Gui::SelectionSingleton::SelObj> selObjs = Gui::Selection().getSelection(msg.pDocName); std::vector<Gui::SelectionSingleton::SelObj> selObjs =
Gui::Selection().getSelection(msg.pDocName);
if (msg.Type == Gui::SelectionChanges::ClrSelection) { if (msg.Type == Gui::SelectionChanges::ClrSelection) {
clearSceneSelection(); clearSceneSelection();
} else if(msg.Type == Gui::SelectionChanges::SetSelection) { //replace entire selection set }
else if (msg.Type == Gui::SelectionChanges::SetSelection) {//replace entire selection set
clearSceneSelection(); clearSceneSelection();
blockSceneSelection(true); blockSceneSelection(true);
for (auto& so : selObjs) { for (auto& so : selObjs) {
@@ -862,7 +882,8 @@ void MDIViewPage::onSelectionChanged(const Gui::SelectionChanges& msg)
} }
} }
blockSceneSelection(false); blockSceneSelection(false);
} else if(msg.Type == Gui::SelectionChanges::AddSelection) { }
else if (msg.Type == Gui::SelectionChanges::AddSelection) {
blockSceneSelection(true); blockSceneSelection(true);
for (auto& so : selObjs) { for (auto& so : selObjs) {
if (so.pObject->isDerivedFrom(TechDraw::DrawView::getClassTypeId())) { if (so.pObject->isDerivedFrom(TechDraw::DrawView::getClassTypeId())) {
@@ -870,7 +891,8 @@ void MDIViewPage::onSelectionChanged(const Gui::SelectionChanges& msg)
} }
} }
blockSceneSelection(false); blockSceneSelection(false);
} else { }
else {
Base::Console().Log("MDIVP::onSelectionChanged - unhandled: %d\n", msg.Type); Base::Console().Log("MDIVP::onSelectionChanged - unhandled: %d\n", msg.Type);
} }
} }
@@ -887,8 +909,7 @@ void MDIViewPage::sceneSelectionManager()
return; return;
} }
if (m_qgSceneSelected.isEmpty() && if (m_qgSceneSelected.isEmpty() && !sceneSel.isEmpty()) {
!sceneSel.isEmpty()) {
m_qgSceneSelected.push_back(sceneSel.front()); m_qgSceneSelected.push_back(sceneSel.front());
return; return;
} }
@@ -957,12 +978,14 @@ void MDIViewPage::setTreeToSceneSelect()
QGIEdge* edge = dynamic_cast<QGIEdge*>(*it); QGIEdge* edge = dynamic_cast<QGIEdge*>(*it);
if (edge) { if (edge) {
QGraphicsItem* parent = edge->parentItem(); QGraphicsItem* parent = edge->parentItem();
if(!parent) if (!parent) {
continue; continue;
}
QGIView* viewItem = dynamic_cast<QGIView*>(parent); QGIView* viewItem = dynamic_cast<QGIView*>(parent);
if(!viewItem) if (!viewItem) {
continue; continue;
}
TechDraw::DrawView* viewObj = viewItem->getViewObject(); TechDraw::DrawView* viewObj = viewItem->getViewObject();
@@ -972,8 +995,7 @@ void MDIViewPage::setTreeToSceneSelect()
static_cast<void>(Gui::Selection().addSelection(viewObj->getDocument()->getName(), static_cast<void>(Gui::Selection().addSelection(viewObj->getDocument()->getName(),
viewObj->getNameInDocument(), viewObj->getNameInDocument(),
ss.str().c_str())); ss.str().c_str()));
showStatusMsg(viewObj->getDocument()->getName(), showStatusMsg(viewObj->getDocument()->getName(), viewObj->getNameInDocument(),
viewObj->getNameInDocument(),
ss.str().c_str()); ss.str().c_str());
continue; continue;
} }
@@ -981,12 +1003,14 @@ void MDIViewPage::setTreeToSceneSelect()
QGIVertex* vert = dynamic_cast<QGIVertex*>(*it); QGIVertex* vert = dynamic_cast<QGIVertex*>(*it);
if (vert) { if (vert) {
QGraphicsItem* parent = vert->parentItem(); QGraphicsItem* parent = vert->parentItem();
if(!parent) if (!parent) {
continue; continue;
}
QGIView* viewItem = dynamic_cast<QGIView*>(parent); QGIView* viewItem = dynamic_cast<QGIView*>(parent);
if(!viewItem) if (!viewItem) {
continue; continue;
}
TechDraw::DrawView* viewObj = viewItem->getViewObject(); TechDraw::DrawView* viewObj = viewItem->getViewObject();
@@ -996,8 +1020,7 @@ void MDIViewPage::setTreeToSceneSelect()
static_cast<void>(Gui::Selection().addSelection(viewObj->getDocument()->getName(), static_cast<void>(Gui::Selection().addSelection(viewObj->getDocument()->getName(),
viewObj->getNameInDocument(), viewObj->getNameInDocument(),
ss.str().c_str())); ss.str().c_str()));
showStatusMsg(viewObj->getDocument()->getName(), showStatusMsg(viewObj->getDocument()->getName(), viewObj->getNameInDocument(),
viewObj->getNameInDocument(),
ss.str().c_str()); ss.str().c_str());
continue; continue;
} }
@@ -1005,12 +1028,14 @@ void MDIViewPage::setTreeToSceneSelect()
QGIFace* face = dynamic_cast<QGIFace*>(*it); QGIFace* face = dynamic_cast<QGIFace*>(*it);
if (face) { if (face) {
QGraphicsItem* parent = face->parentItem(); QGraphicsItem* parent = face->parentItem();
if(!parent) if (!parent) {
continue; continue;
}
QGIView* viewItem = dynamic_cast<QGIView*>(parent); QGIView* viewItem = dynamic_cast<QGIView*>(parent);
if(!viewItem) if (!viewItem) {
continue; continue;
}
TechDraw::DrawView* viewObj = viewItem->getViewObject(); TechDraw::DrawView* viewObj = viewItem->getViewObject();
@@ -1020,8 +1045,7 @@ void MDIViewPage::setTreeToSceneSelect()
static_cast<void>(Gui::Selection().addSelection(viewObj->getDocument()->getName(), static_cast<void>(Gui::Selection().addSelection(viewObj->getDocument()->getName(),
viewObj->getNameInDocument(), viewObj->getNameInDocument(),
ss.str().c_str())); ss.str().c_str()));
showStatusMsg(viewObj->getDocument()->getName(), showStatusMsg(viewObj->getDocument()->getName(), viewObj->getNameInDocument(),
viewObj->getNameInDocument(),
ss.str().c_str()); ss.str().c_str());
continue; continue;
} }
@@ -1029,13 +1053,15 @@ void MDIViewPage::setTreeToSceneSelect()
QGIDatumLabel* dimLabel = dynamic_cast<QGIDatumLabel*>(*it); QGIDatumLabel* dimLabel = dynamic_cast<QGIDatumLabel*>(*it);
if (dimLabel) { if (dimLabel) {
QGraphicsItem* dimParent = dimLabel->QGraphicsItem::parentItem(); QGraphicsItem* dimParent = dimLabel->QGraphicsItem::parentItem();
if(!dimParent) if (!dimParent) {
continue; continue;
}
QGIView* dimItem = dynamic_cast<QGIView*>(dimParent); QGIView* dimItem = dynamic_cast<QGIView*>(dimParent);
if(!dimItem) if (!dimItem) {
continue; continue;
}
TechDraw::DrawView* dimObj = dimItem->getViewObject(); TechDraw::DrawView* dimObj = dimItem->getViewObject();
if (!dimObj) { if (!dimObj) {
@@ -1048,7 +1074,8 @@ void MDIViewPage::setTreeToSceneSelect()
} }
//bool accepted = //bool accepted =
static_cast<void> (Gui::Selection().addSelection(dimObj->getDocument()->getName(), dimObj->getNameInDocument())); static_cast<void>(Gui::Selection().addSelection(dimObj->getDocument()->getName(),
dimObj->getNameInDocument()));
} }
QGMText* mText = dynamic_cast<QGMText*>(*it); QGMText* mText = dynamic_cast<QGMText*>(*it);
@@ -1074,10 +1101,11 @@ void MDIViewPage::setTreeToSceneSelect()
} }
//bool accepted = //bool accepted =
static_cast<void> (Gui::Selection().addSelection(parentFeat->getDocument()->getName(), parentFeat->getNameInDocument())); static_cast<void>(Gui::Selection().addSelection(
parentFeat->getDocument()->getName(), parentFeat->getNameInDocument()));
} }
}
} else { else {
TechDraw::DrawView* viewObj = itemView->getViewObject(); TechDraw::DrawView* viewObj = itemView->getViewObject();
if (viewObj && !viewObj->isRemoving()) { if (viewObj && !viewObj->isRemoving()) {
@@ -1085,9 +1113,7 @@ void MDIViewPage::setTreeToSceneSelect()
std::string obj_name = viewObj->getNameInDocument(); std::string obj_name = viewObj->getNameInDocument();
Gui::Selection().addSelection(doc_name.c_str(), obj_name.c_str()); Gui::Selection().addSelection(doc_name.c_str(), obj_name.c_str());
showStatusMsg(doc_name.c_str(), showStatusMsg(doc_name.c_str(), obj_name.c_str(), "");
obj_name.c_str(),
"");
} }
} }
} }
@@ -1096,15 +1122,18 @@ void MDIViewPage::setTreeToSceneSelect()
blockSelection(saveBlock); blockSelection(saveBlock);
} }
bool MDIViewPage::compareSelections(std::vector<Gui::SelectionObject> treeSel, QList<QGraphicsItem*> sceneSel) bool MDIViewPage::compareSelections(std::vector<Gui::SelectionObject> treeSel,
QList<QGraphicsItem*> sceneSel)
{ {
bool result = true; bool result = true;
if (treeSel.empty() && sceneSel.empty()) { if (treeSel.empty() && sceneSel.empty()) {
return true; return true;
} else if (treeSel.empty() && !sceneSel.empty()) { }
else if (treeSel.empty() && !sceneSel.empty()) {
return false; return false;
} else if (!treeSel.empty() && sceneSel.empty()) { }
else if (!treeSel.empty() && sceneSel.empty()) {
return false; return false;
} }
@@ -1162,7 +1191,8 @@ bool MDIViewPage::compareSelections(std::vector<Gui::SelectionObject> treeSel, Q
if (s == (*treePtr)) { if (s == (*treePtr)) {
treePtr++; treePtr++;
continue; continue;
} else { }
else {
return false; return false;
} }
} }
@@ -1180,9 +1210,7 @@ bool MDIViewPage::compareSelections(std::vector<Gui::SelectionObject> treeSel, Q
void MDIViewPage::showStatusMsg(const char* string1, const char* string2, const char* string3) const void MDIViewPage::showStatusMsg(const char* string1, const char* string2, const char* string3) const
{ {
QString msg = QString::fromLatin1("%1 %2.%3.%4 ") QString msg = QString::fromLatin1("%1 %2.%3.%4 ")
.arg(tr("Selected:"), .arg(tr("Selected:"), QString::fromUtf8(string1), QString::fromUtf8(string2),
QString::fromUtf8(string1),
QString::fromUtf8(string2),
QString::fromUtf8(string3)); QString::fromUtf8(string3));
if (Gui::getMainWindow()) { if (Gui::getMainWindow()) {
Gui::getMainWindow()->showMessage(msg, 6000); Gui::getMainWindow()->showMessage(msg, 6000);
@@ -1200,25 +1228,23 @@ void MDIViewPagePy::init_type()
behaviors().supportGetattr(); behaviors().supportGetattr();
behaviors().supportSetattr(); behaviors().supportSetattr();
add_varargs_method("getPage", &MDIViewPagePy::getPage, "getPage() returns the page being displayed"); add_varargs_method("getPage", &MDIViewPagePy::getPage,
add_varargs_method("cast_to_base", &MDIViewPagePy::cast_to_base, "cast_to_base() cast to MDIView class"); "getPage() returns the page being displayed");
add_varargs_method("cast_to_base", &MDIViewPagePy::cast_to_base,
"cast_to_base() cast to MDIView class");
behaviors().readyType(); behaviors().readyType();
} }
MDIViewPagePy::MDIViewPagePy(MDIViewPage *mdi) MDIViewPagePy::MDIViewPagePy(MDIViewPage* mdi) : base(mdi) {}
: base(mdi)
{
}
MDIViewPagePy::~MDIViewPagePy() MDIViewPagePy::~MDIViewPagePy() {}
{
}
Py::Object MDIViewPagePy::repr() Py::Object MDIViewPagePy::repr()
{ {
std::ostringstream s_out; std::ostringstream s_out;
if (!getMDIViewPagePtr()) if (!getMDIViewPagePtr()) {
throw Py::RuntimeError("Cannot print representation of deleted object"); throw Py::RuntimeError("Cannot print representation of deleted object");
}
s_out << "MDI view page"; s_out << "MDI view page";
return Py::String(s_out.str()); return Py::String(s_out.str());
} }
@@ -1260,8 +1286,9 @@ MDIViewPage* MDIViewPagePy::getMDIViewPagePtr()
Py::Object MDIViewPagePy::getPage(const Py::Tuple& args) Py::Object MDIViewPagePy::getPage(const Py::Tuple& args)
{ {
if (!PyArg_ParseTuple(args.ptr(), "")) if (!PyArg_ParseTuple(args.ptr(), "")) {
throw Py::Exception(); throw Py::Exception();
}
return Py::asObject(new TechDraw::DrawPagePy(getMDIViewPagePtr()->getPage())); return Py::asObject(new TechDraw::DrawPagePy(getMDIViewPagePtr()->getPage()));
} }

View File

@@ -91,7 +91,12 @@ App::Color PreferencesGui::sectionLineColor()
QColor PreferencesGui::sectionLineQColor() QColor PreferencesGui::sectionLineQColor()
{ {
return sectionLineColor().asValue<QColor>(); //if the App::Color version has already lightened the color, we don't want to do it agin
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Decorations");
App::Color fcColor;
fcColor.setPackedValue(hGrp->GetUnsigned("SectionColor", 0x000000FF));
return fcColor.asValue<QColor>();
} }
App::Color PreferencesGui::centerColor() App::Color PreferencesGui::centerColor()
@@ -105,7 +110,11 @@ App::Color PreferencesGui::centerColor()
QColor PreferencesGui::centerQColor() QColor PreferencesGui::centerQColor()
{ {
return centerColor().asValue<QColor>(); Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter().
GetGroup("BaseApp")->GetGroup("Preferences")->
GetGroup("Mod/TechDraw/Decorations");
App::Color fcColor = App::Color((uint32_t) hGrp->GetUnsigned("CenterColor", 0x000000FF));
return fcColor.asValue<QColor>();
} }
QColor PreferencesGui::vertexQColor() QColor PreferencesGui::vertexQColor()
@@ -118,30 +127,39 @@ App::Color PreferencesGui::dimColor()
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter(). Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter().
GetGroup("BaseApp")->GetGroup("Preferences")-> GetGroup("BaseApp")->GetGroup("Preferences")->
GetGroup("Mod/TechDraw/Dimensions"); GetGroup("Mod/TechDraw/Dimensions");
App::Color result; App::Color fcColor;
result.setPackedValue(hGrp->GetUnsigned("Color", 0x000000FF)); //#000000 black fcColor.setPackedValue(hGrp->GetUnsigned("Color", 0x000000FF)); //#000000 black
return result; return fcColor;
} }
QColor PreferencesGui::dimQColor() QColor PreferencesGui::dimQColor()
{ {
return PreferencesGui::dimColor().asValue<QColor>(); Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter().
GetGroup("BaseApp")->GetGroup("Preferences")->
GetGroup("Mod/TechDraw/Dimensions");
App::Color fcColor;
fcColor.setPackedValue(hGrp->GetUnsigned("Color", 0x000000FF)); //#000000 black
return fcColor.asValue<QColor>();
} }
App::Color PreferencesGui::leaderColor() App::Color PreferencesGui::leaderColor()
{ {
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter(). Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter().
GetGroup("BaseApp")->GetGroup("Preferences")-> GetGroup("BaseApp")->GetGroup("Preferences")->
GetGroup("Mod/TechDraw/LeaderLine"); GetGroup("Mod/TechDraw/LeaderLine");
App::Color result; App::Color fcColor;
result.setPackedValue(hGrp->GetUnsigned("Color", 0x000000FF)); //#000000 black fcColor.setPackedValue(hGrp->GetUnsigned("Color", 0x000000FF)); //#000000 black
return result; return fcColor;
} }
QColor PreferencesGui::leaderQColor() QColor PreferencesGui::leaderQColor()
{ {
return PreferencesGui::leaderColor().asValue<QColor>(); Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter().
GetGroup("BaseApp")->GetGroup("Preferences")->
GetGroup("Mod/TechDraw/LeaderLine");
App::Color fcColor;
fcColor.setPackedValue(hGrp->GetUnsigned("Color", 0x000000FF)); //#000000 black
return fcColor.asValue<QColor>();
} }
int PreferencesGui::dimArrowStyle() int PreferencesGui::dimArrowStyle()
@@ -208,20 +226,24 @@ QString PreferencesGui::weldingDirectory()
return qSymbolDir; return qSymbolDir;
} }
App::Color PreferencesGui::gridColor() App::Color PreferencesGui::gridColor()
{ {
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter(). Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter().
GetGroup("BaseApp")->GetGroup("Preferences")-> GetGroup("BaseApp")->GetGroup("Preferences")->
GetGroup("Mod/TechDraw/Colors"); GetGroup("Mod/TechDraw/Colors");
App::Color result; App::Color fcColor;
result.setPackedValue(hGrp->GetUnsigned("gridColor", 0x000000FF)); //#000000 black fcColor.setPackedValue(hGrp->GetUnsigned("gridColor", 0x000000FF)); //#000000 black
return result; return fcColor;
} }
QColor PreferencesGui::gridQColor() QColor PreferencesGui::gridQColor()
{ {
return PreferencesGui::gridColor().asValue<QColor>(); Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter().
GetGroup("BaseApp")->GetGroup("Preferences")->
GetGroup("Mod/TechDraw/Colors");
App::Color fcColor;
fcColor.setPackedValue(hGrp->GetUnsigned("gridColor", 0x000000FF)); //#000000 black
return fcColor.asValue<QColor>();
} }
double PreferencesGui::gridSpacing() double PreferencesGui::gridSpacing()
@@ -241,3 +263,70 @@ bool PreferencesGui::showGrid()
bool show = hGrp->GetBool("showGrid", false); bool show = hGrp->GetBool("showGrid", false);
return show; return show;
} }
App::Color PreferencesGui::pageColor()
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter().
GetGroup("BaseApp")->GetGroup("Preferences")->
GetGroup("Mod/TechDraw/Colors");
App::Color result;
result.setPackedValue(hGrp->GetUnsigned("PageColor", 0xFFFFFFFF)); //#FFFFFFFF white
return result;
}
QColor PreferencesGui::pageQColor()
{
return PreferencesGui::pageColor().asValue<QColor>();
}
QColor PreferencesGui::getAccessibleQColor(QColor orig)
{
if (Preferences::lightOnDark() && Preferences::monochrome()) {
return lightTextQColor();
}
if (Preferences::lightOnDark()) {
return lightenColor(orig);
}
return orig;
}
QColor PreferencesGui::lightTextQColor()
{
return Preferences::lightTextColor().asValue<QColor>();
}
QColor PreferencesGui::reverseColor(QColor orig)
{
int revRed = 255 - orig.red();
int revBlue = 255 - orig.blue();
int revGreen = 255 - orig.green();
return QColor(revRed, revGreen, revBlue);
}
// largely based on code from https://invent.kde.org/graphics/okular and
// https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB
QColor PreferencesGui::lightenColor(QColor orig)
{
// get component colours on [0, 255]
uchar red = orig.red();
uchar blue = orig.blue();
uchar green = orig.green();
uchar alpha = orig.alpha();
// shift color values
uchar m = std::min( {red, blue, green} );
red -= m;
blue -= m;
green -= m;
// calculate chroma (colour range)
uchar chroma = std::max( {red, blue, green} );
// calculate lightened colour value
uchar newm = 255 - chroma - m;
red += newm;
green += newm;
blue += newm;
return QColor(red, green, blue, alpha);
}

View File

@@ -55,6 +55,8 @@ static App::Color leaderColor();
static QColor leaderQColor(); static QColor leaderQColor();
static App::Color dimColor(); static App::Color dimColor();
static QColor dimQColor(); static QColor dimQColor();
static App::Color pageColor();
static QColor pageQColor();
static int dimArrowStyle(); static int dimArrowStyle();
static double dimArrowSize(); static double dimArrowSize();
@@ -71,6 +73,10 @@ static App::Color gridColor();
static QColor gridQColor(); static QColor gridQColor();
static double gridSpacing(); static double gridSpacing();
static QColor getAccessibleQColor(QColor orig);
static QColor lightTextQColor();
static QColor reverseColor(QColor orig);
static QColor lightenColor(QColor orig);
}; };
} //end namespace TechDrawGui } //end namespace TechDrawGui

View File

@@ -234,7 +234,7 @@ void QGEPath::showMarkers(std::vector<QPointF> points)
//TODO: double r = getMarkerSize(); //TODO: double r = getMarkerSize();
// v->setRadius(r); // v->setRadius(r);
v->setRadius(50.0); v->setRadius(50.0);
v->setNormalColor(QColor(Qt::black)); v->setNormalColor(PreferencesGui::getAccessibleQColor(QColor(Qt::black)));
v->setZValue(ZVALUE::VERTEX); v->setZValue(ZVALUE::VERTEX);
v->setPos(p); v->setPos(p);
v->show(); v->show();

View File

@@ -34,7 +34,7 @@
#include <Base/Parameter.h> #include <Base/Parameter.h>
#include "QGICMark.h" #include "QGICMark.h"
#include "PreferencesGui.h"
using namespace TechDrawGui; using namespace TechDrawGui;
@@ -68,10 +68,7 @@ void QGICMark::setThick(float t)
QColor QGICMark::getCMarkColor() QColor QGICMark::getCMarkColor()
{ {
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter() return PreferencesGui::centerQColor();
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Colors");
App::Color fcColor = App::Color((uint32_t) hGrp->GetUnsigned("CMarkColor", 0x08080800));
return fcColor.asValue<QColor>();
} }
void QGICMark::setPrettyNormal() { void QGICMark::setPrettyNormal() {

View File

@@ -85,7 +85,7 @@ QColor QGIEdge::getHiddenColor()
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter() Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Colors"); .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Colors");
App::Color fcColor = App::Color((uint32_t) hGrp->GetUnsigned("HiddenColor", 0x000000FF)); App::Color fcColor = App::Color((uint32_t) hGrp->GetUnsigned("HiddenColor", 0x000000FF));
return fcColor.asValue<QColor>(); return PreferencesGui::getAccessibleQColor(fcColor.asValue<QColor>());
} }
Qt::PenStyle QGIEdge::getHiddenStyle() Qt::PenStyle QGIEdge::getHiddenStyle()

View File

@@ -38,6 +38,7 @@
#include <Base/Parameter.h> #include <Base/Parameter.h>
#include <Mod/TechDraw/App/DrawUtil.h> #include <Mod/TechDraw/App/DrawUtil.h>
#include "PreferencesGui.h"
#include "QGIFace.h" #include "QGIFace.h"
#include <QByteArrayMatcher> #include <QByteArrayMatcher>
#include "QGCustomImage.h" #include "QGCustomImage.h"
@@ -48,7 +49,6 @@
#include "Rez.h" #include "Rez.h"
#include "ZVALUE.h" #include "ZVALUE.h"
using namespace TechDrawGui; using namespace TechDrawGui;
using namespace TechDraw; using namespace TechDraw;
@@ -64,7 +64,7 @@ QGIFace::QGIFace(int index) :
//setStyle(Qt::NoPen); //don't draw face lines, just fill for debugging //setStyle(Qt::NoPen); //don't draw face lines, just fill for debugging
setStyle(Qt::DashLine); setStyle(Qt::DashLine);
m_geomColor = QColor(Qt::black); m_geomColor = PreferencesGui::getAccessibleQColor(QColor(Qt::black));
setLineWeight(0.5); //0 = cosmetic setLineWeight(0.5); //0 = cosmetic
setPrettyNormal(); setPrettyNormal();

View File

@@ -37,10 +37,10 @@
#include <Mod/TechDraw/App/DrawUtil.h> #include <Mod/TechDraw/App/DrawUtil.h>
#include <Mod/TechDraw/App/LineGroup.h> #include <Mod/TechDraw/App/LineGroup.h>
#include "QGILeaderLine.h"
#include "PreferencesGui.h" #include "PreferencesGui.h"
#include "QGEPath.h" #include "QGEPath.h"
#include "QGIArrow.h" #include "QGIArrow.h"
#include "QGILeaderLine.h"
#include "QGIPrimPath.h" #include "QGIPrimPath.h"
#include "Rez.h" #include "Rez.h"
#include "ViewProviderLeader.h" #include "ViewProviderLeader.h"
@@ -51,8 +51,8 @@ using namespace TechDrawGui;
using namespace TechDraw; using namespace TechDraw;
//************************************************************** //**************************************************************
QGILeaderLine::QGILeaderLine() : QGILeaderLine::QGILeaderLine()
m_parentItem(nullptr), : m_parentItem(nullptr),
m_lineColor(Qt::black), m_lineColor(Qt::black),
m_lineStyle(Qt::SolidLine), m_lineStyle(Qt::SolidLine),
m_hasHover(false), m_hasHover(false),
@@ -96,10 +96,10 @@ QGILeaderLine::QGILeaderLine() :
setZValue(ZVALUE::DIMENSION); setZValue(ZVALUE::DIMENSION);
QObject::connect( QObject::connect(m_editPath,
m_editPath, SIGNAL(pointsUpdated(QPointF, std::vector<QPointF>)), SIGNAL(pointsUpdated(QPointF, std::vector<QPointF>)),
this , SLOT (onLineEditFinished(QPointF, std::vector<QPointF>)) this,
); SLOT(onLineEditFinished(QPointF, std::vector<QPointF>)));
} }
void QGILeaderLine::setLeaderFeature(TechDraw::DrawLeaderLine* feat) void QGILeaderLine::setLeaderFeature(TechDraw::DrawLeaderLine* feat)
@@ -123,11 +123,13 @@ QVariant QGILeaderLine::itemChange(GraphicsItemChange change, const QVariant &va
if (change == ItemSelectedHasChanged && scene()) { if (change == ItemSelectedHasChanged && scene()) {
if (isSelected()) { if (isSelected()) {
setPrettySel(); setPrettySel();
} else { }
else {
setPrettyNormal(); setPrettyNormal();
} }
draw(); draw();
} else if(change == ItemSceneChange && scene()) { }
else if (change == ItemSceneChange && scene()) {
// nothing special! // nothing special!
} }
return QGIView::itemChange(change, value); return QGIView::itemChange(change, value);
@@ -176,37 +178,43 @@ void QGILeaderLine::onSourceChange(TechDraw::DrawView* newParent)
m_parentItem = qgiParent; m_parentItem = qgiParent;
setParentItem(m_parentItem); setParentItem(m_parentItem);
draw(); draw();
} else { }
Base::Console().Warning("QGILL::onSourceChange - new parent %s has no QGIView\n", parentName.c_str()); else {
Base::Console().Warning("QGILL::onSourceChange - new parent %s has no QGIView\n",
parentName.c_str());
} }
} }
void QGILeaderLine::setNormalColorAll() void QGILeaderLine::setNormalColorAll()
{ {
// Base::Console().Message("QGILL::setNormalColorAll - normal color: %s\n", qPrintable(getNormalColor().name())); // Base::Console().Message("QGILL::setNormalColorAll - normal color: %s\n", qPrintable(getNormalColor().name()));
m_line->setNormalColor(getNormalColor()); QColor qc = prefNormalColor();
m_editPath->setNormalColor(getNormalColor()); m_line->setNormalColor(qc);
m_arrow1->setNormalColor(getNormalColor()); m_editPath->setNormalColor(qc);
m_arrow1->setFillColor(getNormalColor()); m_arrow1->setNormalColor(qc);
m_arrow2->setNormalColor(getNormalColor()); m_arrow1->setFillColor(qc);
m_arrow2->setFillColor(getNormalColor()); m_arrow2->setNormalColor(qc);
m_arrow2->setFillColor(qc);
} }
void QGILeaderLine::setPrettyNormal() { void QGILeaderLine::setPrettyNormal()
{
// Base::Console().Message("QGILL::setPrettyNormal()\n"); // Base::Console().Message("QGILL::setPrettyNormal()\n");
m_line->setPrettyNormal(); m_line->setPrettyNormal();
m_arrow1->setPrettyNormal(); m_arrow1->setPrettyNormal();
m_arrow2->setPrettyNormal(); m_arrow2->setPrettyNormal();
} }
void QGILeaderLine::setPrettyPre() { void QGILeaderLine::setPrettyPre()
{
// Base::Console().Message("QGILL::setPrettyPre()\n"); // Base::Console().Message("QGILL::setPrettyPre()\n");
m_line->setPrettyPre(); m_line->setPrettyPre();
m_arrow1->setPrettyPre(); m_arrow1->setPrettyPre();
m_arrow2->setPrettyPre(); m_arrow2->setPrettyPre();
} }
void QGILeaderLine::setPrettySel() { void QGILeaderLine::setPrettySel()
{
// Base::Console().Message("QGILL::setPrettySel()\n"); // Base::Console().Message("QGILL::setPrettySel()\n");
m_line->setPrettySel(); m_line->setPrettySel();
m_arrow1->setPrettySel(); m_arrow1->setPrettySel();
@@ -230,18 +238,17 @@ void QGILeaderLine::onLineEditFinished(QPointF tipDisplace, std::vector<QPointF>
// points.size()); // points.size());
m_blockDraw = true; m_blockDraw = true;
auto featLeader = getFeature(); auto featLeader = getFeature();
if (!featLeader) if (!featLeader) {
return; return;
}
double baseScale = featLeader->getBaseScale(); double baseScale = featLeader->getBaseScale();
if ( !(TechDraw::DrawUtil::fpCompare(tipDisplace.x(), 0.0) && if (!(TechDraw::DrawUtil::fpCompare(tipDisplace.x(), 0.0)
TechDraw::DrawUtil::fpCompare(tipDisplace.y(), 0.0)) ) { && TechDraw::DrawUtil::fpCompare(tipDisplace.y(), 0.0))) {
//tip was moved. need to change AttachPoint //tip was moved. need to change AttachPoint
QPointF oldAttach = getAttachFromFeature(); QPointF oldAttach = getAttachFromFeature();
QPointF newAttach = oldAttach + (tipDisplace / baseScale); QPointF newAttach = oldAttach + (tipDisplace / baseScale);
featLeader->setPosition(Rez::appX(newAttach.x()), featLeader->setPosition(Rez::appX(newAttach.x()), Rez::appX(-newAttach.y()), true);
Rez::appX(- newAttach.y()),
true);
} }
std::vector<Base::Vector3d> waypoints; std::vector<Base::Vector3d> waypoints;
@@ -268,8 +275,9 @@ void QGILeaderLine::startPathEdit()
{ {
saveState(); saveState();
auto featLeader(dynamic_cast<TechDraw::DrawLeaderLine*>(getViewObject())); auto featLeader(dynamic_cast<TechDraw::DrawLeaderLine*>(getViewObject()));
if (!featLeader) if (!featLeader) {
return; return;
}
double scale = featLeader->getScale(); double scale = featLeader->getScale();
m_editPath->setScale(scale); m_editPath->setScale(scale);
@@ -314,38 +322,47 @@ void QGILeaderLine::updateView(bool update)
} }
auto vp = static_cast<ViewProviderLeader*>(getViewProvider(getViewObject())); auto vp = static_cast<ViewProviderLeader*>(getViewProvider(getViewObject()));
if (!vp) if (!vp) {
return; return;
}
draw(); draw();
} }
void QGILeaderLine::draw() void QGILeaderLine::draw()
{ {
// Base::Console().Message("QGILL::draw()- %s\n", getViewObject()->getNameInDocument()); // Base::Console().Message("QGILL::draw()- %s\n", getViewObject()->getNameInDocument());
if (m_blockDraw) if (m_blockDraw) {
return; return;
if (!isVisible()) }
if (!isVisible()) {
return; return;
}
TechDraw::DrawLeaderLine* featLeader = getFeature(); TechDraw::DrawLeaderLine* featLeader = getFeature();
if (!featLeader) if (!featLeader) {
return; return;
}
auto vp = static_cast<ViewProviderLeader*>(getViewProvider(getViewObject())); auto vp = static_cast<ViewProviderLeader*>(getViewProvider(getViewObject()));
if (!vp) if (!vp) {
return; return;
}
double scale = 1.0; double scale = 1.0;
TechDraw::DrawView* parent = featLeader->getBaseView(); TechDraw::DrawView* parent = featLeader->getBaseView();
if (parent) if (parent) {
scale = parent->getScale(); scale = parent->getScale();
}
if (m_editPath->inEdit()) if (m_editPath->inEdit()) {
return; return;
}
//******** //********
if (featLeader->isLocked()) if (featLeader->isLocked()) {
setFlag(QGraphicsItem::ItemIsMovable, false); setFlag(QGraphicsItem::ItemIsMovable, false);
else }
else {
setFlag(QGraphicsItem::ItemIsMovable, true); setFlag(QGraphicsItem::ItemIsMovable, true);
}
m_lineStyle = static_cast<Qt::PenStyle>(vp->LineStyle.getValue()); m_lineStyle = static_cast<Qt::PenStyle>(vp->LineStyle.getValue());
double baseScale = featLeader->getBaseScale(); double baseScale = featLeader->getBaseScale();
@@ -374,9 +391,11 @@ void QGILeaderLine::draw()
if (isSelected()) { if (isSelected()) {
setPrettySel(); setPrettySel();
} else if (m_hasHover) { }
else if (m_hasHover) {
setPrettyPre(); setPrettyPre();
} else { }
else {
setPrettyNormal(); setPrettyNormal();
} }
update(boundingRect()); update(boundingRect());
@@ -491,7 +510,8 @@ void QGILeaderLine::setArrows(std::vector<QPointF> pathPoints)
} }
m_arrow1->draw(); m_arrow1->draw();
m_arrow1->show(); m_arrow1->show();
} else { }
else {
m_arrow1->hide(); m_arrow1->hide();
} }
@@ -511,7 +531,8 @@ void QGILeaderLine::setArrows(std::vector<QPointF> pathPoints)
} }
m_arrow2->draw(); m_arrow2->draw();
m_arrow2->show(); m_arrow2->show();
} else { }
else {
m_arrow2->hide(); m_arrow2->hide();
} }
} }
@@ -536,15 +557,15 @@ void QGILeaderLine::abandonEdit()
double QGILeaderLine::getLineWidth() double QGILeaderLine::getLineWidth()
{ {
auto vp = static_cast<ViewProviderLeader*>(getViewProvider(getViewObject())); auto vp = static_cast<ViewProviderLeader*>(getViewProvider(getViewObject()));
if (!vp) if (!vp) {
return Rez::guiX(LineGroup::getDefaultWidth("Graphic")); return Rez::guiX(LineGroup::getDefaultWidth("Graphic"));
}
return Rez::guiX(vp->LineWidth.getValue()); return Rez::guiX(vp->LineWidth.getValue());
} }
TechDraw::DrawLeaderLine* QGILeaderLine::getFeature() TechDraw::DrawLeaderLine* QGILeaderLine::getFeature()
{ {
TechDraw::DrawLeaderLine* result = TechDraw::DrawLeaderLine* result = static_cast<TechDraw::DrawLeaderLine*>(getViewObject());
static_cast<TechDraw::DrawLeaderLine*>(getViewObject());
return result; return result;
} }
@@ -560,7 +581,8 @@ QColor QGILeaderLine::prefNormalColor()
auto vp = dynamic_cast<ViewProviderLeader*>(getViewProvider(getViewObject())); auto vp = dynamic_cast<ViewProviderLeader*>(getViewProvider(getViewObject()));
if (vp) { if (vp) {
setNormalColor(vp->Color.getValue().asValue<QColor>()); QColor normal = vp->Color.getValue().asValue<QColor>();
setNormalColor(PreferencesGui::getAccessibleQColor(normal));
} }
return getNormalColor(); return getNormalColor();
} }
@@ -570,7 +592,9 @@ QRectF QGILeaderLine::boundingRect() const
return childrenBoundingRect(); return childrenBoundingRect();
} }
void QGILeaderLine::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) { void QGILeaderLine::paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
QWidget* widget)
{
QStyleOptionGraphicsItem myOption(*option); QStyleOptionGraphicsItem myOption(*option);
myOption.state &= ~QStyle::State_Selected; myOption.state &= ~QStyle::State_Selected;

View File

@@ -36,10 +36,11 @@
#include "QGIView.h" #include "QGIView.h"
namespace TechDraw { namespace TechDraw
{
class DrawLeaderLine; class DrawLeaderLine;
class DrawView; class DrawView;
} }// namespace TechDraw
namespace TechDrawGui namespace TechDrawGui
{ {
@@ -55,14 +56,19 @@ class TechDrawGuiExport QGILeaderLine : public QGIView
Q_OBJECT Q_OBJECT
public: public:
enum {Type = QGraphicsItem::UserType + 232}; enum
{
Type = QGraphicsItem::UserType + 232
};
explicit QGILeaderLine(); explicit QGILeaderLine();
~QGILeaderLine() = default; ~QGILeaderLine() = default;
int type() const override { return Type;} int type() const override
void paint( QPainter * painter, {
const QStyleOptionGraphicsItem * option, return Type;
}
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
QWidget* widget = nullptr) override; QWidget* widget = nullptr) override;
QRectF boundingRect() const override; QRectF boundingRect() const override;
@@ -92,7 +98,8 @@ public:
void setLeaderFeature(TechDraw::DrawLeaderLine* feat); void setLeaderFeature(TechDraw::DrawLeaderLine* feat);
public Q_SLOTS: public Q_SLOTS:
void onLineEditFinished(QPointF tipDisplace, std::vector<QPointF> points); //QGEPath is finished editing points void onLineEditFinished(QPointF tipDisplace,
std::vector<QPointF> points);//QGEPath is finished editing points
void onSourceChange(TechDraw::DrawView* newParent) override; void onSourceChange(TechDraw::DrawView* newParent) override;
Q_SIGNALS: Q_SIGNALS:
@@ -104,8 +111,7 @@ protected:
std::vector<QPointF> getWayPointsFromFeature(); std::vector<QPointF> getWayPointsFromFeature();
QPointF getAttachFromFeature(); QPointF getAttachFromFeature();
QVariant itemChange( GraphicsItemChange change, QVariant itemChange(GraphicsItemChange change, const QVariant& value) override;
const QVariant &value ) override;
void saveState(); void saveState();
void restoreState(); void restoreState();
@@ -134,6 +140,6 @@ private:
bool m_blockDraw;//prevent redraws while updating. bool m_blockDraw;//prevent redraws while updating.
}; };
} }// namespace TechDrawGui
#endif// DRAWINGGUI_QGRAPHICSITEMLEADERLINE_H #endif// DRAWINGGUI_QGRAPHICSITEMLEADERLINE_H

View File

@@ -25,6 +25,8 @@
#ifndef _PreComp_ #ifndef _PreComp_
#include <QDomDocument> #include <QDomDocument>
#include <QFile> #include <QFile>
#include <QGraphicsColorizeEffect>
#include <QGraphicsEffect>
#include <QGraphicsSvgItem> #include <QGraphicsSvgItem>
#include <QPen> #include <QPen>
#include <QSvgRenderer> #include <QSvgRenderer>
@@ -36,22 +38,21 @@
#include <Base/Console.h> #include <Base/Console.h>
#include <Base/Parameter.h> #include <Base/Parameter.h>
#include <Mod/TechDraw/App/DrawUtil.h>
#include <Mod/TechDraw/App/DrawSVGTemplate.h> #include <Mod/TechDraw/App/DrawSVGTemplate.h>
#include <Mod/TechDraw/App/DrawUtil.h>
#include <Mod/TechDraw/App/QDomNodeModel.h> #include <Mod/TechDraw/App/QDomNodeModel.h>
#include "PreferencesGui.h"
#include "QGISVGTemplate.h" #include "QGISVGTemplate.h"
#include "QGSPage.h" #include "QGSPage.h"
#include "Rez.h" #include "Rez.h"
#include "TemplateTextField.h" #include "TemplateTextField.h"
#include "ZVALUE.h" #include "ZVALUE.h"
using namespace TechDrawGui; using namespace TechDrawGui;
using namespace TechDraw;
QGISVGTemplate::QGISVGTemplate(QGSPage* scene) QGISVGTemplate::QGISVGTemplate(QGSPage* scene) : QGITemplate(scene), firstTime(true)
: QGITemplate(scene),
firstTime(true)
{ {
m_svgItem = new QGraphicsSvgItem(this); m_svgItem = new QGraphicsSvgItem(this);
@@ -66,18 +67,11 @@ QGISVGTemplate::QGISVGTemplate(QGSPage* scene)
m_svgItem->setZValue(ZVALUE::SVGTEMPLATE); m_svgItem->setZValue(ZVALUE::SVGTEMPLATE);
setZValue(ZVALUE::SVGTEMPLATE); setZValue(ZVALUE::SVGTEMPLATE);
} }
QGISVGTemplate::~QGISVGTemplate() QGISVGTemplate::~QGISVGTemplate() { delete m_svgRender; }
{
delete m_svgRender;
}
void QGISVGTemplate::openFile(const QFile &file) void QGISVGTemplate::openFile(const QFile& file) { Q_UNUSED(file); }
{
Q_UNUSED(file);
}
void QGISVGTemplate::load(const QByteArray& svgCode) void QGISVGTemplate::load(const QByteArray& svgCode)
{ {
@@ -101,22 +95,39 @@ void QGISVGTemplate::load(const QByteArray &svgCode)
qtrans.translate(0.0, Rez::guiX(-tmplte->getHeight())); qtrans.translate(0.0, Rez::guiX(-tmplte->getHeight()));
qtrans.scale(Rez::guiX(xaspect), Rez::guiX(yaspect)); qtrans.scale(Rez::guiX(xaspect), Rez::guiX(yaspect));
m_svgItem->setTransform(qtrans); m_svgItem->setTransform(qtrans);
if (Preferences::lightOnDark()) {
QColor color = PreferencesGui::getAccessibleQColor(QColor(Qt::black));
QGraphicsColorizeEffect* colorizeEffect = new QGraphicsColorizeEffect();
colorizeEffect->setColor(color);
m_svgItem->setGraphicsEffect(colorizeEffect);
}
else {
//remove and delete any existing graphics effect
if (m_svgItem->graphicsEffect()) {
m_svgItem->setGraphicsEffect(nullptr);
}
}
} }
TechDraw::DrawSVGTemplate* QGISVGTemplate::getSVGTemplate() TechDraw::DrawSVGTemplate* QGISVGTemplate::getSVGTemplate()
{ {
if(pageTemplate && pageTemplate->isDerivedFrom(TechDraw::DrawSVGTemplate::getClassTypeId())) if (pageTemplate && pageTemplate->isDerivedFrom(TechDraw::DrawSVGTemplate::getClassTypeId())) {
return static_cast<TechDraw::DrawSVGTemplate*>(pageTemplate); return static_cast<TechDraw::DrawSVGTemplate*>(pageTemplate);
else }
else {
return nullptr; return nullptr;
} }
}
void QGISVGTemplate::draw() void QGISVGTemplate::draw()
{ {
TechDraw::DrawSVGTemplate* tmplte = getSVGTemplate(); TechDraw::DrawSVGTemplate* tmplte = getSVGTemplate();
if(!tmplte) if (!tmplte) {
throw Base::RuntimeError("Template Feature not set for QGISVGTemplate"); throw Base::RuntimeError("Template Feature not set for QGISVGTemplate");
load(tmplte->processTemplate().toUtf8()); }
QString templateSvg = tmplte->processTemplate();
load(templateSvg.toUtf8());
} }
void QGISVGTemplate::updateView(bool update) void QGISVGTemplate::updateView(bool update)
@@ -141,7 +152,8 @@ void QGISVGTemplate::createClickHandles()
QFile file(templateFilename); QFile file(templateFilename);
if (!file.open(QIODevice::ReadOnly)) { if (!file.open(QIODevice::ReadOnly)) {
Base::Console().Error("QGISVGTemplate::createClickHandles - error opening template file %s\n", Base::Console().Error(
"QGISVGTemplate::createClickHandles - error opening template file %s\n",
svgTemplate->PageResult.getValue()); svgTemplate->PageResult.getValue());
return; return;
} }
@@ -160,8 +172,7 @@ void QGISVGTemplate::createClickHandles()
query.setFocus(QXmlItem(model.fromDomNode(templateDocElem))); query.setFocus(QXmlItem(model.fromDomNode(templateDocElem)));
// XPath query to select all <text> nodes with "freecad:editable" attribute // XPath query to select all <text> nodes with "freecad:editable" attribute
query.setQuery(QString::fromUtf8( query.setQuery(QString::fromUtf8("declare default element namespace \"" SVG_NS_URI "\"; "
"declare default element namespace \"" SVG_NS_URI "\"; "
"declare namespace freecad=\"" FREECAD_SVG_NS_URI "\"; " "declare namespace freecad=\"" FREECAD_SVG_NS_URI "\"; "
"//text[@freecad:editable]")); "//text[@freecad:editable]"));
@@ -170,8 +181,11 @@ void QGISVGTemplate::createClickHandles()
//TODO: Find location of special fields (first/third angle) and make graphics items for them //TODO: Find location of special fields (first/third angle) and make graphics items for them
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter() Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/General"); .GetUserParameter()
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/General");
double editClickBoxSize = Rez::guiX(hGrp->GetFloat("TemplateDotSize", 3.0)); double editClickBoxSize = Rez::guiX(hGrp->GetFloat("TemplateDotSize", 3.0));
QColor editClickBoxColor = Qt::green; QColor editClickBoxColor = Qt::green;
@@ -180,17 +194,19 @@ void QGISVGTemplate::createClickHandles()
double width = editClickBoxSize; double width = editClickBoxSize;
double height = editClickBoxSize; double height = editClickBoxSize;
while (!queryResult.next().isNull()) while (!queryResult.next().isNull()) {
{ QDomElement textElement =
QDomElement textElement = model.toDomNode(queryResult.current().toNodeModelIndex()).toElement(); model.toDomNode(queryResult.current().toNodeModelIndex()).toElement();
QString name = textElement.attribute(QString::fromUtf8("freecad:editable")); QString name = textElement.attribute(QString::fromUtf8("freecad:editable"));
double x = Rez::guiX(textElement.attribute(QString::fromUtf8("x"), QString::fromUtf8("0.0")).toDouble()); double x = Rez::guiX(
double y = Rez::guiX(textElement.attribute(QString::fromUtf8("y"), QString::fromUtf8("0.0")).toDouble()); textElement.attribute(QString::fromUtf8("x"), QString::fromUtf8("0.0")).toDouble());
double y = Rez::guiX(
textElement.attribute(QString::fromUtf8("y"), QString::fromUtf8("0.0")).toDouble());
if (name.isEmpty()) { if (name.isEmpty()) {
Base::Console().Warning("QGISVGTemplate::createClickHandles - no name for editable text at %f, %f\n", Base::Console().Warning(
x, y); "QGISVGTemplate::createClickHandles - no name for editable text at %f, %f\n", x, y);
continue; continue;
} }

View File

@@ -32,7 +32,8 @@ class QSvgRenderer;
class QFile; class QFile;
class QString; class QString;
namespace TechDraw { namespace TechDraw
{
class DrawSVGTemplate; class DrawSVGTemplate;
} }
@@ -48,13 +49,16 @@ class TechDrawGuiExport QGISVGTemplate : public QGITemplate
public: public:
explicit QGISVGTemplate(QGSPage* scene); explicit QGISVGTemplate(QGSPage* scene);
virtual ~QGISVGTemplate(); ~QGISVGTemplate() override;
enum {Type = QGraphicsItem::UserType + 153}; enum
{
Type = QGraphicsItem::UserType + 153
};
int type() const { return Type; } int type() const { return Type; }
void draw(); void draw();
virtual void updateView(bool update = false); void updateView(bool update = false) override;
TechDraw::DrawSVGTemplate* getSVGTemplate(); TechDraw::DrawSVGTemplate* getSVGTemplate();
@@ -69,6 +73,6 @@ protected:
QSvgRenderer* m_svgRender; QSvgRenderer* m_svgRender;
};// class QGISVGTemplate };// class QGISVGTemplate
} }// namespace TechDrawGui
#endif// DRAWINGGUI_QGRAPHICSITEMSVGTEMPLATE_H #endif// DRAWINGGUI_QGRAPHICSITEMSVGTEMPLATE_H

View File

@@ -325,7 +325,7 @@ QColor QGITile::getTileColor() const
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter() Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Colors"); .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Colors");
App::Color fcColor = App::Color((uint32_t) hGrp->GetUnsigned("TileColor", 0x00000000)); App::Color fcColor = App::Color((uint32_t) hGrp->GetUnsigned("TileColor", 0x00000000));
return fcColor.asValue<QColor>(); return PreferencesGui::getAccessibleQColor( fcColor.asValue<QColor>());
} }
double QGITile::getSymbolWidth() const double QGITile::getSymbolWidth() const

View File

@@ -200,7 +200,7 @@ QVariant QGIView::itemChange(GraphicsItemChange change, const QVariant &value)
m_colCurrent = getSelectColor(); m_colCurrent = getSelectColor();
// m_selectState = 2; // m_selectState = 2;
} else { } else {
m_colCurrent = PreferencesGui::normalQColor(); m_colCurrent = PreferencesGui::getAccessibleQColor(PreferencesGui::normalQColor());
// m_selectState = 0; // m_selectState = 0;
} }
drawBorder(); drawBorder();
@@ -268,7 +268,7 @@ void QGIView::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
if(isSelected()) { if(isSelected()) {
m_colCurrent = getSelectColor(); m_colCurrent = getSelectColor();
} else { } else {
m_colCurrent = PreferencesGui::normalQColor(); m_colCurrent = PreferencesGui::getAccessibleQColor(PreferencesGui::normalQColor());
} }
drawBorder(); drawBorder();
} }
@@ -709,17 +709,17 @@ void QGIView::setStackFromVP()
QColor QGIView::prefNormalColor() QColor QGIView::prefNormalColor()
{ {
return PreferencesGui::normalQColor(); return PreferencesGui::getAccessibleQColor(PreferencesGui::normalQColor());
} }
QColor QGIView::getPreColor() QColor QGIView::getPreColor()
{ {
return PreferencesGui::preselectQColor(); return PreferencesGui::getAccessibleQColor(PreferencesGui::preselectQColor());
} }
QColor QGIView::getSelectColor() QColor QGIView::getSelectColor()
{ {
return PreferencesGui::selectQColor(); return PreferencesGui::getAccessibleQColor(PreferencesGui::selectQColor());
} }
Base::Reference<ParameterGrp> QGIView::getParmGroupCol() Base::Reference<ParameterGrp> QGIView::getParmGroupCol()

View File

@@ -39,13 +39,15 @@
#include <App/Application.h> #include <App/Application.h>
#include <Base/Console.h> #include <Base/Console.h>
#include <Gui/MainWindow.h>
#include <Gui/Widgets.h> #include <Gui/Widgets.h>
#include <Mod/TechDraw/App/DrawViewAnnotation.h> #include <Mod/TechDraw/App/DrawViewAnnotation.h>
#include <Mod/TechDraw/App/Preferences.h>
#include "QGIViewAnnotation.h" #include "QGIViewAnnotation.h"
#include "QGCustomText.h" #include "QGCustomText.h"
#include "Rez.h" #include "Rez.h"
#include "DlgStringListEditor.h"
using namespace TechDrawGui; using namespace TechDrawGui;
@@ -135,6 +137,7 @@ void QGIViewAnnotation::drawAnnotation()
} }
ss << "line-height:" << viewAnno->LineSpace.getValue() << "%; "; ss << "line-height:" << viewAnno->LineSpace.getValue() << "%; ";
App::Color c = viewAnno->TextColor.getValue(); App::Color c = viewAnno->TextColor.getValue();
c = TechDraw::Preferences::getAccessibleColor(c);
ss << "color:" << c.asHexString() << "; "; ss << "color:" << c.asHexString() << "; ";
ss << "}\n</style>\n</head>\n<body>\n<p>"; ss << "}\n</style>\n</head>\n<body>\n<p>";
for(std::vector<std::string>::const_iterator it = annoText.begin(); it != annoText.end(); it++) { for(std::vector<std::string>::const_iterator it = annoText.begin(); it != annoText.end(); it++) {
@@ -173,44 +176,11 @@ void QGIViewAnnotation::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event)
} }
const std::vector<std::string> &values = annotation->Text.getValues(); const std::vector<std::string> &values = annotation->Text.getValues();
QString text; DlgStringListEditor dlg(values, Gui::getMainWindow());
if (!values.empty()) { dlg.setWindowTitle(QString::fromUtf8("Annotation Text Editor"));
text = QString::fromUtf8(values[0].c_str()); if (dlg.exec() == QDialog::Accepted) {
for (unsigned int i = 1; i < values.size(); ++i) {
text += QChar::fromLatin1('\n');
text += QString::fromUtf8(values[i].c_str());
}
}
QDialog dialog(nullptr);
dialog.setWindowTitle(tr("Text"));
Gui::PropertyListEditor editor(&dialog);
editor.setPlainText(text);
QDialogButtonBox buttonBox(&dialog);
buttonBox.setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
QVBoxLayout boxLayout(&dialog);
boxLayout.addWidget(&editor);
boxLayout.addWidget(&buttonBox);
connect(&buttonBox, SIGNAL(accepted()), &dialog, SLOT(accept()));
connect(&buttonBox, SIGNAL(rejected()), &dialog, SLOT(reject()));
if (dialog.exec() == QDialog::Accepted) {
QString newText = editor.toPlainText();
if (newText != text) {
QStringList list = newText.split(QChar::fromLatin1('\n'));
std::vector<std::string> newValues;
for (int i = 0; i < list.size(); ++i) {
newValues.push_back(list[i].toStdString());
}
App::GetApplication().setActiveTransaction("Set Annotation Text"); App::GetApplication().setActiveTransaction("Set Annotation Text");
annotation->Text.setValues(newValues); annotation->Text.setValues(dlg.getTexts());
App::GetApplication().closeActiveTransaction(); App::GetApplication().closeActiveTransaction();
} }
} }
}

View File

@@ -41,15 +41,15 @@
#include <Gui/Tools.h> #include <Gui/Tools.h>
#include <Mod/TechDraw/App/ArrowPropEnum.h> #include <Mod/TechDraw/App/ArrowPropEnum.h>
#include <Mod/TechDraw/App/DrawPage.h> #include <Mod/TechDraw/App/DrawPage.h>
#include <Mod/TechDraw/App/DrawUtil.h>
#include <Mod/TechDraw/App/DrawViewBalloon.h> #include <Mod/TechDraw/App/DrawViewBalloon.h>
#include <Mod/TechDraw/App/DrawViewPart.h> #include <Mod/TechDraw/App/DrawViewPart.h>
#include <Mod/TechDraw/App/DrawUtil.h>
#include <Mod/TechDraw/App/Geometry.h> #include <Mod/TechDraw/App/Geometry.h>
#include "QGIViewBalloon.h"
#include "PreferencesGui.h" #include "PreferencesGui.h"
#include "QGIArrow.h" #include "QGIArrow.h"
#include "QGIDimLines.h" #include "QGIDimLines.h"
#include "QGIViewBalloon.h"
#include "Rez.h" #include "Rez.h"
#include "ViewProviderBalloon.h" #include "ViewProviderBalloon.h"
#include "ViewProviderViewPart.h" #include "ViewProviderViewPart.h"
@@ -88,12 +88,14 @@ QVariant QGIBalloonLabel::itemChange(GraphicsItemChange change, const QVariant &
if (isSelected()) { if (isSelected()) {
Q_EMIT selected(true); Q_EMIT selected(true);
setPrettySel(); setPrettySel();
} else { }
else {
Q_EMIT selected(false); Q_EMIT selected(false);
setPrettyNormal(); setPrettyNormal();
} }
update(); update();
} else if(change == ItemPositionHasChanged && scene()) { }
else if (change == ItemPositionHasChanged && scene()) {
setLabelCenter(); setLabelCenter();
if (m_drag) { if (m_drag) {
Q_EMIT dragging(m_ctrl); Q_EMIT dragging(m_ctrl);
@@ -115,8 +117,7 @@ void QGIBalloonLabel::mousePressEvent(QGraphicsSceneMouseEvent * event)
void QGIBalloonLabel::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) void QGIBalloonLabel::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
{ {
if (QLineF(event->screenPos(), event->buttonDownScreenPos(Qt::LeftButton)) if (QLineF(event->screenPos(), event->buttonDownScreenPos(Qt::LeftButton)).length() > 0) {
.length() > 0) {
if (scene() && this == scene()->mouseGrabberItem()) { if (scene() && this == scene()->mouseGrabberItem()) {
Q_EMIT dragFinished(); Q_EMIT dragFinished();
} }
@@ -134,7 +135,8 @@ void QGIBalloonLabel::mouseDoubleClickEvent(QGraphicsSceneMouseEvent * event)
return; return;
} }
auto ViewProvider = dynamic_cast<ViewProviderBalloon*>(qgivBalloon->getViewProvider(qgivBalloon->getViewObject())); auto ViewProvider = dynamic_cast<ViewProviderBalloon*>(
qgivBalloon->getViewProvider(qgivBalloon->getViewObject()));
if (!ViewProvider) { if (!ViewProvider) {
qWarning() << "QGIBalloonLabel::mouseDoubleClickEvent: No valid view provider"; qWarning() << "QGIBalloonLabel::mouseDoubleClickEvent: No valid view provider";
return; return;
@@ -150,7 +152,8 @@ void QGIBalloonLabel::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
hasHover = true; hasHover = true;
if (!isSelected()) { if (!isSelected()) {
setPrettyPre(); setPrettyPre();
} else { }
else {
setPrettySel(); setPrettySel();
} }
QGraphicsItem::hoverEnterEvent(event); QGraphicsItem::hoverEnterEvent(event);
@@ -166,7 +169,8 @@ void QGIBalloonLabel::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
hasHover = false; hasHover = false;
if (!isSelected()) { if (!isSelected()) {
setPrettyNormal(); setPrettyNormal();
} else { }
else {
setPrettySel(); setPrettySel();
} }
QGraphicsItem::hoverLeaveEvent(event); QGraphicsItem::hoverLeaveEvent(event);
@@ -177,7 +181,8 @@ QRectF QGIBalloonLabel::boundingRect() const
return childrenBoundingRect(); return childrenBoundingRect();
} }
void QGIBalloonLabel::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) void QGIBalloonLabel::paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
QWidget* widget)
{ {
Q_UNUSED(widget); Q_UNUSED(widget);
Q_UNUSED(painter); Q_UNUSED(painter);
@@ -190,7 +195,8 @@ void QGIBalloonLabel::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
void QGIBalloonLabel::setPosFromCenter(const double& xCenter, const double& yCenter) void QGIBalloonLabel::setPosFromCenter(const double& xCenter, const double& yCenter)
{ {
//set label's Qt position(top, left) given boundingRect center point //set label's Qt position(top, left) given boundingRect center point
setPos(xCenter - m_labelText->boundingRect().width() / 2., yCenter - m_labelText->boundingRect().height() / 2.); setPos(xCenter - m_labelText->boundingRect().width() / 2.,
yCenter - m_labelText->boundingRect().height() / 2.);
} }
void QGIBalloonLabel::setLabelCenter() void QGIBalloonLabel::setLabelCenter()
@@ -240,8 +246,8 @@ void QGIBalloonLabel::setColor(QColor color)
} }
//************************************************************** //**************************************************************
QGIViewBalloon::QGIViewBalloon() : QGIViewBalloon::QGIViewBalloon()
dvBalloon(nullptr), : dvBalloon(nullptr),
hasHover(false), hasHover(false),
m_lineWidth(0.0), m_lineWidth(0.0),
m_obtuse(false), m_obtuse(false),
@@ -269,7 +275,7 @@ QGIViewBalloon::QGIViewBalloon() :
balloonShape = new QGIDimLines(); balloonShape = new QGIDimLines();
addToGroup(balloonShape); addToGroup(balloonShape);
balloonShape->setNormalColor(prefNormalColor()); balloonShape->setNormalColor(prefNormalColor());
balloonShape->setFill(Qt::white, Qt::SolidPattern); balloonShape->setFill(Qt::transparent, Qt::SolidPattern);
balloonShape->setFillOverride(true); balloonShape->setFillOverride(true);
balloonShape->setPrettyNormal(); balloonShape->setPrettyNormal();
@@ -292,21 +298,13 @@ QGIViewBalloon::QGIViewBalloon() :
balloonLabel->setPosFromCenter(0, 0); balloonLabel->setPosFromCenter(0, 0);
// connecting the needed slots and signals // connecting the needed slots and signals
QObject::connect( QObject::connect(balloonLabel, SIGNAL(dragging(bool)), this, SLOT(balloonLabelDragged(bool)));
balloonLabel, SIGNAL(dragging(bool)),
this , SLOT (balloonLabelDragged(bool)));
QObject::connect( QObject::connect(balloonLabel, SIGNAL(dragFinished()), this, SLOT(balloonLabelDragFinished()));
balloonLabel, SIGNAL(dragFinished()),
this , SLOT (balloonLabelDragFinished()));
QObject::connect( QObject::connect(balloonLabel, SIGNAL(selected(bool)), this, SLOT(select(bool)));
balloonLabel, SIGNAL(selected(bool)),
this , SLOT (select(bool)));
QObject::connect( QObject::connect(balloonLabel, SIGNAL(hover(bool)), this, SLOT(hover(bool)));
balloonLabel, SIGNAL(hover(bool)),
this , SLOT (hover(bool)));
setZValue(ZVALUE::DIMENSION); setZValue(ZVALUE::DIMENSION);
} }
@@ -316,7 +314,8 @@ QVariant QGIViewBalloon::itemChange(GraphicsItemChange change, const QVariant &v
if (change == ItemSelectedHasChanged && scene()) { if (change == ItemSelectedHasChanged && scene()) {
if (isSelected()) { if (isSelected()) {
balloonLabel->setSelected(true); balloonLabel->setSelected(true);
} else { }
else {
balloonLabel->setSelected(false); balloonLabel->setSelected(false);
} }
draw(); draw();
@@ -350,8 +349,9 @@ void QGIViewBalloon::hover(bool state)
void QGIViewBalloon::setViewPartFeature(TechDraw::DrawViewBalloon* balloonFeat) void QGIViewBalloon::setViewPartFeature(TechDraw::DrawViewBalloon* balloonFeat)
{ {
// Base::Console().Message("QGIVB::setViewPartFeature()\n"); // Base::Console().Message("QGIVB::setViewPartFeature()\n");
if (!balloonFeat) if (!balloonFeat) {
return; return;
}
setViewFeature(static_cast<TechDraw::DrawView*>(balloonFeat)); setViewFeature(static_cast<TechDraw::DrawView*>(balloonFeat));
dvBalloon = balloonFeat; dvBalloon = balloonFeat;
@@ -361,9 +361,10 @@ void QGIViewBalloon::setViewPartFeature(TechDraw::DrawViewBalloon *balloonFeat)
App::DocumentObject* docObj = balloonFeat->SourceView.getValue(); App::DocumentObject* docObj = balloonFeat->SourceView.getValue();
if (docObj) { if (docObj) {
balloonParent = dynamic_cast<DrawView*>(docObj); balloonParent = dynamic_cast<DrawView*>(docObj);
if (balloonParent) if (balloonParent) {
scale = balloonParent->getScale(); scale = balloonParent->getScale();
} }
}
float x = Rez::guiX(balloonFeat->X.getValue() * scale); float x = Rez::guiX(balloonFeat->X.getValue() * scale);
float y = Rez::guiX(-balloonFeat->Y.getValue() * scale); float y = Rez::guiX(-balloonFeat->Y.getValue() * scale);
@@ -384,22 +385,19 @@ void QGIViewBalloon::updateView(bool update)
// Base::Console().Message("QGIVB::updateView()\n"); // Base::Console().Message("QGIVB::updateView()\n");
Q_UNUSED(update); Q_UNUSED(update);
auto balloon(dynamic_cast<TechDraw::DrawViewBalloon*>(getViewObject())); auto balloon(dynamic_cast<TechDraw::DrawViewBalloon*>(getViewObject()));
if (!balloon) if (!balloon) {
return; return;
}
auto vp = static_cast<ViewProviderBalloon*>(getViewProvider(getViewObject())); auto vp = static_cast<ViewProviderBalloon*>(getViewProvider(getViewObject()));
if (!vp) if (!vp) {
return; return;
}
if (update) { if (update) {
QString labelText = QString::fromUtf8(balloon->Text.getStrValue().data()); QString labelText = QString::fromUtf8(balloon->Text.getStrValue().data());
balloonLabel->setDimString(labelText, Rez::guiX(balloon->TextWrapLen.getValue())); balloonLabel->setDimString(labelText, Rez::guiX(balloon->TextWrapLen.getValue()));
balloonLabel->setColor(getNormalColor()); setNormalColorAll();
balloonLines->setNormalColor(getNormalColor());
balloonShape->setNormalColor(getNormalColor());
arrow->setNormalColor(getNormalColor());
arrow->setFillColor(getNormalColor());
} }
updateBalloon(); updateBalloon();
@@ -426,8 +424,7 @@ void QGIViewBalloon::updateBalloon(bool obtuse)
QFont font; QFont font;
font.setFamily(QString::fromUtf8(vp->Font.getValue())); font.setFamily(QString::fromUtf8(vp->Font.getValue()));
font.setPixelSize(exactFontSize(vp->Font.getValue(), font.setPixelSize(exactFontSize(vp->Font.getValue(), vp->Fontsize.getValue()));
vp->Fontsize.getValue()));
balloonLabel->setFont(font); balloonLabel->setFont(font);
QString labelText = QString::fromUtf8(balloon->Text.getStrValue().data()); QString labelText = QString::fromUtf8(balloon->Text.getStrValue().data());
@@ -456,8 +453,9 @@ void QGIViewBalloon::balloonLabelDragged(bool ctrl)
{ {
m_ctrl = ctrl; m_ctrl = ctrl;
auto dvb(dynamic_cast<TechDraw::DrawViewBalloon*>(getViewObject())); auto dvb(dynamic_cast<TechDraw::DrawViewBalloon*>(getViewObject()));
if (!dvb) if (!dvb) {
return; return;
}
if (!m_dragInProgress) {//first drag movement if (!m_dragInProgress) {//first drag movement
m_dragInProgress = true; m_dragInProgress = true;
@@ -467,45 +465,54 @@ void QGIViewBalloon::balloonLabelDragged(bool ctrl)
} }
// store if origin is also moving to be able to later calc new origin and update feature // store if origin is also moving to be able to later calc new origin and update feature
if (ctrl) if (ctrl) {
m_originDragged = true; m_originDragged = true;
}
DrawView* balloonParent = getSourceView(); DrawView* balloonParent = getSourceView();
if (balloonParent) if (balloonParent) {
// redraw the balloon at the new position // redraw the balloon at the new position
// note that we don't store the new position to the X/Y properties // note that we don't store the new position to the X/Y properties
// since the dragging is not yet finished // since the dragging is not yet finished
drawBalloon(true); drawBalloon(true);
} }
}
void QGIViewBalloon::balloonLabelDragFinished() void QGIViewBalloon::balloonLabelDragFinished()
{ {
// stores the final drag position for undo // stores the final drag position for undo
auto dvb(dynamic_cast<TechDraw::DrawViewBalloon*>(getViewObject())); auto dvb(dynamic_cast<TechDraw::DrawViewBalloon*>(getViewObject()));
if (!dvb) if (!dvb) {
return; return;
}
double scale = 1.0; double scale = 1.0;
DrawView* balloonParent = getSourceView(); DrawView* balloonParent = getSourceView();
if (balloonParent) if (balloonParent) {
scale = balloonParent->getScale(); scale = balloonParent->getScale();
}
//set feature position (x, y) from graphic position //set feature position (x, y) from graphic position
double x = Rez::appX(balloonLabel->X() / scale), double x = Rez::appX(balloonLabel->X() / scale), y = Rez::appX(balloonLabel->Y() / scale);
y = Rez::appX(balloonLabel->Y() / scale);
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Drag Balloon")); Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Drag Balloon"));
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.X = %f", dvb->getNameInDocument(), x); Gui::Command::doCommand(
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Y = %f", dvb->getNameInDocument(), -y); Gui::Command::Doc, "App.ActiveDocument.%s.X = %f", dvb->getNameInDocument(), x);
Gui::Command::doCommand(
Gui::Command::Doc, "App.ActiveDocument.%s.Y = %f", dvb->getNameInDocument(), -y);
// for the case that origin was also dragged, calc new origin and update feature // for the case that origin was also dragged, calc new origin and update feature
if (m_originDragged) { if (m_originDragged) {
Base::Vector3d pos(x, -y, 0.0); Base::Vector3d pos(x, -y, 0.0);
Base::Vector3d newOrg = pos - m_saveOffset; Base::Vector3d newOrg = pos - m_saveOffset;
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.OriginX = %f", Gui::Command::doCommand(Gui::Command::Doc,
dvb->getNameInDocument(), newOrg.x); "App.ActiveDocument.%s.OriginX = %f",
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.OriginY = %f", dvb->getNameInDocument(),
dvb->getNameInDocument(), newOrg.y); newOrg.x);
Gui::Command::doCommand(Gui::Command::Doc,
"App.ActiveDocument.%s.OriginY = %f",
dvb->getNameInDocument(),
newOrg.y);
} }
Gui::Command::commitCommand(); Gui::Command::commitCommand();
@@ -563,8 +570,7 @@ void QGIViewBalloon::placeBalloon(QPointF pos)
QFont font = balloonLabel->getFont(); QFont font = balloonLabel->getFont();
font.setPixelSize(calculateFontPixelSize(vp->Fontsize.getValue())); font.setPixelSize(calculateFontPixelSize(vp->Fontsize.getValue()));
font.setFamily(QString::fromUtf8(vp->Font.getValue())); font.setFamily(QString::fromUtf8(vp->Font.getValue()));
font.setPixelSize(exactFontSize(vp->Font.getValue(), font.setPixelSize(exactFontSize(vp->Font.getValue(), vp->Fontsize.getValue()));
vp->Fontsize.getValue()));
balloonLabel->setFont(font); balloonLabel->setFont(font);
prepareGeometryChange(); prepareGeometryChange();
@@ -646,8 +652,10 @@ void QGIViewBalloon::drawBalloon(bool dragged)
if (balloon->isLocked()) { if (balloon->isLocked()) {
balloonLabel->setFlag(QGraphicsItem::ItemIsMovable, false); balloonLabel->setFlag(QGraphicsItem::ItemIsMovable, false);
} else }
else {
balloonLabel->setFlag(QGraphicsItem::ItemIsMovable, true); balloonLabel->setFlag(QGraphicsItem::ItemIsMovable, true);
}
Base::Vector3d dLineStart; Base::Vector3d dLineStart;
Base::Vector3d kinkPoint; Base::Vector3d kinkPoint;
@@ -664,25 +672,36 @@ void QGIViewBalloon::drawBalloon(bool dragged)
double balloonRadius = sqrt(pow((textHeight / 2.0), 2) + pow((textWidth / 2.0), 2)); double balloonRadius = sqrt(pow((textHeight / 2.0), 2) + pow((textWidth / 2.0), 2));
balloonRadius = balloonRadius * scale; balloonRadius = balloonRadius * scale;
balloonPath.moveTo(lblCenter.x, lblCenter.y); balloonPath.moveTo(lblCenter.x, lblCenter.y);
balloonPath.addEllipse(lblCenter.x - balloonRadius, lblCenter.y - balloonRadius, balloonRadius * 2, balloonRadius * 2); balloonPath.addEllipse(lblCenter.x - balloonRadius,
lblCenter.y - balloonRadius,
balloonRadius * 2,
balloonRadius * 2);
offsetLR = balloonRadius; offsetLR = balloonRadius;
} else if (strcmp(balloonType, "None") == 0) { }
else if (strcmp(balloonType, "None") == 0) {
balloonPath = QPainterPath(); balloonPath = QPainterPath();
offsetLR = (textWidth / 2.0) + Rez::guiX(2.0); offsetLR = (textWidth / 2.0) + Rez::guiX(2.0);
} else if (strcmp(balloonType, "Rectangle") == 0) { }
else if (strcmp(balloonType, "Rectangle") == 0) {
//Add some room //Add some room
textHeight = (textHeight * scale) + Rez::guiX(1.0); textHeight = (textHeight * scale) + Rez::guiX(1.0);
// we add some textWidth later because we first need to handle the text separators // we add some textWidth later because we first need to handle the text separators
if (balloonLabel->getVerticalSep()) { if (balloonLabel->getVerticalSep()) {
for (auto& sep : balloonLabel->getSeps()) { for (auto& sep : balloonLabel->getSeps()) {
balloonPath.moveTo(lblCenter.x - (textWidth / 2.0) + sep, lblCenter.y - (textHeight / 2.0)); balloonPath.moveTo(lblCenter.x - (textWidth / 2.0) + sep,
balloonPath.lineTo(lblCenter.x - (textWidth / 2.0) + sep, lblCenter.y + (textHeight / 2.0)); lblCenter.y - (textHeight / 2.0));
balloonPath.lineTo(lblCenter.x - (textWidth / 2.0) + sep,
lblCenter.y + (textHeight / 2.0));
} }
} }
textWidth = (textWidth * scale) + Rez::guiX(2.0); textWidth = (textWidth * scale) + Rez::guiX(2.0);
balloonPath.addRect(lblCenter.x - (textWidth / 2.0), lblCenter.y - (textHeight / 2.0), textWidth, textHeight); balloonPath.addRect(lblCenter.x - (textWidth / 2.0),
lblCenter.y - (textHeight / 2.0),
textWidth,
textHeight);
offsetLR = (textWidth / 2.0); offsetLR = (textWidth / 2.0);
} else if (strcmp(balloonType, "Triangle") == 0) { }
else if (strcmp(balloonType, "Triangle") == 0) {
double radius = sqrt(pow((textHeight / 2.0), 2) + pow((textWidth / 2.0), 2)); double radius = sqrt(pow((textHeight / 2.0), 2) + pow((textWidth / 2.0), 2));
radius = radius * scale; radius = radius * scale;
radius += Rez::guiX(3.0); radius += Rez::guiX(3.0);
@@ -691,30 +710,45 @@ void QGIViewBalloon::drawBalloon(bool dragged)
double startAngle = -M_PI / 2; double startAngle = -M_PI / 2;
double angle = startAngle; double angle = startAngle;
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
triangle += QPointF(lblCenter.x + (radius * cos(angle)), lblCenter.y + (radius * sin(angle))); triangle +=
QPointF(lblCenter.x + (radius * cos(angle)), lblCenter.y + (radius * sin(angle)));
angle += (2 * M_PI / 3); angle += (2 * M_PI / 3);
} }
balloonPath.moveTo(lblCenter.x + (radius * cos(startAngle)), lblCenter.y + (radius * sin(startAngle))); balloonPath.moveTo(lblCenter.x + (radius * cos(startAngle)),
lblCenter.y + (radius * sin(startAngle)));
balloonPath.addPolygon(triangle); balloonPath.addPolygon(triangle);
} else if (strcmp(balloonType, "Inspection") == 0) { }
else if (strcmp(balloonType, "Inspection") == 0) {
//Add some room //Add some room
textWidth = (textWidth * scale) + Rez::guiX(2.0); textWidth = (textWidth * scale) + Rez::guiX(2.0);
textHeight = (textHeight * scale) + Rez::guiX(1.0); textHeight = (textHeight * scale) + Rez::guiX(1.0);
QPointF textBoxCorner(lblCenter.x - (textWidth / 2.0), lblCenter.y - (textHeight / 2.0)); QPointF textBoxCorner(lblCenter.x - (textWidth / 2.0), lblCenter.y - (textHeight / 2.0));
balloonPath.moveTo(textBoxCorner); balloonPath.moveTo(textBoxCorner);
balloonPath.lineTo(textBoxCorner.x() + textWidth, textBoxCorner.y()); balloonPath.lineTo(textBoxCorner.x() + textWidth, textBoxCorner.y());
balloonPath.arcTo(textBoxCorner.x() + textWidth - (textHeight / 2.0), textBoxCorner.y(), textHeight, textHeight, 90, -180); balloonPath.arcTo(textBoxCorner.x() + textWidth - (textHeight / 2.0),
textBoxCorner.y(),
textHeight,
textHeight,
90,
-180);
balloonPath.lineTo(textBoxCorner.x(), textBoxCorner.y() + textHeight); balloonPath.lineTo(textBoxCorner.x(), textBoxCorner.y() + textHeight);
balloonPath.arcTo(textBoxCorner.x() - (textHeight / 2), textBoxCorner.y(), textHeight, textHeight, -90, -180); balloonPath.arcTo(textBoxCorner.x() - (textHeight / 2),
textBoxCorner.y(),
textHeight,
textHeight,
-90,
-180);
offsetLR = (textWidth / 2.0) + (textHeight / 2.0); offsetLR = (textWidth / 2.0) + (textHeight / 2.0);
} else if (strcmp(balloonType, "Square") == 0) { }
else if (strcmp(balloonType, "Square") == 0) {
//Add some room //Add some room
textWidth = (textWidth * scale) + Rez::guiX(2.0); textWidth = (textWidth * scale) + Rez::guiX(2.0);
textHeight = (textHeight * scale) + Rez::guiX(1.0); textHeight = (textHeight * scale) + Rez::guiX(1.0);
double max = std::max(textWidth, textHeight); double max = std::max(textWidth, textHeight);
balloonPath.addRect(lblCenter.x - (max / 2.0), lblCenter.y - (max / 2.0), max, max); balloonPath.addRect(lblCenter.x - (max / 2.0), lblCenter.y - (max / 2.0), max, max);
offsetLR = (max / 2.0); offsetLR = (max / 2.0);
} else if (strcmp(balloonType, "Hexagon") == 0) { }
else if (strcmp(balloonType, "Hexagon") == 0) {
double radius = sqrt(pow((textHeight / 2.0), 2) + pow((textWidth / 2.0), 2)); double radius = sqrt(pow((textHeight / 2.0), 2) + pow((textWidth / 2.0), 2));
radius = radius * scale; radius = radius * scale;
radius += Rez::guiX(1.0); radius += Rez::guiX(1.0);
@@ -723,10 +757,12 @@ void QGIViewBalloon::drawBalloon(bool dragged)
double startAngle = -2 * M_PI / 3; double startAngle = -2 * M_PI / 3;
double angle = startAngle; double angle = startAngle;
for (int i = 0; i < 7; i++) { for (int i = 0; i < 7; i++) {
triangle += QPointF(lblCenter.x + (radius * cos(angle)), lblCenter.y + (radius * sin(angle))); triangle +=
QPointF(lblCenter.x + (radius * cos(angle)), lblCenter.y + (radius * sin(angle)));
angle += (2 * M_PI / 6); angle += (2 * M_PI / 6);
} }
balloonPath.moveTo(lblCenter.x + (radius * cos(startAngle)), lblCenter.y + (radius * sin(startAngle))); balloonPath.moveTo(lblCenter.x + (radius * cos(startAngle)),
lblCenter.y + (radius * sin(startAngle)));
balloonPath.addPolygon(triangle); balloonPath.addPolygon(triangle);
} }
else if (strcmp(balloonType, "Line") == 0) { else if (strcmp(balloonType, "Line") == 0) {
@@ -744,10 +780,13 @@ void QGIViewBalloon::drawBalloon(bool dragged)
offsetLR = (lblCenter.x < arrowTipX) ? offsetLR : -offsetLR; offsetLR = (lblCenter.x < arrowTipX) ? offsetLR : -offsetLR;
if (DrawUtil::fpCompare(kinkLength, 0.0) && strcmp(balloonType, "Line")) { //if no kink, then dLine start sb on line from center to arrow if (DrawUtil::fpCompare(kinkLength, 0.0)
&& strcmp(balloonType,
"Line")) {//if no kink, then dLine start sb on line from center to arrow
dLineStart = lblCenter; dLineStart = lblCenter;
kinkPoint = dLineStart; kinkPoint = dLineStart;
} else { }
else {
dLineStart.y = lblCenter.y + offsetUD; dLineStart.y = lblCenter.y + offsetUD;
dLineStart.x = lblCenter.x + offsetLR; dLineStart.x = lblCenter.x + offsetLR;
kinkLength = (lblCenter.x < arrowTipX) ? kinkLength : -kinkLength; kinkLength = (lblCenter.x < arrowTipX) ? kinkLength : -kinkLength;
@@ -762,12 +801,13 @@ void QGIViewBalloon::drawBalloon(bool dragged)
double xAdj = 0.0; double xAdj = 0.0;
double yAdj = 0.0; double yAdj = 0.0;
int endType = balloon->EndType.getValue(); int endType = balloon->EndType.getValue();
double arrowAdj = QGIArrow::getOverlapAdjust(endType, double arrowAdj = QGIArrow::getOverlapAdjust(
balloon->EndTypeScale.getValue()*QGIArrow::getPrefArrowSize()); endType, balloon->EndTypeScale.getValue() * QGIArrow::getPrefArrowSize());
if (endType == ArrowType::NONE) { if (endType == ArrowType::NONE) {
arrow->hide(); arrow->hide();
} else { }
else {
arrow->setStyle(endType); arrow->setStyle(endType);
arrow->setSize(balloon->EndTypeScale.getValue() * QGIArrow::getPrefArrowSize()); arrow->setSize(balloon->EndTypeScale.getValue() * QGIArrow::getPrefArrowSize());
@@ -777,26 +817,29 @@ void QGIViewBalloon::drawBalloon(bool dragged)
Base::Vector3d dirballoonLinesLine; Base::Vector3d dirballoonLinesLine;
if (!DrawUtil::fpCompare(kinkLength, 0.0)) { if (!DrawUtil::fpCompare(kinkLength, 0.0)) {
dirballoonLinesLine = (arrowTipPos - kinkPoint).Normalize(); dirballoonLinesLine = (arrowTipPos - kinkPoint).Normalize();
} else { }
else {
dirballoonLinesLine = (arrowTipPos - dLineStart).Normalize(); dirballoonLinesLine = (arrowTipPos - dLineStart).Normalize();
} }
float arAngle = atan2(dirballoonLinesLine.y, dirballoonLinesLine.x) * 180 / M_PI; float arAngle = atan2(dirballoonLinesLine.y, dirballoonLinesLine.x) * 180 / M_PI;
arrow->setPos(arrowTipX, arrowTipY); arrow->setPos(arrowTipX, arrowTipY);
if ( (endType == ArrowType::FILLED_TRIANGLE) && if ((endType == ArrowType::FILLED_TRIANGLE) && (prefOrthoPyramid())) {
(prefOrthoPyramid()) ) {
if (arAngle < 0.0) { if (arAngle < 0.0) {
arAngle += 360.0; arAngle += 360.0;
} }
//set the angle to closest cardinal direction //set the angle to closest cardinal direction
if ((45.0 < arAngle) && (arAngle < 135.0)) { if ((45.0 < arAngle) && (arAngle < 135.0)) {
arAngle = 90.0; arAngle = 90.0;
} else if ( (135.0 < arAngle) && (arAngle < 225.0) ) { }
else if ((135.0 < arAngle) && (arAngle < 225.0)) {
arAngle = 180.0; arAngle = 180.0;
} else if ( (225.0 < arAngle) && (arAngle < 315.0) ) { }
else if ((225.0 < arAngle) && (arAngle < 315.0)) {
arAngle = 270.0; arAngle = 270.0;
} else { }
else {
arAngle = 0; arAngle = 0;
} }
double radAngle = arAngle * M_PI / 180.0; double radAngle = arAngle * M_PI / 180.0;
@@ -820,15 +863,18 @@ void QGIViewBalloon::drawBalloon(bool dragged)
// redraw the Balloon and the parent View // redraw the Balloon and the parent View
if (hasHover && !isSelected()) { if (hasHover && !isSelected()) {
setPrettyPre(); setPrettyPre();
} else if (isSelected()) { }
else if (isSelected()) {
setPrettySel(); setPrettySel();
} else { }
else {
setPrettyNormal(); setPrettyNormal();
} }
if (parentItem()) { if (parentItem()) {
parentItem()->update(); parentItem()->update();
} else { }
else {
Base::Console().Log("INFO - QGIVB::draw - no parent to update\n"); Base::Console().Log("INFO - QGIVB::draw - no parent to update\n");
} }
} }
@@ -867,7 +913,9 @@ void QGIViewBalloon::drawBorder(void)
// Base::Console().Message("TRACE - QGIViewDimension::drawBorder - doing nothing!\n"); // Base::Console().Message("TRACE - QGIViewDimension::drawBorder - doing nothing!\n");
} }
void QGIViewBalloon::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) { void QGIViewBalloon::paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
QWidget* widget)
{
QStyleOptionGraphicsItem myOption(*option); QStyleOptionGraphicsItem myOption(*option);
myOption.state &= ~QStyle::State_Selected; myOption.state &= ~QStyle::State_Selected;
@@ -876,7 +924,8 @@ void QGIViewBalloon::paint ( QPainter * painter, const QStyleOptionGraphicsItem
setPens(); setPens();
if (svg) { if (svg) {
setSvgPens(); setSvgPens();
} else { }
else {
setPens(); setPens();
} }
QGIView::paint(painter, &myOption, widget); QGIView::paint(painter, &myOption, widget);
@@ -898,16 +947,26 @@ void QGIViewBalloon::setPens(void)
arrow->setWidth(m_lineWidth); arrow->setWidth(m_lineWidth);
} }
void QGIViewBalloon::setNormalColorAll()
{
QColor qc = prefNormalColor();
balloonLabel->setColor(qc);
balloonLines->setNormalColor(qc);
balloonShape->setNormalColor(qc);
arrow->setNormalColor(qc);
arrow->setFillColor(qc);
}
QColor QGIViewBalloon::prefNormalColor() QColor QGIViewBalloon::prefNormalColor()
{ {
setNormalColor(PreferencesGui::dimQColor()); setNormalColor(PreferencesGui::getAccessibleQColor(PreferencesGui::dimQColor()));
ViewProviderBalloon* vpBalloon = nullptr; ViewProviderBalloon* vpBalloon = nullptr;
Gui::ViewProvider* vp = getViewProvider(getBalloonFeat()); Gui::ViewProvider* vp = getViewProvider(getBalloonFeat());
if (vp) { if (vp) {
vpBalloon = dynamic_cast<ViewProviderBalloon*>(vp); vpBalloon = dynamic_cast<ViewProviderBalloon*>(vp);
if (vpBalloon) { if (vpBalloon) {
App::Color fcColor = vpBalloon->Color.getValue(); App::Color fcColor = Preferences::getAccessibleColor(vpBalloon->Color.getValue());
setNormalColor(fcColor.asValue<QColor>()); setNormalColor(fcColor.asValue<QColor>());
} }
} }
@@ -924,9 +983,11 @@ int QGIViewBalloon::prefDefaultArrow() const
//when would you want a crooked pyramid? //when would you want a crooked pyramid?
bool QGIViewBalloon::prefOrthoPyramid() const bool QGIViewBalloon::prefOrthoPyramid() const
{ {
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter() Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetGroup("BaseApp")->GetGroup("Preferences")-> .GetUserParameter()
GetGroup("Mod/TechDraw/Decorations"); .GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/Decorations");
bool ortho = hGrp->GetBool("PyramidOrtho", true); bool ortho = hGrp->GetBool("PyramidOrtho", true);
return ortho; return ortho;
} }

View File

@@ -38,15 +38,17 @@
#include "QGIView.h" #include "QGIView.h"
namespace TechDraw { namespace TechDraw
{
class DrawViewBalloon; class DrawViewBalloon;
class DrawView; class DrawView;
} }// namespace TechDraw
namespace TechDraw { namespace TechDraw
{
class BaseGeom; class BaseGeom;
class AOC; class AOC;
} }// namespace TechDraw
namespace TechDrawGui namespace TechDrawGui
{ {
@@ -62,21 +64,35 @@ public:
QGIBalloonLabel(); QGIBalloonLabel();
~QGIBalloonLabel() = default; ~QGIBalloonLabel() = default;
enum {Type = QGraphicsItem::UserType + 141}; enum
int type() const override { return Type;} {
Type = QGraphicsItem::UserType + 141
};
int type() const override
{
return Type;
}
QRectF boundingRect() const override; QRectF boundingRect() const override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override; void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override;
void paint( QPainter *painter, void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
const QStyleOptionGraphicsItem *option,
QWidget* widget = nullptr) override; QWidget* widget = nullptr) override;
void setLabelCenter(); void setLabelCenter();
void setPosFromCenter(const double& xCenter, const double& yCenter); void setPosFromCenter(const double& xCenter, const double& yCenter);
double X() const { return posX; } double X() const
double Y() const { return posY; } //minus posY? {
return posX;
}
double Y() const
{
return posY;
}//minus posY?
void setFont(QFont font); void setFont(QFont font);
QFont getFont() { return m_labelText->font(); } QFont getFont()
{
return m_labelText->font();
}
void setDimString(QString text); void setDimString(QString text);
void setDimString(QString text, qreal maxWidth); void setDimString(QString text, qreal maxWidth);
void setPrettySel(); void setPrettySel();
@@ -84,16 +100,37 @@ public:
void setPrettyNormal(); void setPrettyNormal();
void setColor(QColor color); void setColor(QColor color);
void setQBalloon(QGIViewBalloon* qBalloon) { parent = qBalloon;} void setQBalloon(QGIViewBalloon* qBalloon)
{
parent = qBalloon;
}
QGCustomText* getDimText() { return m_labelText; } QGCustomText* getDimText()
{
return m_labelText;
}
void setDimText(QGCustomText* newText) { m_labelText = newText; } void setDimText(QGCustomText* newText)
bool getVerticalSep() const { return verticalSep; } {
void setVerticalSep(bool sep) { verticalSep = sep; } m_labelText = newText;
std::vector<int> getSeps() const { return seps; } }
void setSeps(std::vector<int> newSeps) { seps = newSeps; } bool getVerticalSep() const
{
return verticalSep;
}
void setVerticalSep(bool sep)
{
verticalSep = sep;
}
std::vector<int> getSeps() const
{
return seps;
}
void setSeps(std::vector<int> newSeps)
{
seps = newSeps;
}
Q_SIGNALS: Q_SIGNALS:
void dragging(bool state); void dragging(bool state);
@@ -131,18 +168,23 @@ class TechDrawGuiExport QGIViewBalloon : public QGIView
Q_OBJECT Q_OBJECT
public: public:
enum {Type = QGraphicsItem::UserType + 140}; enum
{
Type = QGraphicsItem::UserType + 140
};
explicit QGIViewBalloon(); explicit QGIViewBalloon();
~QGIViewBalloon() = default; ~QGIViewBalloon() = default;
void setViewPartFeature(TechDraw::DrawViewBalloon* balloonFeat); void setViewPartFeature(TechDraw::DrawViewBalloon* balloonFeat);
int type() const override { return Type;} int type() const override
{
return Type;
}
void drawBorder() override; void drawBorder() override;
void updateView(bool update = false) override; void updateView(bool update = false) override;
void paint( QPainter * painter, void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
const QStyleOptionGraphicsItem * option,
QWidget* widget = nullptr) override; QWidget* widget = nullptr) override;
QString getLabelText(); QString getLabelText();
@@ -152,12 +194,20 @@ public:
void setPrettyNormal(); void setPrettyNormal();
void setGroupSelection(bool isSelected) override; void setGroupSelection(bool isSelected) override;
virtual QGIBalloonLabel* getBalloonLabel() { return balloonLabel; } virtual QGIBalloonLabel* getBalloonLabel()
{
return balloonLabel;
}
void setNormalColorAll();
QColor prefNormalColor(); QColor prefNormalColor();
int prefDefaultArrow() const; int prefDefaultArrow() const;
bool prefOrthoPyramid() const; bool prefOrthoPyramid() const;
TechDraw::DrawViewBalloon* getBalloonFeat() { return dvBalloon; }
TechDraw::DrawViewBalloon* getBalloonFeat()
{
return dvBalloon;
}
public Q_SLOTS: public Q_SLOTS:
void balloonLabelDragged(bool ctrl); void balloonLabelDragged(bool ctrl);
@@ -169,8 +219,7 @@ public Q_SLOTS:
protected: protected:
void draw() override; void draw() override;
void drawBalloon(bool dragged = false); void drawBalloon(bool dragged = false);
QVariant itemChange( GraphicsItemChange change, QVariant itemChange(GraphicsItemChange change, const QVariant& value) override;
const QVariant &value ) override;
virtual void setSvgPens(); virtual void setSvgPens();
virtual void setPens(); virtual void setPens();
QString getPrecision(); QString getPrecision();
@@ -194,6 +243,6 @@ private:
Base::Vector3d m_saveOffset; Base::Vector3d m_saveOffset;
}; };
} // namespace }// namespace TechDrawGui
#endif// TECHDRAWGUI_QGIVBALLOON_H #endif// TECHDRAWGUI_QGIVBALLOON_H

File diff suppressed because it is too large Load Diff

View File

@@ -482,8 +482,7 @@ void QGIViewPart::drawViewPart()
} }
// Draw Edges // Draw Edges
QColor edgeColor = PreferencesGui::normalQColor(); QColor edgeColor = PreferencesGui::getAccessibleQColor(PreferencesGui::normalQColor());
const TechDraw::BaseGeomPtrVector& geoms = viewPart->getEdgeGeometry(); const TechDraw::BaseGeomPtrVector& geoms = viewPart->getEdgeGeometry();
TechDraw::BaseGeomPtrVector::const_iterator itGeom = geoms.begin(); TechDraw::BaseGeomPtrVector::const_iterator itGeom = geoms.begin();
QGIEdge* item; QGIEdge* item;
@@ -530,7 +529,8 @@ void QGIViewPart::drawViewPart()
else { else {
TechDraw::GeomFormat* gf = viewPart->getGeomFormatBySelection(i); TechDraw::GeomFormat* gf = viewPart->getGeomFormatBySelection(i);
if (gf) { if (gf) {
item->setNormalColor(gf->m_format.m_color.asValue<QColor>()); App::Color color = Preferences::getAccessibleColor(gf->m_format.m_color);
item->setNormalColor(color.asValue<QColor>());
item->setWidth(gf->m_format.m_weight * lineScaleFactor); item->setWidth(gf->m_format.m_weight * lineScaleFactor);
item->setStyle(gf->m_format.m_style); item->setStyle(gf->m_format.m_style);
showItem = gf->m_format.m_visible; showItem = gf->m_format.m_visible;
@@ -571,8 +571,7 @@ void QGIViewPart::drawViewPart()
->GetGroup("Preferences") ->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/General"); ->GetGroup("Mod/TechDraw/General");
double vertexScaleFactor = hGrp->GetFloat("VertexScale", 3.0); double vertexScaleFactor = hGrp->GetFloat("VertexScale", 3.0);
QColor vertexColor = PreferencesGui::vertexQColor(); QColor vertexColor = PreferencesGui::getAccessibleQColor(PreferencesGui::vertexQColor());
bool showVertices = true; bool showVertices = true;
bool showCenterMarks = true; bool showCenterMarks = true;
if (getFrameState()) {//frames are on if (getFrameState()) {//frames are on
@@ -637,7 +636,8 @@ bool QGIViewPart::formatGeomFromCosmetic(std::string cTag, QGIEdge* item)
auto partFeat(dynamic_cast<TechDraw::DrawViewPart*>(getViewObject())); auto partFeat(dynamic_cast<TechDraw::DrawViewPart*>(getViewObject()));
TechDraw::CosmeticEdge* ce = partFeat ? partFeat->getCosmeticEdge(cTag) : nullptr; TechDraw::CosmeticEdge* ce = partFeat ? partFeat->getCosmeticEdge(cTag) : nullptr;
if (ce) { if (ce) {
item->setNormalColor(ce->m_format.m_color.asValue<QColor>()); App::Color color = Preferences::getAccessibleColor(ce->m_format.m_color);
item->setNormalColor(color.asValue<QColor>());
item->setWidth(ce->m_format.m_weight * lineScaleFactor); item->setWidth(ce->m_format.m_weight * lineScaleFactor);
item->setStyle(ce->m_format.m_style); item->setStyle(ce->m_format.m_style);
result = ce->m_format.m_visible; result = ce->m_format.m_visible;
@@ -653,7 +653,8 @@ bool QGIViewPart::formatGeomFromCenterLine(std::string cTag, QGIEdge* item)
auto partFeat(dynamic_cast<TechDraw::DrawViewPart*>(getViewObject())); auto partFeat(dynamic_cast<TechDraw::DrawViewPart*>(getViewObject()));
TechDraw::CenterLine* cl = partFeat ? partFeat->getCenterLine(cTag) : nullptr; TechDraw::CenterLine* cl = partFeat ? partFeat->getCenterLine(cTag) : nullptr;
if (cl) { if (cl) {
item->setNormalColor(cl->m_format.m_color.asValue<QColor>()); App::Color color = Preferences::getAccessibleColor(cl->m_format.m_color);
item->setNormalColor(color.asValue<QColor>());
item->setWidth(cl->m_format.m_weight * lineScaleFactor); item->setWidth(cl->m_format.m_weight * lineScaleFactor);
item->setStyle(cl->m_format.m_style); item->setStyle(cl->m_format.m_style);
result = cl->m_format.m_visible; result = cl->m_format.m_visible;
@@ -800,7 +801,8 @@ void QGIViewPart::drawSectionLine(TechDraw::DrawViewSection* viewSection, bool b
addToGroup(sectionLine); addToGroup(sectionLine);
sectionLine->setSymbol(const_cast<char*>(viewSection->SectionSymbol.getValue())); sectionLine->setSymbol(const_cast<char*>(viewSection->SectionSymbol.getValue()));
sectionLine->setSectionStyle(vp->SectionLineStyle.getValue()); sectionLine->setSectionStyle(vp->SectionLineStyle.getValue());
sectionLine->setSectionColor(vp->SectionLineColor.getValue().asValue<QColor>()); App::Color color = Preferences::getAccessibleColor(vp->SectionLineColor.getValue());
sectionLine->setSectionColor(color.asValue<QColor>());
sectionLine->setPathMode(false); sectionLine->setPathMode(false);
//find the ends of the section line //find the ends of the section line
@@ -883,7 +885,8 @@ void QGIViewPart::drawComplexSectionLine(TechDraw::DrawViewSection* viewSection,
addToGroup(sectionLine); addToGroup(sectionLine);
sectionLine->setSymbol(const_cast<char*>(viewSection->SectionSymbol.getValue())); sectionLine->setSymbol(const_cast<char*>(viewSection->SectionSymbol.getValue()));
sectionLine->setSectionStyle(vp->SectionLineStyle.getValue()); sectionLine->setSectionStyle(vp->SectionLineStyle.getValue());
sectionLine->setSectionColor(vp->SectionLineColor.getValue().asValue<QColor>()); App::Color color = Preferences::getAccessibleColor(vp->SectionLineColor.getValue());
sectionLine->setSectionColor(color.asValue<QColor>());
sectionLine->setPathMode(true); sectionLine->setPathMode(true);
sectionLine->setPath(wirePath); sectionLine->setPath(wirePath);
sectionLine->setEnds(vStart, vEnd); sectionLine->setEnds(vStart, vEnd);
@@ -988,7 +991,8 @@ void QGIViewPart::drawHighlight(TechDraw::DrawViewDetail* viewDetail, bool b)
scene()->addItem(highlight); scene()->addItem(highlight);
highlight->setReference(viewDetail->Reference.getValue()); highlight->setReference(viewDetail->Reference.getValue());
highlight->setStyle((Qt::PenStyle)vp->HighlightLineStyle.getValue()); highlight->setStyle((Qt::PenStyle)vp->HighlightLineStyle.getValue());
highlight->setColor(vp->HighlightLineColor.getValue().asValue<QColor>()); App::Color color = Preferences::getAccessibleColor(vp->HighlightLineColor.getValue());
highlight->setColor(color.asValue<QColor>());
highlight->setFeatureName(viewDetail->getNameInDocument()); highlight->setFeatureName(viewDetail->getNameInDocument());
highlight->setInteractive(true); highlight->setInteractive(true);

View File

@@ -23,11 +23,12 @@
#include "PreCompiled.h" #include "PreCompiled.h"
#ifndef _PreComp_ #ifndef _PreComp_
# include <cmath> #include <QGraphicsColorizeEffect>
# include <sstream> #include <QGraphicsEffect>
#include <QGraphicsItem> #include <QGraphicsItem>
#include <QRectF> #include <QRectF>
#include <cmath>
#include <sstream>
#endif #endif
#include <Base/Console.h> #include <Base/Console.h>
@@ -36,13 +37,14 @@
#include <Mod/TechDraw/App/DrawViewDraft.h> #include <Mod/TechDraw/App/DrawViewDraft.h>
#include <Mod/TechDraw/App/DrawViewSymbol.h> #include <Mod/TechDraw/App/DrawViewSymbol.h>
#include "QGIViewSymbol.h" #include "PreferencesGui.h"
#include "QGCustomSvg.h" #include "QGCustomSvg.h"
#include "QGDisplayArea.h" #include "QGDisplayArea.h"
#include "QGIViewSymbol.h"
#include "Rez.h" #include "Rez.h"
using namespace TechDrawGui; using namespace TechDrawGui;
using namespace TechDraw;
QGIViewSymbol::QGIViewSymbol() QGIViewSymbol::QGIViewSymbol()
{ {
@@ -79,9 +81,7 @@ void QGIViewSymbol::updateView(bool update)
if (!viewSymbol) if (!viewSymbol)
return; return;
if (update || if (update || viewSymbol->isTouched() || viewSymbol->Symbol.isTouched()) {
viewSymbol->isTouched() ||
viewSymbol->Symbol.isTouched()) {
draw(); draw();
} }
@@ -114,10 +114,11 @@ void QGIViewSymbol::drawSvg()
// double pxMm = 3.54; //90px/25.4mm ( inkscape value version <= 0.91) // double pxMm = 3.54; //90px/25.4mm ( inkscape value version <= 0.91)
//some software uses different px/in, so symbol will need Scale adjusted. //some software uses different px/in, so symbol will need Scale adjusted.
//Arch/Draft views are in px and need to be scaled @ rezfactor px/mm to ensure proper representation //Arch/Draft views are in px and need to be scaled @ rezfactor px/mm to ensure proper representation
if (viewSymbol->isDerivedFrom(TechDraw::DrawViewArch::getClassTypeId()) || if (viewSymbol->isDerivedFrom(TechDraw::DrawViewArch::getClassTypeId())
viewSymbol->isDerivedFrom(TechDraw::DrawViewDraft::getClassTypeId()) ) { || viewSymbol->isDerivedFrom(TechDraw::DrawViewDraft::getClassTypeId())) {
scaling = scaling * rezfactor; scaling = scaling * rezfactor;
} else { }
else {
scaling = scaling * rezfactor / pxMm; scaling = scaling * rezfactor / pxMm;
} }
m_svgItem->setScale(scaling); m_svgItem->setScale(scaling);
@@ -135,9 +136,23 @@ void QGIViewSymbol::symbolToSvg(QByteArray qba)
prepareGeometryChange(); prepareGeometryChange();
if (!m_svgItem->load(&qba)) { if (!m_svgItem->load(&qba)) {
Base::Console().Error("Error - Could not load Symbol into SVG renderer for %s\n", getViewName()); Base::Console().Error("Error - Could not load Symbol into SVG renderer for %s\n",
getViewName());
} }
m_svgItem->centerAt(0., 0.); m_svgItem->centerAt(0., 0.);
if (Preferences::lightOnDark()) {
QColor color = PreferencesGui::getAccessibleQColor(QColor(Qt::black));
QGraphicsColorizeEffect* colorizeEffect = new QGraphicsColorizeEffect();
colorizeEffect->setColor(color);
m_svgItem->setGraphicsEffect(colorizeEffect);
}
else {
//remove and delete any existing graphics effect
if (m_svgItem->graphicsEffect()) {
m_svgItem->setGraphicsEffect(nullptr);
}
}
} }
void QGIViewSymbol::rotateView() void QGIViewSymbol::rotateView()
@@ -147,4 +162,3 @@ void QGIViewSymbol::rotateView()
double rot = getViewObject()->Rotation.getValue(); double rot = getViewObject()->Rotation.getValue();
m_displayArea->setRotation(-rot); m_displayArea->setRotation(-rot);
} }

View File

@@ -39,6 +39,7 @@
#include <Base/Console.h> #include <Base/Console.h>
#include <Mod/TechDraw/App/DrawUtil.h> #include <Mod/TechDraw/App/DrawUtil.h>
#include "PreferencesGui.h"
#include "QGTracker.h" #include "QGTracker.h"
#include "QGIView.h" #include "QGIView.h"
#include "QGSPage.h" #include "QGSPage.h"
@@ -480,7 +481,7 @@ QColor QGTracker::getTrackerColor()
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")-> Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")->
GetGroup("Preferences")->GetGroup("Mod/TechDraw/Tracker"); GetGroup("Preferences")->GetGroup("Mod/TechDraw/Tracker");
App::Color trackColor = App::Color((uint32_t) hGrp->GetUnsigned("TrackerColor", 0xFF000000)); App::Color trackColor = App::Color((uint32_t) hGrp->GetUnsigned("TrackerColor", 0xFF000000));
result = trackColor.asValue<QColor>(); result = PreferencesGui::getAccessibleQColor(trackColor.asValue<QColor>());
return result; return result;
} }

View File

@@ -338,7 +338,7 @@ void QGVPage::drawBackground(QPainter *painter, const QRectF &)
QRectF paperRect(0, -pageHeight, pageWidth, pageHeight); QRectF paperRect(0, -pageHeight, pageWidth, pageHeight);
QPolygon poly = mapFromScene(paperRect); QPolygon poly = mapFromScene(paperRect);
QBrush pageBrush(Qt::white); QBrush pageBrush(PreferencesGui::pageQColor());
painter->setBrush(pageBrush); painter->setBrush(pageBrush);
painter->drawRect(poly.boundingRect()); painter->drawRect(poly.boundingRect());

View File

@@ -31,8 +31,8 @@
#include <QMessageBox> #include <QMessageBox>
#include <QPointer> #include <QPointer>
#include <QTextStream> #include <QTextStream>
# include <boost_signals2.hpp>
#include <boost/signals2/connection.hpp> #include <boost/signals2/connection.hpp>
#include <boost_signals2.hpp>
#endif #endif
#include <App/Document.h> #include <App/Document.h>
@@ -44,14 +44,15 @@
#include <Gui/MainWindow.h> #include <Gui/MainWindow.h>
#include <Gui/ViewProviderDocumentObject.h> #include <Gui/ViewProviderDocumentObject.h>
#include <Mod/TechDraw/App/DrawPage.h>
#include <Mod/TechDraw/App/DrawView.h>
#include <Mod/TechDraw/App/DrawProjGroupItem.h>
#include <Mod/TechDraw/App/DrawViewDimension.h>
#include <Mod/TechDraw/App/DrawViewBalloon.h>
#include <Mod/TechDraw/App/DrawLeaderLine.h>
#include <Mod/TechDraw/App/DrawRichAnno.h>
#include <Mod/TechDraw/App/DrawHatch.h> #include <Mod/TechDraw/App/DrawHatch.h>
#include <Mod/TechDraw/App/DrawLeaderLine.h>
#include <Mod/TechDraw/App/DrawPage.h>
#include <Mod/TechDraw/App/DrawProjGroupItem.h>
#include <Mod/TechDraw/App/DrawRichAnno.h>
#include <Mod/TechDraw/App/DrawTemplate.h>
#include <Mod/TechDraw/App/DrawView.h>
#include <Mod/TechDraw/App/DrawViewBalloon.h>
#include <Mod/TechDraw/App/DrawViewDimension.h>
#include <Mod/TechDraw/App/DrawWeldSymbol.h> #include <Mod/TechDraw/App/DrawWeldSymbol.h>
#include "MDIViewPage.h" #include "MDIViewPage.h"
@@ -59,9 +60,9 @@
#include "QGITemplate.h" #include "QGITemplate.h"
#include "QGSPage.h" #include "QGSPage.h"
#include "QGVPage.h" #include "QGVPage.h"
#include "ViewProviderTemplate.h"
#include "ViewProviderPage.h" #include "ViewProviderPage.h"
#include "ViewProviderPageExtension.h" #include "ViewProviderPageExtension.h"
#include "ViewProviderTemplate.h"
using namespace TechDrawGui; using namespace TechDrawGui;
using namespace TechDraw; using namespace TechDraw;
@@ -77,26 +78,26 @@ PROPERTY_SOURCE(TechDrawGui::ViewProviderPage, Gui::ViewProviderDocumentObject)
// Construction/Destruction // Construction/Destruction
ViewProviderPage::ViewProviderPage() ViewProviderPage::ViewProviderPage()
: m_mdiView(nullptr), : m_mdiView(nullptr), m_pageName(""), m_graphicsView(nullptr), m_graphicsScene(nullptr)
m_pageName(""),
m_graphicsView(nullptr),
m_graphicsScene(nullptr)
{ {
initExtension(this); initExtension(this);
sPixmap = "TechDraw_TreePage"; sPixmap = "TechDraw_TreePage";
static const char* group = "Grid"; static const char* group = "Grid";
ADD_PROPERTY_TYPE(ShowFrames ,(true), group, App::Prop_None, "Show or hide View frames and Labels on this Page"); ADD_PROPERTY_TYPE(ShowFrames, (true), group, App::Prop_None,
ADD_PROPERTY_TYPE(ShowGrid ,(PreferencesGui::showGrid()), group, App::Prop_None, "Show or hide a grid on this Page"); "Show or hide View frames and Labels on this Page");
ADD_PROPERTY_TYPE(GridSpacing, (PreferencesGui::gridSpacing()), group, (App::PropertyType::Prop_None), ADD_PROPERTY_TYPE(ShowGrid, (PreferencesGui::showGrid()), group, App::Prop_None,
"Grid line spacing in mm"); "Show or hide a grid on this Page");
ADD_PROPERTY_TYPE(GridSpacing, (PreferencesGui::gridSpacing()), group,
(App::PropertyType::Prop_None), "Grid line spacing in mm");
ShowFrames.setStatus(App::Property::Hidden, true); ShowFrames.setStatus(App::Property::Hidden, true);
DisplayMode.setStatus(App::Property::Hidden, true); DisplayMode.setStatus(App::Property::Hidden, true);
m_graphicsScene = new QGSPage(this); m_graphicsScene = new QGSPage(this);
m_graphicsScene->setItemIndexMethod(QGraphicsScene::NoIndex); //this prevents crash when deleting dims. m_graphicsScene->setItemIndexMethod(
QGraphicsScene::NoIndex);//this prevents crash when deleting dims.
//scene(view?) indices of dirty regions gets //scene(view?) indices of dirty regions gets
//out of sync. missing prepareGeometryChange //out of sync. missing prepareGeometryChange
//somewhere???? QTBUG-18021??? //somewhere???? QTBUG-18021???
@@ -118,7 +119,8 @@ void ViewProviderPage::attach(App::DocumentObject *pcFeat)
connectGuiRepaint = feature->signalGuiPaint.connect(bnd); connectGuiRepaint = feature->signalGuiPaint.connect(bnd);
m_pageName = feature->getNameInDocument(); m_pageName = feature->getNameInDocument();
m_graphicsScene->setObjectName(QString::fromLocal8Bit(m_pageName.c_str())); m_graphicsScene->setObjectName(QString::fromLocal8Bit(m_pageName.c_str()));
} else { }
else {
Base::Console().Log("VPP::attach has no Feature!\n"); Base::Console().Log("VPP::attach has no Feature!\n");
} }
} }
@@ -140,9 +142,11 @@ void ViewProviderPage::onChanged(const App::Property *prop)
{ {
if (prop == &(ShowGrid)) { if (prop == &(ShowGrid)) {
setGrid(); setGrid();
} else if (prop == &(GridSpacing)) { }
else if (prop == &(GridSpacing)) {
setGrid(); setGrid();
} else if (prop == &Visibility) { }
else if (prop == &Visibility) {
//Visibility changes are handled in VPDO::onChanged -> show() or hide() //Visibility changes are handled in VPDO::onChanged -> show() or hide()
} }
@@ -159,23 +163,26 @@ void ViewProviderPage::updateData(const App::Property* prop)
if (prop == &(page->KeepUpdated)) { if (prop == &(page->KeepUpdated)) {
if (getDrawPage()->KeepUpdated.getValue()) { if (getDrawPage()->KeepUpdated.getValue()) {
sPixmap = "TechDraw_TreePage"; sPixmap = "TechDraw_TreePage";
} else { }
else {
sPixmap = "TechDraw_TreePageUnsync"; sPixmap = "TechDraw_TreePageUnsync";
} }
signalChangeIcon(); signalChangeIcon();
//if the template is changed, rebuild the visual //if the template is changed, rebuild the visual
} else if (prop == &(page->Template)) { }
else if (prop == &(page->Template)) {
if (!page->isUnsetting()) { if (!page->isUnsetting()) {
//check if a template has been added to scene first? //check if a template has been added to scene first?
m_graphicsScene->matchSceneRectToTemplate(); m_graphicsScene->matchSceneRectToTemplate();
m_graphicsScene->updateTemplate(); m_graphicsScene->updateTemplate();
} }
} else if (prop == &(page->Label)) { }
if (m_mdiView && else if (prop == &(page->Label)) {
!page->isUnsetting()) { if (m_mdiView && !page->isUnsetting()) {
m_mdiView->setTabText(page->Label.getValue()); m_mdiView->setTabText(page->Label.getValue());
} }
} else if (prop == &page->Views) { }
else if (prop == &page->Views) {
if (!page->isUnsetting()) if (!page->isUnsetting())
m_graphicsScene->fixOrphans(); m_graphicsScene->fixOrphans();
} }
@@ -202,25 +209,26 @@ bool ViewProviderPage::onDelete(const std::vector<std::string> &)
isTemplate = false; isTemplate = false;
} }
if (!objs.empty() && !isTemplate) if (!objs.empty() && !isTemplate) {
{
// generate dialog // generate dialog
QString bodyMessage; QString bodyMessage;
QTextStream bodyMessageStream(&bodyMessage); QTextStream bodyMessageStream(&bodyMessage);
bodyMessageStream << qApp->translate("Std_Delete", bodyMessageStream << qApp->translate(
"Std_Delete",
"The page is not empty, therefore the\nfollowing referencing objects might be lost:"); "The page is not empty, therefore the\nfollowing referencing objects might be lost:");
bodyMessageStream << '\n'; bodyMessageStream << '\n';
for (auto ObjIterator : objs) for (auto ObjIterator : objs)
bodyMessageStream << '\n' << QString::fromUtf8(ObjIterator->Label.getValue()); bodyMessageStream << '\n' << QString::fromUtf8(ObjIterator->Label.getValue());
bodyMessageStream << "\n\n" << QObject::tr("Are you sure you want to continue?"); bodyMessageStream << "\n\n" << QObject::tr("Are you sure you want to continue?");
// show and evaluate the dialog // show and evaluate the dialog
int DialogResult = QMessageBox::warning(Gui::getMainWindow(), int DialogResult = QMessageBox::warning(
qApp->translate("Std_Delete", "Object dependencies"), bodyMessage, Gui::getMainWindow(), qApp->translate("Std_Delete", "Object dependencies"), bodyMessage,
QMessageBox::Yes, QMessageBox::No); QMessageBox::Yes, QMessageBox::No);
if (DialogResult == QMessageBox::Yes) { if (DialogResult == QMessageBox::Yes) {
removeMDIView(); removeMDIView();
return true; return true;
} else }
else
return false; return false;
} }
else { else {
@@ -243,14 +251,16 @@ bool ViewProviderPage::setEdit(int ModNum)
if (ModNum == _SHOWDRAWING) { if (ModNum == _SHOWDRAWING) {
showMDIViewPage();// show the drawing showMDIViewPage();// show the drawing
return false; //finished editing return false; //finished editing
} else if (ModNum == _TOGGLEUPDATE) { }
else if (ModNum == _TOGGLEUPDATE) {
auto page = getDrawPage(); auto page = getDrawPage();
if (page) { if (page) {
page->KeepUpdated.setValue(!page->KeepUpdated.getValue()); page->KeepUpdated.setValue(!page->KeepUpdated.getValue());
page->recomputeFeature(); page->recomputeFeature();
} }
return false; return false;
} else { }
else {
return Gui::ViewProviderDocumentObject::setEdit(ModNum); return Gui::ViewProviderDocumentObject::setEdit(ModNum);
} }
} }
@@ -293,9 +303,11 @@ bool ViewProviderPage::showMDIViewPage()
m_graphicsScene->updateTemplate(true); m_graphicsScene->updateTemplate(true);
m_graphicsScene->redrawAllViews(); m_graphicsScene->redrawAllViews();
m_graphicsScene->fixOrphans(true); m_graphicsScene->fixOrphans(true);
} else { }
else {
m_graphicsScene->redrawAllViews(); m_graphicsScene->redrawAllViews();
m_graphicsScene->fixOrphans(true); m_graphicsScene->fixOrphans(true);
m_graphicsView->update();
} }
m_graphicsView->centerOnPage(); m_graphicsView->centerOnPage();
@@ -311,8 +323,7 @@ bool ViewProviderPage::showMDIViewPage()
void ViewProviderPage::createMDIViewPage() void ViewProviderPage::createMDIViewPage()
{ {
Gui::Document* doc = Gui::Application::Instance->getDocument Gui::Document* doc = Gui::Application::Instance->getDocument(pcObject->getDocument());
(pcObject->getDocument());
m_mdiView = new MDIViewPage(this, doc, Gui::getMainWindow()); m_mdiView = new MDIViewPage(this, doc, Gui::getMainWindow());
if (!m_graphicsView) { if (!m_graphicsView) {
m_graphicsView = new QGVPage(this, m_graphicsScene, m_mdiView); m_graphicsView = new QGVPage(this, m_graphicsScene, m_mdiView);
@@ -340,7 +351,9 @@ void ViewProviderPage::removeMDIView(void)
Gui::getMainWindow()->removeWindow(m_mdiView); Gui::getMainWindow()->removeWindow(m_mdiView);
m_mdiView = nullptr; //m_mdiView will eventually be deleted and m_mdiView = nullptr; //m_mdiView will eventually be deleted and
m_graphicsView = nullptr;//will take m_graphicsView with it m_graphicsView = nullptr;//will take m_graphicsView with it
Gui::MDIView* aw = Gui::getMainWindow()->activeWindow(); //WF: this bit should be in the remove window logic, not here. Gui::MDIView* aw =
Gui::getMainWindow()
->activeWindow();//WF: this bit should be in the remove window logic, not here.
if (aw) if (aw)
aw->showMaximized(); aw->showMaximized();
} }
@@ -355,6 +368,25 @@ MDIViewPage* ViewProviderPage::getMDIViewPage() const
return m_mdiView; return m_mdiView;
} }
DrawTemplate* ViewProviderPage::getTemplate() const
{
return dynamic_cast<DrawTemplate*>(getDrawPage()->Template.getValue());
}
QGITemplate* ViewProviderPage::getQTemplate() const
{
Gui::Document* guiDoc = Gui::Application::Instance->getDocument(getDrawPage()->getDocument());
if (guiDoc) {
Gui::ViewProvider* vp = guiDoc->getViewProvider(getTemplate());
auto vpTemplate = dynamic_cast<ViewProviderTemplate*>(vp);
if (vpTemplate) {
return vpTemplate->getQTemplate();
}
}
return nullptr;
}
std::vector<App::DocumentObject*> ViewProviderPage::claimChildren(void) const std::vector<App::DocumentObject*> ViewProviderPage::claimChildren(void) const
{ {
std::vector<App::DocumentObject*> temp; std::vector<App::DocumentObject*> temp;
@@ -379,7 +411,8 @@ std::vector<App::DocumentObject*> ViewProviderPage::claimChildren(void) const
const std::vector<App::DocumentObject*>& views = getDrawPage()->Views.getValues(); const std::vector<App::DocumentObject*>& views = getDrawPage()->Views.getValues();
try { try {
for (std::vector<App::DocumentObject *>::const_iterator it = views.begin(); it != views.end(); ++it) { for (std::vector<App::DocumentObject*>::const_iterator it = views.begin();
it != views.end(); ++it) {
TechDraw::DrawView* featView = dynamic_cast<TechDraw::DrawView*>(*it); TechDraw::DrawView* featView = dynamic_cast<TechDraw::DrawView*>(*it);
App::DocumentObject* docObj = *it; App::DocumentObject* docObj = *it;
//DrawRichAnno with no parent is child of Page //DrawRichAnno with no parent is child of Page
@@ -392,38 +425,30 @@ std::vector<App::DocumentObject*> ViewProviderPage::claimChildren(void) const
} }
// Don't collect if dimension, projection group item, hatch or member of ClipGroup as these should be grouped elsewhere // Don't collect if dimension, projection group item, hatch or member of ClipGroup as these should be grouped elsewhere
if (docObj->isDerivedFrom(TechDraw::DrawProjGroupItem::getClassTypeId()) || if (docObj->isDerivedFrom(TechDraw::DrawProjGroupItem::getClassTypeId())
docObj->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId()) || || docObj->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId())
docObj->isDerivedFrom(TechDraw::DrawHatch::getClassTypeId()) || || docObj->isDerivedFrom(TechDraw::DrawHatch::getClassTypeId())
docObj->isDerivedFrom(TechDraw::DrawViewBalloon::getClassTypeId()) || || docObj->isDerivedFrom(TechDraw::DrawViewBalloon::getClassTypeId())
docObj->isDerivedFrom(TechDraw::DrawRichAnno::getClassTypeId()) || || docObj->isDerivedFrom(TechDraw::DrawRichAnno::getClassTypeId())
docObj->isDerivedFrom(TechDraw::DrawLeaderLine::getClassTypeId()) || || docObj->isDerivedFrom(TechDraw::DrawLeaderLine::getClassTypeId())
docObj->isDerivedFrom(TechDraw::DrawWeldSymbol::getClassTypeId()) || || docObj->isDerivedFrom(TechDraw::DrawWeldSymbol::getClassTypeId())
(featView && featView->isInClip()) ) || (featView && featView->isInClip()))
continue; continue;
else else
temp.push_back(*it); temp.push_back(*it);
} }
return temp; return temp;
} catch (...) { }
catch (...) {
return std::vector<App::DocumentObject*>(); return std::vector<App::DocumentObject*>();
} }
} }
bool ViewProviderPage::isShow(void) const bool ViewProviderPage::isShow(void) const { return Visibility.getValue(); }
{
return Visibility.getValue();
}
bool ViewProviderPage::getFrameState() bool ViewProviderPage::getFrameState() { return ShowFrames.getValue(); }
{
return ShowFrames.getValue();
}
void ViewProviderPage::setFrameState(bool state) void ViewProviderPage::setFrameState(bool state) { ShowFrames.setValue(state); }
{
ShowFrames.setValue(state);
}
void ViewProviderPage::toggleFrameState() void ViewProviderPage::toggleFrameState()
{ {
@@ -473,10 +498,10 @@ bool ViewProviderPage::canDragObject(App::DocumentObject* docObj) const
} }
bool ViewProviderPage::canDropObjectEx(App::DocumentObject* obj, App::DocumentObject* owner, bool ViewProviderPage::canDropObjectEx(App::DocumentObject* obj, App::DocumentObject* owner,
const char *subname, const std::vector<std::string> &elements) const const char* subname,
const std::vector<std::string>& elements) const
{ {
return getVPPExtension()->extensionCanDropObjectEx(obj, owner, subname, elements); return getVPPExtension()->extensionCanDropObjectEx(obj, owner, subname, elements);
} }
bool ViewProviderPage::canDropObject(App::DocumentObject* docObj) const bool ViewProviderPage::canDropObject(App::DocumentObject* docObj) const
@@ -510,10 +535,7 @@ TechDraw::DrawPage* ViewProviderPage::getDrawPage() const
return dynamic_cast<TechDraw::DrawPage*>(pcObject); return dynamic_cast<TechDraw::DrawPage*>(pcObject);
} }
Gui::MDIView *ViewProviderPage::getMDIView() const Gui::MDIView* ViewProviderPage::getMDIView() const { return m_mdiView.data(); }
{
return m_mdiView.data();
}
void ViewProviderPage::setGrid() void ViewProviderPage::setGrid()
{ {
@@ -533,7 +555,8 @@ void ViewProviderPage::setGrid()
if (ShowGrid.getValue()) { if (ShowGrid.getValue()) {
widget->showGrid(true); widget->showGrid(true);
widget->makeGrid(pageWidth, pageHeight, gridStep); widget->makeGrid(pageWidth, pageHeight, gridStep);
} else { }
else {
widget->showGrid(false); widget->showGrid(false);
} }
widget->updateViewport(); widget->updateViewport();
@@ -547,7 +570,4 @@ ViewProviderPageExtension* ViewProviderPage::getVPPExtension() const
return vppe; return vppe;
} }
const char* ViewProviderPage::whoAmI() const const char* ViewProviderPage::whoAmI() const { return m_pageName.c_str(); }
{
return m_pageName.c_str();
}

View File

@@ -26,23 +26,27 @@
#include <Mod/TechDraw/TechDrawGlobal.h> #include <Mod/TechDraw/TechDrawGlobal.h>
#include <boost_signals2.hpp>
#include <QPointer>
#include <QObject> #include <QObject>
#include <QPointer>
#include <boost_signals2.hpp>
#include <App/PropertyUnits.h> #include <App/PropertyUnits.h>
#include <Gui/ViewProviderDocumentObject.h> #include <Gui/ViewProviderDocumentObject.h>
#include <ViewProviderPageExtension.h> #include <ViewProviderPageExtension.h>
namespace TechDraw{ namespace TechDraw
{
class DrawPage; class DrawPage;
} class DrawTemplate;
}// namespace TechDraw
namespace TechDrawGui { namespace TechDrawGui
{
class MDIViewPage; class MDIViewPage;
class QGVPage; class QGVPage;
class QGSPage; class QGSPage;
class QGITemplate;
class TechDrawGuiExport ViewProviderPage: public Gui::ViewProviderDocumentObject, class TechDrawGuiExport ViewProviderPage: public Gui::ViewProviderDocumentObject,
public ViewProviderPageExtension public ViewProviderPageExtension
@@ -69,8 +73,8 @@ public:
void dropObject(App::DocumentObject* docObj) override; void dropObject(App::DocumentObject* docObj) override;
void constDropObject(App::DocumentObject* docObj) const; void constDropObject(App::DocumentObject* docObj) const;
bool canDropObjectEx(App::DocumentObject *obj, App::DocumentObject *owner, bool canDropObjectEx(App::DocumentObject* obj, App::DocumentObject* owner, const char* subname,
const char *subname, const std::vector<std::string> &elements) const override; const std::vector<std::string>& elements) const override;
bool useNewSelectionModel() const override { return false; } bool useNewSelectionModel() const override { return false; }
/// returns a list of all possible modes /// returns a list of all possible modes
@@ -92,6 +96,8 @@ public:
void updateData(const App::Property* prop) override; void updateData(const App::Property* prop) override;
TechDraw::DrawPage* getDrawPage() const; TechDraw::DrawPage* getDrawPage() const;
TechDraw::DrawTemplate* getTemplate() const;
QGITemplate* getQTemplate(void) const;
//slots & connections //slots & connections
void onGuiRepaint(const TechDraw::DrawPage* dp); void onGuiRepaint(const TechDraw::DrawPage* dp);