diff --git a/src/Mod/TechDraw/Gui/DlgPrefsTechDrawColors.ui b/src/Mod/TechDraw/Gui/DlgPrefsTechDrawColors.ui index 1fe564dd84..b57e52b80c 100644 --- a/src/Mod/TechDraw/Gui/DlgPrefsTechDrawColors.ui +++ b/src/Mod/TechDraw/Gui/DlgPrefsTechDrawColors.ui @@ -49,36 +49,15 @@ - - - - Monochrome text color + + + + + true + - - LightTextColor - - - Mod/TechDraw/Colors - - - - - - - Hidden line color - - - - 0 - 0 - 0 - - - - HiddenColor - - - Mod/TechDraw/Colors + + Geometric Hatch @@ -99,66 +78,21 @@ - - + + - Color of dimension lines and text. + If checked FreeCAD will use a single color for all text and lines. + + - - - 0 - 0 - 0 - + + Monochrome - Color + Monochrome - Mod/TechDraw/Dimensions - - - - - - - - true - - - - Background - - - - - - - - true - - - - Preselected - - - - - - - Grid Color - - - - - - - - true - - - - Detail Highlight + /Mod/TechDraw/Colors @@ -174,69 +108,6 @@ - - - - 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. - - - Light on dark - - - LightOnDark - - - /Mod/TechDraw/Colors - - - - - - - Hatch image color - - - - 0 - 0 - 0 - - - - Hatch - - - /Mod/TechDraw/Colors - - - - - - - Default color for leader lines - - - - 0 - 0 - 0 - - - - Color - - - Mod/TechDraw/Markups - - - - - - - Page Color - - - @@ -257,49 +128,6 @@ - - - - - true - - - - Section Face - - - - - - - Section Line - - - - - - - Centerline - - - - - - - - 0 - 0 - 0 - - - - gridColor - - - /Mod/TechDraw/Colors - - - @@ -313,46 +141,10 @@ - - - - - true - - - - Geometric Hatch - - - - - - - - true - - - - Leaderline - - - - - - - - true - - - - Hatch - - - - - + + - Section line color + Centerline color @@ -362,30 +154,29 @@ - SectionColor + CenterColor - /Mod/TechDraw/Decorations + Mod/TechDraw/Decorations - - - - Face color (if not transparent) + + + + + true + - - - 255 - 255 - 255 - + + Section Face - - FaceColor - - - /Mod/TechDraw/Colors + + + + + + Centerline @@ -409,19 +200,103 @@ - - + + + + Vertex + + + + + true - Hidden Line + Background - + + + + Face color (if not transparent) + + + + 255 + 255 + 255 + + + + FaceColor + + + /Mod/TechDraw/Colors + + + + + + + + true + + + + Preselected + + + + + + + + true + + + + Leaderline + + + + + + + Monochrome text color + + + LightTextColor + + + Mod/TechDraw/Colors + + + + + + + Color of dimension lines and text. + + + + 0 + 0 + 0 + + + + Color + + + Mod/TechDraw/Dimensions + + + + Use a light color for dark text and dark color for light text. @@ -441,6 +316,127 @@ + + + + + + + + + + + Hatch image color + + + + 0 + 0 + 0 + + + + Hatch + + + /Mod/TechDraw/Colors + + + + + + + Section line color + + + + 0 + 0 + 0 + + + + SectionColor + + + /Mod/TechDraw/Decorations + + + + + + + Geometric hatch pattern color + + + + 0 + 0 + 0 + + + + GeomHatch + + + /Mod/TechDraw/Colors + + + + + + + + true + + + + Detail Highlight + + + + + + + + true + + + + Hatch + + + + + + + Page Color + + + + + + + Section Line + + + + + + + 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. + + + Light on dark + + + LightOnDark + + + /Mod/TechDraw/Colors + + + @@ -461,10 +457,10 @@ - - + + - Centerline color + Default color for leader lines @@ -474,77 +470,10 @@ - CenterColor + Color - Mod/TechDraw/Decorations - - - - - - - Vertex - - - - - - - Normal line color - - - - 0 - 0 - 0 - - - - NormalColor - - - Mod/TechDraw/Colors - - - - - - - Section face color - - - - 211 - 211 - 211 - - - - CutSurfaceColor - - - Mod/TechDraw/Colors - - - - - - - Color of vertices in views - - - - 0 - 0 - 0 - - - - VertexColor - - - Mod/TechDraw/Decorations + Mod/TechDraw/Markups @@ -575,10 +504,10 @@ - - + + - Geometric hatch pattern color + Normal line color @@ -588,13 +517,96 @@ - GeomHatch + NormalColor + + + Mod/TechDraw/Colors + + + + + + + Hidden line color + + + + 0 + 0 + 0 + + + + HiddenColor + + + Mod/TechDraw/Colors + + + + + + + + 0 + 0 + 0 + + + + gridColor /Mod/TechDraw/Colors + + + + Dimension + + + + + + + Color of vertices in views + + + + 0 + 0 + 0 + + + + VertexColor + + + Mod/TechDraw/Decorations + + + + + + + Grid Color + + + + + + + + true + + + + Hidden Line + + + @@ -607,35 +619,47 @@ - - - - Dimension - - - - - + + - If checked FreeCAD will use a single color for all text and lines. - - + Section face color - - Monochrome + + + 211 + 211 + 211 + - Monochrome + CutSurfaceColor - /Mod/TechDraw/Colors + Mod/TechDraw/Colors - + - + Template Underline + + + + + + + + 0 + 0 + 255 + + + + TemplateUnderlineColor + + + /Mod/TechDraw/Colors diff --git a/src/Mod/TechDraw/Gui/DlgPrefsTechDrawColorsImp.cpp b/src/Mod/TechDraw/Gui/DlgPrefsTechDrawColorsImp.cpp index 19591eb91c..bf51d29f59 100644 --- a/src/Mod/TechDraw/Gui/DlgPrefsTechDrawColorsImp.cpp +++ b/src/Mod/TechDraw/Gui/DlgPrefsTechDrawColorsImp.cpp @@ -65,6 +65,7 @@ void DlgPrefsTechDrawColorsImp::saveSettings() ui->pcbLightOnDark->onSave(); ui->pcbMonochrome->onSave(); ui->pcbLightTextColor->onSave(); + ui->pcbUnderline->onSave(); } void DlgPrefsTechDrawColorsImp::loadSettings() @@ -90,6 +91,7 @@ void DlgPrefsTechDrawColorsImp::loadSettings() ui->pcbLightOnDark->onRestore(); ui->pcbMonochrome->onRestore(); ui->pcbLightTextColor->onRestore(); + ui->pcbUnderline->onRestore(); } /** diff --git a/src/Mod/TechDraw/Gui/PreferencesGui.cpp b/src/Mod/TechDraw/Gui/PreferencesGui.cpp index d2b1565bf1..a5fa7ba9da 100644 --- a/src/Mod/TechDraw/Gui/PreferencesGui.cpp +++ b/src/Mod/TechDraw/Gui/PreferencesGui.cpp @@ -279,3 +279,16 @@ QColor PreferencesGui::lightenColor(QColor orig) return QColor(red, green, blue, alpha); } + +double PreferencesGui::templateClickBoxSize() +{ + return Preferences::getPreferenceGroup("General")->GetFloat("TemplateDotSize", 5.0); +} + + +QColor PreferencesGui::templateClickBoxColor() +{ + App::Color fcColor; + fcColor.setPackedValue(Preferences::getPreferenceGroup("Colors")->GetUnsigned("TemplateUnderlineColor", 0x0000FFFF)); //#0000FF blue + return fcColor.asValue(); +} diff --git a/src/Mod/TechDraw/Gui/PreferencesGui.h b/src/Mod/TechDraw/Gui/PreferencesGui.h index 6c877bc1c7..5f45b7dc69 100644 --- a/src/Mod/TechDraw/Gui/PreferencesGui.h +++ b/src/Mod/TechDraw/Gui/PreferencesGui.h @@ -78,6 +78,9 @@ static QColor getAccessibleQColor(QColor orig); static QColor lightTextQColor(); static QColor reverseColor(QColor orig); static QColor lightenColor(QColor orig); + +static double templateClickBoxSize(); +static QColor templateClickBoxColor(); }; } //end namespace TechDrawGui diff --git a/src/Mod/TechDraw/Gui/QGISVGTemplate.cpp b/src/Mod/TechDraw/Gui/QGISVGTemplate.cpp index f9ae2eb389..72a1e5b894 100644 --- a/src/Mod/TechDraw/Gui/QGISVGTemplate.cpp +++ b/src/Mod/TechDraw/Gui/QGISVGTemplate.cpp @@ -29,11 +29,14 @@ # include # include # include +# include +# include #endif// #ifndef _PreComp_ #include #include #include +#include #include #include @@ -165,13 +168,10 @@ void QGISVGTemplate::createClickHandles() //TODO: Find location of special fields (first/third angle) and make graphics items for them - double editClickBoxSize = Rez::guiX(Preferences::getPreferenceGroup("General")->GetFloat("TemplateDotSize", 3.0)); + double editClickBoxSize = Rez::guiX(PreferencesGui::templateClickBoxSize()); + QColor editClickBoxColor = PreferencesGui::templateClickBoxColor(); - QColor editClickBoxColor = Qt::green; - editClickBoxColor.setAlpha(128);//semi-transparent - - double width = editClickBoxSize; - double height = editClickBoxSize; + auto textMap = svgTemplate->EditableTexts.getValues(); TechDraw::XMLQuery query(templateDocument); @@ -185,27 +185,47 @@ void QGISVGTemplate::createClickHandles() 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); return true; } + std::string itemText = textMap[Base::Tools::toStdString(name)]; + // default box size + double textHeight = editClickBoxSize; + double charWidth = textHeight * 0.6; + QString style = textElement.attribute(QString::fromUtf8("style")); + if (!style.isEmpty()) { + QRegularExpression rxFontSize(QString::fromUtf8("font-size:([0-9]*\.?[0-9]*)px;")); + QRegularExpression rxAnchor(QString::fromUtf8("text-anchor:(middle);")); + QRegularExpressionMatch match; + + int pos{0}; + pos = style.indexOf(rxFontSize, pos, &match); + if (pos != -1) { + textHeight = match.captured(1).toDouble() * 10.0; + } + charWidth = textHeight * 0.6; + pos = 0; + pos = style.indexOf(rxAnchor, pos, &match); + if (pos != -1) { + x = x - itemText.length() * charWidth / 2; + } + } + double textLength = itemText.length() * charWidth; + textLength = std::max(charWidth, textLength); auto item(new TemplateTextField(this, svgTemplate, name.toStdString())); double pad = 1.0; - item->setRect(x - pad, Rez::guiX(-svgTemplate->getHeight()) + y - height - 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 - item->setPen(myPen); - - QBrush myBrush(editClickBoxColor, Qt::SolidPattern); - item->setBrush(myBrush); + double top = Rez::guiX(-svgTemplate->getHeight()) + y - textHeight - pad; + double bottom = top + textHeight + 2.0 * pad; + double left = x - pad; + item->setRectangle(QRectF(left, top, + textLength + 2.0 * pad, textHeight + 2.0 * pad)); + item->setLine(QPointF( left, bottom), + QPointF(left + textLength + 2.0 * pad, bottom)); + item->setLineColor(editClickBoxColor); item->setZValue(ZVALUE::SVGTEMPLATE + 1); addToGroup(item); diff --git a/src/Mod/TechDraw/Gui/TemplateTextField.cpp b/src/Mod/TechDraw/Gui/TemplateTextField.cpp index 1ada1c0ae7..e21b5eb820 100644 --- a/src/Mod/TechDraw/Gui/TemplateTextField.cpp +++ b/src/Mod/TechDraw/Gui/TemplateTextField.cpp @@ -40,25 +40,34 @@ using namespace TechDrawGui; TemplateTextField::TemplateTextField(QGraphicsItem *parent, TechDraw::DrawTemplate *myTmplte, const std::string &myFieldName) - : QGraphicsRectItem(parent), + : QGraphicsItemGroup(parent), tmplte(myTmplte), fieldNameStr(myFieldName) { setToolTip(QObject::tr("Click to update text")); + m_rect = new QGraphicsRectItem(); + addToGroup(m_rect); + QPen rectPen(Qt::transparent); + QBrush rectBrush(Qt::NoBrush); + m_rect->setPen(rectPen); + m_rect->setBrush(rectBrush); + + m_line = new QGraphicsPathItem(); + addToGroup(m_line); } void TemplateTextField::mousePressEvent(QGraphicsSceneMouseEvent *event) { - if ( tmplte && rect().contains(event->pos()) ) { + if ( tmplte && m_rect->rect().contains(event->pos()) ) { event->accept(); } else { - QGraphicsRectItem::mousePressEvent(event); + QGraphicsItemGroup::mousePressEvent(event); } } void TemplateTextField::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - if ( tmplte && rect().contains(event->pos()) ) { + if ( tmplte && m_rect->rect().contains(event->pos()) ) { event->accept(); DlgTemplateField ui; @@ -77,7 +86,25 @@ void TemplateTextField::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) } } else { - QGraphicsRectItem::mouseReleaseEvent(event); + QGraphicsItemGroup::mouseReleaseEvent(event); } } +void TemplateTextField::setRectangle(QRectF rect) +{ + m_rect->setRect(rect); +} + +void TemplateTextField::setLine(QPointF from, QPointF to) +{ + QPainterPath path(from); + path.lineTo(to); + m_line->setPath(path); +} + +void TemplateTextField::setLineColor(QColor color) +{ + QPen pen(color); + pen.setWidth(5); + m_line->setPen(pen); +} diff --git a/src/Mod/TechDraw/Gui/TemplateTextField.h b/src/Mod/TechDraw/Gui/TemplateTextField.h index 3b880277e0..1971a7dc2b 100644 --- a/src/Mod/TechDraw/Gui/TemplateTextField.h +++ b/src/Mod/TechDraw/Gui/TemplateTextField.h @@ -25,7 +25,9 @@ #include +#include #include +#include namespace TechDraw { class DrawTemplate; @@ -33,12 +35,12 @@ class DrawTemplate; namespace TechDrawGui { - /// QGraphicsRectItem-derived class for the text fields in title blocks + /// QGraphicsItemGroupm-derived class for the text fields in title blocks /*! * Makes an area on the drawing that's clickable, so appropriate * Properties of the template can be modified. */ -class TechDrawGuiExport TemplateTextField : public QGraphicsRectItem +class TechDrawGuiExport TemplateTextField : public QGraphicsItemGroup { public: TemplateTextField(QGraphicsItem *parent, @@ -53,6 +55,10 @@ class TechDrawGuiExport TemplateTextField : public QGraphicsRectItem /// Returns the field name that this TemplateTextField represents std::string fieldName() const { return fieldNameStr; } + void setRectangle(QRectF rect); + void setLine(QPointF from, QPointF to); + void setLineColor(QColor color); + protected: TechDraw::DrawTemplate *tmplte; std::string fieldNameStr; @@ -62,6 +68,9 @@ class TechDrawGuiExport TemplateTextField : public QGraphicsRectItem /// Trigger the dialog for editing template text void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; + + QGraphicsRectItem* m_rect; + QGraphicsPathItem* m_line; }; } // namespace TechDrawGui