[TD]control svg scaling at object level
This commit is contained in:
@@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>440</width>
|
||||
<height>342</height>
|
||||
<width>457</width>
|
||||
<height>481</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
@@ -49,6 +49,19 @@
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="2" column="1">
|
||||
<spacer name="horizontalSpacer">
|
||||
<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="0" column="0">
|
||||
<widget class="QLabel" name="label_13">
|
||||
<property name="font">
|
||||
@@ -61,49 +74,15 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="Gui::PrefDoubleSpinBox" name="pdsbPageScale">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>174</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Default scale for new pages</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="decimals">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>1.000000000000000</double>
|
||||
</property>
|
||||
<property name="prefEntry" stdset="0">
|
||||
<cstring>DefaultScale</cstring>
|
||||
</property>
|
||||
<property name="prefPath" stdset="0">
|
||||
<cstring>Mod/TechDraw/General</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_14">
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_15">
|
||||
<property name="font">
|
||||
<font>
|
||||
<italic>true</italic>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>View Scale Type</string>
|
||||
<string>View Custom Scale</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -150,30 +129,39 @@
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_15">
|
||||
<property name="font">
|
||||
<font>
|
||||
<italic>true</italic>
|
||||
</font>
|
||||
<item row="0" column="2">
|
||||
<widget class="Gui::PrefDoubleSpinBox" name="pdsbPageScale">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>View Custom Scale</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
<width>174</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
<property name="toolTip">
|
||||
<string>Default scale for new pages</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="decimals">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>1.000000000000000</double>
|
||||
</property>
|
||||
<property name="prefEntry" stdset="0">
|
||||
<cstring>DefaultScale</cstring>
|
||||
</property>
|
||||
<property name="prefPath" stdset="0">
|
||||
<cstring>Mod/TechDraw/General</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="Gui::PrefDoubleSpinBox" name="pdsbViewScale">
|
||||
@@ -215,6 +203,39 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_14">
|
||||
<property name="font">
|
||||
<font>
|
||||
<italic>true</italic>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>View Scale Type</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="Gui::PrefCheckBox" name="cbLegacyScale">
|
||||
<property name="font">
|
||||
<font>
|
||||
<italic>true</italic>
|
||||
</font>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string><html><head/><body><p>If checked, Svg symbols, spreadsheet views and Draft views will use the original (incorrect) scaling method as used in v1.0 and earlier. If unchecked, a more accurate method will be used. </p></body></html></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Legacy Symbol Scaling</string>
|
||||
</property>
|
||||
<property name="prefEntry" stdset="0">
|
||||
<cstring>LegacySvgScaling</cstring>
|
||||
</property>
|
||||
<property name="prefPath" stdset="0">
|
||||
<cstring>Mod/TechDraw/General</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
@@ -306,7 +327,7 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<item row="1" column="2">
|
||||
<widget class="Gui::PrefDoubleSpinBox" name="pdsbCenterScale">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
@@ -351,7 +372,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="Gui::PrefUnitSpinBox" name="pdsbTemplateMark">
|
||||
<widget class="Gui::PrefUnitSpinBox" name="pdsbTemplateMark" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
@@ -367,10 +388,7 @@
|
||||
<property name="toolTip">
|
||||
<string>Size of template field click handles</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="value">
|
||||
<property name="value" stdset="0">
|
||||
<double>3.000000000000000</double>
|
||||
</property>
|
||||
<property name="prefEntry" stdset="0">
|
||||
@@ -410,7 +428,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
@@ -424,7 +442,7 @@
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string><html><head/><body><p><span style=" font-weight:600;">Note:</span> Items in <span style=" font-style:italic;">italics</span> are default values for new objects. They have no effect on existing objects.</p></body></html></string>
|
||||
<string><html><head/><body><p><span style=" font-weight:600;">Note:</span> Items in <span style=" font-style:italic;">italics</span> are default values for new objects. They have no effect on existing objects.</p></body></html></string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
@@ -452,6 +470,11 @@
|
||||
<extends>QWidget</extends>
|
||||
<header>Gui/QuantitySpinBox.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>Gui::PrefCheckBox</class>
|
||||
<extends>QCheckBox</extends>
|
||||
<header>Gui/PrefWidgets.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>Gui::PrefComboBox</class>
|
||||
<extends>QComboBox</extends>
|
||||
|
||||
@@ -67,6 +67,7 @@ void DlgPrefsTechDrawScaleImp::saveSettings()
|
||||
ui->pdsbCenterScale->onSave();
|
||||
ui->pdsbTemplateMark->onSave();
|
||||
ui->pdsbSymbolScale->onSave();
|
||||
ui->cbLegacyScale->onSave();
|
||||
}
|
||||
|
||||
void DlgPrefsTechDrawScaleImp::loadSettings()
|
||||
@@ -80,6 +81,7 @@ void DlgPrefsTechDrawScaleImp::loadSettings()
|
||||
ui->pdsbTemplateMark->setValue(markDefault);
|
||||
ui->pdsbTemplateMark->onRestore();
|
||||
ui->pdsbSymbolScale->onRestore();
|
||||
ui->cbLegacyScale->onRestore();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
#include "QGCustomSvg.h"
|
||||
#include "QGDisplayArea.h"
|
||||
#include "Rez.h"
|
||||
#include "ViewProviderSymbol.h"
|
||||
|
||||
|
||||
using namespace TechDrawGui;
|
||||
@@ -110,8 +111,14 @@ void QGIViewSymbol::drawSvg()
|
||||
return;
|
||||
}
|
||||
|
||||
auto vp = getViewProvider(viewSymbol);
|
||||
auto vps = dynamic_cast<ViewProviderSymbol*>(vp);
|
||||
if (!vp || !vps) {
|
||||
return;
|
||||
}
|
||||
|
||||
double scaling{1};
|
||||
if (Preferences::useLegacySvgScaling()) {
|
||||
if (vps->LegacyScaling.getValue()) {
|
||||
scaling = legacyScaler(viewSymbol);
|
||||
} else {
|
||||
scaling = symbolScaler(viewSymbol);
|
||||
@@ -206,18 +213,15 @@ double QGIViewSymbol::symbolScaler(TechDraw::DrawViewSymbol* feature) const
|
||||
matchUnits = matchHeight.captured(1);
|
||||
}
|
||||
|
||||
if (matchUnits.isEmpty() ||
|
||||
matchUnits == pxToken) {
|
||||
scaling *= rezfactor;
|
||||
}
|
||||
// if there are no units specified, or the units are px, we just draw the symbol
|
||||
|
||||
if (matchUnits == mmToken) {
|
||||
auto svgSize = m_svgItem->renderer()->defaultSize();
|
||||
auto vpSize = m_svgItem->renderer()->viewBox();
|
||||
auto vportSize = m_svgItem->renderer()->viewBox();
|
||||
// wf: this calculation works, but I don't know why. :(
|
||||
// hints here: https://stackoverflow.com/questions/49866474/get-svg-size-from-qsvgrenderer
|
||||
// and here: https://stackoverflow.com/questions/7544921/qt-qgraphicssvgitem-renders-too-big-0-5-unit-on-each-side
|
||||
scaling *= rezfactor * vpSize.width() / svgSize.width();
|
||||
scaling *= rezfactor * vportSize.width() / svgSize.width();
|
||||
}
|
||||
|
||||
return scaling;
|
||||
|
||||
@@ -24,9 +24,15 @@
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#include <App/DocumentObject.h>
|
||||
|
||||
#include <Mod/TechDraw/App/Preferences.h>
|
||||
|
||||
#include "QGIViewSymbol.h"
|
||||
#include "ViewProviderSymbol.h"
|
||||
|
||||
using namespace TechDrawGui;
|
||||
using namespace TechDraw;
|
||||
|
||||
|
||||
PROPERTY_SOURCE(TechDrawGui::ViewProviderSymbol, TechDrawGui::ViewProviderDrawingView)
|
||||
|
||||
@@ -36,6 +42,11 @@ PROPERTY_SOURCE(TechDrawGui::ViewProviderSymbol, TechDrawGui::ViewProviderDrawin
|
||||
ViewProviderSymbol::ViewProviderSymbol()
|
||||
{
|
||||
sPixmap = "TechDraw_TreeSymbol";
|
||||
|
||||
ADD_PROPERTY_TYPE(LegacyScaling, (Preferences::useLegacySvgScaling()), "Svg Scaling", App::Prop_None,
|
||||
"If true, Svg will be scaled using the original (v1.0 and earlier) scaling method.\
|
||||
If false, a more accurate method will be used.");
|
||||
|
||||
}
|
||||
|
||||
ViewProviderSymbol::~ViewProviderSymbol()
|
||||
@@ -55,6 +66,18 @@ void ViewProviderSymbol::updateData(const App::Property* prop)
|
||||
ViewProviderDrawingView::updateData(prop);
|
||||
}
|
||||
|
||||
void ViewProviderSymbol::onChanged(const App::Property* prop)
|
||||
{
|
||||
if (prop == &(LegacyScaling)) {
|
||||
QGIView* qgiv = getQView();
|
||||
if (qgiv) {
|
||||
qgiv->updateView(true);
|
||||
}
|
||||
}
|
||||
|
||||
ViewProviderDrawingView::onChanged(prop);
|
||||
}
|
||||
|
||||
TechDraw::DrawViewSymbol* ViewProviderSymbol::getViewObject() const
|
||||
{
|
||||
return dynamic_cast<TechDraw::DrawViewSymbol*>(pcObject);
|
||||
|
||||
@@ -43,8 +43,11 @@ public:
|
||||
/// destructor
|
||||
~ViewProviderSymbol() override;
|
||||
|
||||
App::PropertyBool LegacyScaling;
|
||||
|
||||
bool useNewSelectionModel() const override {return false;}
|
||||
void updateData(const App::Property*) override;
|
||||
void onChanged(const App::Property* prop) override;
|
||||
|
||||
TechDraw::DrawViewSymbol* getViewObject() const override;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user