Commit 1bde9e70 authored by Ivan Yossi's avatar Ivan Yossi 👌

Allow export multidimention gih

parent 27ee40f5
......@@ -45,7 +45,9 @@ struct KisBrushExportOptions {
qreal spacing;
bool mask;
int brushStyle;
int selectionMode;
int dimensions;
qint32 ranks[KisPipeBrushParasite::MaxDim];
qint32 selectionModes[KisPipeBrushParasite::MaxDim];
QString name;
};
......@@ -74,6 +76,7 @@ KisImportExportErrorCode KisBrushExport::convert(KisDocument *document, QIODevic
// }
KisBrushExportOptions exportOptions;
if (document->savingImage()->dynamicPropertyNames().contains("brushspacing")) {
exportOptions.spacing = document->savingImage()->property("brushspacing").toFloat();
}
......@@ -86,9 +89,15 @@ KisImportExportErrorCode KisBrushExport::convert(KisDocument *document, QIODevic
else {
exportOptions.name = document->savingImage()->objectName();
}
exportOptions.mask = configuration->getBool("mask");
exportOptions.selectionMode = configuration->getInt("selectionMode");
exportOptions.brushStyle = configuration->getInt("brushStyle");
exportOptions.dimensions = configuration->getInt("dimensions");
for (int i = 0; i < KisPipeBrushParasite::MaxDim; ++i) {
exportOptions.selectionModes[i] = configuration->getInt("selectionMode" + QString::number(i));
exportOptions.ranks[i] = configuration->getInt("rank" + QString::number(i));
}
KisGbrBrush *brush = 0;
if (mimeType() == "image/x-gimp-brush") {
......@@ -107,8 +116,6 @@ KisImportExportErrorCode KisBrushExport::convert(KisDocument *document, QIODevic
brush->setSpacing(exportOptions.spacing);
KisImagePipeBrush *pipeBrush = dynamic_cast<KisImagePipeBrush*>(brush);
if (pipeBrush) {
// Create parasite. XXX: share with KisCustomBrushWidget
......@@ -120,28 +127,34 @@ KisImportExportErrorCode KisBrushExport::convert(KisDocument *document, QIODevic
QList<KisNodeSP> layers = document->savingImage()->root()->childNodes(QStringList("KisLayer"), properties);
Q_FOREACH (KisNodeSP node, layers) {
devices[0].push_back(node->projection().data());
// push_front to behave exactly as gimp for gih creation
devices[0].push_front(node->projection().data());
}
QVector<KisParasite::SelectionMode > modes;
switch (exportOptions.selectionMode) {
case 0: modes.push_back(KisParasite::Constant); break;
case 1: modes.push_back(KisParasite::Random); break;
case 2: modes.push_back(KisParasite::Incremental); break;
case 3: modes.push_back(KisParasite::Pressure); break;
case 4: modes.push_back(KisParasite::Angular); break;
case 5: modes.push_back(KisParasite::Velocity); break;
default: modes.push_back(KisParasite::Incremental);
for (int i = 0; i < KisPipeBrushParasite::MaxDim; ++i) {
switch (exportOptions.selectionModes[i]) {
case 0: modes.push_back(KisParasite::Constant); break;
case 1: modes.push_back(KisParasite::Random); break;
case 2: modes.push_back(KisParasite::Incremental); break;
case 3: modes.push_back(KisParasite::Pressure); break;
case 4: modes.push_back(KisParasite::Angular); break;
case 5: modes.push_back(KisParasite::Velocity); break;
default: modes.push_back(KisParasite::Incremental);
}
}
KisPipeBrushParasite parasite;
// XXX: share code with KisImagePipeBrush, when we figure out how to support more gih features
parasite.dim = devices.count();
// XXX Change for multidim! :
parasite.dim = exportOptions.dimensions;
parasite.ncells = devices.at(0).count();
parasite.rank[0] = parasite.ncells; // ### This can mask some bugs, be careful here in the future
parasite.selection[0] = modes.at(0);
for (int i = 0; i < KisPipeBrushParasite::MaxDim; ++i) {
// ### This can mask some bugs, be careful here in the future
parasite.rank[i] = exportOptions.ranks[i];
parasite.selection[i] = modes.at(i);
}
// XXX needs movement!
parasite.setBrushesCount();
pipeBrush->setParasite(parasite);
......@@ -184,8 +197,13 @@ KisPropertiesConfigurationSP KisBrushExport::defaultConfiguration(const QByteArr
cfg->setProperty("spacing", 1.0);
cfg->setProperty("name", "");
cfg->setProperty("mask", true);
cfg->setProperty("selectionMode", 0);
cfg->setProperty("brushStyle", 0);
cfg->setProperty("dimensions", 1);
for (int i = 0; i < KisPipeBrushParasite::MaxDim; ++i) {
cfg->setProperty("selectionMode" + QString::number(i), 2);
cfg->getInt("rank" + QString::number(i), 0);
}
return cfg;
}
......@@ -194,10 +212,16 @@ KisConfigWidget *KisBrushExport::createConfigurationWidget(QWidget *parent, cons
KisWdgOptionsBrush *wdg = new KisWdgOptionsBrush(parent);
if (to == "image/x-gimp-brush") {
wdg->groupBox->setVisible(false);
wdg->animStyleGroup->setVisible(false);
}
else if (to == "image/x-gimp-brush-animated") {
wdg->groupBox->setVisible(true);
wdg->animStyleGroup->setVisible(true);
}
// preload gih name with chosen filename
QFileInfo fileLocation(filename());
wdg->nameLineEdit->setText(fileLocation.baseName());
return wdg;
}
......@@ -217,10 +241,22 @@ void KisBrushExport::initializeCapabilities()
void KisWdgOptionsBrush::setConfiguration(const KisPropertiesConfigurationSP cfg)
{
spacingWidget->setSpacing(false, cfg->getDouble("spacing"));
nameLineEdit->setText(cfg->getString("name"));
if(nameLineEdit->text().isEmpty()){
nameLineEdit->setText(cfg->getString("name"));
}
colorAsMask->setChecked(cfg->getBool("mask"));
brushStyle->setCurrentIndex(cfg->getInt("brushStyle"));
cmbSelectionMode->setCurrentIndex(cfg->getInt("selectionMode"));
dimensionSpin->setValue(cfg->getInt("dimensions"));
QLayoutItem *item;
BrushPipeSelectionModeHelper *bp;
for (int i = 0; i < dimensionSpin->maximum(); ++i) {
if((item = dimRankLayout->itemAt(i)) != 0) {
bp = dynamic_cast<BrushPipeSelectionModeHelper*>(item->widget());
bp->cmbSelectionMode.setCurrentIndex(cfg->getInt("selectionMode" + QString::number(i)));
bp->rank.setValue(cfg->getInt("rank" + QString::number(i)));
}
}
}
KisPropertiesConfigurationSP KisWdgOptionsBrush::configuration() const
......@@ -229,8 +265,19 @@ KisPropertiesConfigurationSP KisWdgOptionsBrush::configuration() const
cfg->setProperty("spacing", spacingWidget->spacing());
cfg->setProperty("name", nameLineEdit->text());
cfg->setProperty("mask", colorAsMask->isChecked());
cfg->setProperty("selectionMode", cmbSelectionMode->currentIndex());
cfg->setProperty("brushStyle", brushStyle->currentIndex());
cfg->setProperty("dimensions", dimensionSpin->value());
QLayoutItem *item;
BrushPipeSelectionModeHelper *bp;
for (int i = 0; i < dimensionSpin->maximum(); ++i) {
if((item = dimRankLayout->itemAt(i)) != 0) {
bp = dynamic_cast<BrushPipeSelectionModeHelper*>(item->widget());
cfg->setProperty("selectionMode" + QString::number(i), bp->cmbSelectionMode.currentIndex());
cfg->setProperty("rank" + QString::number(i), bp->rank.value());
}
}
return cfg;
}
......
......@@ -21,12 +21,75 @@
#define _KIS_Brush_EXPORT_H_
#include <QVariant>
#include <QSpinBox>
#include <QPainter>
#include <KisImportExportFilter.h>
#include <ui_wdg_export_gih.h>
#include <kis_config_widget.h>
#include <kis_properties_configuration.h>
class SelectionModeComboBox : public QComboBox
{
Q_OBJECT
public:
SelectionModeComboBox(QWidget *parent)
: QComboBox(parent)
{
this->addItem(i18n("Constant"));
this->addItem(i18n("Random"));
this->addItem(i18n("Incremental"));
this->addItem(i18n("Pressure"));
this->addItem(i18n("Angular"));
this->addItem(i18n("Velocity"));
}
};
class BrushPipeSelectionModeHelper : public QWidget
{
Q_OBJECT
public:
BrushPipeSelectionModeHelper(QWidget *parent)
: QWidget(parent)
, cmbSelectionMode(this)
, rank(this)
, rankLbl(this)
, horizLayout(this)
{
horizLayout.setSpacing(6);
horizLayout.setMargin(0);
QSizePolicy sizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed));
sizePolicy.setHorizontalStretch(1);
sizePolicy.setVerticalStretch(0);
this->setSizePolicy(sizePolicy);
cmbSelectionMode.setSizePolicy(sizePolicy);
cmbSelectionMode.setCurrentIndex(2);
rank.setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred));
rankLbl.setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
rankLbl.setText(i18n("Rank"));
horizLayout.addWidget(&rankLbl);
horizLayout.addWidget(&rank);
horizLayout.addWidget(&cmbSelectionMode);
this->hide();
this->setEnabled(false);
}
SelectionModeComboBox cmbSelectionMode;
QSpinBox rank;
QLabel rankLbl;
QHBoxLayout horizLayout;
};
class KisWdgOptionsBrush : public KisConfigWidget, public Ui::WdgExportGih
{
Q_OBJECT
......@@ -34,21 +97,60 @@ class KisWdgOptionsBrush : public KisConfigWidget, public Ui::WdgExportGih
public:
KisWdgOptionsBrush(QWidget *parent)
: KisConfigWidget(parent)
, currentDimensions(0)
{
setupUi(this);
connect(this->brushStyle, SIGNAL(currentIndexChanged(int)), SLOT(enableSelectionMedthod(int)));
connect(this->dimensionSpin, SIGNAL(valueChanged(int)), SLOT(activateDimensionRanks()));
enableSelectionMedthod(brushStyle->currentIndex());
for (int i = 0; i < this->dimensionSpin->maximum(); i++) {
dimRankLayout->addWidget(new BrushPipeSelectionModeHelper(0));
}
activateDimensionRanks();
}
void setConfiguration(const KisPropertiesConfigurationSP cfg) override;
KisPropertiesConfigurationSP configuration() const override;
public Q_SLOTS:
void enableSelectionMedthod(int value) {
if (value == 0) {
cmbSelectionMode->setEnabled(false);
animStyleGroup->setEnabled(false);
} else {
cmbSelectionMode->setEnabled(true);
animStyleGroup->setEnabled(true);
}
}
void activateDimensionRanks()
{
QLayoutItem *item;
BrushPipeSelectionModeHelper *bp;
int dim = this->dimensionSpin->value();
if(dim >= currentDimensions) {
for (int i = currentDimensions; i < dim; ++i) {
if((item = dimRankLayout->itemAt(i)) != 0) {
bp = dynamic_cast<BrushPipeSelectionModeHelper*>(item->widget());
bp->setEnabled(true);
bp->show();
}
}
}
else {
for (int i = currentDimensions -1; i >= dim; --i) {
if((item = dimRankLayout->itemAt(i)) != 0) {
bp = dynamic_cast<BrushPipeSelectionModeHelper*>(item->widget());
bp->setEnabled(false);
bp->hide();
}
}
}
currentDimensions = dim;
}
private:
int currentDimensions;
};
......
......@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>468</width>
<height>318</height>
<height>429</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_3">
......@@ -55,7 +55,7 @@
<property name="minimumSize">
<size>
<width>0</width>
<height>110</height>
<height>0</height>
</size>
</property>
<property name="title">
......@@ -66,12 +66,15 @@
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_2">
<property name="spacing">
<layout class="QGridLayout" name="gridLayout_2" columnstretch="0,0">
<property name="horizontalSpacing">
<number>9</number>
</property>
<property name="verticalSpacing">
<number>3</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="textLabel2">
<widget class="QLabel" name="styleLbl">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
......@@ -106,75 +109,142 @@
</item>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="textLabel3">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Selection mode:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="cmbSelectionMode">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="currentIndex">
<number>2</number>
</property>
<item>
<property name="text">
<string>Constant</string>
</property>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="animStyleGroup">
<property name="title">
<string>Animated style options</string>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number>
</property>
<property name="verticalSpacing">
<number>0</number>
</property>
<item row="2" column="0">
<layout class="QVBoxLayout" name="animStyleLayout">
<property name="spacing">
<number>3</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,0,1">
<item>
<property name="text">
<string>Random</string>
</property>
<widget class="QLabel" name="dimensionLbl">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Dimensions</string>
</property>
<property name="margin">
<number>0</number>
</property>
</widget>
</item>
<item>
<property name="text">
<string>Incremental</string>
</property>
<widget class="QSpinBox" name="dimensionSpin">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>4</number>
</property>
</widget>
</item>
<item>
<property name="text">
<string>Pressure</string>
</property>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="spacing">
<number>6</number>
</property>
<item>
<property name="text">
<string>Angular</string>
</property>
<widget class="QLabel" name="selectionModeLbl">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Selection mode:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<property name="text">
<string>Velocity</string>
</property>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</widget>
</layout>
</item>
</layout>
</item>
<item row="3" column="0">
<layout class="QVBoxLayout" name="dimRankLayout">
<property name="spacing">
<number>3</number>
</property>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>6</number>
</property>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
......
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