From 53d9b1899f6e0edf3a181dfeb0e9e4e0e4e3acc5 Mon Sep 17 00:00:00 2001 From: VM4Dim <96398106+VM4Dim@users.noreply.github.com> Date: Mon, 18 Jul 2022 12:52:00 +0300 Subject: [PATCH] [PartGui] Add Font and Color Preferences to Measure dimensions (#7148) * [Part] Add Font and Color Preferences to Measure dimensions v4 authored-by: VM4Dim Co-authored-by: Uwe --- src/Mod/Part/Gui/AppPartGui.cpp | 2 + src/Mod/Part/Gui/CMakeLists.txt | 8 + src/Mod/Part/Gui/DlgSettingsMeasure.cpp | 96 +++++++++ src/Mod/Part/Gui/DlgSettingsMeasure.h | 58 +++++ src/Mod/Part/Gui/DlgSettingsMeasure.ui | 269 ++++++++++++++++++++++++ src/Mod/Part/Gui/TaskDimension.cpp | 38 ++-- src/Mod/Part/Gui/TaskDimension.h | 5 +- 7 files changed, 461 insertions(+), 15 deletions(-) create mode 100644 src/Mod/Part/Gui/DlgSettingsMeasure.cpp create mode 100644 src/Mod/Part/Gui/DlgSettingsMeasure.h create mode 100644 src/Mod/Part/Gui/DlgSettingsMeasure.ui diff --git a/src/Mod/Part/Gui/AppPartGui.cpp b/src/Mod/Part/Gui/AppPartGui.cpp index d410f28c44..1a72be0124 100644 --- a/src/Mod/Part/Gui/AppPartGui.cpp +++ b/src/Mod/Part/Gui/AppPartGui.cpp @@ -33,6 +33,7 @@ #include "TaskDimension.h" #include "DlgSettings3DViewPartImp.h" #include "DlgSettingsGeneral.h" +#include "DlgSettingsMeasure.h" #include "DlgSettingsObjectColor.h" #include "ViewProvider.h" #include "ViewProvider2DObject.h" @@ -212,6 +213,7 @@ PyMOD_INIT_FUNC(PartGui) (void)new Gui::PrefPageProducer(QT_TRANSLATE_NOOP("QObject", "Part/Part Design")); (void)new Gui::PrefPageProducer(QT_TRANSLATE_NOOP("QObject", "Part/Part Design")); (void)new Gui::PrefPageProducer(QT_TRANSLATE_NOOP("QObject", "Part/Part Design")); + (void)new Gui::PrefPageProducer(QT_TRANSLATE_NOOP("QObject", "Part/Part Design")); (void)new Gui::PrefPageProducer(QT_TRANSLATE_NOOP("QObject", "Import-Export")); (void)new Gui::PrefPageProducer(QT_TRANSLATE_NOOP("QObject", "Import-Export")); Gui::ViewProviderBuilder::add( diff --git a/src/Mod/Part/Gui/CMakeLists.txt b/src/Mod/Part/Gui/CMakeLists.txt index 43d8b3d1ff..8e4132c964 100644 --- a/src/Mod/Part/Gui/CMakeLists.txt +++ b/src/Mod/Part/Gui/CMakeLists.txt @@ -60,7 +60,9 @@ set(PartGui_UIC_SRCS DlgRevolution.ui DlgSettings3DViewPart.ui DlgSettingsGeneral.ui + DlgSettingsMeasure.ui DlgSettingsObjectColor.ui + DlgSettingsMeasure.ui DlgProjectionOnSurface.ui SectionCutting.ui ShapeFromMesh.ui @@ -131,9 +133,15 @@ SET(PartGui_SRCS DlgSettingsGeneral.cpp DlgSettingsGeneral.h DlgSettingsGeneral.ui + DlgSettingsMeasure.cpp + DlgSettingsMeasure.h + DlgSettingsMeasure.ui DlgSettingsObjectColor.cpp DlgSettingsObjectColor.h DlgSettingsObjectColor.ui + DlgSettingsMeasure.cpp + DlgSettingsMeasure.h + DlgSettingsMeasure.ui DlgProjectionOnSurface.cpp DlgProjectionOnSurface.h DlgProjectionOnSurface.ui diff --git a/src/Mod/Part/Gui/DlgSettingsMeasure.cpp b/src/Mod/Part/Gui/DlgSettingsMeasure.cpp new file mode 100644 index 0000000000..1611774c61 --- /dev/null +++ b/src/Mod/Part/Gui/DlgSettingsMeasure.cpp @@ -0,0 +1,96 @@ +/*************************************************************************** + * Copyright (c) 2022 * + * * + * 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., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" + +#include "DlgSettingsMeasure.h" +#include "ui_DlgSettingsMeasure.h" +#include + +#include + +using namespace PartGui; + +DlgSettingsMeasure::DlgSettingsMeasure(QWidget* parent) + : PreferencePage(parent) , ui(new Ui_DlgSettingsMeasure) +{ + ui->setupUi(this); + connect(ui->pushButtonRefresh, &QPushButton::clicked, this, &DlgSettingsMeasure::onMeasureRefresh); +} + +/** + * Destroys the object and frees any allocated resources + */ +DlgSettingsMeasure::~DlgSettingsMeasure() +{ + // no need to delete child widgets, Qt does it all for us +} + +void DlgSettingsMeasure::saveSettings() +{ + ui->dim3dColorButton->onSave(); + ui->dimDeltaColorButton->onSave(); + ui->dimAngularColorButton->onSave(); + + ui->fontSizeSpinBox->onSave(); + ui->fontNameComboBox->onSave(); + + ui->fontStyleBoldCheckBox->onSave(); + ui->fontStyleItalicCheckBox->onSave(); +} + +void DlgSettingsMeasure::loadSettings() +{ + ui->dim3dColorButton->onRestore(); + ui->dimDeltaColorButton->onRestore(); + ui->dimAngularColorButton->onRestore(); + + ui->fontSizeSpinBox->onRestore(); + ui->fontNameComboBox->onRestore(); + ui->fontNameComboBox->addItems(QStringList({QString::fromUtf8("defaultFont")})); + + ui->fontStyleBoldCheckBox->onRestore(); + ui->fontStyleItalicCheckBox->onRestore(); +} + +/** + * Sets the strings of the subwidgets using the current language. + */ +void DlgSettingsMeasure::changeEvent(QEvent *e) +{ + if (e->type() == QEvent::LanguageChange) { + ui->retranslateUi(this); + } + else { + QWidget::changeEvent(e); + } +} + + +void DlgSettingsMeasure::onMeasureRefresh() +{ + DlgSettingsMeasure::saveSettings(); + Gui::Command::runCommand(Gui::Command::Gui, "Gui.runCommand('Part_Measure_Refresh',0)"); +} + +#include "moc_DlgSettingsMeasure.cpp" diff --git a/src/Mod/Part/Gui/DlgSettingsMeasure.h b/src/Mod/Part/Gui/DlgSettingsMeasure.h new file mode 100644 index 0000000000..ddbf155f82 --- /dev/null +++ b/src/Mod/Part/Gui/DlgSettingsMeasure.h @@ -0,0 +1,58 @@ +/*************************************************************************** + * Copyright (c) 2022 * + * * + * 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., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef PARTGUI_DIALOG_DLGSETTINGSMEASURE_H +#define PARTGUI_DIALOG_DLGSETTINGSMEASURE_H + +#include +#include + +namespace PartGui { +class Ui_DlgSettingsMeasure; + +/** + * The DlgSettingsMeasure class implements a preference page to change color + * and font settings for Measure Dimensions + */ +class DlgSettingsMeasure : public Gui::Dialog::PreferencePage +{ + Q_OBJECT + +public: + DlgSettingsMeasure(QWidget* parent = nullptr); + ~DlgSettingsMeasure(); + + void saveSettings(); + void loadSettings(); + +protected: + void changeEvent(QEvent *e); + +private: + std::unique_ptr ui; + void onMeasureRefresh(); +}; + +} // namespace PartGui + +#endif // PARTGUI_DIALOG_DLGSETTINGSMEASURE_H diff --git a/src/Mod/Part/Gui/DlgSettingsMeasure.ui b/src/Mod/Part/Gui/DlgSettingsMeasure.ui new file mode 100644 index 0000000000..6753055403 --- /dev/null +++ b/src/Mod/Part/Gui/DlgSettingsMeasure.ui @@ -0,0 +1,269 @@ + + + PartGui::DlgSettingsMeasure + + + + 0 + 0 + 500 + 400 + + + + + 0 + 0 + + + + Measure + + + + + + Dimension settings + + + + + + + + + 255 + 0 + 0 + + + + Dimensions3dColor + + + View + + + + + + + 3d Color + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 255 + 0 + + + + DimensionsDeltaColor + + + View + + + + + + + Delta Color + + + + + + + + 0 + 0 + 255 + + + + DimensionsAngularColor + + + View + + + + + + + Angular Color + + + + + + + + + + + + + + + 80 + 28 + + + + 30 + + + DimensionsFontSize + + + View + + + + + + + Font Size + + + + + + + + 75 + true + + + + Bold + + + DimensionsFontStyleBold + + + View + + + + + + + + true + + + + Italic + + + DimensionsFontStyleItalic + + + View + + + + + + + QFontDatabase::Latin + + + + Serif + + + + DimensionsFontName + + + View + + + + + + + Font Name + + + + + + + + + + + + + + Measure Refresh + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + Gui::PrefCheckBox + QCheckBox +
Gui/PrefWidgets.h
+
+ + Gui::PrefSpinBox + QSpinBox +
Gui/PrefWidgets.h
+
+ + Gui::PrefFontBox + QFontComboBox +
Gui/PrefWidgets.h
+
+ + Gui::PrefColorButton + QWidget +
Gui/PrefWidgets.h
+
+
+ + +
diff --git a/src/Mod/Part/Gui/TaskDimension.cpp b/src/Mod/Part/Gui/TaskDimension.cpp index 8ca37dd9a8..49cc0f2351 100644 --- a/src/Mod/Part/Gui/TaskDimension.cpp +++ b/src/Mod/Part/Gui/TaskDimension.cpp @@ -224,6 +224,21 @@ void PartGui::dumpLinearResults(const BRepExtrema_DistShapeShape &measure) Base::Console().Message(out.str().c_str()); } +auto PartGui::getDimensionsFontName() +{ + ParameterGrp::handle group = App::GetApplication().GetUserParameter().GetGroup("BaseApp/Preferences/View"); + std::string fontName = group->GetASCII("DimensionsFontName", "defaultFont") + + (group->GetBool("DimensionsFontStyleBold", false) ? " :Bold" : "") + + (group->GetBool("DimensionsFontStyleItalic", false) ? " :Italic" : ""); + return fontName; +} + +auto PartGui::getDimensionsFontSize() +{ + ParameterGrp::handle group = App::GetApplication().GetUserParameter().GetGroup("BaseApp/Preferences/View"); + return group->GetInt("DimensionsFontSize", 30); +} + Gui::View3DInventorViewer * PartGui::getViewer() { Gui::Document *doc = Gui::Application::Instance->activeDocument(); @@ -240,12 +255,9 @@ Gui::View3DInventorViewer * PartGui::getViewer() void PartGui::addLinearDimensions(const BRepExtrema_DistShapeShape &measure) { - ParameterGrp::handle group = App::GetApplication().GetUserParameter(). - GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("View"); - App::Color c(1.0,0.0,0.0); - c.fromHexString(group->GetASCII("Dimensions3dColor", c.asHexString().c_str())); - App::Color d(0.0,1.0,0.0); - d.fromHexString(group->GetASCII("DimensionsDeltaColor", d.asHexString().c_str())); + ParameterGrp::handle group = App::GetApplication().GetUserParameter().GetGroup("BaseApp/Preferences/View"); + App::Color c((uint32_t) group->GetUnsigned("Dimensions3dColor", 0xFF000000)); + App::Color d((uint32_t) group->GetUnsigned("DimensionsDeltaColor", 0x00FF0000)); Gui::View3DInventorViewer *viewer = getViewer(); if (!viewer) @@ -503,8 +515,8 @@ void PartGui::DimensionLinear::setupDimension() textSep->addChild(textTransform); SoFont *fontNode = new SoFont(); - fontNode->name.setValue("defaultFont"); - fontNode->size.setValue(30); + fontNode->name.setValue(getDimensionsFontName().c_str()); + fontNode->size.setValue(getDimensionsFontSize()); textSep->addChild(fontNode); SoText2 *textNode = new SoText2(); @@ -1106,10 +1118,8 @@ void PartGui::goDimensionAngularNoTask(const VectorAdapter &vector1Adapter, cons dimSys = dimSys.transpose(); } - ParameterGrp::handle group = App::GetApplication().GetUserParameter(). - GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("View"); - App::Color c(0.0,0.0,1.0); - c.fromHexString(group->GetASCII("DimensionsAngularColor", c.asHexString().c_str())); + ParameterGrp::handle group = App::GetApplication().GetUserParameter().GetGroup("BaseApp/Preferences/View"); + App::Color c((uint32_t) group->GetUnsigned("DimensionsAngularColor", 0x0000FF00)); DimensionAngular *dimension = new DimensionAngular(); dimension->ref(); @@ -1288,8 +1298,8 @@ void PartGui::DimensionAngular::setupDimension() textSep->addChild(textTransform); SoFont *fontNode = new SoFont(); - fontNode->name.setValue("defaultFont"); - fontNode->size.setValue(30); + fontNode->name.setValue(getDimensionsFontName().c_str()); + fontNode->size.setValue(getDimensionsFontSize()); textSep->addChild(fontNode); SoText2 *textNode = new SoText2(); diff --git a/src/Mod/Part/Gui/TaskDimension.h b/src/Mod/Part/Gui/TaskDimension.h index b1a9729831..5936bdabf5 100644 --- a/src/Mod/Part/Gui/TaskDimension.h +++ b/src/Mod/Part/Gui/TaskDimension.h @@ -108,7 +108,10 @@ namespace PartGui void ensure3dDimensionVisible(); /*convert a vertex to vector*/ gp_Vec convert(const TopoDS_Vertex &vertex); - + + auto getDimensionsFontName(); + auto getDimensionsFontSize(); + class DimensionLinear : public SoSeparatorKit { SO_KIT_HEADER(DimensionLinear);