Commit 1d123e38 authored by Halla Rempt's avatar Halla Rempt

Fully port the heightmap plugin to the configuration architecture

parent de93193d
......@@ -43,8 +43,7 @@
#include <kis_config.h>
#include <kis_iterator_ng.h>
#include <kis_random_accessor_ng.h>
#include "ui_kis_wdg_options_heightmap.h"
#include <kis_config_widget.h>
K_PLUGIN_FACTORY_WITH_JSON(KisHeightMapExportFactory, "krita_heightmap_export.json", registerPlugin<KisHeightMapExport>();)
......@@ -73,7 +72,7 @@ KisPropertiesConfigurationSP KisHeightMapExport::lastSavedConfiguration(const QB
KisConfigWidget *KisHeightMapExport::createConfigurationWidget(QWidget *parent, const QByteArray &/*from*/, const QByteArray &/*to*/) const
{
return 0;
return new KisWdgOptionsHeightmap(parent);
}
KisImportExportFilter::ConversionStatus KisHeightMapExport::convert(const QByteArray& from, const QByteArray& to, KisPropertiesConfigurationSP configuration)
......@@ -107,42 +106,31 @@ KisImportExportFilter::ConversionStatus KisHeightMapExport::convert(const QByteA
KoDialog* kdb = new KoDialog(0);
kdb->setWindowTitle(i18n("HeightMap Export Options"));
kdb->setButtons(KoDialog::Ok | KoDialog::Cancel);
Ui::WdgOptionsHeightMap optionsHeightMap;
QWidget* wdg = new QWidget(kdb);
optionsHeightMap.setupUi(wdg);
KisConfigWidget *wdg = createConfigurationWidget(kdb, from, to);
kdb->setMainWidget(wdg);
QApplication::restoreOverrideCursor();
KisPropertiesConfigurationSP cfg = lastSavedConfiguration();
optionsHeightMap.intSize->setValue(image->width());
int endianness = cfg->getInt("endianness", 0);
QDataStream::ByteOrder bo = QDataStream::LittleEndian;
optionsHeightMap.radioPC->setChecked(true);
QApplication::restoreOverrideCursor();
if (endianness == 0) {
bo = QDataStream::BigEndian;
optionsHeightMap.radioMac->setChecked(true);
// If a configuration object was passed to the convert method, we use that, otherwise we load from the settings
KisPropertiesConfigurationSP cfg(new KisPropertiesConfiguration());
if (configuration) {
cfg->fromXML(configuration->toXML());
}
else {
cfg = lastSavedConfiguration(from, to);
}
cfg->setProperty("width", image->width());
wdg->setConfiguration(cfg);
if (!getBatchMode()) {
if (kdb->exec() == QDialog::Rejected) {
return KisImportExportFilter::UserCancelled;
}
}
cfg = wdg->configuration();
QDataStream::ByteOrder bo = cfg->getInt("endianness", 0) ? QDataStream::BigEndian : QDataStream::LittleEndian;
if (optionsHeightMap.radioMac->isChecked()) {
cfg->setProperty("endianness", 0);
bo = QDataStream::BigEndian;
}
else {
cfg->setProperty("endianness", 1);
bo = QDataStream::LittleEndian;
}
KisConfig().setExportConfiguration("HeightMap", *cfg.data());
bool downscale = false;
......@@ -183,4 +171,24 @@ KisImportExportFilter::ConversionStatus KisHeightMapExport::convert(const QByteA
return KisImportExportFilter::OK;
}
void KisWdgOptionsHeightmap::setConfiguration(const KisPropertiesConfigurationSP cfg)
{
intSize->setValue(cfg->getInt("width"));
int endianness = cfg->getInt("endianness", 0);
radioMac->setChecked(endianness == 0);
}
KisPropertiesConfigurationSP KisWdgOptionsHeightmap::configuration() const
{
KisPropertiesConfigurationSP cfg = new KisPropertiesConfiguration();
if (radioMac->isChecked()) {
cfg->setProperty("endianness", 0);
}
else {
cfg->setProperty("endianness", 1);
}
return cfg;
}
#include "kis_heightmap_export.moc"
......@@ -22,6 +22,24 @@
#include <QVariant>
#include <KisImportExportFilter.h>
#include <kis_config_widget.h>
#include "ui_kis_wdg_options_heightmap.h"
class KisWdgOptionsHeightmap : public KisConfigWidget, public Ui::WdgOptionsHeightMap
{
Q_OBJECT
public:
KisWdgOptionsHeightmap(QWidget *parent)
: KisConfigWidget(parent)
{
setupUi(this);
}
void setConfiguration(const KisPropertiesConfigurationSP cfg);
KisPropertiesConfigurationSP configuration() const;
};
class KisHeightMapExport : public KisImportExportFilter
{
......
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