All Classes Namespaces Functions Variables Enumerations Properties Pages
exportimagedialog.cpp
1 /*
2 
3 Pencil2D - Traditional Animation Software
4 Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5 Copyright (C) 2012-2020 Matthew Chiawen Chang
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; version 2 of the License.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 */
17 
18 #include "exportimagedialog.h"
19 #include "ui_exportimageoptions.h"
20 #include "util.h"
21 
22 ExportImageDialog::ExportImageDialog(QWidget* parent, FileType eFileType) :
23  ImportExportDialog(parent, ImportExportDialog::Export, eFileType),
24  ui(new Ui::ExportImageOptions)
25 {
26  ui->setupUi(getOptionsGroupBox());
27  if (eFileType == FileType::IMAGE_SEQUENCE)
28  {
29  setWindowTitle(tr("Export image sequence"));
30  }
31  else
32  {
33  setWindowTitle(tr("Export image"));
34  ui->frameRangeGroupBox->hide();
35  }
36 
37  connect(ui->formatComboBox, &QComboBox::currentTextChanged, this, &ExportImageDialog::formatChanged);
38  formatChanged(getExportFormat()); // Make sure file extension matches format combobox
39 }
40 
41 ExportImageDialog::~ExportImageDialog()
42 {
43  delete ui;
44 }
45 
46 void ExportImageDialog::setCamerasInfo(const std::vector<std::pair<QString, QSize>>& cameraInfo)
47 {
48  Q_ASSERT(ui->cameraCombo);
49 
50  ui->cameraCombo->clear();
51  for (const std::pair<QString, QSize>& it : cameraInfo)
52  {
53  ui->cameraCombo->addItem(it.first, it.second);
54  }
55 
56  const auto indexChanged = static_cast<void(QComboBox::*)(int i)>(&QComboBox::currentIndexChanged);
57  connect(ui->cameraCombo, indexChanged, this, &ExportImageDialog::cameraComboChanged);
58 
59  cameraComboChanged(0);
60 }
61 
62 void ExportImageDialog::setDefaultRange(int startFrame, int endFrame, int endFrameWithSounds)
63 {
64  mEndFrame = endFrame;
65  mEndFrameWithSounds = endFrameWithSounds;
66 
67  QSignalBlocker b1( ui->startSpinBox );
68  QSignalBlocker b2( ui->endSpinBox );
69 
70  ui->startSpinBox->setValue( startFrame );
71  ui->endSpinBox->setValue( endFrame );
72 
73  connect(ui->frameCheckBox, &QCheckBox::clicked, this, &ExportImageDialog::frameCheckboxClicked);
74 }
75 
76 int ExportImageDialog::getStartFrame() const
77 {
78  return ui->startSpinBox->value();
79 }
80 
81 int ExportImageDialog::getEndFrame() const
82 {
83  return ui->endSpinBox->value();
84 }
85 
86 void ExportImageDialog::frameCheckboxClicked(bool checked)
87 {
88  int e = (checked) ? mEndFrameWithSounds : mEndFrame;
89  ui->endSpinBox->setValue(e);
90 }
91 
92 void ExportImageDialog::setExportSize(QSize size)
93 {
94  ui->imgWidthSpinBox->setValue(size.width());
95  ui->imgHeightSpinBox->setValue(size.height());
96 }
97 
98 QSize ExportImageDialog::getExportSize() const
99 {
100  return QSize(ui->imgWidthSpinBox->value(), ui->imgHeightSpinBox->value());
101 }
102 
103 bool ExportImageDialog::getTransparency() const
104 {
105  return ui->cbTransparency->checkState() == Qt::Checked;
106 }
107 
108 bool ExportImageDialog::getExportKeyframesOnly() const
109 {
110  return ui->cbExportKeyframesOnly->checkState() == Qt::Checked;
111 }
112 
113 QString ExportImageDialog::getExportFormat() const
114 {
115  return ui->formatComboBox->currentText();
116 }
117 
118 QString ExportImageDialog::getCameraLayerName() const
119 {
120  return ui->cameraCombo->currentText();
121 }
122 
123 void ExportImageDialog::formatChanged(const QString& format)
124 {
125  setFileExtension(format.toLower());
126  setTransparencyOptionVisibility(format);
127 }
128 
129 void ExportImageDialog::cameraComboChanged(int index)
130 {
131  const QSize cameraSize = ui->cameraCombo->itemData(index).toSize();
132 
133  ui->imgWidthSpinBox->setValue(cameraSize.width());
134  ui->imgHeightSpinBox->setValue(cameraSize.height());
135 }
136 
137 void ExportImageDialog::setTransparencyOptionVisibility(const QString &format)
138 {
139  if (format == "JPG" || format == "BMP")
140  ui->cbTransparency->setDisabled(true);
141  else
142  ui->cbTransparency->setDisabled(false);
143 }
int width() const const
QString tr(const char *sourceText, const char *disambiguation, int n)
void clicked(bool checked)
QString toLower() const const
void currentTextChanged(const QString &text)
void setWindowTitle(const QString &)
int height() const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void currentIndexChanged(int index)