scidavis  2.3.0
About: SciDAVis is a free application for Scientific Data Analysis and Visualization (a fork off of QtiPlot).
  Fossies Dox: scidavis-2.3.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

ImageExportDialog.cpp
Go to the documentation of this file.
1 
14 
32 #include "ImageExportDialog.h"
33 #include "ApplicationWindow.h"
34 
35 #include <QStackedWidget>
36 #include <QImageWriter>
37 #include <QGroupBox>
38 #include <QPushButton>
39 #include <QGridLayout>
40 #include <QPrinter>
41 #include <QLabel>
42 #include <QComboBox>
43 #include <QCloseEvent>
44 
45 ImageExportDialog::ImageExportDialog(QWidget * parent, bool vector_options, bool extended, Qt::WindowFlags flags)
46  : ExtensibleFileDialog( parent, extended, flags )
47 {
48  setWindowTitle( tr( "Choose a filename to save under" ) );
49  setAcceptMode(QFileDialog::AcceptSave);
50 
51  QList<QByteArray> list = QImageWriter::supportedImageFormats();
52  list<<"EPS";
53  list<<"PS";
54  list<<"PDF";
55  #if QT_VERSION >= 0x040300
56  list<<"SVG";
57  #endif
58 
59  QStringList filters;
60  for(int i=0 ; i<list.count() ; i++)
61  filters << "*."+list[i].toLower();
62 
63  filters.sort();
64  setNameFilters(filters);
65  setFileMode( QFileDialog::AnyFile );
66 
68  d_vector_options->setEnabled(vector_options);
70 
71 #if QT_VERSION >= 0x040300
72  connect(this, SIGNAL(filterSelected ( const QString & )),
73  this, SLOT(updateAdvancedOptions ( const QString & )));
74 #else
75  QList<QComboBox*> combo_boxes = findChildren<QComboBox*>();
76  if (combo_boxes.size() >= 2)
77  connect(combo_boxes[1], SIGNAL(currentIndexChanged ( const QString & )),
78  this, SLOT(updateAdvancedOptions ( const QString & )));
79 #endif
80  updateAdvancedOptions(selectedNameFilter());
81 }
82 
84 {
85  ApplicationWindow *app = (ApplicationWindow *)this->parent();
86  d_advanced_options = new QStackedWidget();
87 
88  d_vector_options = new QGroupBox();
89  QGridLayout *vector_layout = new QGridLayout(d_vector_options);
91 
92  vector_layout->addWidget(new QLabel(tr("Resolution (DPI)")), 1, 0);
93  d_resolution = new QSpinBox();
94  d_resolution->setRange(0, 1000);
95  d_resolution->setValue(app->d_export_resolution);
96  vector_layout->addWidget(d_resolution, 1, 1);
97  d_resolution->setEnabled(false); // FIXME temporary disabled
98 
99  d_color = new QCheckBox();
100  d_color->setText(tr("Export in &color"));
101  d_color->setChecked(app->d_export_color);
102  vector_layout->addWidget(d_color, 2, 0, 1, 2);
103 
104  d_standard_page = new QCheckBox();
105  d_standard_page->setText(tr("Export to &standard page size"));
106  vector_layout->addWidget(d_standard_page, 3, 0, 1, 2);
107 
108  d_box_page_size = new QComboBox();
109  d_box_page_size->addItem(tr("A0 - 841 x 1189 mm"), QVariant(QPrinter::A0));
110  d_box_page_size->addItem(tr("A1 - 594 x 841 mm"), QVariant(QPrinter::A1));
111  d_box_page_size->addItem(tr("A2 - 420 x 594 mm"), QVariant(QPrinter::A2));
112  d_box_page_size->addItem(tr("A3 - 297 x 420 mm"), QVariant(QPrinter::A3));
113  d_box_page_size->addItem(tr("A4 - 210 x 297 mm"), QVariant(QPrinter::A4));
114  d_box_page_size->addItem(tr("A5 - 148 x 210 mm"), QVariant(QPrinter::A5));
115  d_box_page_size->addItem(tr("A6 - 105 x 148 mm"), QVariant(QPrinter::A6));
116  d_box_page_size->addItem(tr("A7 - 74 x 105 mm"), QVariant(QPrinter::A7));
117  d_box_page_size->addItem(tr("A8 - 52 x 74 mm"), QVariant(QPrinter::A8));
118  d_box_page_size->addItem(tr("A9 - 37 x 52 mm"), QVariant(QPrinter::A9));
119  d_box_page_size->addItem(tr("B0 - 1030 x 1456 mm"), QVariant(QPrinter::B0));
120  d_box_page_size->addItem(tr("B1 - 728 x 1030 mm"), QVariant(QPrinter::B1));
121  d_box_page_size->addItem(tr("B2 - 515 x 728 mm"), QVariant(QPrinter::B2));
122  d_box_page_size->addItem(tr("B3 - 364 x 515 mm"), QVariant(QPrinter::B3));
123  d_box_page_size->addItem(tr("B4 - 257 x 364 mm"), QVariant(QPrinter::B4));
124  d_box_page_size->addItem(tr("B5 - 182 x 257 mm"), QVariant(QPrinter::B5));
125  d_box_page_size->addItem(tr("B6 - 128 x 182 mm"), QVariant(QPrinter::B6));
126  d_box_page_size->addItem(tr("B7 - 91 x 128 mm"), QVariant(QPrinter::B7));
127  d_box_page_size->addItem(tr("B8 - 64 x 91 mm"), QVariant(QPrinter::B8));
128  d_box_page_size->addItem(tr("B9 - 45 x 64 mm"), QVariant(QPrinter::B9));
129  d_box_page_size->addItem(tr("B10 - 32 x 45 mm"), QVariant(QPrinter::B10));
130  d_box_page_size->addItem(tr("C5E - 163 x 226 mm"), QVariant(QPrinter::C5E));
131  d_box_page_size->addItem(tr("Comm10E - 105 x 241 mm"), QVariant(QPrinter::Comm10E));
132  d_box_page_size->addItem(tr("DLE - 110 x 220 mm"), QVariant(QPrinter::DLE));
133  d_box_page_size->addItem(tr("Executive - 191 x 254 mm"), QVariant(QPrinter::Executive));
134  d_box_page_size->addItem(tr("Folio 210 x 330 mm"), QVariant(QPrinter::Folio));
135  d_box_page_size->addItem(tr("Ledger 432 x 279 mm"), QVariant(QPrinter::Ledger));
136  d_box_page_size->addItem(tr("Legal 216 x 356 mm"), QVariant(QPrinter::Legal));
137  d_box_page_size->addItem(tr("Letter 216 x 279 mm"), QVariant(QPrinter::Letter));
138  d_box_page_size->addItem(tr("Tabloid 279 x 432 mm"), QVariant(QPrinter::Tabloid));
139 
140  vector_layout->addWidget(new QLabel(tr("Page size")), 4, 0);
141  setPageSize((QPrinter::PageSize)app->d_export_vector_size);
142  d_standard_page->setChecked(app->d_export_vector_size != QPrinter::Custom);
143  d_box_page_size->setEnabled(app->d_export_vector_size != QPrinter::Custom);
144  vector_layout->addWidget(d_box_page_size, 4, 1, 1, 2);
145 
146  vector_layout->addWidget(new QLabel(tr("Orientation")), 5, 0);
147  d_box_page_orientation = new QComboBox();
148  d_box_page_orientation->addItem(tr("Portrait","page orientation"), QVariant(QPrinter::Portrait));
149  d_box_page_orientation->addItem(tr("Landscape","page orientation"), QVariant(QPrinter::Landscape));
150  d_box_page_orientation->setCurrentIndex(app->d_export_orientation);
151  d_box_page_orientation->setEnabled(app->d_export_vector_size != QPrinter::Custom);
152  vector_layout->addWidget(d_box_page_orientation, 5, 1, 1, 2);
153 
154  connect(d_standard_page, SIGNAL(toggled(bool)), d_box_page_size, SLOT(setEnabled(bool)));
155  connect(d_standard_page, SIGNAL(toggled(bool)), d_box_page_orientation, SLOT(setEnabled(bool)));
156 
157  d_keep_aspect = new QCheckBox();
158  d_keep_aspect->setText(tr("&Keep aspect ratio"));
159  d_keep_aspect->setChecked(app->d_keep_plot_aspect);
160  vector_layout->addWidget(d_keep_aspect, 6, 0, 1, 2);
161 
162  d_raster_options = new QGroupBox();
163  QGridLayout *raster_layout = new QGridLayout(d_raster_options);
165 
166  raster_layout->addWidget(new QLabel(tr("Image quality")), 1, 0);
167  d_quality = new QSpinBox();
168  d_quality->setRange(1, 100);
169  d_quality->setValue(app->d_export_quality);
170  raster_layout->addWidget(d_quality, 1, 1);
171 }
172 
173 void ImageExportDialog::updateAdvancedOptions (const QString & filter)
174 {
175  if (filter.contains("*.svg")) {
176  d_extension_toggle->setChecked(false);
177  d_extension_toggle->setEnabled(false);
178  return;
179  }
180  d_extension_toggle->setEnabled(true);
181  if (filter.contains("*.eps") || filter.contains("*.ps") || filter.contains("*.pdf"))
182  d_advanced_options->setCurrentIndex(0);
183  else {
184  d_advanced_options->setCurrentIndex(1);
185  }
186 }
187 
188 void ImageExportDialog::closeEvent(QCloseEvent* e)
189 {
190  ApplicationWindow *app = (ApplicationWindow *)this->parent();
191  if (app){
192  app->d_extended_export_dialog = this->isExtended();
193  app->d_image_export_filter = this->selectedNameFilter();
194  app->d_export_quality = d_quality->value();
195 
196  app->d_export_resolution = d_resolution->value();
197  app->d_export_color = d_color->isChecked();
198  app->d_export_vector_size = (int)pageSize();
199  app->d_keep_plot_aspect = d_keep_aspect->isChecked();
200  app->d_export_orientation = d_box_page_orientation->currentIndex();
201  }
202 
203  e->accept();
204 }
205 
206 QPrinter::PageSize ImageExportDialog::pageSize() const
207 {
208  if (!d_standard_page->isChecked())
209  return QPrinter::Custom;
210 
211  QPrinter::PageSize size;
212  switch (d_box_page_size->currentIndex())
213  {
214  case -1:
215  size = QPrinter::A4;
216  break;
217  default:
218  size = (QPrinter::PageSize)d_box_page_size->itemData(d_box_page_size->currentIndex()).toInt();
219  break;
220  }
221  return size;
222 }
223 
224 QPrinter::Orientation ImageExportDialog::pageOrientation() const
225 {
226  QPrinter::Orientation orientation;
227  switch (d_box_page_orientation->currentIndex())
228  {
229  case -1:
230  orientation = QPrinter::Portrait;
231  break;
232  default:
233  orientation = (QPrinter::Orientation)d_box_page_orientation->itemData(d_box_page_orientation->currentIndex()).toInt();
234  break;
235  }
236  return orientation;
237 }
238 
239 void ImageExportDialog::setPageSize(QPrinter::PageSize size)
240 {
241  if (size == QPrinter::Custom)
242  return;
243 
244  int index = d_box_page_size->findData(QVariant(size));
245  if (index != -1)
246  d_box_page_size->setCurrentIndex(index);
247  else
248  {
249  index = d_box_page_size->findData(QVariant(QPrinter::A4));
250  Q_ASSERT(index != -1);
251  d_box_page_size->setCurrentIndex(index);
252  }
253 }
254 
255 void ImageExportDialog::setOrientation(QPrinter::Orientation orientation)
256 {
257  int index = d_box_page_orientation->findData(QVariant(orientation));
258  if (index != -1)
259  d_box_page_orientation->setCurrentIndex(index);
260  else
261  d_box_page_orientation->setCurrentIndex(0);
262 }
263 
264 void ImageExportDialog::selectFilter(const QString & filter)
265 {
266  QFileDialog::selectNameFilter(filter);
267  updateAdvancedOptions(filter);
268 }
ImageExportDialog::ImageExportDialog
ImageExportDialog(QWidget *parent=0, bool vector_options=true, bool extended=true, Qt::WindowFlags flags=0)
Constructor.
Definition: ImageExportDialog.cpp:45
ApplicationWindow::d_image_export_filter
QString d_image_export_filter
Last selected filter in export image dialog.
Definition: ApplicationWindow.h:910
ImageExportDialog::d_quality
QSpinBox * d_quality
Definition: ImageExportDialog.h:67
ImageExportDialog::d_box_page_orientation
QComboBox * d_box_page_orientation
Definition: ImageExportDialog.h:63
ImageExportDialog::setPageSize
void setPageSize(QPrinter::PageSize size)
Definition: ImageExportDialog.cpp:239
ImageExportDialog::selectFilter
void selectFilter(const QString &filter)
Definition: ImageExportDialog.cpp:264
ApplicationWindow::d_export_vector_size
int d_export_vector_size
Definition: ApplicationWindow.h:912
ImageExportDialog::d_box_page_size
QComboBox * d_box_page_size
Definition: ImageExportDialog.h:62
ExtensibleFileDialog::setExtensionWidget
void setExtensionWidget(QWidget *extension)
Set the extension widget to be displayed when the user presses the toggle button.
Definition: ExtensibleFileDialog.cpp:66
ImageExportDialog::d_standard_page
QCheckBox * d_standard_page
Definition: ImageExportDialog.h:61
ExtensibleFileDialog::d_extension_toggle
QPushButton * d_extension_toggle
Button for toggling display of extension on/off.
Definition: ExtensibleFileDialog.h:62
ImageExportDialog::d_vector_options
QGroupBox * d_vector_options
Container widget for all options available for vector formats.
Definition: ImageExportDialog.h:57
python-sipcmd.flags
list flags
Definition: python-sipcmd.py:61
ExtensibleFileDialog
QFileDialog plus generic extension support.
Definition: ExtensibleFileDialog.h:45
ApplicationWindow::d_keep_plot_aspect
bool d_keep_plot_aspect
Definition: ApplicationWindow.h:911
ApplicationWindow::d_export_color
bool d_export_color
Definition: ApplicationWindow.h:916
ApplicationWindow::d_export_orientation
int d_export_orientation
Default paper orientation for image exports.
Definition: ApplicationWindow.h:918
ImageExportDialog::pageSize
QPrinter::PageSize pageSize() const
For vector formats: returns a standard output page size (default: QPrinter::Custom).
Definition: ImageExportDialog.cpp:206
ImageExportDialog::d_raster_options
QGroupBox * d_raster_options
Container widget for all options available for raster formats.
Definition: ImageExportDialog.h:66
ApplicationWindow
SciDAVis's main window.
Definition: ApplicationWindow.h:122
ImageExportDialog::initAdvancedOptions
void initAdvancedOptions()
Create d_advanced_options and everything it contains.
Definition: ImageExportDialog.cpp:83
ApplicationWindow::d_export_resolution
int d_export_resolution
Definition: ApplicationWindow.h:915
ImageExportDialog.h
ApplicationWindow::d_extended_export_dialog
bool d_extended_export_dialog
Definition: ApplicationWindow.h:930
ExtensibleFileDialog::isExtended
bool isExtended()
Definition: ExtensibleFileDialog.h:61
ImageExportDialog::pageOrientation
QPrinter::Orientation pageOrientation() const
Definition: ImageExportDialog.cpp:224
ImageExportDialog::d_advanced_options
QStackedWidget * d_advanced_options
Container widget for all advanced options.
Definition: ImageExportDialog.h:54
ImageExportDialog::d_resolution
QSpinBox * d_resolution
Definition: ImageExportDialog.h:58
ImageExportDialog::d_color
QCheckBox * d_color
Definition: ImageExportDialog.h:59
ImageExportDialog::setOrientation
void setOrientation(QPrinter::Orientation orientation)
Definition: ImageExportDialog.cpp:255
ApplicationWindow.h
ApplicationWindow::d_export_quality
int d_export_quality
Definition: ApplicationWindow.h:914
ImageExportDialog::updateAdvancedOptions
void updateAdvancedOptions(const QString &filter)
Update which options are visible and enabled based on the output format.
Definition: ImageExportDialog.cpp:173
ImageExportDialog::d_keep_aspect
QCheckBox * d_keep_aspect
Definition: ImageExportDialog.h:60
ImageExportDialog::closeEvent
void closeEvent(QCloseEvent *)
Definition: ImageExportDialog.cpp:188