ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvRenderToFileDlg.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #include "ecvRenderToFileDlg.h"
9 
10 #include "ui_renderToFileDialog.h"
11 
12 // CV_DB_LIB
13 #include <CVLog.h>
14 
15 // Qt
16 #include <QDoubleSpinBox>
17 #include <QFileDialog>
18 #include <QImageWriter>
19 #include <QList>
20 #include <QSettings>
21 #include <QStandardPaths>
22 
23 namespace {
24 // we keep track of the zoom for the session only!
25 double s_renderZoom = 1.0;
26 } // namespace
27 
29  unsigned baseHeight,
30  QWidget* parent /*=0*/)
31  : QDialog(parent),
32  w(baseWidth),
33  h(baseHeight),
34  m_ui(new Ui::RenderToFileDialog) {
35  m_ui->setupUi(this);
36 
37  // we grab the list of supported image file formats (output)
38  QList<QByteArray> list = QImageWriter::supportedImageFormats();
39  if (list.size() < 1) {
40  CVLog::Error("No supported image format on this platform?!");
41  reject();
42  return;
43  }
44 
45  // we convert this list into a proper "filters" string
46  QString firstExtension(list[0].data());
47  QString firstFilter;
48  for (int i = 0; i < list.size(); ++i) {
49  filters.append(QString("%1 image (*.%2)\n")
50  .arg(QString(list[i].data()).toUpper())
51  .arg(list[i].data()));
52  if (i == 0 || QString(list[i].data()) == "jpg") {
53  firstFilter = filters;
54  }
55  }
56 
57  QSettings settings;
58  settings.beginGroup("RenderToFile");
59  selectedFilter = settings.value("selectedFilter", firstFilter).toString();
60  QString currentPath =
61  settings.value("currentPath",
62  QStandardPaths::writableLocation(
63  QStandardPaths::DocumentsLocation))
64  .toString();
65  QString selectedExtension =
66  settings.value("selectedExtension", firstExtension).toString();
67  QString baseFilename = settings.value("baseFilename", "capture").toString();
68  bool dontScale =
69  settings.value("dontScaleFeatures", dontScalePoints()).toBool();
70  bool doRenderOverlayItems =
71  settings.value("renderOverlayItems", renderOverlayItems()).toBool();
72  settings.endGroup();
73 
74  m_ui->dontScaleFeaturesCheckBox->setChecked(dontScale);
75  m_ui->renderOverlayItemsCheckBox->setChecked(doRenderOverlayItems);
76  m_ui->filenameLineEdit->setText(currentPath + QString("/") + baseFilename +
77  QString(".") + selectedExtension);
78 
79  m_ui->zoomDoubleSpinBox->setValue(s_renderZoom);
80 
81  connect(m_ui->chooseFileButton, SIGNAL(clicked()), this,
82  SLOT(chooseFile()));
83  connect(m_ui->zoomDoubleSpinBox, SIGNAL(valueChanged(double)), this,
84  SLOT(updateInfo()));
85  connect(m_ui->buttonBox, SIGNAL(accepted()), this, SLOT(saveSettings()));
86 
87  updateInfo();
88 }
89 
91  // we update current file path
92  QFileInfo fi(m_ui->filenameLineEdit->text());
93  QString currentPath = fi.absolutePath();
94  QString selectedExtension = fi.suffix();
95  QString baseFilename = fi.completeBaseName();
96 
97  QSettings settings;
98  settings.beginGroup("RenderToFile");
99  settings.setValue("currentPath", currentPath);
100  settings.setValue("selectedExtension", selectedExtension);
101  settings.setValue("selectedFilter", selectedFilter);
102  settings.setValue("baseFilename", baseFilename);
103  settings.setValue("dontScaleFeatures", dontScalePoints());
104  settings.setValue("renderOverlayItems", renderOverlayItems());
105  settings.endGroup();
106 }
107 
109  QString selectedFileName = QFileDialog::getSaveFileName(
110  this, tr("Save Image"), m_ui->filenameLineEdit->text(), filters,
111  &selectedFilter);
112 
113  // if operation is canceled, selectedFileName is empty
114  if (selectedFileName.size() < 1) return;
115 
116  m_ui->filenameLineEdit->setText(selectedFileName);
117 }
118 
120 
122  m_ui->dontScaleFeaturesCheckBox->setChecked(false);
123  m_ui->dontScaleFeaturesCheckBox->setVisible(false);
124  m_ui->renderOverlayItemsCheckBox->setChecked(false);
125  m_ui->renderOverlayItemsCheckBox->setVisible(false);
126 }
127 
129  return static_cast<float>(m_ui->zoomDoubleSpinBox->value());
130 }
131 
133  return m_ui->filenameLineEdit->text();
134 }
135 
137  return m_ui->dontScaleFeaturesCheckBox->isChecked();
138 }
139 
141  return m_ui->renderOverlayItemsCheckBox->isChecked();
142 }
143 
145  s_renderZoom = getZoom();
146 
147  unsigned w2 = static_cast<unsigned>(w * s_renderZoom);
148  unsigned h2 = static_cast<unsigned>(h * s_renderZoom);
149 
150  m_ui->finalSizeLabel->setText(QString("(%1 x %2)").arg(w2).arg(h2));
151 }
static bool Error(const char *format,...)
Display an error dialog with formatted message.
Definition: CVLog.cpp:143
void hideOptions()
Disable and hide the scale and overlay checkboxes.
Ui::RenderToFileDialog * m_ui
bool dontScalePoints() const
On dialog acceptance, returns whether points should be scaled or not.
ccRenderToFileDlg(unsigned baseWidth, unsigned baseHeight, QWidget *parent=0)
Default constructor.
bool renderOverlayItems() const
Whether overlay items should be rendered.
float getZoom() const
On dialog acceptance, returns requested zoom.
QString getFilename() const
On dialog acceptance, returns requested output filename.
GraphType data
Definition: graph_cut.cc:138
Definition: sfEditDlg.h:16