[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:
@@ -23,19 +23,19 @@
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#ifndef _PreComp_
|
||||
# include <sstream>
|
||||
# include <QDomDocument>
|
||||
# include "QDomNodeModel.h"
|
||||
# include <QXmlQuery>
|
||||
# include <QXmlResultItems>
|
||||
#include "QDomNodeModel.h"
|
||||
#include <QDomDocument>
|
||||
#include <QXmlQuery>
|
||||
#include <QXmlResultItems>
|
||||
#include <sstream>
|
||||
#endif
|
||||
|
||||
#include <Base/Console.h>
|
||||
|
||||
#include "DrawViewSymbol.h"
|
||||
#include "DrawViewSymbolPy.h" // generated from DrawViewSymbolPy.xml
|
||||
#include "DrawPage.h"
|
||||
#include "DrawUtil.h"
|
||||
#include "DrawViewSymbol.h"
|
||||
#include "DrawViewSymbolPy.h"// generated from DrawViewSymbolPy.xml
|
||||
|
||||
|
||||
using namespace TechDraw;
|
||||
@@ -49,18 +49,17 @@ PROPERTY_SOURCE(TechDraw::DrawViewSymbol, TechDraw::DrawView)
|
||||
|
||||
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(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");
|
||||
Scale.setStatus(App::Property::ReadOnly, false);
|
||||
Symbol.setStatus(App::Property::Hidden, true);
|
||||
}
|
||||
|
||||
DrawViewSymbol::~DrawViewSymbol()
|
||||
{
|
||||
}
|
||||
DrawViewSymbol::~DrawViewSymbol() {}
|
||||
|
||||
void DrawViewSymbol::onChanged(const App::Property* prop)
|
||||
{
|
||||
@@ -69,7 +68,8 @@ void DrawViewSymbol::onChanged(const App::Property* prop)
|
||||
std::vector<std::string> editables = getEditableFields();
|
||||
EditableTexts.setValues(editables);
|
||||
}
|
||||
} else if (prop == &EditableTexts) {
|
||||
}
|
||||
else if (prop == &EditableTexts) {
|
||||
//this will change Symbol, which will call onChanged(Symbol),
|
||||
//which will change EditableTexts, but the loop stops after
|
||||
//1 cycle
|
||||
@@ -79,7 +79,7 @@ void DrawViewSymbol::onChanged(const App::Property* prop)
|
||||
TechDraw::DrawView::onChanged(prop);
|
||||
}
|
||||
|
||||
App::DocumentObjectExecReturn *DrawViewSymbol::execute()
|
||||
App::DocumentObjectExecReturn* DrawViewSymbol::execute()
|
||||
{
|
||||
//nothing to do. DVS is just a container for properties.
|
||||
//the action takes place on the Gui side.
|
||||
@@ -88,9 +88,9 @@ App::DocumentObjectExecReturn *DrawViewSymbol::execute()
|
||||
|
||||
QRectF DrawViewSymbol::getRect() const
|
||||
{
|
||||
double w = 64.0; //must default to something
|
||||
double h = 64.0;
|
||||
return (QRectF(0, 0,w, h));
|
||||
double w = 64.0;//must default to something
|
||||
double h = 64.0;
|
||||
return (QRectF(0, 0, w, h));
|
||||
}
|
||||
|
||||
//!Assume all svg files fit the page and/or the user will scale manually
|
||||
@@ -117,15 +117,15 @@ std::vector<std::string> DrawViewSymbol::getEditableFields()
|
||||
|
||||
// XPath query to select all <tspan> nodes whose <text> parent
|
||||
// has "freecad:editable" attribute
|
||||
query.setQuery(QString::fromUtf8(
|
||||
"declare default element namespace \"" SVG_NS_URI "\"; "
|
||||
"declare namespace freecad=\"" FREECAD_SVG_NS_URI "\"; "
|
||||
"//text[@freecad:editable]/tspan"));
|
||||
query.setQuery(QString::fromUtf8("declare default element namespace \"" SVG_NS_URI "\"; "
|
||||
"declare namespace freecad=\"" FREECAD_SVG_NS_URI "\"; "
|
||||
"//text[@freecad:editable]/tspan"));
|
||||
|
||||
query.evaluateTo(&queryResult);
|
||||
|
||||
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();
|
||||
editables.emplace_back(editableValue.toUtf8().constData());
|
||||
}
|
||||
@@ -153,19 +153,19 @@ void DrawViewSymbol::updateFieldsInSymbol()
|
||||
|
||||
// XPath query to select all <tspan> nodes whose <text> parent
|
||||
// has "freecad:editable" attribute
|
||||
query.setQuery(QString::fromUtf8(
|
||||
"declare default element namespace \"" SVG_NS_URI "\"; "
|
||||
"declare namespace freecad=\"" FREECAD_SVG_NS_URI "\"; "
|
||||
"//text[@freecad:editable]/tspan"));
|
||||
query.setQuery(QString::fromUtf8("declare default element namespace \"" SVG_NS_URI "\"; "
|
||||
"declare namespace freecad=\"" FREECAD_SVG_NS_URI "\"; "
|
||||
"//text[@freecad:editable]/tspan"));
|
||||
query.evaluateTo(&queryResult);
|
||||
|
||||
unsigned int count = 0;
|
||||
while (!queryResult.next().isNull())
|
||||
{
|
||||
QDomElement tspanElement = model.toDomNode(queryResult.current().toNodeModelIndex()).toElement();
|
||||
while (!queryResult.next().isNull()) {
|
||||
QDomElement tspanElement =
|
||||
model.toDomNode(queryResult.current().toNodeModelIndex()).toElement();
|
||||
|
||||
// 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)
|
||||
while (!tspanElement.lastChild().isNull()) {
|
||||
@@ -173,8 +173,8 @@ void DrawViewSymbol::updateFieldsInSymbol()
|
||||
}
|
||||
|
||||
// Finally append text node with editable replacement as the only <tspan> descendant
|
||||
tspanElement.appendChild(symbolDocument.createTextNode(
|
||||
QString::fromUtf8(editText[count].c_str())));
|
||||
tspanElement.appendChild(
|
||||
symbolDocument.createTextNode(QString::fromUtf8(editText[count].c_str())));
|
||||
++count;
|
||||
}
|
||||
Symbol.setValue(symbolDocument.toString(1).toStdString());
|
||||
@@ -186,6 +186,9 @@ bool DrawViewSymbol::loadQDomDocument(QDomDocument& symbolDocument)
|
||||
{
|
||||
const char* symbol = Symbol.getValue();
|
||||
QByteArray qba(symbol);
|
||||
if (qba.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
QString errorMsg;
|
||||
int errorLine;
|
||||
int errorCol;
|
||||
@@ -193,15 +196,16 @@ bool DrawViewSymbol::loadQDomDocument(QDomDocument& symbolDocument)
|
||||
bool rc = symbolDocument.setContent(qba, nsProcess, &errorMsg, &errorLine, &errorCol);
|
||||
if (!rc) {
|
||||
//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",
|
||||
getNameInDocument(), strlen(symbol), rc,
|
||||
qPrintable(errorMsg), errorLine, errorCol);
|
||||
getNameInDocument(), strlen(symbol), rc, qPrintable(errorMsg),
|
||||
errorLine, errorCol);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
PyObject *DrawViewSymbol::getPyObject()
|
||||
PyObject* DrawViewSymbol::getPyObject()
|
||||
{
|
||||
if (PythonObject.is(Py::_None())) {
|
||||
// ref counter is set to 1
|
||||
@@ -212,14 +216,16 @@ PyObject *DrawViewSymbol::getPyObject()
|
||||
|
||||
// Python Drawing feature ---------------------------------------------------------
|
||||
|
||||
namespace App {
|
||||
namespace App
|
||||
{
|
||||
/// @cond DOXERR
|
||||
PROPERTY_SOURCE_TEMPLATE(TechDraw::DrawViewSymbolPython, TechDraw::DrawViewSymbol)
|
||||
template<> const char* TechDraw::DrawViewSymbolPython::getViewProviderName() const {
|
||||
template<> const char* TechDraw::DrawViewSymbolPython::getViewProviderName() const
|
||||
{
|
||||
return "TechDrawGui::ViewProviderSymbol";
|
||||
}
|
||||
/// @endcond
|
||||
|
||||
// explicit template instantiation
|
||||
template class TechDrawExport FeaturePythonT<TechDraw::DrawViewSymbol>;
|
||||
}
|
||||
}// namespace App
|
||||
|
||||
Reference in New Issue
Block a user