Engauge Digitizer  2
NonPdf.cpp
1 /******************************************************************************************************
2  * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3  * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4  * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5  ******************************************************************************************************/
6 
7 #include "DlgImportCroppingNonPdf.h"
8 #include "ImportCroppingUtilNonPdf.h"
9 #include "NonPdf.h"
10 #include <QApplication>
11 #include <QImage>
12 #include <QString>
13 
15 {
16 }
17 
18 NonPdfReturn NonPdf::load (const QString &fileName,
19  QImage &image,
20  ImportCropping importCropping,
21  bool isErrorReportRegressionTest) const
22 {
23  ImportCroppingUtilNonPdf importCroppingUtil;
24  bool cropping = importCroppingUtil.applyImportCropping (isErrorReportRegressionTest,
25  importCropping);
26 
27  NonPdfReturn rtn;
28  QApplication::setOverrideCursor(Qt::BusyCursor); // Since loading can be slow
29  if (cropping) {
30 
31  rtn = loadWithCropping (fileName,
32  image);
33 
34  } else {
35 
36  rtn = loadWithoutCropping (fileName,
37  image);
38 
39  }
40  QApplication::restoreOverrideCursor();
41 
42  return rtn;
43 }
44 
45 NonPdfReturn NonPdf::loadWithCropping (const QString &fileName,
46  QImage &image) const
47 {
48  NonPdfReturn nonPdfReturn = NON_PDF_RETURN_FAILED;
49 
50  // Get page and extent. At this point it is always true that the image can be read
51  DlgImportCroppingNonPdf dlg (fileName);
52  if (dlg.exec() == QDialog::Accepted) {
53 
54  // Returned image is null if it could not be read
55  image = dlg.image ();
56 
57  if (!image.isNull()) {
58  nonPdfReturn = NON_PDF_RETURN_SUCCESS;
59  }
60 
61  } else {
62  nonPdfReturn = NON_PDF_RETURN_CANCELED;
63  }
64 
65  return nonPdfReturn;
66 }
67 
68 NonPdfReturn NonPdf::loadWithoutCropping (const QString &fileName,
69  QImage &image) const
70 {
71  NonPdfReturn nonPdfReturn = NON_PDF_RETURN_FAILED;
72 
73  if (image.load (fileName)) {
74  nonPdfReturn = NON_PDF_RETURN_SUCCESS;
75  }
76 
77  return nonPdfReturn;
78 }
bool applyImportCropping(bool isRegression, ImportCropping importCropping) const
Skip cropping dialog during regression testing, otherwise crop if it is always turned on...
NonPdf()
Single constructor.
Definition: NonPdf.cpp:14
NonPdfReturn load(const QString &fileName, QImage &image, ImportCropping importCropping, bool isErrorReportRegressionTest) const
Try to load the specified file. Success is indicated in the function return value.
Definition: NonPdf.cpp:18
Dialog for selecting a page and frame on that page when importing an image from a non-pdf file...
Import of non-pdf files.
QImage image() const
Image that was selected. Value is null if loading failed.