[PartGui] Add Font and Color Preferences to Measure dimensions (#7148)

* [Part] Add Font and Color Preferences to Measure dimensions v4

authored-by: VM4Dim <vm4dim@users.noreply.github.com>
Co-authored-by: Uwe <donovaly@users.noreply.github.com>
This commit is contained in:
VM4Dim
2022-07-18 12:52:00 +03:00
committed by GitHub
parent 217b1e82cb
commit 53d9b1899f
7 changed files with 461 additions and 15 deletions

View File

@@ -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<PartGui::DlgSettingsGeneral>(QT_TRANSLATE_NOOP("QObject", "Part/Part Design"));
(void)new Gui::PrefPageProducer<PartGui::DlgSettings3DViewPart>(QT_TRANSLATE_NOOP("QObject", "Part/Part Design"));
(void)new Gui::PrefPageProducer<PartGui::DlgSettingsObjectColor>(QT_TRANSLATE_NOOP("QObject", "Part/Part Design"));
(void)new Gui::PrefPageProducer<PartGui::DlgSettingsMeasure>(QT_TRANSLATE_NOOP("QObject", "Part/Part Design"));
(void)new Gui::PrefPageProducer<PartGui::DlgImportExportIges>(QT_TRANSLATE_NOOP("QObject", "Import-Export"));
(void)new Gui::PrefPageProducer<PartGui::DlgImportExportStep>(QT_TRANSLATE_NOOP("QObject", "Import-Export"));
Gui::ViewProviderBuilder::add(

View File

@@ -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

View File

@@ -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 <Gui/PrefWidgets.h>
#include <Gui/Command.h>
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"

View File

@@ -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 <Gui/PropertyPage.h>
#include <memory>
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_DlgSettingsMeasure> ui;
void onMeasureRefresh();
};
} // namespace PartGui
#endif // PARTGUI_DIALOG_DLGSETTINGSMEASURE_H

View File

@@ -0,0 +1,269 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PartGui::DlgSettingsMeasure</class>
<widget class="QWidget" name="PartGui::DlgSettingsMeasure">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>500</width>
<height>400</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Measure</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Dimension settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="Gui::PrefColorButton" name="dim3dColorButton" native="true">
<property name="color" stdset="0">
<color>
<red>255</red>
<green>0</green>
<blue>0</blue>
</color>
</property>
<property name="prefEntry" stdset="0">
<cstring>Dimensions3dColor</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>View</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_1">
<property name="text">
<string>3d Color</string>
</property>
</widget>
</item>
<item row="0" column="4">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<widget class="Gui::PrefColorButton" name="dimDeltaColorButton" native="true">
<property name="color" stdset="0">
<color>
<red>0</red>
<green>255</green>
<blue>0</blue>
</color>
</property>
<property name="prefEntry" stdset="0">
<cstring>DimensionsDeltaColor</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>View</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Delta Color</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="Gui::PrefColorButton" name="dimAngularColorButton" native="true">
<property name="color" stdset="0">
<color>
<red>0</red>
<green>0</green>
<blue>255</blue>
</color>
</property>
<property name="prefEntry" stdset="0">
<cstring>DimensionsAngularColor</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>View</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Angular Color</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="Gui::PrefSpinBox" name="fontSizeSpinBox">
<property name="maximumSize">
<size>
<width>80</width>
<height>28</height>
</size>
</property>
<property name="value">
<number>30</number>
</property>
<property name="prefEntry" stdset="0">
<cstring>DimensionsFontSize</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>View</cstring>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Font Size</string>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="Gui::PrefCheckBox" name="fontStyleBoldCheckBox">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Bold</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>DimensionsFontStyleBold</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>View</cstring>
</property>
</widget>
</item>
<item row="4" column="3">
<widget class="Gui::PrefCheckBox" name="fontStyleItalicCheckBox">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Italic</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>DimensionsFontStyleItalic</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>View</cstring>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<widget class="Gui::PrefFontBox" name="fontNameComboBox">
<property name="writingSystem">
<enum>QFontDatabase::Latin</enum>
</property>
<property name="currentFont">
<font>
<family>Serif</family>
</font>
</property>
<property name="prefEntry" stdset="0">
<cstring>DimensionsFontName</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>View</cstring>
</property>
</widget>
</item>
<item row="5" column="2">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Font Name</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="7" column="1" colspan="2" alignment="Qt::AlignHCenter">
<widget class="QPushButton" name="pushButtonRefresh">
<property name="text">
<string>Measure Refresh</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Gui::PrefCheckBox</class>
<extends>QCheckBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefSpinBox</class>
<extends>QSpinBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefFontBox</class>
<extends>QFontComboBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefColorButton</class>
<extends>QWidget</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@@ -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();

View File

@@ -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);