Commit de93193d authored by Halla Rempt's avatar Halla Rempt

Add the configuration api to the relevant import/export filters

The gbr/gih export filter also has a config widget, but doesn't
store its settings -- that's a todo for later.
parent 078c0b48
......@@ -55,6 +55,26 @@ exrExport::~exrExport()
{
}
KisPropertiesConfigurationSP exrExport::defaultConfiguration(const QByteArray &/*from*/, const QByteArray &/*to*/) const
{
KisPropertiesConfigurationSP cfg = new KisPropertiesConfiguration();
cfg->setProperty("flatten", false);
return cfg;
}
KisPropertiesConfigurationSP exrExport::lastSavedConfiguration(const QByteArray &/*from*/, const QByteArray &/*to*/) const
{
KisPropertiesConfigurationSP cfg = new KisPropertiesConfiguration();
QString filterConfig = KisConfig().exportConfiguration("EXR");
cfg->fromXML(filterConfig);
return cfg;
}
KisConfigWidget *exrExport::createConfigurationWidget(QWidget *parent, const QByteArray &/*from*/, const QByteArray &/*to*/) const
{
return 0;
}
KisImportExportFilter::ConversionStatus exrExport::convert(const QByteArray& from, const QByteArray& to, KisPropertiesConfigurationSP configuration)
{
dbgFile << "EXR export! From:" << from << ", To:" << to << "";
......@@ -77,11 +97,9 @@ KisImportExportFilter::ConversionStatus exrExport::convert(const QByteArray& fro
dialog.setMainWidget(page);
dialog.resize(dialog.minimumSize());
QString filterConfig = KisConfig().exportConfiguration("EXR");
KisPropertiesConfiguration cfg;
cfg.fromXML(filterConfig);
KisPropertiesConfigurationSP cfg = lastSavedConfiguration(from, to);
widget.flatten->setChecked(cfg.getBool("flatten", false));
widget.flatten->setChecked(cfg->getBool("flatten", false));
if (!getBatchMode() ) {
QApplication::restoreOverrideCursor();
......@@ -90,8 +108,8 @@ KisImportExportFilter::ConversionStatus exrExport::convert(const QByteArray& fro
}
}
cfg.setProperty("flatten", widget.flatten->isChecked());
KisConfig().setExportConfiguration("EXR", cfg);
cfg->setProperty("flatten", widget.flatten->isChecked());
KisConfig().setExportConfiguration("EXR", *cfg.data());
QString filename = outputFile();
if (filename.isEmpty()) return KisImportExportFilter::FileNotFound;
......
......@@ -30,6 +30,9 @@ class exrExport : public KisImportExportFilter
public:
exrExport(QObject *parent, const QVariantList &);
virtual ~exrExport();
KisPropertiesConfigurationSP defaultConfiguration(const QByteArray& from = "", const QByteArray& to = "") const;
KisPropertiesConfigurationSP lastSavedConfiguration(const QByteArray &from = "", const QByteArray &to = "") const;
KisConfigWidget *createConfigurationWidget(QWidget *parent, const QByteArray& from = "", const QByteArray& to = "") const;
public:
virtual KisImportExportFilter::ConversionStatus convert(const QByteArray& from, const QByteArray& to, KisPropertiesConfigurationSP configuration = 0);
};
......
......@@ -56,6 +56,26 @@ KisHeightMapExport::~KisHeightMapExport()
{
}
KisPropertiesConfigurationSP KisHeightMapExport::defaultConfiguration(const QByteArray &/*from*/, const QByteArray &/*to*/) const
{
KisPropertiesConfigurationSP cfg = new KisPropertiesConfiguration();
cfg->setProperty("endianness", 0);
return cfg;
}
KisPropertiesConfigurationSP KisHeightMapExport::lastSavedConfiguration(const QByteArray &/*from*/, const QByteArray &/*to*/) const
{
KisPropertiesConfigurationSP cfg = new KisPropertiesConfiguration();
QString filterConfig = KisConfig().exportConfiguration("HeightMap");
cfg->fromXML(filterConfig);
return cfg;
}
KisConfigWidget *KisHeightMapExport::createConfigurationWidget(QWidget *parent, const QByteArray &/*from*/, const QByteArray &/*to*/) const
{
return 0;
}
KisImportExportFilter::ConversionStatus KisHeightMapExport::convert(const QByteArray& from, const QByteArray& to, KisPropertiesConfigurationSP configuration)
{
dbgFile << "HeightMap export! From:" << from << ", To:" << to;
......@@ -96,13 +116,11 @@ KisImportExportFilter::ConversionStatus KisHeightMapExport::convert(const QByteA
kdb->setMainWidget(wdg);
QApplication::restoreOverrideCursor();
QString filterConfig = KisConfig().exportConfiguration("HeightMap");
KisPropertiesConfiguration cfg;
cfg.fromXML(filterConfig);
KisPropertiesConfigurationSP cfg = lastSavedConfiguration();
optionsHeightMap.intSize->setValue(image->width());
int endianness = cfg.getInt("endianness", 0);
int endianness = cfg->getInt("endianness", 0);
QDataStream::ByteOrder bo = QDataStream::LittleEndian;
optionsHeightMap.radioPC->setChecked(true);
......@@ -118,14 +136,14 @@ KisImportExportFilter::ConversionStatus KisHeightMapExport::convert(const QByteA
}
if (optionsHeightMap.radioMac->isChecked()) {
cfg.setProperty("endianness", 0);
cfg->setProperty("endianness", 0);
bo = QDataStream::BigEndian;
}
else {
cfg.setProperty("endianness", 1);
cfg->setProperty("endianness", 1);
bo = QDataStream::LittleEndian;
}
KisConfig().setExportConfiguration("HeightMap", cfg);
KisConfig().setExportConfiguration("HeightMap", *cfg.data());
bool downscale = false;
if (to == "image/x-r8" && image->colorSpace()->colorDepthId() == Integer16BitsColorDepthID) {
......@@ -134,7 +152,7 @@ KisImportExportFilter::ConversionStatus KisHeightMapExport::convert(const QByteA
i18nc("@title:window", "Downscale Image"),
i18n("You specified the .r8 extension for a 16 bit/channel image. Do you want to save as 8 bit? Your image data will not be changed."),
QMessageBox::Yes | QMessageBox::No)
== QMessageBox::Yes);
== QMessageBox::Yes);
}
......
......@@ -29,6 +29,9 @@ class KisHeightMapExport : public KisImportExportFilter
public:
KisHeightMapExport(QObject *parent, const QVariantList &);
virtual ~KisHeightMapExport();
KisPropertiesConfigurationSP defaultConfiguration(const QByteArray& from = "", const QByteArray& to = "") const;
KisPropertiesConfigurationSP lastSavedConfiguration(const QByteArray &from = "", const QByteArray &to = "") const;
KisConfigWidget *createConfigurationWidget(QWidget *parent, const QByteArray& from = "", const QByteArray& to = "") const;
public:
virtual KisImportExportFilter::ConversionStatus convert(const QByteArray& from, const QByteArray& to, KisPropertiesConfigurationSP configuration = 0);
};
......
......@@ -54,6 +54,27 @@ jp2Export::~jp2Export()
{
}
KisPropertiesConfigurationSP jp2Export::defaultConfiguration(const QByteArray &/*from*/, const QByteArray &/*to*/) const
{
KisPropertiesConfigurationSP cfg = new KisPropertiesConfiguration();
cfg->setProperty("number_resolutions", 6);
cfg->setProperty("quality", 100);
return cfg;
}
KisPropertiesConfigurationSP jp2Export::lastSavedConfiguration(const QByteArray &/*from*/, const QByteArray &/*to*/) const
{
KisPropertiesConfigurationSP cfg = new KisPropertiesConfiguration();
QString filterConfig = KisConfig().exportConfiguration("JP2");
cfg->fromXML(filterConfig);
return cfg;
}
KisConfigWidget *jp2Export::createConfigurationWidget(QWidget *parent, const QByteArray &/*from*/, const QByteArray &/*to*/) const
{
return 0;
}
KisImportExportFilter::ConversionStatus jp2Export::convert(const QByteArray& from, const QByteArray& to, KisPropertiesConfigurationSP configuration)
{
dbgFile << "JP2 export! From:" << from << ", To:" << to << "";
......@@ -81,11 +102,10 @@ KisImportExportFilter::ConversionStatus jp2Export::convert(const QByteArray& fro
QWidget* wdg = new QWidget(kdb);
optionsJP2.setupUi(wdg);
QString filterConfig = KisConfig().exportConfiguration("JP2");
KisPropertiesConfiguration cfg;
cfg.fromXML(filterConfig);
optionsJP2.numberResolutions->setValue(cfg.getInt("number_resolutions", 6));
optionsJP2.qualityLevel->setValue(cfg.getInt("quality", 100));
KisPropertiesConfigurationSP cfg = lastSavedConfiguration();
optionsJP2.numberResolutions->setValue(cfg->getInt("number_resolutions", 6));
optionsJP2.qualityLevel->setValue(cfg->getInt("quality", 100));
kdb->setMainWidget(wdg);
QApplication::restoreOverrideCursor();
......@@ -98,11 +118,11 @@ KisImportExportFilter::ConversionStatus jp2Export::convert(const QByteArray& fro
JP2ConvertOptions options;
options.numberresolution = optionsJP2.numberResolutions->value();
cfg.setProperty("number_resolutions", options.numberresolution);
cfg->setProperty("number_resolutions", options.numberresolution);
options.rate = optionsJP2.qualityLevel->value();
cfg.setProperty("quality", options.rate);
cfg->setProperty("quality", options.rate);
KisConfig().setExportConfiguration("JP2", cfg);
KisConfig().setExportConfiguration("JP2", *cfg.data());
// the image must be locked at the higher levels
......
......@@ -29,6 +29,9 @@ class jp2Export : public KisImportExportFilter
public:
jp2Export(QObject *parent, const QVariantList &);
virtual ~jp2Export();
KisPropertiesConfigurationSP defaultConfiguration(const QByteArray& from = "", const QByteArray& to = "") const;
KisPropertiesConfigurationSP lastSavedConfiguration(const QByteArray &from = "", const QByteArray &to = "") const;
KisConfigWidget *createConfigurationWidget(QWidget *parent, const QByteArray& from = "", const QByteArray& to = "") const;
public:
virtual KisImportExportFilter::ConversionStatus convert(const QByteArray& from, const QByteArray& to, KisPropertiesConfigurationSP configuration = 0);
};
......
......@@ -89,41 +89,39 @@ KisImportExportFilter::ConversionStatus KisJPEGExport::convert(const QByteArray&
KisMetaData::FilterRegistryModel frm;
wdgUi.metaDataFilters->setModel(&frm);
QString filterConfig = KisConfig().exportConfiguration("JPEG");
KisPropertiesConfiguration cfg;
cfg.fromXML(filterConfig);
KisPropertiesConfigurationSP cfg = defaultConfiguration(from, to);
wdgUi.progressive->setChecked(cfg.getBool("progressive", false));
wdgUi.progressive->setChecked(cfg->getBool("progressive", false));
wdgUi.qualityLevel->setValue(cfg.getInt("quality", 80));
wdgUi.qualityLevel->setValue(cfg->getInt("quality", 80));
wdgUi.qualityLevel->setRange(0, 100, 0);
wdgUi.qualityLevel->setSuffix("%");
wdgUi.optimize->setChecked(cfg.getBool("optimize", true));
wdgUi.optimize->setChecked(cfg->getBool("optimize", true));
wdgUi.smoothLevel->setValue(cfg.getInt("smoothing", 0));
wdgUi.smoothLevel->setValue(cfg->getInt("smoothing", 0));
wdgUi.smoothLevel->setRange(0, 100, 0);
wdgUi.smoothLevel->setSuffix("%");
wdgUi.baseLineJPEG->setChecked(cfg.getBool("baseline", true));
wdgUi.subsampling->setCurrentIndex(cfg.getInt("subsampling", 0));
wdgUi.exif->setChecked(cfg.getBool("exif", true));
wdgUi.iptc->setChecked(cfg.getBool("iptc", true));
wdgUi.xmp->setChecked(cfg.getBool("xmp", true));
wdgUi.baseLineJPEG->setChecked(cfg->getBool("baseline", true));
wdgUi.subsampling->setCurrentIndex(cfg->getInt("subsampling", 0));
wdgUi.exif->setChecked(cfg->getBool("exif", true));
wdgUi.iptc->setChecked(cfg->getBool("iptc", true));
wdgUi.xmp->setChecked(cfg->getBool("xmp", true));
const KoColorSpace* cs = image->projection()->colorSpace();
bool sRGB = cs->profile()->name().contains(QLatin1String("srgb"), Qt::CaseInsensitive);
wdgUi.chkForceSRGB->setVisible(!sRGB);
wdgUi.chkForceSRGB->setChecked(cfg.getBool("forceSRGB", false));
wdgUi.chkForceSRGB->setChecked(cfg->getBool("forceSRGB", false));
wdgUi.chkSaveProfile->setChecked(cfg.getBool("saveProfile", true));
wdgUi.chkSaveProfile->setChecked(cfg->getBool("saveProfile", true));
QStringList rgb = cfg.getString("transparencyFillcolor", "255,255,255").split(',');
QStringList rgb = cfg->getString("transparencyFillcolor", "255,255,255").split(',');
wdgUi.bnTransparencyFillColor->setDefaultColor(Qt::white);
wdgUi.bnTransparencyFillColor->setColor(QColor(rgb[0].toInt(), rgb[1].toInt(), rgb[2].toInt()));
frm.setEnabledFilters(cfg.getString("filters").split(','));
frm.setEnabledFilters(cfg->getString("filters").split(','));
kdb->setMainWidget(wdg);
QApplication::restoreOverrideCursor();
......@@ -137,42 +135,42 @@ KisImportExportFilter::ConversionStatus KisJPEGExport::convert(const QByteArray&
KisJPEGOptions options;
options.progressive = wdgUi.progressive->isChecked();
cfg.setProperty("progressive", options.progressive);
cfg->setProperty("progressive", options.progressive);
options.quality = (int)wdgUi.qualityLevel->value();
cfg.setProperty("quality", options.quality);
cfg->setProperty("quality", options.quality);
options.forceSRGB = wdgUi.chkForceSRGB->isChecked();
cfg.setProperty("forceSRGB", options.forceSRGB);
cfg->setProperty("forceSRGB", options.forceSRGB);
options.saveProfile = wdgUi.chkSaveProfile->isChecked();
cfg.setProperty("saveProfile", options.saveProfile);
cfg->setProperty("saveProfile", options.saveProfile);
// Advanced
options.optimize = wdgUi.optimize->isChecked();
cfg.setProperty("optimize", options.optimize);
cfg->setProperty("optimize", options.optimize);
options.smooth = (int)wdgUi.smoothLevel->value();
cfg.setProperty("smoothing", options.smooth);
cfg->setProperty("smoothing", options.smooth);
options.baseLineJPEG = wdgUi.baseLineJPEG->isChecked();
cfg.setProperty("baseline", options.baseLineJPEG);
cfg->setProperty("baseline", options.baseLineJPEG);
options.subsampling = wdgUi.subsampling->currentIndex();
cfg.setProperty("subsampling", options.subsampling);
cfg->setProperty("subsampling", options.subsampling);
// Jpeg
options.exif = wdgUi.exif->isChecked();
cfg.setProperty("exif", options.exif);
cfg->setProperty("exif", options.exif);
options.iptc = wdgUi.iptc->isChecked();
cfg.setProperty("iptc", options.iptc);
cfg->setProperty("iptc", options.iptc);
options.xmp = wdgUi.xmp->isChecked();
cfg.setProperty("xmp", options.xmp);
cfg->setProperty("xmp", options.xmp);
QColor c = wdgUi.bnTransparencyFillColor->color();
options.transparencyFillColor = c;
cfg.setProperty("transparencyFillcolor", QString("%1,%2,%3").arg(c.red()).arg(c.green()).arg(c.blue()));
cfg->setProperty("transparencyFillcolor", QString("%1,%2,%3").arg(c.red()).arg(c.green()).arg(c.blue()));
options.filters = frm.enabledFilters();
QString enabledFilters;
......@@ -180,9 +178,9 @@ KisImportExportFilter::ConversionStatus KisJPEGExport::convert(const QByteArray&
enabledFilters = enabledFilters + filter->id() + ',';
}
cfg.setProperty("filters", enabledFilters);
cfg->setProperty("filters", enabledFilters);
KisConfig().setExportConfiguration("JPEG", cfg);
KisConfig().setExportConfiguration("JPEG", *cfg.data());
delete kdb;
// XXX: Add dialog about flattening layers here
......@@ -222,5 +220,38 @@ KisImportExportFilter::ConversionStatus KisJPEGExport::convert(const QByteArray&
return KisImportExportFilter::InternalError;
}
KisPropertiesConfigurationSP KisJPEGExport::defaultConfiguration(const QByteArray &/*from*/, const QByteArray &/*to*/) const
{
KisPropertiesConfigurationSP cfg = new KisPropertiesConfiguration();
cfg->setProperty("progressive", false);
cfg->setProperty("quality", 80);
cfg->setProperty("forceSRGB", false);
cfg->setProperty("saveProfile", true);
cfg->setProperty("optimize", true);
cfg->setProperty("smoothing", 0);
cfg->setProperty("baseline", true);
cfg->setProperty("subsampling", 0);
cfg->setProperty("exif", true);
cfg->setProperty("iptc", true);
cfg->setProperty("xmp", true);
cfg->setProperty("transparencyFillcolor", QString("255,255,255"));
cfg->setProperty("filters", "");
return cfg;
}
KisPropertiesConfigurationSP KisJPEGExport::lastSavedConfiguration(const QByteArray &/*from*/, const QByteArray &/*to*/) const
{
KisPropertiesConfigurationSP cfg = new KisPropertiesConfiguration();
QString filterConfig = KisConfig().exportConfiguration("JPEG");
cfg->fromXML(filterConfig);
return cfg;
}
KisConfigWidget *KisJPEGExport::createConfigurationWidget(QWidget *parent, const QByteArray &/*from*/, const QByteArray &/*to*/) const
{
return 0;
}
#include <kis_jpeg_export.moc>
......@@ -32,6 +32,9 @@ public:
virtual ~KisJPEGExport();
public:
virtual KisImportExportFilter::ConversionStatus convert(const QByteArray& from, const QByteArray& to, KisPropertiesConfigurationSP configuration = 0);
KisPropertiesConfigurationSP defaultConfiguration(const QByteArray& from = "", const QByteArray& to = "") const;
KisPropertiesConfigurationSP lastSavedConfiguration(const QByteArray &from = "", const QByteArray &to = "") const;
KisConfigWidget *createConfigurationWidget(QWidget *parent, const QByteArray& from = "", const QByteArray& to = "") const;
};
#endif
......@@ -163,11 +163,9 @@ KisImportExportFilter::ConversionStatus KisPPMExport::convert(const QByteArray&
kdb->setMainWidget(wdg);
QApplication::restoreOverrideCursor();
QString filterConfig = KisConfig().exportConfiguration("PPM");
KisPropertiesConfiguration cfg;
cfg.fromXML(filterConfig);
KisPropertiesConfigurationSP cfg = lastSavedConfiguration(from, to);
optionsPPM.type->setCurrentIndex(cfg.getInt("type", 0));
optionsPPM.type->setCurrentIndex(cfg->getInt("type", 0));
if (!getBatchMode()) {
if (kdb->exec() == QDialog::Rejected) {
......@@ -177,8 +175,8 @@ KisImportExportFilter::ConversionStatus KisPPMExport::convert(const QByteArray&
bool rgb = (to == "image/x-portable-pixmap");
bool binary = optionsPPM.type->currentIndex() == 0;
cfg.setProperty("type", optionsPPM.type->currentIndex());
KisConfig().setExportConfiguration("PPM", cfg);
cfg->setProperty("type", optionsPPM.type->currentIndex());
KisConfig().setExportConfiguration("PPM", *cfg.data());
bool bitmap = (to == "image/x-portable-bitmap");
......@@ -283,4 +281,24 @@ KisImportExportFilter::ConversionStatus KisPPMExport::convert(const QByteArray&
return KisImportExportFilter::OK;
}
KisPropertiesConfigurationSP KisPPMExport::defaultConfiguration(const QByteArray &/*from*/, const QByteArray &/*to*/) const
{
KisPropertiesConfigurationSP cfg = new KisPropertiesConfiguration();
cfg->setProperty("type", 0);
return cfg;
}
KisPropertiesConfigurationSP KisPPMExport::lastSavedConfiguration(const QByteArray &/*from*/, const QByteArray &/*to*/) const
{
KisPropertiesConfigurationSP cfg = new KisPropertiesConfiguration();
QString filterConfig = KisConfig().exportConfiguration("PPM");
cfg->fromXML(filterConfig);
return cfg;
}
KisConfigWidget *KisPPMExport::createConfigurationWidget(QWidget *parent, const QByteArray &/*from*/, const QByteArray &/*to*/) const
{
return 0;
}
#include "kis_ppm_export.moc"
......@@ -31,6 +31,9 @@ public:
virtual ~KisPPMExport();
public:
virtual KisImportExportFilter::ConversionStatus convert(const QByteArray& from, const QByteArray& to, KisPropertiesConfigurationSP configuration = 0);
KisPropertiesConfigurationSP defaultConfiguration(const QByteArray& from = "", const QByteArray& to = "") const;
KisPropertiesConfigurationSP lastSavedConfiguration(const QByteArray &from = "", const QByteArray &to = "") const;
KisConfigWidget *createConfigurationWidget(QWidget *parent, const QByteArray& from = "", const QByteArray& to = "") const;
};
#endif
......@@ -33,6 +33,7 @@ class KisDlgOptionsTIFF : public KoDialog
public:
KisDlgOptionsTIFF(QWidget *parent = 0);
~KisDlgOptionsTIFF();
public Q_SLOTS:
void activated(int index);
void flattenToggled(bool);
......
......@@ -36,7 +36,7 @@
#include <kis_image.h>
#include <kis_paint_layer.h>
#include <kis_paint_device.h>
#include <kis_config.h>
#include "kis_tiff_converter.h"
#include "kis_dlg_options_tiff.h"
......@@ -123,5 +123,34 @@ KisImportExportFilter::ConversionStatus KisTIFFExport::convert(const QByteArray&
return KisImportExportFilter::InternalError;
}
KisPropertiesConfigurationSP KisTIFFExport::defaultConfiguration(const QByteArray &/*from*/, const QByteArray &/*to*/) const
{
KisPropertiesConfigurationSP cfg = new KisPropertiesConfiguration();
cfg->setProperty("compressiontype", 0);
cfg->setProperty("predictor", 0);
cfg->setProperty("alpha", true);
cfg->setProperty("flatten", true);
cfg->setProperty("quality", 80);
cfg->setProperty("deflate", 6);
cfg->setProperty("faxmode", 0);
cfg->setProperty("pixarlog", 6);
cfg->setProperty("saveProfile", true);
return cfg;
}
KisPropertiesConfigurationSP KisTIFFExport::lastSavedConfiguration(const QByteArray &/*from*/, const QByteArray &/*to*/) const
{
QString filterConfig = KisConfig().exportConfiguration("TIFF");
KisPropertiesConfigurationSP cfg = new KisPropertiesConfiguration();
cfg->fromXML(filterConfig);
return cfg;
}
KisConfigWidget *KisTIFFExport::createConfigurationWidget(QWidget *parent, const QByteArray &/*from*/, const QByteArray &/*to*/) const
{
return 0;
}
#include <kis_tiff_export.moc>
......@@ -32,6 +32,9 @@ public:
virtual ~KisTIFFExport();
public:
virtual KisImportExportFilter::ConversionStatus convert(const QByteArray& from, const QByteArray& to, KisPropertiesConfigurationSP configuration = 0);
KisPropertiesConfigurationSP defaultConfiguration(const QByteArray& from = "", const QByteArray& to = "") const;
KisPropertiesConfigurationSP lastSavedConfiguration(const QByteArray &from = "", const QByteArray &to = "") const;
KisConfigWidget *createConfigurationWidget(QWidget *parent, const QByteArray& from = "", const QByteArray& to = "") const;
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment