mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
Issue #284: Scaling dimensions [Enhancements, Features]
This commit is contained in:
@@ -23,7 +23,6 @@
|
||||
#include "dimensionsplugin.h"
|
||||
#include "pdfdrawwidget.h"
|
||||
#include "pdfwidgetutils.h"
|
||||
#include "pdfcms.h"
|
||||
#include "settingsdialog.h"
|
||||
|
||||
#include <QPainter>
|
||||
@@ -216,8 +215,7 @@ void DimensionsPlugin::drawPage(QPainter* painter,
|
||||
qreal angle = line.angle();
|
||||
QFontMetricsF fontMetrics(painter->font());
|
||||
QRectF textRect(-line.length() * 0.5, -fontMetrics.lineSpacing(), line.length(), fontMetrics.lineSpacing());
|
||||
|
||||
QString text = QString("%1 %2").arg(locale.toString(dimension.getMeasuredValue() * m_lengthUnit.scale, 'f', 2), m_lengthUnit.symbol);
|
||||
QString text = QString("%1 %2").arg(locale.toString(dimension.getMeasuredValue() * m_scale * m_lengthUnit.scale, 'f', 2), m_lengthUnit.symbol);
|
||||
|
||||
painter->save();
|
||||
painter->translate(textPoint);
|
||||
@@ -270,11 +268,11 @@ void DimensionsPlugin::drawPage(QPainter* painter,
|
||||
|
||||
if (isArea)
|
||||
{
|
||||
text = tr("A = %1 %2").arg(locale.toString(dimension.getMeasuredValue() * m_areaUnit.scale, 'f', 2), m_areaUnit.symbol);
|
||||
text = tr("A = %1 %2").arg(locale.toString(dimension.getMeasuredValue() * m_scale * m_scale * m_areaUnit.scale, 'f', 2), m_areaUnit.symbol);
|
||||
}
|
||||
else
|
||||
{
|
||||
text = tr("p = %1 %2").arg(locale.toString(dimension.getMeasuredValue() * m_lengthUnit.scale, 'f', 2), m_lengthUnit.symbol);
|
||||
text = tr("p = %1 %2").arg(locale.toString(dimension.getMeasuredValue() * m_scale * m_lengthUnit.scale, 'f', 2), m_lengthUnit.symbol);
|
||||
}
|
||||
painter->drawText(centerPoint, text);
|
||||
|
||||
@@ -349,7 +347,7 @@ void DimensionsPlugin::onClearDimensionsTriggered()
|
||||
|
||||
void DimensionsPlugin::onSettingsTriggered()
|
||||
{
|
||||
SettingsDialog dialog(m_widget, m_lengthUnit, m_areaUnit, m_angleUnit);
|
||||
SettingsDialog dialog(m_widget, m_lengthUnit, m_areaUnit, m_angleUnit, m_scale);
|
||||
dialog.exec();
|
||||
|
||||
updateGraphics();
|
||||
|
@@ -55,6 +55,9 @@ public:
|
||||
const pdf::PDFColorConvertor& convertor,
|
||||
QList<pdf::PDFRenderError>& errors) const override;
|
||||
|
||||
void setScale(double scale);
|
||||
double getScale() const;
|
||||
|
||||
private:
|
||||
void onShowDimensionsTriggered();
|
||||
void onClearDimensionsTriggered();
|
||||
@@ -73,6 +76,9 @@ private:
|
||||
DimensionUnit m_lengthUnit;
|
||||
DimensionUnit m_areaUnit;
|
||||
DimensionUnit m_angleUnit;
|
||||
|
||||
// New member variable for scaling
|
||||
double m_scale = 1.0;
|
||||
};
|
||||
|
||||
} // namespace pdfplugin
|
||||
|
@@ -289,6 +289,9 @@ DimensionUnits DimensionUnit::getLengthUnits()
|
||||
units.emplace_back(pdf::PDF_POINT_TO_INCH, DimensionTool::tr("in"));
|
||||
units.emplace_back(pdf::PDF_POINT_TO_MM, DimensionTool::tr("mm"));
|
||||
units.emplace_back(pdf::PDF_POINT_TO_MM * 0.1, DimensionTool::tr("cm"));
|
||||
units.emplace_back(pdf::PDF_POINT_TO_MM * 0.001, DimensionTool::tr("m"));
|
||||
units.emplace_back(pdf::PDF_POINT_TO_INCH * 12.0, DimensionTool::tr("ft")); // Feet
|
||||
units.emplace_back(pdf::PDF_POINT_TO_INCH * 36.0, DimensionTool::tr("yd")); // Yards
|
||||
|
||||
return units;
|
||||
}
|
||||
@@ -301,6 +304,9 @@ DimensionUnits DimensionUnit::getAreaUnits()
|
||||
units.emplace_back(pdf::PDF_POINT_TO_INCH * pdf::PDF_POINT_TO_INCH, DimensionTool::tr("sq. in"));
|
||||
units.emplace_back(pdf::PDF_POINT_TO_MM * pdf::PDF_POINT_TO_MM, DimensionTool::tr("sq. mm"));
|
||||
units.emplace_back(pdf::PDF_POINT_TO_MM * 0.1 * pdf::PDF_POINT_TO_MM * 0.1, DimensionTool::tr("sq. cm"));
|
||||
units.emplace_back(pdf::PDF_POINT_TO_MM * 0.001 * pdf::PDF_POINT_TO_MM * 0.001, DimensionTool::tr("sq. m"));
|
||||
units.emplace_back(pdf::PDF_POINT_TO_INCH * 12.0 * pdf::PDF_POINT_TO_INCH * 12.0, DimensionTool::tr("sq. ft")); // Square Feet
|
||||
units.emplace_back(pdf::PDF_POINT_TO_INCH * 36.0 * pdf::PDF_POINT_TO_INCH * 36.0, DimensionTool::tr("sq. yd")); // Square Yards
|
||||
|
||||
return units;
|
||||
}
|
||||
|
@@ -25,12 +25,17 @@
|
||||
|
||||
#include "pdfwidgetutils.h"
|
||||
|
||||
SettingsDialog::SettingsDialog(QWidget* parent, DimensionUnit& lengthUnit, DimensionUnit& areaUnit, DimensionUnit& angleUnit) :
|
||||
SettingsDialog::SettingsDialog(QWidget* parent,
|
||||
DimensionUnit& lengthUnit,
|
||||
DimensionUnit& areaUnit,
|
||||
DimensionUnit& angleUnit,
|
||||
double& scale) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::SettingsDialog),
|
||||
m_lengthUnit(lengthUnit),
|
||||
m_areaUnit(areaUnit),
|
||||
m_angleUnit(angleUnit)
|
||||
m_angleUnit(angleUnit),
|
||||
m_scale(scale)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
@@ -41,6 +46,7 @@ SettingsDialog::SettingsDialog(QWidget* parent, DimensionUnit& lengthUnit, Dimen
|
||||
initComboBox(m_lengthUnits, m_lengthUnit, ui->lengthsComboBox);
|
||||
initComboBox(m_areaUnits, m_areaUnit, ui->areasComboBox);
|
||||
initComboBox(m_angleUnits, m_angleUnit, ui->anglesComboBox);
|
||||
ui->scaleEdit->setValue(m_scale);
|
||||
|
||||
setMinimumSize(pdf::PDFWidgetUtils::scaleDPI(this, QSize(320, 240)));
|
||||
pdf::PDFWidgetUtils::style(this);
|
||||
@@ -66,6 +72,7 @@ void SettingsDialog::accept()
|
||||
m_lengthUnit = m_lengthUnits[ui->lengthsComboBox->currentIndex()];
|
||||
m_areaUnit = m_areaUnits[ui->areasComboBox->currentIndex()];
|
||||
m_angleUnit = m_angleUnits[ui->anglesComboBox->currentIndex()];
|
||||
m_scale = ui->scaleEdit->value();
|
||||
|
||||
QDialog::accept();
|
||||
}
|
||||
|
@@ -42,7 +42,8 @@ public:
|
||||
explicit SettingsDialog(QWidget* parent,
|
||||
DimensionUnit& lengthUnit,
|
||||
DimensionUnit& areaUnit,
|
||||
DimensionUnit& angleUnit);
|
||||
DimensionUnit& angleUnit,
|
||||
double& scale);
|
||||
virtual ~SettingsDialog() override;
|
||||
|
||||
virtual void accept() override;
|
||||
@@ -58,6 +59,7 @@ private:
|
||||
DimensionUnit& m_lengthUnit;
|
||||
DimensionUnit& m_areaUnit;
|
||||
DimensionUnit& m_angleUnit;
|
||||
double& m_scale;
|
||||
};
|
||||
|
||||
#endif // SETTINGSDIALOG_H
|
||||
|
@@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>254</width>
|
||||
<height>165</height>
|
||||
<width>405</width>
|
||||
<height>186</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@@ -50,16 +50,33 @@
|
||||
<item row="2" column="1">
|
||||
<widget class="QComboBox" name="anglesComboBox"/>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QDoubleSpinBox" name="scaleEdit">
|
||||
<property name="minimum">
|
||||
<double>1.000000000000000</double>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>1000000.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="scaleLabel">
|
||||
<property name="text">
|
||||
<string>Scale 1:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
Reference in New Issue
Block a user