Commit e75cefac authored by Ivan Yossi's avatar Ivan Yossi 👌

Refactor impex brush_export

parent 8b492777
......@@ -2,6 +2,7 @@ add_subdirectory(tests)
set(kritabrushexport_PART_SRCS
kis_brush_export.cpp
KisWdgOptionsBrush.cpp
KisAnimatedBrushAnnotation.cpp
)
......
/*
* Copyright (c) 2016 Boudewijn Rempt <boud@valdyas.org>
* Copyright (c) 2019 Iván SantaMaría <ghevan@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "KisWdgOptionsBrush.h"
#include <KisViewManager.h>
#include <kis_image.h>
#include <KoProperties.h>
#include <KisDocument.h>
KisWdgOptionsBrush::KisWdgOptionsBrush(QWidget *parent)
: KisConfigWidget(parent)
, currentDimensions(0)
, m_layersCount(0)
, m_view(0)
{
setupUi(this);
connect(this->brushStyle, SIGNAL(currentIndexChanged(int)), SLOT(slotEnableSelectionMethod(int)));
connect(this->dimensionSpin, SIGNAL(valueChanged(int)), SLOT(slotActivateDimensionRanks()));
slotEnableSelectionMethod(brushStyle->currentIndex());
BrushPipeSelectionModeHelper *bp;
for (int i = 0; i < this->dimensionSpin->maximum(); i++) {
bp = new BrushPipeSelectionModeHelper(0, i);
connect(bp, SIGNAL(sigRankChanged(int)), SLOT(slotRecalculateRanks(int)));
dimRankLayout->addWidget(bp);
}
slotActivateDimensionRanks();
}
void KisWdgOptionsBrush::setConfiguration(const KisPropertiesConfigurationSP cfg)
{
spacingWidget->setSpacing(false, cfg->getDouble("spacing"));
if(nameLineEdit->text().isEmpty()){
nameLineEdit->setText(cfg->getString("name"));
}
colorAsMask->setChecked(cfg->getBool("mask"));
brushStyle->setCurrentIndex(cfg->getInt("brushStyle"));
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->rankSpinBox.setValue(cfg->getInt("rank" + QString::number(i)));
}
}
}
KisPropertiesConfigurationSP KisWdgOptionsBrush::configuration() const
{
KisPropertiesConfigurationSP cfg = new KisPropertiesConfiguration();
cfg->setProperty("spacing", spacingWidget->spacing());
cfg->setProperty("name", nameLineEdit->text());
cfg->setProperty("mask", colorAsMask->isChecked());
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->rankSpinBox.value());
}
}
return cfg;
}
void KisWdgOptionsBrush::setView(KisViewManager *view)
{
if (view) {
m_view = view;
KoProperties properties;
properties.setProperty("visible", true);
m_layersCount = m_view->image()->root()->childNodes(QStringList("KisLayer"), properties).count();
slotRecalculateRanks();
}
}
void KisWdgOptionsBrush::slotEnableSelectionMethod(int value) {
if (value == 0) {
animStyleGroup->setEnabled(false);
} else {
animStyleGroup->setEnabled(true);
}
}
void KisWdgOptionsBrush::slotActivateDimensionRanks()
{
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;
}
void KisWdgOptionsBrush::slotRecalculateRanks(int rankDimension) {
// currentDimensions;
int rankSum = 0;
int maxDim = this->dimensionSpin->maximum();
QVector<BrushPipeSelectionModeHelper *> bp;
QLayoutItem *item;
for (int i = 0; i < maxDim; ++i) {
if((item = dimRankLayout->itemAt(i)) != 0) {
bp.push_back(dynamic_cast<BrushPipeSelectionModeHelper*>(item->widget()));
rankSum += bp.at(i)->rankSpinBox.value();
}
}
BrushPipeSelectionModeHelper *currentBrushHelper;
BrushPipeSelectionModeHelper *callerBrushHelper = bp.at(rankDimension);
QVectorIterator<BrushPipeSelectionModeHelper*> bpIterator(bp);
while (rankSum > m_layersCount && bpIterator.hasNext()) {
currentBrushHelper = bpIterator.next();
if(currentBrushHelper != callerBrushHelper) {
int currentValue = currentBrushHelper->rankSpinBox.value();
currentBrushHelper->rankSpinBox.setValue(currentValue -1);
rankSum -= currentValue;
}
}
if (rankSum > m_layersCount) {
callerBrushHelper->rankSpinBox.setValue(m_layersCount);
}
if (rankSum == 0) {
bp.at(0)->rankSpinBox.setValue(m_layersCount);
return;
}
}
/*
* Copyright (c) 2016 Boudewijn Rempt <boud@valdyas.org>
* Copyright (c) 2019 Iván SantaMaría <ghevan@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef KISWDGOPTIONSBRUSH_H
#define KISWDGOPTIONSBRUSH_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 BrushPipeSelectionModeHelper : public QWidget
{
Q_OBJECT
public:
BrushPipeSelectionModeHelper(QWidget *parent, int dimension)
: QWidget(parent)
, cmbSelectionMode(this)
, rankSpinBox(this)
, rankLbl(this)
, horizLayout(this)
, dimension(dimension)
{
cmbSelectionMode.addItem(i18n("Constant"));
cmbSelectionMode.addItem(i18n("Random"));
cmbSelectionMode.addItem(i18n("Incremental"));
cmbSelectionMode.addItem(i18n("Pressure"));
cmbSelectionMode.addItem(i18n("Angular"));
cmbSelectionMode.addItem(i18n("Velocity"));
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);
rankSpinBox.setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred));
rankLbl.setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
rankLbl.setText(i18n("Rank"));
horizLayout.addWidget(&rankLbl);
horizLayout.addWidget(&rankSpinBox);
horizLayout.addWidget(&cmbSelectionMode);
connect(&rankSpinBox, SIGNAL(valueChanged(int)), this, SLOT(slotRankChanged()));
this->hide();
this->setEnabled(false);
}
QComboBox cmbSelectionMode;
QSpinBox rankSpinBox;
QLabel rankLbl;
QHBoxLayout horizLayout;
int dimension;
Q_SIGNALS:
void sigRankChanged(int rankEmitter);
public Q_SLOTS:
void slotRankChanged()
{
emit sigRankChanged(dimension);
}
};
class KisWdgOptionsBrush : public KisConfigWidget, public Ui::WdgExportGih
{
Q_OBJECT
public:
KisWdgOptionsBrush(QWidget *parent);
void setConfiguration(const KisPropertiesConfigurationSP cfg) override;
KisPropertiesConfigurationSP configuration() const override;
void setView(KisViewManager *view) override;
public Q_SLOTS:
void slotEnableSelectionMethod(int value);
void slotActivateDimensionRanks();
void slotRecalculateRanks(int rankDimension = 0);
private:
int currentDimensions;
int m_layersCount;
KisViewManager *m_view;
};
#endif // KISWDGOPTIONSBRUSH_H
......@@ -30,6 +30,9 @@
#include <KisExportCheckRegistry.h>
#include <kis_paint_device.h>
#include <KisViewManager.h>
#include <kis_image.h>
#include <KoProperties.h>
#include <KisDocument.h>
#include <kis_image.h>
#include <kis_paint_layer.h>
......@@ -38,6 +41,7 @@
#include <kis_imagepipe_brush.h>
#include <kis_pipebrush_parasite.h>
#include <KisAnimatedBrushAnnotation.h>
#include <KisWdgOptionsBrush.h>
#include <KisImportExportManager.h>
#include <kis_config.h>
......@@ -244,49 +248,5 @@ void KisBrushExport::initializeCapabilities()
}
void KisWdgOptionsBrush::setConfiguration(const KisPropertiesConfigurationSP cfg)
{
spacingWidget->setSpacing(false, cfg->getDouble("spacing"));
if(nameLineEdit->text().isEmpty()){
nameLineEdit->setText(cfg->getString("name"));
}
colorAsMask->setChecked(cfg->getBool("mask"));
brushStyle->setCurrentIndex(cfg->getInt("brushStyle"));
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
{
KisPropertiesConfigurationSP cfg = new KisPropertiesConfiguration();
cfg->setProperty("spacing", spacingWidget->spacing());
cfg->setProperty("name", nameLineEdit->text());
cfg->setProperty("mask", colorAsMask->isChecked());
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;
}
#include "kis_brush_export.moc"
......@@ -25,214 +25,9 @@
#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, int dimension)
: QWidget(parent)
, cmbSelectionMode(this)
, rank(this)
, rankLbl(this)
, horizLayout(this)
, dimension(dimension)
{
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);
connect(&rank, SIGNAL(valueChanged(int)), this, SLOT(slotRankChanged()));
this->hide();
this->setEnabled(false);
}
SelectionModeComboBox cmbSelectionMode;
QSpinBox rank;
QLabel rankLbl;
QHBoxLayout horizLayout;
int dimension;
Q_SIGNALS:
void rankChanged(int rankEmitter);
public Q_SLOTS:
void slotRankChanged()
{
emit rankChanged(dimension);
}
};
#include <KisViewManager.h>
#include <kis_image.h>
#include <KoProperties.h>
class KisWdgOptionsBrush : public KisConfigWidget, public Ui::WdgExportGih
{
Q_OBJECT
public:
KisWdgOptionsBrush(QWidget *parent)
: KisConfigWidget(parent)
, currentDimensions(0)
, m_layersCount(0)
, m_view(0)
{
setupUi(this);
connect(this->brushStyle, SIGNAL(currentIndexChanged(int)), SLOT(enableSelectionMethod(int)));
connect(this->dimensionSpin, SIGNAL(valueChanged(int)), SLOT(activateDimensionRanks()));
enableSelectionMethod(brushStyle->currentIndex());
BrushPipeSelectionModeHelper *bp;
for (int i = 0; i < this->dimensionSpin->maximum(); i++) {
bp = new BrushPipeSelectionModeHelper(0, i);
connect(bp, SIGNAL(rankChanged(int)), SLOT(recalculateRanks(int)));
dimRankLayout->addWidget(bp);
}
activateDimensionRanks();
}
void setConfiguration(const KisPropertiesConfigurationSP cfg) override;
KisPropertiesConfigurationSP configuration() const override;
public Q_SLOTS:
void enableSelectionMethod(int value) {
if (value == 0) {
animStyleGroup->setEnabled(false);
} else {
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;
}
void recalculateRanks(int rankDimension = 0) {
// currentDimensions;
int rankSum = 0;
int maxDim = this->dimensionSpin->maximum();
QVector<BrushPipeSelectionModeHelper *> bp;
QLayoutItem *item;
for (int i = 0; i < maxDim; ++i) {
if((item = dimRankLayout->itemAt(i)) != 0) {
bp.push_back(dynamic_cast<BrushPipeSelectionModeHelper*>(item->widget()));
rankSum += bp.at(i)->rank.value();
}
}
BrushPipeSelectionModeHelper *currentBrushHelper;
BrushPipeSelectionModeHelper *callerBrushHelper = bp.at(rankDimension);
QVectorIterator<BrushPipeSelectionModeHelper*> bpIterator(bp);
while (rankSum > m_layersCount && bpIterator.hasNext()) {
currentBrushHelper = bpIterator.next();
if(currentBrushHelper != callerBrushHelper) {
int currentValue = currentBrushHelper->rank.value();
currentBrushHelper->rank.setValue(currentValue -1);
rankSum -= currentValue;
}
}
if (rankSum > m_layersCount) {
callerBrushHelper->rank.setValue(m_layersCount);
}
if (rankSum == 0) {
bp.at(0)->rank.setValue(m_layersCount);
return;
}
}
void setView(KisViewManager *view) override
{
if (view) {
m_view = view;
KoProperties properties;
properties.setProperty("visible", true);
m_layersCount = m_view->image()->root()->childNodes(QStringList("KisLayer"), properties).count();
recalculateRanks();
}
}
private:
int currentDimensions;
int m_layersCount;
KisViewManager *m_view;
};
class KisBrushExport : 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