From be3ce13a7c5212e52101d32844292f4c59c4434f Mon Sep 17 00:00:00 2001 From: Alfredo Monclus Date: Mon, 20 Jan 2025 16:50:51 -0300 Subject: [PATCH 1/4] PD(hole taskpanel): Add image-based hole cut panel * feat(PD): hole taskpanel: new image based cut panel * fix(PD): hole taskpanel fix dynamic cut types * refactor(PD): hole taskpanel: renames and vlayouts to keep labels closer * fix(PD): hole diagram tweaks --- src/Gui/CMakeLists.txt | 4 + src/Gui/ElideCheckBox.cpp | 68 + src/Gui/ElideCheckBox.h | 51 + src/Gui/ElideLabel.cpp | 59 + src/Gui/ElideLabel.h | 49 + src/Gui/QuantitySpinBox.cpp | 2 +- src/Mod/PartDesign/App/FeatureHole.h | 4 +- .../PartDesign/Gui/Resources/PartDesign.qrc | 8 + .../images/hole_counterbore_angled.svg | 128 ++ .../images/hole_counterbore_flat.svg | 99 + .../images/hole_counterdrill_angled.svg | 128 ++ .../images/hole_counterdrill_flat.svg | 105 ++ .../images/hole_countersink_angled.svg | 137 ++ .../images/hole_countersink_flat.svg | 113 ++ .../Gui/Resources/images/hole_none_angled.svg | 106 ++ .../Gui/Resources/images/hole_none_flat.svg | 82 + src/Mod/PartDesign/Gui/TaskHoleParameters.cpp | 197 +- src/Mod/PartDesign/Gui/TaskHoleParameters.h | 1 + src/Mod/PartDesign/Gui/TaskHoleParameters.ui | 1589 ++++++++++------- 19 files changed, 2167 insertions(+), 763 deletions(-) create mode 100644 src/Gui/ElideCheckBox.cpp create mode 100644 src/Gui/ElideCheckBox.h create mode 100644 src/Gui/ElideLabel.cpp create mode 100644 src/Gui/ElideLabel.h create mode 100644 src/Mod/PartDesign/Gui/Resources/images/hole_counterbore_angled.svg create mode 100644 src/Mod/PartDesign/Gui/Resources/images/hole_counterbore_flat.svg create mode 100644 src/Mod/PartDesign/Gui/Resources/images/hole_counterdrill_angled.svg create mode 100644 src/Mod/PartDesign/Gui/Resources/images/hole_counterdrill_flat.svg create mode 100644 src/Mod/PartDesign/Gui/Resources/images/hole_countersink_angled.svg create mode 100644 src/Mod/PartDesign/Gui/Resources/images/hole_countersink_flat.svg create mode 100644 src/Mod/PartDesign/Gui/Resources/images/hole_none_angled.svg create mode 100644 src/Mod/PartDesign/Gui/Resources/images/hole_none_flat.svg diff --git a/src/Gui/CMakeLists.txt b/src/Gui/CMakeLists.txt index 412c35ad63..df9d37ee4c 100644 --- a/src/Gui/CMakeLists.txt +++ b/src/Gui/CMakeLists.txt @@ -1136,6 +1136,8 @@ SET(Widget_CPP_SRCS Widgets.cpp Window.cpp WorkbenchSelector.cpp + ElideLabel.cpp + ElideCheckBox.cpp ) SET(Widget_HPP_SRCS FileDialog.h @@ -1157,6 +1159,8 @@ SET(Widget_HPP_SRCS Widgets.h Window.h WorkbenchSelector.h + ElideLabel.h + ElideCheckBox.h ) SET(Widget_SRCS ${Widget_CPP_SRCS} diff --git a/src/Gui/ElideCheckBox.cpp b/src/Gui/ElideCheckBox.cpp new file mode 100644 index 0000000000..33169dbe4a --- /dev/null +++ b/src/Gui/ElideCheckBox.cpp @@ -0,0 +1,68 @@ +/*************************************************************************** + * Copyright (c) 2025 Alfredo Monclus * + * * + * 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 adds the missing ellipsize functionality in QT5 + +#include "ElideCheckBox.h" + +const int CheckboxSpacing = 25; + +ElideCheckBox::ElideCheckBox(QWidget *parent) + : QCheckBox(parent) { +} + +void ElideCheckBox::paintEvent(QPaintEvent *event) { + Q_UNUSED(event); + QStyleOptionButton option; + option.initFrom(this); + option.state = (isChecked() ? QStyle::State_On : QStyle::State_Off) | + (isEnabled() ? QStyle::State_Enabled : QStyle::State_ReadOnly); + + QPainter painter(this); + style()->drawControl(QStyle::CE_CheckBox, &option, &painter, this); + + QRect textRect = option.rect; + int padding = 4; + textRect.setX(textRect.x() + 25); + + QFontMetrics fm(font()); + QString elidedText = fm.elidedText(text(), Qt::ElideRight, textRect.width() - padding); + + painter.setPen(palette().color(QPalette::WindowText)); + painter.drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, elidedText); +} + +QSize ElideCheckBox::sizeHint() const { + QFontMetrics fm(font()); + int width = fm.horizontalAdvance(this->text()) + CheckboxSpacing; + int height = fm.height(); + return QSize(width, height); +} + +QSize ElideCheckBox::minimumSizeHint() const { + QFontMetrics fm(font()); + QString minimumText = QStringLiteral("A..."); + int width = fm.horizontalAdvance(minimumText) + CheckboxSpacing; + int height = fm.height(); + return QSize(width, height); +} + diff --git a/src/Gui/ElideCheckBox.h b/src/Gui/ElideCheckBox.h new file mode 100644 index 0000000000..8a32fb9484 --- /dev/null +++ b/src/Gui/ElideCheckBox.h @@ -0,0 +1,51 @@ +/*************************************************************************** + * Copyright (c) 2025 Alfredo Monclus * + * * + * 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 adds the missing ellipsize functionality in QT5 + +#ifndef ELIDECHECKBOX_H +#define ELIDECHECKBOX_H + +#include "PreCompiled.h" +#ifndef _PreComp_ +#include +#include +#include +#include +#endif + + +class ElideCheckBox : public QCheckBox { + Q_OBJECT + +public: + explicit ElideCheckBox(QWidget *parent = nullptr); + ~ElideCheckBox() override = default; + +protected: + void paintEvent(QPaintEvent *event) override; + QSize sizeHint() const override; + QSize minimumSizeHint() const override; +}; + +#endif // ELIDECHECKBOX_H + diff --git a/src/Gui/ElideLabel.cpp b/src/Gui/ElideLabel.cpp new file mode 100644 index 0000000000..5576db31ae --- /dev/null +++ b/src/Gui/ElideLabel.cpp @@ -0,0 +1,59 @@ +/*************************************************************************** + * Copyright (c) 2025 Alfredo Monclus * + * * + * 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 adds the missing ellipsize functionality in QT5 + +#include "ElideLabel.h" + +ElideLabel::ElideLabel(QWidget *parent) + : QLabel(parent) { +} + +void ElideLabel::paintEvent(QPaintEvent *event) { + Q_UNUSED(event); + QPainter painter(this); + painter.setPen(palette().color(QPalette::WindowText)); + painter.setFont(font()); + + QFontMetrics fm(font()); + QString text = this->text(); + int availableWidth = width() - 4; // Account for padding + + QString elidedText = fm.elidedText(text, Qt::ElideRight, availableWidth); + + painter.drawText(2, 2, availableWidth, height(), Qt::AlignLeft | Qt::AlignVCenter, elidedText); +} + +QSize ElideLabel::sizeHint() const { + QFontMetrics fm(font()); + int width = fm.horizontalAdvance(this->text()); + int height = fm.height(); + return QSize(width, height); +} + +QSize ElideLabel::minimumSizeHint() const { + QFontMetrics fm(font()); + QString minimumText = QStringLiteral("A..."); + int width = fm.horizontalAdvance(minimumText); + int height = fm.height(); + return QSize(width, height); +} diff --git a/src/Gui/ElideLabel.h b/src/Gui/ElideLabel.h new file mode 100644 index 0000000000..a356392c45 --- /dev/null +++ b/src/Gui/ElideLabel.h @@ -0,0 +1,49 @@ +/*************************************************************************** + * Copyright (c) 2025 Alfredo Monclus * + * * + * 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 adds the missing ellipsize functionality in QT5 + +#ifndef ELIDELABEL_H +#define ELIDELABEL_H + +#include "PreCompiled.h" +#ifndef _PreComp_ +#include +#include +#include +#endif + + +class ElideLabel : public QLabel { + Q_OBJECT + +public: + explicit ElideLabel(QWidget *parent = nullptr); + ~ElideLabel() override = default; + +protected: + void paintEvent(QPaintEvent *event) override; + QSize sizeHint() const override; + QSize minimumSizeHint() const override; +}; + +#endif // ELIDELABEL_H diff --git a/src/Gui/QuantitySpinBox.cpp b/src/Gui/QuantitySpinBox.cpp index 1ab6a81e84..204a2534f7 100644 --- a/src/Gui/QuantitySpinBox.cpp +++ b/src/Gui/QuantitySpinBox.cpp @@ -834,7 +834,7 @@ QSize QuantitySpinBox::sizeHintCalculator(int h) const const QFontMetrics fm(fontMetrics()); int w = 0; - constexpr int maxStrLen = 12; + constexpr int maxStrLen = 9; QString s; QString fixedContent = QLatin1String(" "); diff --git a/src/Mod/PartDesign/App/FeatureHole.h b/src/Mod/PartDesign/App/FeatureHole.h index b239f44e1b..1647a9b84b 100644 --- a/src/Mod/PartDesign/App/FeatureHole.h +++ b/src/Mod/PartDesign/App/FeatureHole.h @@ -107,6 +107,8 @@ public: void Restore(Base::XMLReader & reader) override; virtual void updateProps(); + bool isDynamicCounterbore(const std::string &thread, const std::string &holeCutType); + bool isDynamicCountersink(const std::string &thread, const std::string &holeCutType); protected: void onChanged(const App::Property* prop) override; @@ -228,8 +230,6 @@ private: const CutDimensionSet& find_cutDimensionSet(const CutDimensionKey &k); void addCutType(const CutDimensionSet& dimensions); - bool isDynamicCounterbore(const std::string &thread, const std::string &holeCutType); - bool isDynamicCountersink(const std::string &thread, const std::string &holeCutType); void updateHoleCutParams(); std::optional determineDiameter() const; void updateDiameterParam(); diff --git a/src/Mod/PartDesign/Gui/Resources/PartDesign.qrc b/src/Mod/PartDesign/Gui/Resources/PartDesign.qrc index 30e408fb50..c396d0e1b1 100644 --- a/src/Mod/PartDesign/Gui/Resources/PartDesign.qrc +++ b/src/Mod/PartDesign/Gui/Resources/PartDesign.qrc @@ -56,5 +56,13 @@ icons/PartDesign_SubtractiveWedge.svg icons/PartDesign_Thickness.svg icons/PartDesignWorkbench.svg + images/hole_counterbore_angled.svg + images/hole_counterdrill_angled.svg + images/hole_countersink_angled.svg + images/hole_none_angled.svg + images/hole_counterbore_flat.svg + images/hole_counterdrill_flat.svg + images/hole_countersink_flat.svg + images/hole_none_flat.svg diff --git a/src/Mod/PartDesign/Gui/Resources/images/hole_counterbore_angled.svg b/src/Mod/PartDesign/Gui/Resources/images/hole_counterbore_angled.svg new file mode 100644 index 0000000000..3af7cd85c9 --- /dev/null +++ b/src/Mod/PartDesign/Gui/Resources/images/hole_counterbore_angled.svg @@ -0,0 +1,128 @@ + + + +Alfredo MonclusFreeCAD LGPL2+FreeCAD diff --git a/src/Mod/PartDesign/Gui/Resources/images/hole_counterbore_flat.svg b/src/Mod/PartDesign/Gui/Resources/images/hole_counterbore_flat.svg new file mode 100644 index 0000000000..658e019a88 --- /dev/null +++ b/src/Mod/PartDesign/Gui/Resources/images/hole_counterbore_flat.svg @@ -0,0 +1,99 @@ + + + + diff --git a/src/Mod/PartDesign/Gui/Resources/images/hole_counterdrill_angled.svg b/src/Mod/PartDesign/Gui/Resources/images/hole_counterdrill_angled.svg new file mode 100644 index 0000000000..35a15ef4a0 --- /dev/null +++ b/src/Mod/PartDesign/Gui/Resources/images/hole_counterdrill_angled.svg @@ -0,0 +1,128 @@ + + + +Alfredo MonclusFreeCAD LGPL2+FreeCAD diff --git a/src/Mod/PartDesign/Gui/Resources/images/hole_counterdrill_flat.svg b/src/Mod/PartDesign/Gui/Resources/images/hole_counterdrill_flat.svg new file mode 100644 index 0000000000..83eb5a6c97 --- /dev/null +++ b/src/Mod/PartDesign/Gui/Resources/images/hole_counterdrill_flat.svg @@ -0,0 +1,105 @@ + + + +Alfredo MonclusFreeCAD LGPL2+FreeCAD diff --git a/src/Mod/PartDesign/Gui/Resources/images/hole_countersink_angled.svg b/src/Mod/PartDesign/Gui/Resources/images/hole_countersink_angled.svg new file mode 100644 index 0000000000..cde675a7cb --- /dev/null +++ b/src/Mod/PartDesign/Gui/Resources/images/hole_countersink_angled.svg @@ -0,0 +1,137 @@ + + + +Alfredo MonclusFreeCAD LGPL2+FreeCAD diff --git a/src/Mod/PartDesign/Gui/Resources/images/hole_countersink_flat.svg b/src/Mod/PartDesign/Gui/Resources/images/hole_countersink_flat.svg new file mode 100644 index 0000000000..9be9f59f9b --- /dev/null +++ b/src/Mod/PartDesign/Gui/Resources/images/hole_countersink_flat.svg @@ -0,0 +1,113 @@ + + + +Alfredo MonclusFreeCAD LGPL2+FreeCAD diff --git a/src/Mod/PartDesign/Gui/Resources/images/hole_none_angled.svg b/src/Mod/PartDesign/Gui/Resources/images/hole_none_angled.svg new file mode 100644 index 0000000000..5c44120455 --- /dev/null +++ b/src/Mod/PartDesign/Gui/Resources/images/hole_none_angled.svg @@ -0,0 +1,106 @@ + + + +Alfredo MonclusFreeCAD LGPL2+FreeCAD diff --git a/src/Mod/PartDesign/Gui/Resources/images/hole_none_flat.svg b/src/Mod/PartDesign/Gui/Resources/images/hole_none_flat.svg new file mode 100644 index 0000000000..b543ab3dad --- /dev/null +++ b/src/Mod/PartDesign/Gui/Resources/images/hole_none_flat.svg @@ -0,0 +1,82 @@ + + + +Alfredo MonclusFreeCAD LGPL2+FreeCAD diff --git a/src/Mod/PartDesign/Gui/TaskHoleParameters.cpp b/src/Mod/PartDesign/Gui/TaskHoleParameters.cpp index 1844cec248..247895e13a 100644 --- a/src/Mod/PartDesign/Gui/TaskHoleParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskHoleParameters.cpp @@ -61,15 +61,15 @@ TaskHoleParameters::TaskHoleParameters(ViewProviderHole* HoleView, QWidget* pare QMetaObject::connectSlotsByName(this); ui->ThreadType->addItem(tr("None"), QByteArray("None")); - ui->ThreadType->addItem(tr("ISO metric regular profile"), QByteArray("ISO")); - ui->ThreadType->addItem(tr("ISO metric fine profile"), QByteArray("ISO")); - ui->ThreadType->addItem(tr("UTS coarse profile"), QByteArray("UTS")); - ui->ThreadType->addItem(tr("UTS fine profile"), QByteArray("UTS")); - ui->ThreadType->addItem(tr("UTS extra fine profile"), QByteArray("UTS")); - ui->ThreadType->addItem(tr("ANSI pipe profile"), QByteArray("NPT")); - ui->ThreadType->addItem(tr("BSP pipe profile"), QByteArray("BSP")); - ui->ThreadType->addItem(tr("BSW whitworth profile"), QByteArray("BSW")); - ui->ThreadType->addItem(tr("BSF whitworth fine profile"), QByteArray("BSF")); + ui->ThreadType->addItem(tr("ISO metric regular"), QByteArray("ISO")); + ui->ThreadType->addItem(tr("ISO metric fine"), QByteArray("ISO")); + ui->ThreadType->addItem(tr("UTS coarse"), QByteArray("UTS")); + ui->ThreadType->addItem(tr("UTS fine"), QByteArray("UTS")); + ui->ThreadType->addItem(tr("UTS extra fine"), QByteArray("UTS")); + ui->ThreadType->addItem(tr("ANSI pipes"), QByteArray("None")); + ui->ThreadType->addItem(tr("ISO/BSP pipes"), QByteArray("None")); + ui->ThreadType->addItem(tr("BSW whitworth"), QByteArray("BS")); + ui->ThreadType->addItem(tr("BSF whitworth fine"), QByteArray("BS")); // read values from the hole properties auto pcHole = getObject(); @@ -129,10 +129,12 @@ TaskHoleParameters::TaskHoleParameters(ViewProviderHole* HoleView, QWidget* pare ui->HoleCutDiameter->setHidden(isNotCut); ui->HoleCutDepth->setHidden(isNotCut); ui->HoleCutCountersinkAngle->setHidden(isNotCut); - ui->HoleCutCustomValues->setHidden(isNotCut); ui->HoleCutCustomValues->setChecked(pcHole->HoleCutCustomValues.getValue()); - ui->HoleCutCustomValues->setDisabled(pcHole->HoleCutCustomValues.isReadOnly()); + ui->HoleCutCustomValues->setHidden( + pcHole->HoleCutType.getValue() < 5 + || pcHole->HoleCutCustomValues.isReadOnly() + ); // HoleCutDiameter must not be smaller or equal than the Diameter ui->HoleCutDiameter->setMinimum(pcHole->Diameter.getValue() + 0.1); ui->HoleCutDiameter->setValue(pcHole->HoleCutDiameter.getValue()); @@ -154,11 +156,9 @@ TaskHoleParameters::TaskHoleParameters(ViewProviderHole* HoleView, QWidget* pare bool isFlatDrill = pcHole->DrillPoint.getValue() == 0L; bool depthIsDimension = std::string(pcHole->DepthType.getValueAsString()) == "Dimension"; - ui->DrillGroupBox->setVisible(depthIsDimension); - ui->drillPointFlat->setChecked(isFlatDrill); - ui->drillPointAngled->setChecked(!isFlatDrill); - ui->DrillPointAngle->setEnabled(!isFlatDrill); - ui->DrillForDepth->setVisible(!isFlatDrill); + ui->DrillPointAngled->setChecked(!isFlatDrill && depthIsDimension); + ui->DrillPointAngle->setEnabled(!isFlatDrill && depthIsDimension); + ui->DrillForDepth->setEnabled(!isFlatDrill && depthIsDimension); ui->Tapered->setChecked(pcHole->Tapered.getValue()); // Angle is only enabled (sensible) if tapered @@ -184,11 +184,14 @@ TaskHoleParameters::TaskHoleParameters(ViewProviderHole* HoleView, QWidget* pare ui->UpdateView->setChecked(false); ui->UpdateView->setVisible(isThreaded && isModeled); - ui->Depth->setEnabled(std::string(pcHole->DepthType.getValueAsString()) == "Dimension"); + ui->Depth->setEnabled(depthIsDimension); ui->ThreadDepthWidget->setVisible(isThreaded && isModeled); - ui->ThreadDepth->setEnabled(ui->Threaded->isChecked() && ui->ModelThread->isChecked() - && std::string(pcHole->ThreadDepthType.getValueAsString()) - == "Dimension"); + + ui->ThreadDepthDimensionWidget->setVisible( + std::string(pcHole->ThreadDepthType.getValueAsString()) == "Dimension" + ); + + setCutPixmap(); // clang-format off connect(ui->Threaded, &QCheckBox::clicked, @@ -221,9 +224,7 @@ TaskHoleParameters::TaskHoleParameters(ViewProviderHole* HoleView, QWidget* pare this, &TaskHoleParameters::depthChanged); connect(ui->Depth, qOverload(&Gui::QuantitySpinBox::valueChanged), this, &TaskHoleParameters::depthValueChanged); - connect(ui->drillPointFlat, &QRadioButton::clicked, - this, &TaskHoleParameters::drillPointChanged); - connect(ui->drillPointAngled, &QRadioButton::clicked, + connect(ui->DrillPointAngled, &QCheckBox::toggled, this, &TaskHoleParameters::drillPointChanged); connect(ui->DrillPointAngle, qOverload(&Gui::QuantitySpinBox::valueChanged), this, &TaskHoleParameters::drillPointAngledValueChanged); @@ -306,7 +307,7 @@ void TaskHoleParameters::modelThreadChanged() ui->CustomThreadClearance->setEnabled(ui->UseCustomThreadClearance->isChecked()); ui->ThreadDepthWidget->setVisible(isThreaded && isModeled); - ui->ThreadDepth->setEnabled( + ui->ThreadDepthDimensionWidget->setVisible( std::string(pcHole->ThreadDepthType.getValueAsString()) == "Dimension" ); @@ -323,7 +324,7 @@ void TaskHoleParameters::threadDepthTypeChanged(int index) { if (auto hole = getObject()) { hole->ThreadDepthType.setValue(index); - ui->ThreadDepth->setEnabled(index == 1); + ui->ThreadDepthDimensionWidget->setVisible(index == 1); ui->ThreadDepth->setValue(hole->ThreadDepth.getValue()); recomputeFeature(); } @@ -333,6 +334,7 @@ void TaskHoleParameters::threadDepthChanged(double value) { if (auto hole = getObject()) { hole->ThreadDepth.setValue(value); + setCutPixmap(); recomputeFeature(); } } @@ -388,7 +390,7 @@ void TaskHoleParameters::holeCutTypeChanged(int index) recomputeFeature(); // apply the result to the widgets - ui->HoleCutCustomValues->setDisabled(hole->HoleCutCustomValues.isReadOnly()); + ui->HoleCutCustomValues->setHidden(hole->HoleCutCustomValues.isReadOnly()); ui->HoleCutCustomValues->setChecked(hole->HoleCutCustomValues.getValue()); // HoleCutCustomValues is only enabled for screw definitions @@ -403,21 +405,23 @@ void TaskHoleParameters::holeCutTypeChanged(int index) ui->HoleCutDiameter->setHidden(isNotCut); ui->HoleCutDepth->setHidden(isNotCut); ui->HoleCutCountersinkAngle->setHidden(isNotCut); - ui->HoleCutCustomValues->setHidden(isNotCut); if (HoleCutTypeString == "None" || HoleCutTypeString == "Counterbore" || HoleCutTypeString == "Countersink" || HoleCutTypeString == "Counterdrill") { - ui->HoleCutCustomValues->setEnabled(false); + ui->HoleCutCustomValues->setVisible(false); if (HoleCutTypeString == "None") { ui->HoleCutDiameter->setEnabled(false); ui->HoleCutDepth->setEnabled(false); - ui->HoleCutCountersinkAngle->setEnabled(false); + ui->labelHoleCutCountersinkAngle->setVisible(false); + ui->HoleCutCountersinkAngle->setVisible(false); } if (HoleCutTypeString == "Counterbore") { - ui->HoleCutCountersinkAngle->setEnabled(false); + ui->labelHoleCutCountersinkAngle->setVisible(false); + ui->HoleCutCountersinkAngle->setVisible(false); } if (HoleCutTypeString == "Countersink") { - ui->HoleCutCountersinkAngle->setEnabled(true); + ui->labelHoleCutCountersinkAngle->setVisible(true); + ui->HoleCutCountersinkAngle->setVisible(true); } } else { // screw definition @@ -427,14 +431,86 @@ void TaskHoleParameters::holeCutTypeChanged(int index) ui->HoleCutDiameter->setEnabled(true); ui->HoleCutDepth->setEnabled(true); if (!hole->HoleCutCountersinkAngle.isReadOnly()) { + ui->HoleCutCountersinkAngle->setVisible(true); + ui->labelHoleCutCountersinkAngle->setVisible(true); ui->HoleCutCountersinkAngle->setEnabled(true); } } else { - ui->HoleCutCustomValues->setEnabled(true); + ui->HoleCutCustomValues->setVisible(true); ui->HoleCutDiameter->setEnabled(false); ui->HoleCutDepth->setEnabled(false); ui->HoleCutCountersinkAngle->setEnabled(false); + ui->labelHoleCutCountersinkAngle->setVisible(true); + ui->HoleCutCountersinkAngle->setVisible(true); + } + } + setCutPixmap(); +} + +void TaskHoleParameters::setCutPixmap() +{ + auto hole = getObject(); + const std::string holeCutTypeString = hole->HoleCutType.getValueAsString(); + const std::string threadTypeString = hole->ThreadType.getValueAsString(); + bool isAngled = ( + std::string(hole->DepthType.getValueAsString()) == "Dimension" + && ui->DrillPointAngled->isChecked() + ); + bool isCountersink = ( + holeCutTypeString == "Countersink" + || hole->isDynamicCountersink(threadTypeString, holeCutTypeString) + ); + bool isCounterbore = ( + holeCutTypeString == "Counterbore" + || hole->isDynamicCounterbore(threadTypeString, holeCutTypeString) + ); + bool isCounterdrill = ( + holeCutTypeString == "Counterdrill" + ); + + if (isCounterbore) { + if (isAngled) { + ui->cutDiagram->setPixmap( + QPixmap(QString::fromUtf8(":/images/hole_counterbore_angled.svg")) + ); + } else { + ui->cutDiagram->setPixmap( + QPixmap(QString::fromUtf8(":/images/hole_counterbore_flat.svg")) + ); + } + } + else if (isCountersink) { + if (isAngled) { + ui->cutDiagram->setPixmap( + QPixmap(QString::fromUtf8(":/images/hole_countersink_angled.svg")) + ); + } else { + ui->cutDiagram->setPixmap( + QPixmap(QString::fromUtf8(":/images/hole_countersink_flat.svg")) + ); + } + } + else if (isCounterdrill) { + if (isAngled) { + ui->cutDiagram->setPixmap( + QPixmap(QString::fromUtf8(":/images/hole_counterdrill_angled.svg")) + ); + } else { + ui->cutDiagram->setPixmap( + QPixmap(QString::fromUtf8(":/images/hole_counterdrill_flat.svg")) + ); + } + } + else { + if (isAngled) { + ui->cutDiagram->setPixmap( + QPixmap(QString::fromUtf8(":/images/hole_none_angled.svg")) + ); + } else { + ui->cutDiagram->setPixmap( + QPixmap(QString::fromUtf8(":/images/hole_none_flat.svg")) + ); } } } @@ -514,17 +590,16 @@ void TaskHoleParameters::depthChanged(int index) if (!hole) { return; } - hole->DepthType.setValue(index); - + recomputeFeature(); + // enabling must be handled after recompute bool DepthisDimension = ( std::string(hole->DepthType.getValueAsString()) == "Dimension" ); - - ui->DrillGroupBox->setVisible(DepthisDimension); - recomputeFeature(); - // enabling must be handled after recompute - ui->ThreadDepth->setEnabled(DepthisDimension); + ui->DrillPointAngled->setEnabled(DepthisDimension); + ui->DrillPointAngle->setEnabled(DepthisDimension); + ui->DrillForDepth->setEnabled(DepthisDimension); + setCutPixmap(); } void TaskHoleParameters::depthValueChanged(double value) @@ -538,17 +613,11 @@ void TaskHoleParameters::depthValueChanged(double value) void TaskHoleParameters::drillPointChanged() { if (auto hole = getObject()) { - if (sender() == ui->drillPointFlat) { - hole->DrillPoint.setValue(0L); - ui->DrillForDepth->setVisible(false); - } - else if (sender() == ui->drillPointAngled) { - hole->DrillPoint.setValue(1L); - ui->DrillForDepth->setVisible(true); - } - else { - assert(0); - } + bool angled = ui->DrillPointAngled->isChecked(); + hole->DrillPoint.setValue(angled); + ui->DrillPointAngle->setEnabled(angled); + ui->DrillForDepth->setEnabled(angled); + setCutPixmap(); recomputeFeature(); } } @@ -932,21 +1001,14 @@ void TaskHoleParameters::changedObject(const App::Document&, const App::Property ui->Depth->setDisabled(ro); } else if (&Prop == &hole->DrillPoint) { - ui->drillPointFlat->setEnabled(true); - ui->drillPointAngled->setEnabled(true); std::string drillPoint(hole->DrillPoint.getValueAsString()); - if (drillPoint == "Flat" && !ui->drillPointFlat->isChecked()) { - ui->drillPointFlat->blockSignals(true); - ui->drillPointFlat->setChecked(true); - ui->drillPointFlat->blockSignals(false); + ui->DrillPointAngled->setEnabled(true); + if (ui->DrillPointAngled->isChecked() ^ (drillPoint == "Angled")) { + ui->DrillPointAngled->blockSignals(true); + ui->DrillPointAngled->setChecked(drillPoint == "Angled"); + ui->DrillPointAngled->blockSignals(false); } - if (drillPoint == "Angled" && !ui->drillPointAngled->isChecked()) { - ui->drillPointAngled->blockSignals(true); - ui->drillPointAngled->setChecked(true); - ui->drillPointAngled->blockSignals(false); - } - ui->drillPointFlat->setDisabled(ro); - ui->drillPointAngled->setDisabled(ro); + ui->DrillPointAngled->setDisabled(ro); } else if (&Prop == &hole->DrillPointAngle) { ui->DrillPointAngle->setEnabled(true); @@ -1131,14 +1193,11 @@ Base::Quantity TaskHoleParameters::getDepth() const long TaskHoleParameters::getDrillPoint() const { - if (ui->drillPointFlat->isChecked()) { - return 0; - } - if (ui->drillPointAngled->isChecked()) { + + if (ui->DrillPointAngled->isChecked()) { return 1; } - assert(0); - return -1; // to avoid a compiler warning + return 0; } Base::Quantity TaskHoleParameters::getDrillPointAngle() const diff --git a/src/Mod/PartDesign/Gui/TaskHoleParameters.h b/src/Mod/PartDesign/Gui/TaskHoleParameters.h index fd2862d9c2..f9fd063311 100644 --- a/src/Mod/PartDesign/Gui/TaskHoleParameters.h +++ b/src/Mod/PartDesign/Gui/TaskHoleParameters.h @@ -108,6 +108,7 @@ private Q_SLOTS: void updateViewChanged(bool isChecked); void threadDepthTypeChanged(int index); void threadDepthChanged(double value); + void setCutPixmap(); private: class Observer : public App::DocumentObserver { diff --git a/src/Mod/PartDesign/Gui/TaskHoleParameters.ui b/src/Mod/PartDesign/Gui/TaskHoleParameters.ui index c0667192c0..52b761daba 100644 --- a/src/Mod/PartDesign/Gui/TaskHoleParameters.ui +++ b/src/Mod/PartDesign/Gui/TaskHoleParameters.ui @@ -6,12 +6,12 @@ 0 0 - 432 - 776 + 391 + 897 - + 0 0 @@ -19,650 +19,406 @@ Task Hole Parameters - - - - - + + + 3 + + + 6 + + + 3 + + + 6 + + + + + 10 + + + - + 0 0 - - Taper angle for the hole -90 degree: straight hole -under 90: smaller hole radius at the bottom -over 90: larger hole radius at the bottom + + Qt::LeftToRight - - false - - - 0.000000000000000 - - - deg + + Depth Type - - - - - - - 0 - 0 - - - - Size - - - - - - + - + + 0 + 0 + + + + Qt::LeftToRight + + + + Dimension + + + + + Through all + + + + + + + + + 0 + 0 + + + + Qt::RightToLeft + + + Head Type + + + + + + + 0 0 - Hole diameter - - - false - - - 0.000000000000000 - - - mm - - - - - - - - - - 0 - 0 - - - - Reverses the hole direction - - - Reversed - - - - - - - - 0 - 0 - - - - Tapered - - - - - - - - - - - - 0 - 0 - - - - Depth - - - - - - - - 0 - 0 - - - - - Dimension - - - - - Through all - - - - - - - - - - - 0 - 0 - - - - false - - - mm - - - - - - - - 0 - 0 - - - - Diameter - - - - - - - - 0 - 0 - - - - - - - - - 0 - 0 - - - - Whether the hole gets a thread - - - Threaded + Cut type for screw heads - - - - + + + + + 0 + 0 + + + + Check to override the values predefined by the 'Type' + + + Qt::LeftToRight + + + Custom head values - - - - - - 0 - 0 - - - - Hole Cut Type - - - - - - - - 0 - 0 - - - - Cut type for screw heads - - - - - - - - 0 - 0 - - - - Diameter - - - - - - - - 0 - 0 - - - - Qt::NoContextMenu - - - false - - - 0.000000000000000 - - - 0.100000000000000 - - - mm - - - - - - - - 0 - 0 - - - - Depth - - - - - - - - 0 - 0 - - - - For countersinks this is the depth of -the screw's top below the surface - - - false - - - 0.000000000000000 - - - 0.100000000000000 - - - mm - - - - - - - - 0 - 0 - - - - Countersink angle - - - - - - - - 0 - 0 - - - - false - - - 0.000000000000000 - - - deg - - - - - - - - 0 - 0 - - - - Check to override the values predefined by the 'Type' - - - Custom values - - - - - - - - + + + + 0 - - - - - - - - 0 - 0 - - - - Drill Point - - - - - - - - 0 - 0 - - - - Flat - - - drillPointButtonGroup - - - - - - - - 0 - 0 - - - - Angled - - - drillPointButtonGroup - - - - - - - - 0 - 0 - - - - false - - - 0.000000000000000 - - - deg - - - - - - - - - - 0 - 0 - - - - The size of the drill point will be taken into -account for the depth of blind holes - - - Take into account for depth - - - - - - - - - - + + 0 - - - 6 - - - 6 - - - 6 - - - 6 - - - 6 - - - - - - 0 + + + + 0 + + + 0 + + + + + 10 0 - - 0 - 0 - - - - 0 - 0 - - - - Class - - + + + + + + 0 + 0 + + + + Head Diameter + + + + + + + + 0 + 0 + + + + Qt::NoContextMenu + + + false + + + 0.000000000000000 + + + 0.100000000000000 + + + mm + + + + - + + + + + + 0 + 0 + + + + Head Depth + + + + + + + + 0 + 0 + + + + For countersinks this is the depth of +the screw's top below the surface + + + false + + + 0.000000000000000 + + + 0.100000000000000 + + + mm + + + + + + + + + true + - + 0 0 - - Tolerance class for threaded holes according to hole profile + + + + + 6 + + + 0 + + + 6 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + Drill angle + + + + + + + + 0 + 0 + + + + false + + + 0.000000000000000 + + + deg + + + + + + + + 0 + 0 + + + + The size of the drill point will be taken into +account for the depth of blind holes + + + Include in depth + + + + - - - - - - - - - 0 - 0 - - - - Direction - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - - - - - 0 - 0 - - - - Left hand - - - directionButtonGroup - - - - - - - - 0 - 0 - - - - - - - Right hand - - - directionButtonGroup - - - - - - - - - 0 - - - 0 - - - - - - 0 - 0 - - - - Whether the hole gets a modelled thread - - - Model Thread - - - - - - - true - - - - 0 - 0 - - - - Live update of changes to the thread -Note that the calculation can take some time - - - Update thread view - - - - - - - - - - 6 + + + + + + 0 + 0 + - - 0 + + + 0 + 0 + + + + + + + :/images/hole_counterdrill_angled.svg + + + true + + + + + + + 8 0 - - 0 - 0 - - - 6 + + + Qt::Vertical - - 0 + + QSizePolicy::Fixed + + + 20 + 8 + + + + + + - + - + + 0 + 0 + + + + Countersink angle + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + false + + + 0.000000000000000 + + + deg + + + + + + + + + + + 0 0 @@ -670,41 +426,15 @@ Note that the calculation can take some time Depth - - - - - - - 0 - 0 - + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - Hole depth - - - - - Dimension - - - - - Tapped (DIN76) - - - - - - - + - + 0 0 @@ -719,107 +449,218 @@ Note that the calculation can take some time - - - - - - - - 6 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 0 - 0 - - - - Customize thread clearance - - - Custom Clearance - - + + + + + + 0 + 0 + + + + Diameter + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + Hole diameter + + + false + + + 0.000000000000000 + + + mm + + + + - - - - 0 - 0 - + + + Qt::Vertical - - Custom Thread clearance value + + QSizePolicy::Fixed - - false + + + 20 + 17 + - - 0.100000000000000 - - - mm - - + - - - - - - - + + + - + + + 0 + + + + + + 0 + 0 + + + + Reverses the hole direction + + + Switch direction + + + + + + + + 0 + 0 + + + + Qt::LeftToRight + + + Tapered + + + + + + + + 0 + 0 + + + + Taper angle for the hole +90 degree: straight hole +under 90: smaller hole radius at the bottom +over 90: larger hole radius at the bottom + + + false + + + 0.000000000000000 + + + deg + + + + + + + + + + + 0 + + + - + + 0 + 0 + + + + + + + + 0 0 - Profile + Size - + - + 0 0 + + + + + 0 + 0 + + + + Standard + + + - - + + - + 0 0 - + + Whether the hole gets a thread + + + Threaded + + + + + + + + 0 + 0 + + + 0 @@ -833,9 +674,9 @@ Note that the calculation can take some time 0 - + - + 0 0 @@ -877,6 +718,361 @@ Only available for holes without thread + + + + + 0 + 0 + + + + false + + + + + + + + + + 6 + + + 6 + + + 6 + + + 6 + + + 6 + + + + + 0 + + + + + + 0 + 0 + + + + Tolerance class for threaded holes according to hole profile + + + + + + + + 0 + 0 + + + + Class + + + + + + + + + 0 + + + + + + 0 + 0 + + + + Direction + + + Qt::AlignHCenter|Qt::AlignTop + + + + + + + 0 + + + + + + 0 + 0 + + + + + + + Right hand + + + directionButtonGroup + + + + + + + + 0 + 0 + + + + Left hand + + + directionButtonGroup + + + + + + + + + + + 0 + + + 0 + + + + + + 0 + 0 + + + + Whether the hole gets a modelled thread + + + Model Thread + + + + + + + true + + + + 0 + 0 + + + + Live update of changes to the thread +Note that the calculation can take some time + + + Update thread view + + + + + + + + + + 0 + 0 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 6 + + + 0 + + + + + + 0 + 0 + + + + Thread Depth Type + + + + + + + + 0 + 0 + + + + + Hole depth + + + + + Dimension + + + + + Tapped (DIN76) + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Thread Depth + + + + + + + + 0 + 0 + + + + false + + + mm + + + + + + + + + + + + + + 6 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + Customize thread clearance + + + Qt::LeftToRight + + + Custom Clearance + + + + + + + + 0 + 0 + + + + Custom Thread clearance value + + + false + + + 0.100000000000000 + + + mm + + + + + + + + + @@ -890,11 +1086,22 @@ Only available for holes without thread Gui::QuantitySpinBox
Gui/PrefWidgets.h
+ + ElideLabel + QLabel +
Gui/ElideLabel.h
+
+ + ElideCheckBox + QCheckBox +
Gui/ElideCheckBox.h
+
- + + + - From de7a237a8aa3b10c98b60d8d7db26a97de8f7a96 Mon Sep 17 00:00:00 2001 From: Alfredo Monclus Date: Wed, 22 Jan 2025 23:19:12 -0300 Subject: [PATCH 2/4] PD(hole taskpanel): Include depth on diagram feat(PD): hole diagram add include depth refactor(PD): hole taskpanel: images add background --- .../PartDesign/Gui/Resources/PartDesign.qrc | 4 + .../images/hole_counterbore_angled.svg | 135 ++++++++-------- .../hole_counterbore_angled_included.svg | 129 ++++++++++++++++ .../images/hole_counterbore_flat.svg | 34 +++-- .../images/hole_counterdrill_angled.svg | 69 ++++----- .../hole_counterdrill_angled_included.svg | 129 ++++++++++++++++ .../images/hole_counterdrill_flat.svg | 21 ++- .../images/hole_countersink_angled.svg | 23 ++- .../hole_countersink_angled_included.svg | 138 +++++++++++++++++ .../images/hole_countersink_flat.svg | 29 ++-- .../Gui/Resources/images/hole_none_angled.svg | 60 ++++---- .../images/hole_none_angled_included.svg | 110 +++++++++++++ .../Gui/Resources/images/hole_none_flat.svg | 10 +- src/Mod/PartDesign/Gui/TaskHoleParameters.cpp | 144 ++++++------------ src/Mod/PartDesign/Gui/TaskHoleParameters.h | 2 +- 15 files changed, 745 insertions(+), 292 deletions(-) create mode 100644 src/Mod/PartDesign/Gui/Resources/images/hole_counterbore_angled_included.svg create mode 100644 src/Mod/PartDesign/Gui/Resources/images/hole_counterdrill_angled_included.svg create mode 100644 src/Mod/PartDesign/Gui/Resources/images/hole_countersink_angled_included.svg create mode 100644 src/Mod/PartDesign/Gui/Resources/images/hole_none_angled_included.svg diff --git a/src/Mod/PartDesign/Gui/Resources/PartDesign.qrc b/src/Mod/PartDesign/Gui/Resources/PartDesign.qrc index c396d0e1b1..50e86ec8d7 100644 --- a/src/Mod/PartDesign/Gui/Resources/PartDesign.qrc +++ b/src/Mod/PartDesign/Gui/Resources/PartDesign.qrc @@ -57,9 +57,13 @@ icons/PartDesign_Thickness.svg icons/PartDesignWorkbench.svg images/hole_counterbore_angled.svg + images/hole_counterbore_angled_included.svg images/hole_counterdrill_angled.svg + images/hole_counterdrill_angled_included.svg images/hole_countersink_angled.svg + images/hole_countersink_angled_included.svg images/hole_none_angled.svg + images/hole_none_angled_included.svg images/hole_counterbore_flat.svg images/hole_counterdrill_flat.svg images/hole_countersink_flat.svg diff --git a/src/Mod/PartDesign/Gui/Resources/images/hole_counterbore_angled.svg b/src/Mod/PartDesign/Gui/Resources/images/hole_counterbore_angled.svg index 3af7cd85c9..1202071514 100644 --- a/src/Mod/PartDesign/Gui/Resources/images/hole_counterbore_angled.svg +++ b/src/Mod/PartDesign/Gui/Resources/images/hole_counterbore_angled.svg @@ -21,24 +21,24 @@ xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/"> + + +Alfredo MonclusFreeCAD LGPL2+FreeCAD diff --git a/src/Mod/PartDesign/Gui/Resources/images/hole_counterbore_flat.svg b/src/Mod/PartDesign/Gui/Resources/images/hole_counterbore_flat.svg index 658e019a88..440eb10f65 100644 --- a/src/Mod/PartDesign/Gui/Resources/images/hole_counterbore_flat.svg +++ b/src/Mod/PartDesign/Gui/Resources/images/hole_counterbore_flat.svg @@ -18,18 +18,18 @@ xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> diff --git a/src/Mod/PartDesign/Gui/Resources/images/hole_counterdrill_angled.svg b/src/Mod/PartDesign/Gui/Resources/images/hole_counterdrill_angled.svg index 35a15ef4a0..85093f317b 100644 --- a/src/Mod/PartDesign/Gui/Resources/images/hole_counterdrill_angled.svg +++ b/src/Mod/PartDesign/Gui/Resources/images/hole_counterdrill_angled.svg @@ -21,18 +21,18 @@ xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">Alfredo MonclusFreeCAD LGPL2+FreeCAD diff --git a/src/Mod/PartDesign/Gui/Resources/images/hole_counterdrill_angled_included.svg b/src/Mod/PartDesign/Gui/Resources/images/hole_counterdrill_angled_included.svg new file mode 100644 index 0000000000..e6e3b847bb --- /dev/null +++ b/src/Mod/PartDesign/Gui/Resources/images/hole_counterdrill_angled_included.svg @@ -0,0 +1,129 @@ + + + +Alfredo MonclusFreeCAD LGPL2+FreeCAD diff --git a/src/Mod/PartDesign/Gui/Resources/images/hole_counterdrill_flat.svg b/src/Mod/PartDesign/Gui/Resources/images/hole_counterdrill_flat.svg index 83eb5a6c97..2c2202e673 100644 --- a/src/Mod/PartDesign/Gui/Resources/images/hole_counterdrill_flat.svg +++ b/src/Mod/PartDesign/Gui/Resources/images/hole_counterdrill_flat.svg @@ -21,18 +21,18 @@ xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">Alfredo MonclusFreeCAD LGPL2+FreeCAD diff --git a/src/Mod/PartDesign/Gui/Resources/images/hole_countersink_angled_included.svg b/src/Mod/PartDesign/Gui/Resources/images/hole_countersink_angled_included.svg new file mode 100644 index 0000000000..5ee7c6e9a6 --- /dev/null +++ b/src/Mod/PartDesign/Gui/Resources/images/hole_countersink_angled_included.svg @@ -0,0 +1,138 @@ + + + +Alfredo MonclusFreeCAD LGPL2+FreeCAD diff --git a/src/Mod/PartDesign/Gui/Resources/images/hole_countersink_flat.svg b/src/Mod/PartDesign/Gui/Resources/images/hole_countersink_flat.svg index 9be9f59f9b..fab3cb98a0 100644 --- a/src/Mod/PartDesign/Gui/Resources/images/hole_countersink_flat.svg +++ b/src/Mod/PartDesign/Gui/Resources/images/hole_countersink_flat.svg @@ -21,18 +21,18 @@ xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">Alfredo MonclusFreeCAD LGPL2+FreeCAD diff --git a/src/Mod/PartDesign/Gui/Resources/images/hole_none_angled.svg b/src/Mod/PartDesign/Gui/Resources/images/hole_none_angled.svg index 5c44120455..8611932f54 100644 --- a/src/Mod/PartDesign/Gui/Resources/images/hole_none_angled.svg +++ b/src/Mod/PartDesign/Gui/Resources/images/hole_none_angled.svg @@ -21,18 +21,18 @@ xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">Alfredo MonclusFreeCAD LGPL2+FreeCAD diff --git a/src/Mod/PartDesign/Gui/Resources/images/hole_none_angled_included.svg b/src/Mod/PartDesign/Gui/Resources/images/hole_none_angled_included.svg new file mode 100644 index 0000000000..15483344b8 --- /dev/null +++ b/src/Mod/PartDesign/Gui/Resources/images/hole_none_angled_included.svg @@ -0,0 +1,110 @@ + + + +Alfredo MonclusFreeCAD LGPL2+FreeCAD diff --git a/src/Mod/PartDesign/Gui/Resources/images/hole_none_flat.svg b/src/Mod/PartDesign/Gui/Resources/images/hole_none_flat.svg index b543ab3dad..4181b96502 100644 --- a/src/Mod/PartDesign/Gui/Resources/images/hole_none_flat.svg +++ b/src/Mod/PartDesign/Gui/Resources/images/hole_none_flat.svg @@ -21,18 +21,18 @@ xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">HoleCutType->setCurrentIndex(pcHole->HoleCutType.getValue()); - bool isNotCut = pcHole->HoleCutType.getValue() == 0L; - ui->labelHoleCutDiameter->setHidden(isNotCut); - ui->labelHoleCutDepth->setHidden(isNotCut); - ui->labelHoleCutCountersinkAngle->setHidden(isNotCut); - ui->HoleCutDiameter->setHidden(isNotCut); - ui->HoleCutDepth->setHidden(isNotCut); - ui->HoleCutCountersinkAngle->setHidden(isNotCut); - ui->HoleCutCustomValues->setChecked(pcHole->HoleCutCustomValues.getValue()); ui->HoleCutCustomValues->setHidden( pcHole->HoleCutType.getValue() < 5 @@ -191,7 +183,7 @@ TaskHoleParameters::TaskHoleParameters(ViewProviderHole* HoleView, QWidget* pare std::string(pcHole->ThreadDepthType.getValueAsString()) == "Dimension" ); - setCutPixmap(); + setCutDiagram(); // clang-format off connect(ui->Threaded, &QCheckBox::clicked, @@ -334,7 +326,7 @@ void TaskHoleParameters::threadDepthChanged(double value) { if (auto hole = getObject()) { hole->ThreadDepth.setValue(value); - setCutPixmap(); + setCutDiagram(); recomputeFeature(); } } @@ -398,57 +390,28 @@ void TaskHoleParameters::holeCutTypeChanged(int index) // the type is a countersink and thus if HoleCutCountersinkAngle can be enabled std::string HoleCutTypeString = hole->HoleCutType.getValueAsString(); - bool isNotCut = HoleCutTypeString == "None"; - ui->labelHoleCutDiameter->setHidden(isNotCut); - ui->labelHoleCutDepth->setHidden(isNotCut); - ui->labelHoleCutCountersinkAngle->setHidden(isNotCut); - ui->HoleCutDiameter->setHidden(isNotCut); - ui->HoleCutDepth->setHidden(isNotCut); - ui->HoleCutCountersinkAngle->setHidden(isNotCut); - - if (HoleCutTypeString == "None" || HoleCutTypeString == "Counterbore" - || HoleCutTypeString == "Countersink" || HoleCutTypeString == "Counterdrill") { + if ( + HoleCutTypeString == "None" + || HoleCutTypeString == "Counterbore" + || HoleCutTypeString == "Countersink" + || HoleCutTypeString == "Counterdrill" + ) { ui->HoleCutCustomValues->setVisible(false); - if (HoleCutTypeString == "None") { - ui->HoleCutDiameter->setEnabled(false); - ui->HoleCutDepth->setEnabled(false); - ui->labelHoleCutCountersinkAngle->setVisible(false); - ui->HoleCutCountersinkAngle->setVisible(false); - } - if (HoleCutTypeString == "Counterbore") { - ui->labelHoleCutCountersinkAngle->setVisible(false); - ui->HoleCutCountersinkAngle->setVisible(false); - } - if (HoleCutTypeString == "Countersink") { - ui->labelHoleCutCountersinkAngle->setVisible(true); - ui->HoleCutCountersinkAngle->setVisible(true); - } } else { // screw definition // we can have the case that we have no normed values // in this case HoleCutCustomValues is read-only AND true - if (ui->HoleCutCustomValues->isChecked()) { - ui->HoleCutDiameter->setEnabled(true); - ui->HoleCutDepth->setEnabled(true); - if (!hole->HoleCutCountersinkAngle.isReadOnly()) { - ui->HoleCutCountersinkAngle->setVisible(true); - ui->labelHoleCutCountersinkAngle->setVisible(true); - ui->HoleCutCountersinkAngle->setEnabled(true); - } - } - else { - ui->HoleCutCustomValues->setVisible(true); - ui->HoleCutDiameter->setEnabled(false); - ui->HoleCutDepth->setEnabled(false); - ui->HoleCutCountersinkAngle->setEnabled(false); - ui->labelHoleCutCountersinkAngle->setVisible(true); - ui->HoleCutCountersinkAngle->setVisible(true); - } + bool isCustom = ui->HoleCutCustomValues->isChecked(); + ui->HoleCutDiameter->setEnabled(isCustom); + ui->HoleCutDepth->setEnabled(isCustom); + ui->HoleCutCountersinkAngle->setEnabled( + isCustom && !hole->HoleCutCountersinkAngle.isReadOnly() + ); } - setCutPixmap(); + setCutDiagram(); } -void TaskHoleParameters::setCutPixmap() +void TaskHoleParameters::setCutDiagram() { auto hole = getObject(); const std::string holeCutTypeString = hole->HoleCutType.getValueAsString(); @@ -465,54 +428,46 @@ void TaskHoleParameters::setCutPixmap() holeCutTypeString == "Counterbore" || hole->isDynamicCounterbore(threadTypeString, holeCutTypeString) ); - bool isCounterdrill = ( - holeCutTypeString == "Counterdrill" - ); + bool isCounterdrill = (holeCutTypeString == "Counterdrill"); + bool includeAngle = hole->DrillForDepth.getValue(); + bool isNotCut = holeCutTypeString == "None"; + ui->labelHoleCutDiameter->setHidden(isNotCut); + ui->labelHoleCutDepth->setHidden(isNotCut); + ui->HoleCutDiameter->setHidden(isNotCut); + ui->HoleCutDepth->setHidden(isNotCut); + + std::string baseFileName; if (isCounterbore) { - if (isAngled) { - ui->cutDiagram->setPixmap( - QPixmap(QString::fromUtf8(":/images/hole_counterbore_angled.svg")) - ); - } else { - ui->cutDiagram->setPixmap( - QPixmap(QString::fromUtf8(":/images/hole_counterbore_flat.svg")) - ); - } + baseFileName = "hole_counterbore"; + ui->HoleCutCountersinkAngle->setVisible(false); + ui->labelHoleCutCountersinkAngle->setVisible(false); } else if (isCountersink) { - if (isAngled) { - ui->cutDiagram->setPixmap( - QPixmap(QString::fromUtf8(":/images/hole_countersink_angled.svg")) - ); - } else { - ui->cutDiagram->setPixmap( - QPixmap(QString::fromUtf8(":/images/hole_countersink_flat.svg")) - ); - } + baseFileName = "hole_countersink"; + ui->HoleCutCountersinkAngle->setVisible(true); + ui->labelHoleCutCountersinkAngle->setVisible(true); } else if (isCounterdrill) { - if (isAngled) { - ui->cutDiagram->setPixmap( - QPixmap(QString::fromUtf8(":/images/hole_counterdrill_angled.svg")) - ); - } else { - ui->cutDiagram->setPixmap( - QPixmap(QString::fromUtf8(":/images/hole_counterdrill_flat.svg")) - ); - } + baseFileName = "hole_counterdrill"; + ui->HoleCutCountersinkAngle->setVisible(true); + ui->labelHoleCutCountersinkAngle->setVisible(true); } else { - if (isAngled) { - ui->cutDiagram->setPixmap( - QPixmap(QString::fromUtf8(":/images/hole_none_angled.svg")) - ); - } else { - ui->cutDiagram->setPixmap( - QPixmap(QString::fromUtf8(":/images/hole_none_flat.svg")) - ); - } + baseFileName = "hole_none"; + ui->HoleCutCountersinkAngle->setVisible(false); + ui->labelHoleCutCountersinkAngle->setVisible(false); } + + if (isAngled) { + baseFileName += includeAngle ? "_angled_included" : "_angled"; + } else { + baseFileName += "_flat"; + } + + ui->cutDiagram->setPixmap( + QPixmap(QString::fromUtf8((":images/" + baseFileName + ".svg").c_str())) + ); } void TaskHoleParameters::holeCutCustomValuesChanged() @@ -599,7 +554,7 @@ void TaskHoleParameters::depthChanged(int index) ui->DrillPointAngled->setEnabled(DepthisDimension); ui->DrillPointAngle->setEnabled(DepthisDimension); ui->DrillForDepth->setEnabled(DepthisDimension); - setCutPixmap(); + setCutDiagram(); } void TaskHoleParameters::depthValueChanged(double value) @@ -617,7 +572,7 @@ void TaskHoleParameters::drillPointChanged() hole->DrillPoint.setValue(angled); ui->DrillPointAngle->setEnabled(angled); ui->DrillForDepth->setEnabled(angled); - setCutPixmap(); + setCutDiagram(); recomputeFeature(); } } @@ -636,6 +591,7 @@ void TaskHoleParameters::drillForDepthChanged() hole->DrillForDepth.setValue(ui->DrillForDepth->isChecked()); recomputeFeature(); } + setCutDiagram(); } void TaskHoleParameters::taperedChanged() diff --git a/src/Mod/PartDesign/Gui/TaskHoleParameters.h b/src/Mod/PartDesign/Gui/TaskHoleParameters.h index f9fd063311..a3f2e30c62 100644 --- a/src/Mod/PartDesign/Gui/TaskHoleParameters.h +++ b/src/Mod/PartDesign/Gui/TaskHoleParameters.h @@ -108,7 +108,7 @@ private Q_SLOTS: void updateViewChanged(bool isChecked); void threadDepthTypeChanged(int index); void threadDepthChanged(double value); - void setCutPixmap(); + void setCutDiagram(); private: class Observer : public App::DocumentObserver { From 3202dde7ca042d26041644b3001908acfcf10be3 Mon Sep 17 00:00:00 2001 From: Alfredo Monclus Date: Fri, 24 Jan 2025 16:36:42 -0300 Subject: [PATCH 3/4] 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 --- src/Gui/CMakeLists.txt | 2 + src/Gui/ElideCheckBox.h | 2 +- src/Gui/ElideLabel.h | 2 +- src/Gui/FontScaledSVG.cpp | 65 +++++++++++++++++++ src/Gui/FontScaledSVG.h | 53 +++++++++++++++ .../images/hole_counterbore_angled.svg | 10 +-- .../hole_counterbore_angled_included.svg | 10 +-- .../images/hole_counterbore_flat.svg | 12 ++-- .../images/hole_countersink_angled.svg | 56 ++++++++-------- .../Gui/Resources/images/hole_none_angled.svg | 8 +-- .../images/hole_none_angled_included.svg | 10 +-- src/Mod/PartDesign/Gui/TaskHoleParameters.cpp | 4 +- src/Mod/PartDesign/Gui/TaskHoleParameters.ui | 64 +++++------------- 13 files changed, 193 insertions(+), 105 deletions(-) create mode 100644 src/Gui/FontScaledSVG.cpp create mode 100644 src/Gui/FontScaledSVG.h diff --git a/src/Gui/CMakeLists.txt b/src/Gui/CMakeLists.txt index df9d37ee4c..4e30723bd6 100644 --- a/src/Gui/CMakeLists.txt +++ b/src/Gui/CMakeLists.txt @@ -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} diff --git a/src/Gui/ElideCheckBox.h b/src/Gui/ElideCheckBox.h index 8a32fb9484..7d83d4d1c0 100644 --- a/src/Gui/ElideCheckBox.h +++ b/src/Gui/ElideCheckBox.h @@ -34,7 +34,7 @@ #endif -class ElideCheckBox : public QCheckBox { +class GuiExport ElideCheckBox : public QCheckBox { Q_OBJECT public: diff --git a/src/Gui/ElideLabel.h b/src/Gui/ElideLabel.h index a356392c45..1afa460f90 100644 --- a/src/Gui/ElideLabel.h +++ b/src/Gui/ElideLabel.h @@ -33,7 +33,7 @@ #endif -class ElideLabel : public QLabel { +class GuiExport ElideLabel : public QLabel { Q_OBJECT public: diff --git a/src/Gui/FontScaledSVG.cpp b/src/Gui/FontScaledSVG.cpp new file mode 100644 index 0000000000..9fa10c948e --- /dev/null +++ b/src/Gui/FontScaledSVG.cpp @@ -0,0 +1,65 @@ +/*************************************************************************** + * Copyright (c) 2025 Alfredo Monclus * + * * + * 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); +} + diff --git a/src/Gui/FontScaledSVG.h b/src/Gui/FontScaledSVG.h new file mode 100644 index 0000000000..04f4f0ba05 --- /dev/null +++ b/src/Gui/FontScaledSVG.h @@ -0,0 +1,53 @@ +/*************************************************************************** + * Copyright (c) 2025 Alfredo Monclus * + * * + * 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 +#include +#include +#include +#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 diff --git a/src/Mod/PartDesign/Gui/Resources/images/hole_counterbore_angled.svg b/src/Mod/PartDesign/Gui/Resources/images/hole_counterbore_angled.svg index 1202071514..56891a95aa 100644 --- a/src/Mod/PartDesign/Gui/Resources/images/hole_counterbore_angled.svg +++ b/src/Mod/PartDesign/Gui/Resources/images/hole_counterbore_angled.svg @@ -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" />cutDiagram->setPixmap( - QPixmap(QString::fromUtf8((":images/" + baseFileName + ".svg").c_str())) + ui->cutDiagram->setSvg( + QString::fromUtf8((":images/" + baseFileName + ".svg").c_str()) ); } diff --git a/src/Mod/PartDesign/Gui/TaskHoleParameters.ui b/src/Mod/PartDesign/Gui/TaskHoleParameters.ui index 52b761daba..b3eb1e2c68 100644 --- a/src/Mod/PartDesign/Gui/TaskHoleParameters.ui +++ b/src/Mod/PartDesign/Gui/TaskHoleParameters.ui @@ -6,8 +6,8 @@ 0 0 - 391 - 897 + 366 + 844 @@ -239,7 +239,7 @@ the screw's top below the surface - + true @@ -249,9 +249,6 @@ the screw's top below the surface 0 - - - 6 @@ -323,28 +320,25 @@ account for the depth of blind holes - + 0 0 + + + 20 + 40 + + 0 0 - - - - - :/images/hole_counterdrill_angled.svg - - - true - @@ -358,22 +352,6 @@ account for the depth of blind holes 0 - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 8 - - - - @@ -497,22 +475,6 @@ account for the depth of blind holes - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 17 - - - - @@ -1096,6 +1058,12 @@ Note that the calculation can take some time QCheckBox
Gui/ElideCheckBox.h
+ + FontScaledSVG + QWidget +
Gui/FontScaledSVG.h
+ 1 +
From da4f584a5085d64fc8a162c7bb900de46d9c144c Mon Sep 17 00:00:00 2001 From: Alfredo Monclus Date: Sun, 9 Feb 2025 15:57:14 -0300 Subject: [PATCH 4/4] PD(hole taskpanel): apply review suggestions * refactor: change to ternary op * refactor: apply recommendations to widgets * refactor: use QSignalBlocker * refactor: address some compiler complaints * refactor: add namespace Gui to new widgets --- src/Gui/ElideCheckBox.cpp | 58 ++-- src/Gui/ElideCheckBox.h | 47 ++-- src/Gui/ElideLabel.cpp | 68 +++-- src/Gui/ElideLabel.h | 47 ++-- src/Gui/FontScaledSVG.cpp | 50 ++-- src/Gui/FontScaledSVG.h | 48 ++-- src/Mod/PartDesign/Gui/TaskHoleParameters.cpp | 252 +++++------------- src/Mod/PartDesign/Gui/TaskHoleParameters.ui | 46 ++-- 8 files changed, 271 insertions(+), 345 deletions(-) diff --git a/src/Gui/ElideCheckBox.cpp b/src/Gui/ElideCheckBox.cpp index 33169dbe4a..8ca88b0d2e 100644 --- a/src/Gui/ElideCheckBox.cpp +++ b/src/Gui/ElideCheckBox.cpp @@ -1,30 +1,35 @@ -/*************************************************************************** - * Copyright (c) 2025 Alfredo Monclus * - * * - * 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 * - * * +// SPDX-License-Identifier: LGPL-2.1-or-later +/**************************************************************************** + * * + * Copyright (c) 2025 Alfredo Monclus * + * * + * This file is part of FreeCAD. * + * * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * + * * + * FreeCAD 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 * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * + * * ***************************************************************************/ // This custom widget adds the missing ellipsize functionality in QT5 +#include "PreCompiled.h" + #include "ElideCheckBox.h" -const int CheckboxSpacing = 25; +namespace Gui { + +const int CheckboxSpacing = 18; ElideCheckBox::ElideCheckBox(QWidget *parent) : QCheckBox(parent) { @@ -41,9 +46,9 @@ void ElideCheckBox::paintEvent(QPaintEvent *event) { style()->drawControl(QStyle::CE_CheckBox, &option, &painter, this); QRect textRect = option.rect; - int padding = 4; - textRect.setX(textRect.x() + 25); + textRect.setX(textRect.x() + CheckboxSpacing); + constexpr int padding = 4; QFontMetrics fm(font()); QString elidedText = fm.elidedText(text(), Qt::ElideRight, textRect.width() - padding); @@ -55,7 +60,7 @@ QSize ElideCheckBox::sizeHint() const { QFontMetrics fm(font()); int width = fm.horizontalAdvance(this->text()) + CheckboxSpacing; int height = fm.height(); - return QSize(width, height); + return {width, height}; } QSize ElideCheckBox::minimumSizeHint() const { @@ -63,6 +68,9 @@ QSize ElideCheckBox::minimumSizeHint() const { QString minimumText = QStringLiteral("A..."); int width = fm.horizontalAdvance(minimumText) + CheckboxSpacing; int height = fm.height(); - return QSize(width, height); + return {width, height}; } +} // namespace Gui + +#include "moc_ElideCheckBox.cpp" // NOLINT diff --git a/src/Gui/ElideCheckBox.h b/src/Gui/ElideCheckBox.h index 7d83d4d1c0..ce93133b53 100644 --- a/src/Gui/ElideCheckBox.h +++ b/src/Gui/ElideCheckBox.h @@ -1,23 +1,24 @@ -/*************************************************************************** - * Copyright (c) 2025 Alfredo Monclus * - * * - * 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 * - * * +// SPDX-License-Identifier: LGPL-2.1-or-later +/**************************************************************************** + * * + * Copyright (c) 2025 Alfredo Monclus * + * * + * This file is part of FreeCAD. * + * * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * + * * + * FreeCAD 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 * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * + * * ***************************************************************************/ // This custom widget adds the missing ellipsize functionality in QT5 @@ -25,7 +26,6 @@ #ifndef ELIDECHECKBOX_H #define ELIDECHECKBOX_H -#include "PreCompiled.h" #ifndef _PreComp_ #include #include @@ -33,6 +33,9 @@ #include #endif +#include + +namespace Gui { class GuiExport ElideCheckBox : public QCheckBox { Q_OBJECT @@ -47,5 +50,7 @@ protected: QSize minimumSizeHint() const override; }; +} // namespace Gui + #endif // ELIDECHECKBOX_H diff --git a/src/Gui/ElideLabel.cpp b/src/Gui/ElideLabel.cpp index 5576db31ae..10d7294522 100644 --- a/src/Gui/ElideLabel.cpp +++ b/src/Gui/ElideLabel.cpp @@ -1,29 +1,34 @@ -/*************************************************************************** - * Copyright (c) 2025 Alfredo Monclus * - * * - * 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 * - * * +// SPDX-License-Identifier: LGPL-2.1-or-later +/**************************************************************************** + * * + * Copyright (c) 2025 Alfredo Monclus * + * * + * This file is part of FreeCAD. * + * * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * + * * + * FreeCAD 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 * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * + * * ***************************************************************************/ // This custom widget adds the missing ellipsize functionality in QT5 +#include "PreCompiled.h" + #include "ElideLabel.h" +namespace Gui { + ElideLabel::ElideLabel(QWidget *parent) : QLabel(parent) { } @@ -34,20 +39,25 @@ void ElideLabel::paintEvent(QPaintEvent *event) { painter.setPen(palette().color(QPalette::WindowText)); painter.setFont(font()); - QFontMetrics fm(font()); - QString text = this->text(); - int availableWidth = width() - 4; // Account for padding + constexpr int padding = 4; + QFontMetrics fm(painter.fontMetrics()); - QString elidedText = fm.elidedText(text, Qt::ElideRight, availableWidth); + int availableWidth = width() - padding * 2; + if (availableWidth < 0) { + return; + } - painter.drawText(2, 2, availableWidth, height(), Qt::AlignLeft | Qt::AlignVCenter, elidedText); + QString elidedText = fm.elidedText(text(), Qt::ElideRight, availableWidth); + + QRect textRect = rect().adjusted(padding, 0, -padding, 0); + painter.drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, elidedText); } QSize ElideLabel::sizeHint() const { QFontMetrics fm(font()); int width = fm.horizontalAdvance(this->text()); int height = fm.height(); - return QSize(width, height); + return {width, height}; } QSize ElideLabel::minimumSizeHint() const { @@ -55,5 +65,9 @@ QSize ElideLabel::minimumSizeHint() const { QString minimumText = QStringLiteral("A..."); int width = fm.horizontalAdvance(minimumText); int height = fm.height(); - return QSize(width, height); + return {width, height}; } + +} // namespace Gui + +#include "moc_ElideLabel.cpp" // NOLINT diff --git a/src/Gui/ElideLabel.h b/src/Gui/ElideLabel.h index 1afa460f90..7191d52f57 100644 --- a/src/Gui/ElideLabel.h +++ b/src/Gui/ElideLabel.h @@ -1,23 +1,24 @@ -/*************************************************************************** - * Copyright (c) 2025 Alfredo Monclus * - * * - * 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 * - * * +// SPDX-License-Identifier: LGPL-2.1-or-later +/**************************************************************************** + * * + * Copyright (c) 2025 Alfredo Monclus * + * * + * This file is part of FreeCAD. * + * * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * + * * + * FreeCAD 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 * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * + * * ***************************************************************************/ // This custom widget adds the missing ellipsize functionality in QT5 @@ -25,13 +26,15 @@ #ifndef ELIDELABEL_H #define ELIDELABEL_H -#include "PreCompiled.h" #ifndef _PreComp_ #include #include #include #endif +#include + +namespace Gui { class GuiExport ElideLabel : public QLabel { Q_OBJECT @@ -46,4 +49,6 @@ protected: QSize minimumSizeHint() const override; }; +} // namespace Gui + #endif // ELIDELABEL_H diff --git a/src/Gui/FontScaledSVG.cpp b/src/Gui/FontScaledSVG.cpp index 9fa10c948e..89c02e3b21 100644 --- a/src/Gui/FontScaledSVG.cpp +++ b/src/Gui/FontScaledSVG.cpp @@ -1,29 +1,34 @@ -/*************************************************************************** - * Copyright (c) 2025 Alfredo Monclus * - * * - * 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 * - * * +// SPDX-License-Identifier: LGPL-2.1-or-later +/**************************************************************************** + * * + * Copyright (c) 2025 Alfredo Monclus * + * * + * This file is part of FreeCAD. * + * * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * + * * + * FreeCAD 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 * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * + * * ***************************************************************************/ // This custom widget scales an svg according to fonts +#include "PreCompiled.h" + #include "FontScaledSVG.h" +namespace Gui { + FontScaledSVG::FontScaledSVG(QWidget *parent) : QWidget(parent), m_svgRenderer(new QSvgRenderer(this)) { setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); @@ -56,10 +61,13 @@ void FontScaledSVG::updateScaledSize() { QFontMetrics metrics(font()); qreal spacing = metrics.lineSpacing(); - int baseFactor = 18; + constexpr int baseFactor = 18; qreal scalingFactor = spacing / baseFactor; QSize targetSize = baseSize * scalingFactor; setFixedSize(targetSize); } +} // namespace Gui + +#include "moc_FontScaledSVG.cpp" // NOLINT diff --git a/src/Gui/FontScaledSVG.h b/src/Gui/FontScaledSVG.h index 04f4f0ba05..ffdc3e666b 100644 --- a/src/Gui/FontScaledSVG.h +++ b/src/Gui/FontScaledSVG.h @@ -1,23 +1,24 @@ -/*************************************************************************** - * Copyright (c) 2025 Alfredo Monclus * - * * - * 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 * - * * +// SPDX-License-Identifier: LGPL-2.1-or-later +/**************************************************************************** + * * + * Copyright (c) 2025 Alfredo Monclus * + * * + * This file is part of FreeCAD. * + * * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * + * * + * FreeCAD 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 * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * + * * ***************************************************************************/ // This custom widget scales an svg according to fonts @@ -25,7 +26,6 @@ #ifndef FONTSCALEDSVG_H #define FONTSCALEDSVG_H -#include "PreCompiled.h" #ifndef _PreComp_ #include #include @@ -33,6 +33,10 @@ #include #endif +#include + +namespace Gui { + class GuiExport FontScaledSVG : public QWidget { Q_OBJECT @@ -50,4 +54,6 @@ private: void updateScaledSize(); }; +} // namespace Gui + #endif // FONTSCALEDSVG_H diff --git a/src/Mod/PartDesign/Gui/TaskHoleParameters.cpp b/src/Mod/PartDesign/Gui/TaskHoleParameters.cpp index fc0640266b..2ebbeed7b4 100644 --- a/src/Mod/PartDesign/Gui/TaskHoleParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskHoleParameters.cpp @@ -68,8 +68,8 @@ TaskHoleParameters::TaskHoleParameters(ViewProviderHole* HoleView, QWidget* pare ui->ThreadType->addItem(tr("UTS extra fine"), QByteArray("UTS")); ui->ThreadType->addItem(tr("ANSI pipes"), QByteArray("None")); ui->ThreadType->addItem(tr("ISO/BSP pipes"), QByteArray("None")); - ui->ThreadType->addItem(tr("BSW whitworth"), QByteArray("BS")); - ui->ThreadType->addItem(tr("BSF whitworth fine"), QByteArray("BS")); + ui->ThreadType->addItem(tr("BSW whitworth"), QByteArray("None")); + ui->ThreadType->addItem(tr("BSF whitworth fine"), QByteArray("None")); // read values from the hole properties auto pcHole = getObject(); @@ -465,9 +465,7 @@ void TaskHoleParameters::setCutDiagram() baseFileName += "_flat"; } - ui->cutDiagram->setSvg( - QString::fromUtf8((":images/" + baseFileName + ".svg").c_str()) - ); + ui->cutDiagram->setSvg(QString::fromUtf8((":images/" + baseFileName + ".svg").c_str())); } void TaskHoleParameters::holeCutCustomValuesChanged() @@ -794,259 +792,145 @@ void TaskHoleParameters::changedObject(const App::Document&, const App::Property { auto hole = getObject(); if (!hole) { - // happens when aborting the command - return; + return; // happens when aborting the command } bool ro = Prop.isReadOnly(); Base::Console().Log("Parameter %s was updated\n", Prop.getName()); + auto updateCheckable = [&](QCheckBox* widget, bool value) { + [[maybe_unused]] QSignalBlocker blocker(widget); + widget->setChecked(value); + widget->setDisabled(ro); + }; + + auto updateRadio = [&](QRadioButton* widget, bool value) { + [[maybe_unused]] QSignalBlocker blocker(widget); + widget->setChecked(value); + widget->setDisabled(ro); + }; + + auto updateComboBox = [&](QComboBox* widget, int value) { + [[maybe_unused]] QSignalBlocker blocker(widget); + widget->setCurrentIndex(value); + widget->setDisabled(ro); + }; + + auto updateSpinBox = [&](Gui::PrefQuantitySpinBox* widget, double value) { + [[maybe_unused]] QSignalBlocker blocker(widget); + widget->setValue(value); + widget->setDisabled(ro); + }; + if (&Prop == &hole->Threaded) { ui->Threaded->setEnabled(true); - if (ui->Threaded->isChecked() ^ hole->Threaded.getValue()) { - ui->Threaded->blockSignals(true); - ui->Threaded->setChecked(hole->Threaded.getValue()); - ui->Threaded->blockSignals(false); - } - ui->Threaded->setDisabled(ro); + updateCheckable(ui->Threaded, hole->Threaded.getValue()); } else if (&Prop == &hole->ThreadType) { ui->ThreadType->setEnabled(true); + updateComboBox(ui->ThreadType, hole->ThreadType.getValue()); - ui->ThreadSize->blockSignals(true); - ui->ThreadSize->clear(); - std::vector cursor = hole->ThreadSize.getEnumVector(); - for (const auto& it : cursor) { - ui->ThreadSize->addItem(QString::fromStdString(it)); - } - ui->ThreadSize->setCurrentIndex(hole->ThreadSize.getValue()); - ui->ThreadSize->blockSignals(false); + // Thread type also updates related properties + auto updateComboBoxItems = [&](QComboBox* widget, const auto& values, int selected) { + QSignalBlocker blocker(widget); + widget->clear(); + for (const auto& it : values) { + widget->addItem(QString::fromStdString(it)); + } + widget->setCurrentIndex(selected); + }; - // Thread type also updates HoleCutType and ThreadClass - ui->HoleCutType->blockSignals(true); - ui->HoleCutType->clear(); - cursor = hole->HoleCutType.getEnumVector(); - for (const auto& it : cursor) { - ui->HoleCutType->addItem(QString::fromStdString(it)); - } - ui->HoleCutType->setCurrentIndex(hole->HoleCutType.getValue()); - ui->HoleCutType->blockSignals(false); - - ui->ThreadClass->blockSignals(true); - ui->ThreadClass->clear(); - cursor = hole->ThreadClass.getEnumVector(); - for (const auto& it : cursor) { - ui->ThreadClass->addItem(QString::fromStdString(it)); - } - ui->ThreadClass->setCurrentIndex(hole->ThreadClass.getValue()); - ui->ThreadClass->blockSignals(false); - - if (ui->ThreadType->currentIndex() != hole->ThreadType.getValue()) { - ui->ThreadType->blockSignals(true); - ui->ThreadType->setCurrentIndex(hole->ThreadType.getValue()); - ui->ThreadType->blockSignals(false); - } - ui->ThreadType->setDisabled(ro); + updateComboBoxItems(ui->ThreadSize, hole->ThreadSize.getEnumVector(), hole->ThreadSize.getValue()); + updateComboBoxItems(ui->HoleCutType, hole->HoleCutType.getEnumVector(), hole->HoleCutType.getValue()); + updateComboBoxItems(ui->ThreadClass, hole->ThreadClass.getEnumVector(), hole->ThreadClass.getValue()); } else if (&Prop == &hole->ThreadSize) { ui->ThreadSize->setEnabled(true); - if (ui->ThreadSize->currentIndex() != hole->ThreadSize.getValue()) { - ui->ThreadSize->blockSignals(true); - ui->ThreadSize->setCurrentIndex(hole->ThreadSize.getValue()); - ui->ThreadSize->blockSignals(false); - } - ui->ThreadSize->setDisabled(ro); + updateComboBox(ui->ThreadSize, hole->ThreadSize.getValue()); } else if (&Prop == &hole->ThreadClass) { ui->ThreadClass->setEnabled(true); - if (ui->ThreadClass->currentIndex() != hole->ThreadClass.getValue()) { - ui->ThreadClass->blockSignals(true); - ui->ThreadClass->setCurrentIndex(hole->ThreadClass.getValue()); - ui->ThreadClass->blockSignals(false); - } - ui->ThreadClass->setDisabled(ro); + updateComboBox(ui->ThreadClass, hole->ThreadClass.getValue()); } else if (&Prop == &hole->ThreadFit) { ui->ThreadFit->setEnabled(true); - if (ui->ThreadFit->currentIndex() != hole->ThreadFit.getValue()) { - ui->ThreadFit->blockSignals(true); - ui->ThreadFit->setCurrentIndex(hole->ThreadFit.getValue()); - ui->ThreadFit->blockSignals(false); - } - ui->ThreadFit->setDisabled(ro); + updateComboBox(ui->ThreadFit, hole->ThreadFit.getValue()); } else if (&Prop == &hole->Diameter) { ui->Diameter->setEnabled(true); - if (ui->Diameter->value().getValue() != hole->Diameter.getValue()) { - ui->Diameter->blockSignals(true); - ui->Diameter->setValue(hole->Diameter.getValue()); - ui->Diameter->blockSignals(false); - } - ui->Diameter->setDisabled(ro); + updateSpinBox(ui->Diameter, hole->Diameter.getValue()); } else if (&Prop == &hole->ThreadDirection) { ui->directionRightHand->setEnabled(true); ui->directionLeftHand->setEnabled(true); + std::string direction(hole->ThreadDirection.getValueAsString()); - if (direction == "Right" && !ui->directionRightHand->isChecked()) { - ui->directionRightHand->blockSignals(true); - ui->directionRightHand->setChecked(true); - ui->directionRightHand->blockSignals(false); - } - if (direction == "Left" && !ui->directionLeftHand->isChecked()) { - ui->directionLeftHand->blockSignals(true); - ui->directionLeftHand->setChecked(true); - ui->directionLeftHand->blockSignals(false); - } - ui->directionRightHand->setDisabled(ro); - ui->directionLeftHand->setDisabled(ro); + updateRadio(ui->directionRightHand, direction == "Right"); + updateRadio(ui->directionLeftHand, direction == "Left"); } else if (&Prop == &hole->HoleCutType) { ui->HoleCutType->setEnabled(true); - if (ui->HoleCutType->currentIndex() != hole->HoleCutType.getValue()) { - ui->HoleCutType->blockSignals(true); - ui->HoleCutType->setCurrentIndex(hole->HoleCutType.getValue()); - ui->HoleCutType->blockSignals(false); - } - ui->HoleCutType->setDisabled(ro); + updateComboBox(ui->HoleCutType, hole->HoleCutType.getValue()); } else if (&Prop == &hole->HoleCutDiameter) { ui->HoleCutDiameter->setEnabled(true); - if (ui->HoleCutDiameter->value().getValue() != hole->HoleCutDiameter.getValue()) { - ui->HoleCutDiameter->blockSignals(true); - ui->HoleCutDiameter->setValue(hole->HoleCutDiameter.getValue()); - ui->HoleCutDiameter->blockSignals(false); - } - ui->HoleCutDiameter->setDisabled(ro); + updateSpinBox(ui->HoleCutDiameter, hole->HoleCutDiameter.getValue()); } else if (&Prop == &hole->HoleCutDepth) { ui->HoleCutDepth->setEnabled(true); - if (ui->HoleCutDepth->value().getValue() != hole->HoleCutDepth.getValue()) { - ui->HoleCutDepth->blockSignals(true); - ui->HoleCutDepth->setValue(hole->HoleCutDepth.getValue()); - ui->HoleCutDepth->blockSignals(false); - } - ui->HoleCutDepth->setDisabled(ro); + updateSpinBox(ui->HoleCutDepth, hole->HoleCutDepth.getValue()); } else if (&Prop == &hole->HoleCutCountersinkAngle) { ui->HoleCutCountersinkAngle->setEnabled(true); - if (ui->HoleCutCountersinkAngle->value().getValue() - != hole->HoleCutCountersinkAngle.getValue()) { - ui->HoleCutCountersinkAngle->blockSignals(true); - ui->HoleCutCountersinkAngle->setValue(hole->HoleCutCountersinkAngle.getValue()); - ui->HoleCutCountersinkAngle->blockSignals(false); - } - ui->HoleCutCountersinkAngle->setDisabled(ro); + updateSpinBox(ui->HoleCutCountersinkAngle, hole->HoleCutCountersinkAngle.getValue()); } else if (&Prop == &hole->DepthType) { ui->DepthType->setEnabled(true); - if (ui->DepthType->currentIndex() != hole->DepthType.getValue()) { - ui->DepthType->blockSignals(true); - ui->DepthType->setCurrentIndex(hole->DepthType.getValue()); - ui->DepthType->blockSignals(false); - } - ui->DepthType->setDisabled(ro); + updateComboBox(ui->DepthType, hole->DepthType.getValue()); } else if (&Prop == &hole->Depth) { ui->Depth->setEnabled(true); - if (ui->Depth->value().getValue() != hole->Depth.getValue()) { - ui->Depth->blockSignals(true); - ui->Depth->setValue(hole->Depth.getValue()); - ui->Depth->blockSignals(false); - } - ui->Depth->setDisabled(ro); + updateSpinBox(ui->Depth, hole->Depth.getValue()); } else if (&Prop == &hole->DrillPoint) { - std::string drillPoint(hole->DrillPoint.getValueAsString()); ui->DrillPointAngled->setEnabled(true); - if (ui->DrillPointAngled->isChecked() ^ (drillPoint == "Angled")) { - ui->DrillPointAngled->blockSignals(true); - ui->DrillPointAngled->setChecked(drillPoint == "Angled"); - ui->DrillPointAngled->blockSignals(false); - } - ui->DrillPointAngled->setDisabled(ro); + updateCheckable(ui->DrillPointAngled, hole->DrillPoint.getValueAsString() == std::string("Angled")); } else if (&Prop == &hole->DrillPointAngle) { ui->DrillPointAngle->setEnabled(true); - if (ui->DrillPointAngle->value().getValue() != hole->DrillPointAngle.getValue()) { - ui->DrillPointAngle->blockSignals(true); - ui->DrillPointAngle->setValue(hole->DrillPointAngle.getValue()); - ui->DrillPointAngle->blockSignals(false); - } - ui->DrillPointAngle->setDisabled(ro); + updateSpinBox(ui->DrillPointAngle, hole->DrillPointAngle.getValue()); } else if (&Prop == &hole->DrillForDepth) { ui->DrillForDepth->setEnabled(true); - if (ui->DrillForDepth->isChecked() ^ hole->DrillForDepth.getValue()) { - ui->DrillForDepth->blockSignals(true); - ui->DrillForDepth->setChecked(hole->DrillForDepth.getValue()); - ui->DrillForDepth->blockSignals(false); - } - ui->DrillForDepth->setDisabled(ro); + updateCheckable(ui->DrillForDepth, hole->DrillForDepth.getValue()); } else if (&Prop == &hole->Tapered) { ui->Tapered->setEnabled(true); - if (ui->Tapered->isChecked() ^ hole->Tapered.getValue()) { - ui->Tapered->blockSignals(true); - ui->Tapered->setChecked(hole->Tapered.getValue()); - ui->Tapered->blockSignals(false); - } - ui->Tapered->setDisabled(ro); + updateCheckable(ui->Tapered, hole->Tapered.getValue()); } else if (&Prop == &hole->TaperedAngle) { ui->TaperedAngle->setEnabled(true); - if (ui->TaperedAngle->value().getValue() != hole->TaperedAngle.getValue()) { - ui->TaperedAngle->blockSignals(true); - ui->TaperedAngle->setValue(hole->TaperedAngle.getValue()); - ui->TaperedAngle->blockSignals(false); - } - ui->TaperedAngle->setDisabled(ro); + updateSpinBox(ui->TaperedAngle, hole->TaperedAngle.getValue()); } else if (&Prop == &hole->ModelThread) { ui->ModelThread->setEnabled(true); - if (ui->ModelThread->isChecked() ^ hole->ModelThread.getValue()) { - ui->ModelThread->blockSignals(true); - ui->ModelThread->setChecked(hole->ModelThread.getValue()); - ui->ModelThread->blockSignals(false); - } - ui->ModelThread->setDisabled(ro); + updateCheckable(ui->ModelThread, hole->ModelThread.getValue()); } else if (&Prop == &hole->UseCustomThreadClearance) { ui->UseCustomThreadClearance->setEnabled(true); - if (ui->UseCustomThreadClearance->isChecked() ^ hole->UseCustomThreadClearance.getValue()) { - ui->UseCustomThreadClearance->blockSignals(true); - ui->UseCustomThreadClearance->setChecked(hole->UseCustomThreadClearance.getValue()); - ui->UseCustomThreadClearance->blockSignals(false); - } - ui->UseCustomThreadClearance->setDisabled(ro); + updateCheckable(ui->UseCustomThreadClearance, hole->UseCustomThreadClearance.getValue()); } else if (&Prop == &hole->CustomThreadClearance) { ui->CustomThreadClearance->setEnabled(true); - if (ui->CustomThreadClearance->value().getValue() - != hole->CustomThreadClearance.getValue()) { - ui->CustomThreadClearance->blockSignals(true); - ui->CustomThreadClearance->setValue(hole->CustomThreadClearance.getValue()); - ui->CustomThreadClearance->blockSignals(false); - } - ui->CustomThreadClearance->setDisabled(ro); + updateSpinBox(ui->CustomThreadClearance, hole->CustomThreadClearance.getValue()); } else if (&Prop == &hole->ThreadDepthType) { ui->ThreadDepthType->setEnabled(true); - if (ui->ThreadDepthType->currentIndex() != hole->ThreadDepthType.getValue()) { - ui->ThreadDepthType->blockSignals(true); - ui->ThreadDepthType->setCurrentIndex(hole->ThreadDepthType.getValue()); - ui->ThreadDepthType->blockSignals(false); - } - ui->ThreadDepthType->setDisabled(ro); + updateComboBox(ui->ThreadDepthType, hole->ThreadDepthType.getValue()); } else if (&Prop == &hole->ThreadDepth) { ui->ThreadDepth->setEnabled(true); - if (ui->ThreadDepth->value().getValue() != hole->ThreadDepth.getValue()) { - ui->ThreadDepth->blockSignals(true); - ui->ThreadDepth->setValue(hole->ThreadDepth.getValue()); - ui->ThreadDepth->blockSignals(false); - } - ui->ThreadDepth->setDisabled(ro); + updateSpinBox(ui->ThreadDepth, hole->ThreadDepth.getValue()); } } @@ -1149,11 +1033,7 @@ Base::Quantity TaskHoleParameters::getDepth() const long TaskHoleParameters::getDrillPoint() const { - - if (ui->DrillPointAngled->isChecked()) { - return 1; - } - return 0; + return ui->DrillPointAngled->isChecked() ? 1 : 0; } Base::Quantity TaskHoleParameters::getDrillPointAngle() const diff --git a/src/Mod/PartDesign/Gui/TaskHoleParameters.ui b/src/Mod/PartDesign/Gui/TaskHoleParameters.ui index b3eb1e2c68..ee923ddf3a 100644 --- a/src/Mod/PartDesign/Gui/TaskHoleParameters.ui +++ b/src/Mod/PartDesign/Gui/TaskHoleParameters.ui @@ -38,7 +38,7 @@ 10 - + 0 @@ -77,7 +77,7 @@ - + 0 @@ -108,7 +108,7 @@ - + 0 @@ -156,7 +156,7 @@ - + 0 @@ -198,7 +198,7 @@ - + 0 @@ -266,7 +266,7 @@ the screw's top below the surface 0 - + 0 @@ -298,7 +298,7 @@ the screw's top below the surface - + 0 @@ -320,7 +320,7 @@ account for the depth of blind holes - + 0 @@ -355,7 +355,7 @@ account for the depth of blind holes - + 0 @@ -394,7 +394,7 @@ account for the depth of blind holes - + 0 @@ -430,7 +430,7 @@ account for the depth of blind holes - + 0 @@ -485,7 +485,7 @@ account for the depth of blind holes 0 - + 0 @@ -561,7 +561,7 @@ over 90: larger hole radius at the bottom - + 0 @@ -584,7 +584,7 @@ over 90: larger hole radius at the bottom - + 0 @@ -636,7 +636,7 @@ over 90: larger hole radius at the bottom 0 - + 0 @@ -732,7 +732,7 @@ Only available for holes without thread - + 0 @@ -820,7 +820,7 @@ Only available for holes without thread 0 - + 0 @@ -836,7 +836,7 @@ Only available for holes without thread - + true @@ -887,7 +887,7 @@ Note that the calculation can take some time 0 - + 0 @@ -989,7 +989,7 @@ Note that the calculation can take some time 0 - + 0 @@ -1049,17 +1049,17 @@ Note that the calculation can take some time
Gui/PrefWidgets.h
- ElideLabel + Gui::ElideLabel QLabel
Gui/ElideLabel.h
- ElideCheckBox + Gui::ElideCheckBox QCheckBox
Gui/ElideCheckBox.h
- FontScaledSVG + Gui::FontScaledSVG QWidget
Gui/FontScaledSVG.h
1