]> Devoid-pointer.net GitWeb - anyanka.git/commitdiff
Initial support for DPI scaling in image exporter
authorMichal Malý <madcatxster@devoid-pointer.net>
Thu, 2 Apr 2015 18:48:32 +0000 (20:48 +0200)
committerMichal Malý <madcatxster@devoid-pointer.net>
Thu, 2 Apr 2015 18:48:32 +0000 (20:48 +0200)
datamanager.cpp
gui/exportgraphtoimagedialog.cpp
gui/exportgraphtoimagedialog.h
gui/exportgraphtoimagedialog.ui
helpers.cpp
helpers.h
imagedrawer.cpp
imagedrawer.h

index ad738964382655acd78d5fbe579ce764474737c6..5dd6d12d6b9ff3a5cbea825a74112b940e6a5976 100644 (file)
@@ -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);
index 705283c69654e43ad2657426feaf438548fb3ade..e054eabb622d9f02f2e5e825a7dce221cfc5966e 100644 (file)
@@ -50,6 +50,7 @@ ExportGraphToImageDialog::ExportGraphToImageDialog(QList<QByteArray> 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();
 }
index d2c2dddafb40e09e1b87a0e46bcd04855fb04c7e..3df4f6673d6d085ad47b4f8ffaec6345ee07a669 100644 (file)
@@ -24,6 +24,7 @@
 #ifndef EXPORTGRAPHTOIMAGEDIALOG_H
 #define EXPORTGRAPHTOIMAGEDIALOG_H
 
+#include "helpers.h"
 #include <unordered_map>
 #include <QtWidgets/QDialog>
 
@@ -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<QByteArray> 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;
index 43e2bea5e3f534baab30211da527cb457b259882..1510d6d4e7a01718992daf50811a3462d9e5a3a3 100644 (file)
        </property>
       </widget>
      </item>
+     <item row="1" column="0">
+      <widget class="QLabel" name="ql_dpi">
+       <property name="text">
+        <string>DPI:</string>
+       </property>
+      </widget>
+     </item>
+     <item row="1" column="1">
+      <widget class="QLineEdit" name="qle_dpi"/>
+     </item>
     </layout>
    </item>
    <item>
index 157bcd52a7afaa3e088b778378a91a2bb52b9734..5a39c5de9ce69a05f7402797b1e6e21128437946 100644 (file)
 */
 
 #include "helpers.h"
+#include <QApplication>
+#include <QDesktopWidget>
 
 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;
index bef1ad5dcf9a4f949ae1bc501e7a949089e21b85..20d978a162001e5f6354d5e74418b5f476b72062 100644 (file)
--- 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);
 
index 22b5f0af5ff01e7d2830fb01cad7863309402671..c60172a7055bf395b1c3f871e9b8e8240e8dd742 100644 (file)
@@ -27,9 +27,9 @@
 #include <QtCore/QFile>
 #include <QtWidgets/QMessageBox>
 
-ImageDrawer::ImageDrawer(std::shared_ptr<SignalController> controller, QObject* parent) :
+ImageDrawer::ImageDrawer(std::shared_ptr<SignalController> controller, const int dpi, QObject* parent) :
   QObject(parent),
-  SignalDrawer(controller),
+  SignalDrawer(controller, Constraints(), dpi, dpi),
   m_controller(controller)
 {
   m_imageWriter.setCompression(0);
index f3f91eddcaf8b8fa3689cffdd80f3e54f8e50d96..4db310a439295b83b74b15ff30542902eb5b4fb5 100644 (file)
@@ -42,7 +42,7 @@ public:
     E_WOULD_OVERWRITE
   };
 
-  explicit ImageDrawer(std::shared_ptr<SignalController> controller, QObject* parent = nullptr);
+  explicit ImageDrawer(std::shared_ptr<SignalController> 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);