From bd615e76e7a3d956d9494b97640790362d7680d2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20Mal=C3=BD?= Date: Thu, 2 Apr 2015 20:48:32 +0200 Subject: [PATCH] Initial support for DPI scaling in image exporter --- datamanager.cpp | 2 +- gui/exportgraphtoimagedialog.cpp | 14 ++++++++++++-- gui/exportgraphtoimagedialog.h | 9 ++++++--- gui/exportgraphtoimagedialog.ui | 10 ++++++++++ helpers.cpp | 12 ++++++++++++ helpers.h | 2 ++ imagedrawer.cpp | 4 ++-- imagedrawer.h | 2 +- 8 files changed, 46 insertions(+), 9 deletions(-) diff --git a/datamanager.cpp b/datamanager.cpp index ad73896..5dd6d12 100644 --- a/datamanager.cpp +++ b/datamanager.cpp @@ -536,7 +536,7 @@ void DataManager::onExportGraphToImage() relFromY = ctrl->valueToRel(absFromY); relToY = ctrl->valueToRel(absToY); - ImageDrawer imageDrawer(ctrl); + ImageDrawer imageDrawer(ctrl, m_graphToImageExportDialog.imageDpi()); drwRet = imageDrawer.render(m_graphToImageExportDialog.path(), m_graphToImageExportDialog.imageFormat().toLatin1(), m_graphToImageExportDialog.imageWidth(), m_graphToImageExportDialog.imageHeight(), relFromX, relFromY, relToX, relToY, gl); diff --git a/gui/exportgraphtoimagedialog.cpp b/gui/exportgraphtoimagedialog.cpp index 705283c..e054eab 100644 --- a/gui/exportgraphtoimagedialog.cpp +++ b/gui/exportgraphtoimagedialog.cpp @@ -50,6 +50,7 @@ ExportGraphToImageDialog::ExportGraphToImageDialog(QList formats, Pa ui->qle_destPath->setText(m_lastUsedPath); ui->qle_width->setText(QString::number(params.width)); ui->qle_height->setText(QString::number(params.height)); + ui->qle_dpi->setText(QString::number(params.dpi)); ui->qcbox_outputFormat->setCurrentIndex(params.formatIdx); ui->qck_includeInteg->setChecked(params.includePeaks); } @@ -90,6 +91,14 @@ bool ExportGraphToImageDialog::includePeaks() const return ui->qck_includeInteg->isChecked(); } +int ExportGraphToImageDialog::imageDpi() const +{ + bool ok; + int dpi = ui->qle_dpi->text().toInt(&ok); + if (!ok) return 0; + return dpi; +} + int ExportGraphToImageDialog::imageHeight() const { bool ok; @@ -100,7 +109,7 @@ int ExportGraphToImageDialog::imageHeight() const ExportGraphToImageDialog::Parameters ExportGraphToImageDialog::parameters() const { - return Parameters(imageWidth(), imageHeight(), ui->qcbox_outputFormat->currentIndex(), ui->qck_includeInteg->isChecked()); + return Parameters(imageWidth(), imageHeight(), ui->qcbox_outputFormat->currentIndex(), ui->qck_includeInteg->isChecked(), imageDpi()); } QString ExportGraphToImageDialog::path() const @@ -216,7 +225,8 @@ void ExportGraphToImageDialog::checkAndAccept() } - m_lastUsedParameters = Parameters(imageWidth(), imageHeight(), ui->qcbox_outputFormat->currentIndex(), ui->qck_includeInteg->isChecked()); + m_lastUsedParameters = Parameters(imageWidth(), imageHeight(), ui->qcbox_outputFormat->currentIndex(), ui->qck_includeInteg->isChecked(), + imageDpi()); m_lastUsedPath = ui->qle_destPath->text(); accept(); } diff --git a/gui/exportgraphtoimagedialog.h b/gui/exportgraphtoimagedialog.h index d2c2ddd..3df4f66 100644 --- a/gui/exportgraphtoimagedialog.h +++ b/gui/exportgraphtoimagedialog.h @@ -24,6 +24,7 @@ #ifndef EXPORTGRAPHTOIMAGEDIALOG_H #define EXPORTGRAPHTOIMAGEDIALOG_H +#include "helpers.h" #include #include @@ -53,14 +54,15 @@ class ExportGraphToImageDialog : public QDialog public: struct Parameters { - Parameters() : width(1000), height(1000), formatIdx(0), includePeaks(false) {} - Parameters(const int width, const int height, const int formatIdx, const bool includePeaks) : - width(width), height(height), formatIdx(formatIdx), includePeaks(includePeaks) {} + Parameters() : width(1000), height(1000), formatIdx(0), includePeaks(false), dpi(Helpers::dpiX()) {} + Parameters(const int width, const int height, const int formatIdx, const bool includePeaks, const int dpi) : + width(width), height(height), formatIdx(formatIdx), includePeaks(includePeaks), dpi(dpi) {} int width; int height; int formatIdx; bool includePeaks; + int dpi; }; explicit ExportGraphToImageDialog(QList formats, Parameters params = Parameters(), QWidget* parent = nullptr); @@ -69,6 +71,7 @@ public: double fromX() const; double fromY() const; QString imageFormat() const; + int imageDpi() const; int imageHeight() const; bool includePeaks() const; Parameters parameters() const; diff --git a/gui/exportgraphtoimagedialog.ui b/gui/exportgraphtoimagedialog.ui index 43e2bea..1510d6d 100644 --- a/gui/exportgraphtoimagedialog.ui +++ b/gui/exportgraphtoimagedialog.ui @@ -107,6 +107,16 @@ + + + + DPI: + + + + + + diff --git a/helpers.cpp b/helpers.cpp index 157bcd5..5a39c5d 100644 --- a/helpers.cpp +++ b/helpers.cpp @@ -21,9 +21,21 @@ */ #include "helpers.h" +#include +#include const double Helpers::EPSILON = 2e-14; +int Helpers::dpiX() +{ + return qApp->desktop()->logicalDpiX(); +} + +int Helpers::dpiY() +{ + return qApp->desktop()->logicalDpiY(); +} + double Helpers::firstTick(const double from, const double step) { double ret; diff --git a/helpers.h b/helpers.h index bef1ad5..20d978a 100644 --- a/helpers.h +++ b/helpers.h @@ -32,6 +32,8 @@ class Helpers { public: static const double EPSILON; + static int dpiX(); + static int dpiY(); static double firstTick(const double from, const double step); static QString getFileNameSuffix(const QString& name); diff --git a/imagedrawer.cpp b/imagedrawer.cpp index 22b5f0a..c60172a 100644 --- a/imagedrawer.cpp +++ b/imagedrawer.cpp @@ -27,9 +27,9 @@ #include #include -ImageDrawer::ImageDrawer(std::shared_ptr controller, QObject* parent) : +ImageDrawer::ImageDrawer(std::shared_ptr controller, const int dpi, QObject* parent) : QObject(parent), - SignalDrawer(controller), + SignalDrawer(controller, Constraints(), dpi, dpi), m_controller(controller) { m_imageWriter.setCompression(0); diff --git a/imagedrawer.h b/imagedrawer.h index f3f91ed..4db310a 100644 --- a/imagedrawer.h +++ b/imagedrawer.h @@ -42,7 +42,7 @@ public: E_WOULD_OVERWRITE }; - explicit ImageDrawer(std::shared_ptr controller, QObject* parent = nullptr); + explicit ImageDrawer(std::shared_ptr controller, const int dpi, QObject* parent = nullptr); ReturnCode render(const QString& filename, const QByteArray format, const int width, const int height, const double fromX, const double fromY, const double toX, const double toY, const GraphLayers layers); -- 2.43.5