[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 6eac8fe8b2
commit 0e402ae075
34 changed files with 3257 additions and 2160 deletions

View File

@@ -23,35 +23,36 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <QDomDocument>
# include <QFile>
# include <QGraphicsSvgItem>
# include <QPen>
# include <QSvgRenderer>
# include <QXmlQuery>
# include <QXmlResultItems>
#endif // #ifndef _PreComp_
#include <QDomDocument>
#include <QFile>
#include <QGraphicsColorizeEffect>
#include <QGraphicsEffect>
#include <QGraphicsSvgItem>
#include <QPen>
#include <QSvgRenderer>
#include <QXmlQuery>
#include <QXmlResultItems>
#endif// #ifndef _PreComp_
#include <App/Application.h>
#include <Base/Console.h>
#include <Base/Parameter.h>
#include <Mod/TechDraw/App/DrawUtil.h>
#include <Mod/TechDraw/App/DrawSVGTemplate.h>
#include <Mod/TechDraw/App/DrawUtil.h>
#include <Mod/TechDraw/App/QDomNodeModel.h>
#include "PreferencesGui.h"
#include "QGISVGTemplate.h"
#include "QGSPage.h"
#include "Rez.h"
#include "TemplateTextField.h"
#include "ZVALUE.h"
using namespace TechDrawGui;
using namespace TechDraw;
QGISVGTemplate::QGISVGTemplate(QGSPage* scene)
: QGITemplate(scene),
firstTime(true)
QGISVGTemplate::QGISVGTemplate(QGSPage* scene) : QGITemplate(scene), firstTime(true)
{
m_svgItem = new QGraphicsSvgItem(this);
@@ -66,22 +67,15 @@ QGISVGTemplate::QGISVGTemplate(QGSPage* scene)
m_svgItem->setZValue(ZVALUE::SVGTEMPLATE);
setZValue(ZVALUE::SVGTEMPLATE);
}
QGISVGTemplate::~QGISVGTemplate()
{
delete m_svgRender;
}
QGISVGTemplate::~QGISVGTemplate() { delete m_svgRender; }
void QGISVGTemplate::openFile(const QFile &file)
{
Q_UNUSED(file);
}
void QGISVGTemplate::openFile(const QFile& file) { Q_UNUSED(file); }
void QGISVGTemplate::load(const QByteArray &svgCode)
void QGISVGTemplate::load(const QByteArray& svgCode)
{
m_svgRender->load(svgCode);
m_svgRender->load(svgCode);
QSize size = m_svgRender->defaultSize();
m_svgItem->setSharedRenderer(m_svgRender);
@@ -92,31 +86,48 @@ void QGISVGTemplate::load(const QByteArray &svgCode)
}
//convert from pixels or mm or inches in svg file to mm page size
TechDraw::DrawSVGTemplate *tmplte = getSVGTemplate();
TechDraw::DrawSVGTemplate* tmplte = getSVGTemplate();
double xaspect, yaspect;
xaspect = tmplte->getWidth() / static_cast<double>(size.width());
yaspect = tmplte->getHeight() / static_cast<double>(size.height());
QTransform qtrans;
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);
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()))
return static_cast<TechDraw::DrawSVGTemplate *>(pageTemplate);
else
if (pageTemplate && pageTemplate->isDerivedFrom(TechDraw::DrawSVGTemplate::getClassTypeId())) {
return static_cast<TechDraw::DrawSVGTemplate*>(pageTemplate);
}
else {
return nullptr;
}
}
void QGISVGTemplate::draw()
{
TechDraw::DrawSVGTemplate *tmplte = getSVGTemplate();
if(!tmplte)
TechDraw::DrawSVGTemplate* tmplte = getSVGTemplate();
if (!tmplte) {
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)
@@ -127,7 +138,7 @@ void QGISVGTemplate::updateView(bool update)
void QGISVGTemplate::createClickHandles()
{
TechDraw::DrawSVGTemplate *svgTemplate = getSVGTemplate();
TechDraw::DrawSVGTemplate* svgTemplate = getSVGTemplate();
if (svgTemplate->isRestoring()) {
//the embedded file is not available yet, so just return
return;
@@ -141,8 +152,9 @@ void QGISVGTemplate::createClickHandles()
QFile file(templateFilename);
if (!file.open(QIODevice::ReadOnly)) {
Base::Console().Error("QGISVGTemplate::createClickHandles - error opening template file %s\n",
svgTemplate->PageResult.getValue());
Base::Console().Error(
"QGISVGTemplate::createClickHandles - error opening template file %s\n",
svgTemplate->PageResult.getValue());
return;
}
@@ -160,37 +172,41 @@ void QGISVGTemplate::createClickHandles()
query.setFocus(QXmlItem(model.fromDomNode(templateDocElem)));
// XPath query to select all <text> nodes with "freecad:editable" attribute
query.setQuery(QString::fromUtf8(
"declare default element namespace \"" SVG_NS_URI "\"; "
"declare namespace freecad=\"" FREECAD_SVG_NS_URI "\"; "
"//text[@freecad:editable]"));
query.setQuery(QString::fromUtf8("declare default element namespace \"" SVG_NS_URI "\"; "
"declare namespace freecad=\"" FREECAD_SVG_NS_URI "\"; "
"//text[@freecad:editable]"));
QXmlResultItems queryResult;
query.evaluateTo(&queryResult);
//TODO: Find location of special fields (first/third angle) and make graphics items for them
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/General");
Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetUserParameter()
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/General");
double editClickBoxSize = Rez::guiX(hGrp->GetFloat("TemplateDotSize", 3.0));
QColor editClickBoxColor = Qt::green;
editClickBoxColor.setAlpha(128); //semi-transparent
editClickBoxColor.setAlpha(128);//semi-transparent
double width = editClickBoxSize;
double height = editClickBoxSize;
while (!queryResult.next().isNull())
{
QDomElement textElement = model.toDomNode(queryResult.current().toNodeModelIndex()).toElement();
while (!queryResult.next().isNull()) {
QDomElement textElement =
model.toDomNode(queryResult.current().toNodeModelIndex()).toElement();
QString name = textElement.attribute(QString::fromUtf8("freecad:editable"));
double x = Rez::guiX(textElement.attribute(QString::fromUtf8("x"), QString::fromUtf8("0.0")).toDouble());
double y = Rez::guiX(textElement.attribute(QString::fromUtf8("y"), QString::fromUtf8("0.0")).toDouble());
double x = Rez::guiX(
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()) {
Base::Console().Warning("QGISVGTemplate::createClickHandles - no name for editable text at %f, %f\n",
x, y);
Base::Console().Warning(
"QGISVGTemplate::createClickHandles - no name for editable text at %f, %f\n", x, y);
continue;
}
@@ -198,12 +214,12 @@ void QGISVGTemplate::createClickHandles()
double pad = 1.0;
item->setRect(x - pad, Rez::guiX(-svgTemplate->getHeight()) + y - height - pad,
width + 2.0*pad, height + 2.0*pad);
width + 2.0 * pad, height + 2.0 * pad);
QPen myPen;
myPen.setStyle(Qt::SolidLine);
myPen.setColor(editClickBoxColor);
myPen.setWidth(0); // 0 means "cosmetic pen" - always 1px
myPen.setWidth(0);// 0 means "cosmetic pen" - always 1px
item->setPen(myPen);
QBrush myBrush(editClickBoxColor, Qt::SolidPattern);