PD(hole taskpanel): Add custom widget for font-scaled SVGs

* feat: add custom widget for font scaled svgs
* refactor(PD): hole taskpanel svg tweaks
* fix(PD): build link on windows
This commit is contained in:
Alfredo Monclus
2025-01-24 16:36:42 -03:00
committed by Chris Hennes
parent de7a237a8a
commit 3202dde7ca
13 changed files with 193 additions and 105 deletions

View File

@@ -1138,6 +1138,7 @@ SET(Widget_CPP_SRCS
WorkbenchSelector.cpp
ElideLabel.cpp
ElideCheckBox.cpp
FontScaledSVG.cpp
)
SET(Widget_HPP_SRCS
FileDialog.h
@@ -1161,6 +1162,7 @@ SET(Widget_HPP_SRCS
WorkbenchSelector.h
ElideLabel.h
ElideCheckBox.h
FontScaledSVG.h
)
SET(Widget_SRCS
${Widget_CPP_SRCS}

View File

@@ -34,7 +34,7 @@
#endif
class ElideCheckBox : public QCheckBox {
class GuiExport ElideCheckBox : public QCheckBox {
Q_OBJECT
public:

View File

@@ -33,7 +33,7 @@
#endif
class ElideLabel : public QLabel {
class GuiExport ElideLabel : public QLabel {
Q_OBJECT
public:

65
src/Gui/FontScaledSVG.cpp Normal file
View File

@@ -0,0 +1,65 @@
/***************************************************************************
* Copyright (c) 2025 Alfredo Monclus <alfredomonclus@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., 51 Franklin Street, *
* Fifth Floor, Boston, MA 02110-1301, USA *
* *
***************************************************************************/
// This custom widget scales an svg according to fonts
#include "FontScaledSVG.h"
FontScaledSVG::FontScaledSVG(QWidget *parent)
: QWidget(parent), m_svgRenderer(new QSvgRenderer(this)) {
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
}
void FontScaledSVG::setSvg(const QString &svgPath) {
if (m_svgRenderer->load(svgPath)) {
updateScaledSize();
update();
}
}
void FontScaledSVG::paintEvent(QPaintEvent *event) {
Q_UNUSED(event);
QPainter painter(this);
if (m_svgRenderer->isValid()) {
QRect targetRect(0, 0, width(), height());
m_svgRenderer->render(&painter, targetRect);
}
}
void FontScaledSVG::resizeEvent(QResizeEvent *event) {
Q_UNUSED(event);
updateScaledSize();
}
void FontScaledSVG::updateScaledSize() {
QSize baseSize = m_svgRenderer->defaultSize();
QFontMetrics metrics(font());
qreal spacing = metrics.lineSpacing();
int baseFactor = 18;
qreal scalingFactor = spacing / baseFactor;
QSize targetSize = baseSize * scalingFactor;
setFixedSize(targetSize);
}

53
src/Gui/FontScaledSVG.h Normal file
View File

@@ -0,0 +1,53 @@
/***************************************************************************
* Copyright (c) 2025 Alfredo Monclus <alfredomonclus@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., 51 Franklin Street, *
* Fifth Floor, Boston, MA 02110-1301, USA *
* *
***************************************************************************/
// This custom widget scales an svg according to fonts
#ifndef FONTSCALEDSVG_H
#define FONTSCALEDSVG_H
#include "PreCompiled.h"
#ifndef _PreComp_
#include <QWidget>
#include <QSvgRenderer>
#include <QPainter>
#include <QFontMetrics>
#endif
class GuiExport FontScaledSVG : public QWidget {
Q_OBJECT
public:
explicit FontScaledSVG(QWidget *parent = nullptr);
void setSvg(const QString &svgPath);
protected:
void paintEvent(QPaintEvent *event) override;
void resizeEvent(QResizeEvent *event) override;
private:
QSvgRenderer *m_svgRenderer;
void updateScaledSize();
};
#endif // FONTSCALEDSVG_H

View File

@@ -30,9 +30,9 @@
inkscape:deskcolor="#d1d1d1"
inkscape:document-units="px"
showgrid="false"
inkscape:zoom="3.4166667"
inkscape:cx="45.073171"
inkscape:cy="90"
inkscape:zoom="4.8318964"
inkscape:cx="28.456736"
inkscape:cy="143.52543"
inkscape:window-width="1600"
inkscape:window-height="824"
inkscape:window-x="0"
@@ -109,11 +109,11 @@
id="path1853"
sodipodi:nodetypes="cc" /><path
style="fill:none;stroke:#999999;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:none;stop-color:#000000"
d="m 185.48737,182.40127 h 3.99998"
d="m 185.48737,193.69499 h 5.1905"
id="path582-6"
sodipodi:nodetypes="cc" /><path
style="fill:none;stroke:#999999;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:none;stop-color:#000000"
d="m 142.29522,298.18949 v 8.24723 h 48.46852"
d="m 142.29522,298.18949 v 6.24723 h 48.46852"
id="path586-7"
sodipodi:nodetypes="ccc" /><path
style="fill:#000000;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:2, 8.00001;stroke-dashoffset:0;stop-color:#000000"

Before

Width:  |  Height:  |  Size: 6.4 KiB

After

Width:  |  Height:  |  Size: 6.4 KiB

View File

@@ -30,9 +30,9 @@
inkscape:deskcolor="#d1d1d1"
inkscape:document-units="px"
showgrid="false"
inkscape:zoom="6.8939342"
inkscape:cx="17.189024"
inkscape:cy="101.90118"
inkscape:zoom="4.8747476"
inkscape:cx="15.69312"
inkscape:cy="131.18628"
inkscape:window-width="1600"
inkscape:window-height="824"
inkscape:window-x="0"
@@ -115,11 +115,11 @@
id="path1853"
sodipodi:nodetypes="cc" /><path
style="fill:none;stroke:#999999;stroke-width:0.558085;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:none;stop-color:#000000"
d="m 121.00398,153.26895 h 1.17716"
d="m 121.00398,156.27154 h 1.52752"
id="path582-6"
sodipodi:nodetypes="cc" /><path
style="fill:none;stroke:#999999;stroke-width:0.558085;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:none;stop-color:#000000"
d="m 108.2929,183.90458 v 2.18208 h 14.26387"
d="m 108.2929,183.90458 v 1.65291 h 14.26387"
id="path586-7"
sodipodi:nodetypes="ccc" /></g><path
style="fill:#000000;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:2, 8.00001;stroke-dashoffset:0;stop-color:#000000"

Before

Width:  |  Height:  |  Size: 6.9 KiB

After

Width:  |  Height:  |  Size: 6.9 KiB

View File

@@ -27,9 +27,9 @@
inkscape:deskcolor="#d1d1d1"
inkscape:document-units="px"
showgrid="false"
inkscape:zoom="3.4469671"
inkscape:cx="41.34069"
inkscape:cy="95.591281"
inkscape:zoom="4.8747476"
inkscape:cx="28.411727"
inkscape:cy="145.75114"
inkscape:window-width="1600"
inkscape:window-height="824"
inkscape:window-x="0"
@@ -84,11 +84,11 @@
id="path1853"
sodipodi:nodetypes="cc" /><path
style="fill:none;stroke:#999999;stroke-width:0.558085;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:none;stop-color:#000000"
d="m 121.00398,153.26895 h 1.17716"
d="m 121.00398,156.27154 h 1.52752"
id="path582-6"
sodipodi:nodetypes="cc" /><path
style="fill:none;stroke:#999999;stroke-width:0.55808458;stroke-linecap:round;stroke-linejoin:round;stop-color:#000000;stroke-dasharray:none"
d="m 108.2929,183.90458 v 2.18208 h 14.26387"
style="fill:none;stroke:#999999;stroke-width:0.558085;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:none;stop-color:#000000"
d="m 108.2929,183.90458 v 1.65291 h 14.26387"
id="path586-7"
sodipodi:nodetypes="ccc" /><g
id="g463"

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

View File

@@ -31,8 +31,8 @@
inkscape:document-units="px"
showgrid="false"
inkscape:zoom="3.4469671"
inkscape:cx="53.815425"
inkscape:cy="108.93635"
inkscape:cx="14.65056"
inkscape:cy="109.22646"
inkscape:window-width="1600"
inkscape:window-height="824"
inkscape:window-x="0"
@@ -62,7 +62,31 @@
id="layer1"
transform="translate(-101.48917,-143.06709)"><g
id="g1241"
transform="translate(-0.18870399,0.37210001)"><path
transform="translate(-0.18870399,0.37210001)"><g
id="g1399"
transform="translate(3.99e-6,6.3499137e-5)"><path
style="fill:none;stroke:#999999;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:none;stop-color:#000000"
d="m 114.8787,268.17673 -7.20083,39.51826 h -5"
id="path472"
sodipodi:nodetypes="ccc" /><path
style="fill:none;stroke:#999999;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:none;stop-color:#000000"
d="m 111.18088,264.17674 17.22369,17.22361"
id="path642" /><path
style="fill:none;stroke:#999999;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:none;stop-color:#000000"
d="m 174.68621,264.1767 -17.22369,17.22361"
id="path642-3" /><path
style="fill:none;stroke:#999999;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:none;stop-color:#000000"
id="path1314"
sodipodi:type="arc"
sodipodi:cx="142.29521"
sodipodi:cy="292.68314"
sodipodi:rx="41.997044"
sodipodi:ry="32.843685"
sodipodi:start="4.0142573"
sodipodi:end="5.4105207"
sodipodi:arc-type="arc"
d="m 115.30003,267.52341 a 41.997044,32.843685 0 0 1 53.99036,0"
sodipodi:open="true" /></g><path
style="fill:none;stroke:#999999;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:none;stop-color:#000000"
d="m 102.62606,150.9342 39.66909,-0.003 v 8.7527"
id="path476"
@@ -101,31 +125,7 @@
sodipodi:nodetypes="ccccccc" /><path
style="fill:#000000;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:2, 8.00001;stroke-dashoffset:0;stop-color:#000000"
d="m 125.63827,142.69499 v 180"
id="path4446" /><g
id="g1399"
transform="translate(3.99e-6,6.3499137e-5)"><path
style="fill:none;stroke:#999999;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:none;stop-color:#000000"
d="m 114.8787,268.17673 -7.20083,39.51826 h -5"
id="path472"
sodipodi:nodetypes="ccc" /><path
style="fill:none;stroke:#999999;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:none;stop-color:#000000"
d="m 111.18088,264.17674 17.22369,17.22361"
id="path642" /><path
style="fill:none;stroke:#999999;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:none;stop-color:#000000"
d="m 174.68621,264.1767 -17.22369,17.22361"
id="path642-3" /><path
style="fill:none;stroke:#999999;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:none;stop-color:#000000"
id="path1314"
sodipodi:type="arc"
sodipodi:cx="142.29521"
sodipodi:cy="292.68314"
sodipodi:rx="41.997044"
sodipodi:ry="32.843685"
sodipodi:start="4.0142573"
sodipodi:end="5.4105207"
sodipodi:arc-type="arc"
d="m 115.30003,267.52341 a 41.997044,32.843685 0 0 1 53.99036,0"
sodipodi:open="true" /></g><path
id="path4446" /><path
style="font-variation-settings:normal;fill:none;fill-opacity:1;stroke:#999999;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;stop-color:#000000"
d="m 171.15735,167.3723 3.28302,-3.26708 h 15.84823"
id="path454-6"

Before

Width:  |  Height:  |  Size: 7.0 KiB

After

Width:  |  Height:  |  Size: 7.0 KiB

View File

@@ -31,14 +31,14 @@
inkscape:document-units="px"
showgrid="false"
inkscape:zoom="4.8747476"
inkscape:cx="21.437007"
inkscape:cy="68.003521"
inkscape:cx="-6.2567342"
inkscape:cy="68.20866"
inkscape:window-width="1600"
inkscape:window-height="824"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="g1241"
inkscape:current-layer="g1399"
showguides="true"><sodipodi:guide
position="-4.1420233,93.999969"
orientation="1,0"
@@ -58,7 +58,7 @@
id="g1399"
transform="translate(1.5e-5,6e-5)"><path
style="fill:none;stroke:#999999;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:none;stop-color:#000000"
d="m 114.8787,268.17673 -7.20083,39.51826 h -5"
d="m 114.8787,268.17673 -7.20083,3.51826 h -5"
id="path472"
sodipodi:nodetypes="ccc" /><path
style="fill:none;stroke:#999999;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:none;stop-color:#000000"

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

View File

@@ -30,15 +30,15 @@
inkscape:deskcolor="#d1d1d1"
inkscape:document-units="px"
showgrid="false"
inkscape:zoom="3.4469671"
inkscape:cx="15.520891"
inkscape:cy="46.562672"
inkscape:zoom="4.8747476"
inkscape:cx="26.565478"
inkscape:cy="63.490466"
inkscape:window-width="1600"
inkscape:window-height="824"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="g1241"
inkscape:current-layer="g1399"
showguides="true"><sodipodi:guide
position="-4.1420233,93.999969"
orientation="1,0"
@@ -62,7 +62,7 @@
id="g1399"
transform="translate(1.5e-5,6e-5)"><path
style="fill:none;stroke:#999999;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:none;stop-color:#000000"
d="m 114.8787,268.17673 -7.20083,39.51826 h -5"
d="m 114.8787,268.17673 -7.20083,3.51826 h -5"
id="path472"
sodipodi:nodetypes="ccc" /><path
style="fill:none;stroke:#999999;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:none;stop-color:#000000"

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

View File

@@ -465,8 +465,8 @@ void TaskHoleParameters::setCutDiagram()
baseFileName += "_flat";
}
ui->cutDiagram->setPixmap(
QPixmap(QString::fromUtf8((":images/" + baseFileName + ".svg").c_str()))
ui->cutDiagram->setSvg(
QString::fromUtf8((":images/" + baseFileName + ".svg").c_str())
);
}

View File

@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>391</width>
<height>897</height>
<width>366</width>
<height>844</height>
</rect>
</property>
<property name="sizePolicy">
@@ -239,7 +239,7 @@ the screw's top below the surface</string>
</layout>
</item>
<item>
<widget class="QGroupBox" name="DrillGroupBox">
<widget class="QFrame" name="DrillFrame">
<property name="enabled">
<bool>true</bool>
</property>
@@ -249,9 +249,6 @@ the screw's top below the surface</string>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string/>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<property name="spacing">
<number>6</number>
@@ -323,28 +320,25 @@ account for the depth of blind holes</string>
</layout>
</item>
<item>
<widget class="QLabel" name="cutDiagram">
<widget class="FontScaledSVG" name="cutDiagram" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
<property name="baseSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="Resources/PartDesign.qrc">:/images/hole_counterdrill_angled.svg</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
<item>
@@ -358,22 +352,6 @@ account for the depth of blind holes</string>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<spacer name="verticalSpacerTop">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>8</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_9">
<item>
@@ -497,22 +475,6 @@ account for the depth of blind holes</string>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacerBottom">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>17</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
@@ -1096,6 +1058,12 @@ Note that the calculation can take some time</string>
<extends>QCheckBox</extends>
<header>Gui/ElideCheckBox.h</header>
</customwidget>
<customwidget>
<class>FontScaledSVG</class>
<extends>QWidget</extends>
<header>Gui/FontScaledSVG.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="Resources/PartDesign.qrc"/>