diff --git a/plugins/filters/indexcolors/indexcolors.cpp b/plugins/filters/indexcolors/indexcolors.cpp --- a/plugins/filters/indexcolors/indexcolors.cpp +++ b/plugins/filters/indexcolors/indexcolors.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -56,15 +57,34 @@ KoColorTransformation* KisFilterIndexColors::createTransformation(const KoColorSpace* cs, const KisFilterConfiguration* config) const { IndexColorPalette pal; + KoResourceServer* rServer = KoResourceServerProvider::instance()->paletteServer(false); + KoColorSet *savedPal = rServer->resourceByName(config->getString("paletteName")); + KoResourceServer* gServer = KoResourceServerProvider::instance()->gradientServer(false); + KoAbstractGradient *savedGradient = gServer->resourceByName(config->getString("gradientName")); + + if (config->getInt("mode")==1 && savedPal){ + for (int i=0; inColors(); i++) { + pal.insertColor(savedPal->getColor(i).color); + } - PaletteGeneratorConfig palCfg; - palCfg.fromByteArray(config->getProperty("paletteGen").toByteArray()); - pal = palCfg.generate(); - if(config->getBool("reduceColorsEnabled")) - { - int maxClrs = config->getInt("colorLimit"); - while(pal.numColors() > maxClrs) - pal.mergeMostReduantColors(); + + } else if(config->getInt("mode")==2 && savedGradient) { + int maxColors = config->getInt("colorLimit"); + for (int i=0; icolorAt(col, (qreal)i/(qreal)maxColors); + pal.insertColor(col); + } + } else { + PaletteGeneratorConfig palCfg; + palCfg.fromByteArray(config->getProperty("paletteGen").toByteArray()); + pal = palCfg.generate(); + if(config->getBool("reduceColorsEnabled")) + { + int maxClrs = config->getInt("colorLimit"); + while(pal.numColors() > maxClrs) + pal.mergeMostReduantColors(); + } } pal.similarityFactors.L = config->getFloat("LFactor"); @@ -97,6 +117,9 @@ config->setProperty("reduceColorsEnabled", false); config->setProperty("colorLimit", 32); config->setProperty("alphaSteps", 1); + config->setProperty("mode", 0); + config->setProperty("paletteName", ""); + config->setProperty("gradientName", ""); return config; } @@ -141,4 +164,4 @@ } } -#include "indexcolors.moc" \ No newline at end of file +#include "indexcolors.moc" diff --git a/plugins/filters/indexcolors/kiswdgindexcolors.h b/plugins/filters/indexcolors/kiswdgindexcolors.h --- a/plugins/filters/indexcolors/kiswdgindexcolors.h +++ b/plugins/filters/indexcolors/kiswdgindexcolors.h @@ -25,9 +25,13 @@ #include #include +#include +#include +#include class QCheckBox; class KColorButton; +class KisColorsetChooser; namespace Ui { class KisWdgIndexColors; @@ -44,6 +48,8 @@ private Q_SLOTS: void slotColorLimitChanged(int value); + void slotColorSetChanged(KoColorSet *set); + void slotGradientChanged(KoResource *resource); private: struct ColorWidgets @@ -53,6 +59,10 @@ }; QVector< QVector > m_colorSelectors; QVector< QSpinBox* > m_stepSpinners; + KoColorSet *m_colorSet; + KoAbstractGradient *m_gradient; + KisColorsetChooser *m_colorsetChoice; + KisGradientChooser *m_gradientChoice; Ui::KisWdgIndexColors* ui; }; diff --git a/plugins/filters/indexcolors/kiswdgindexcolors.cpp b/plugins/filters/indexcolors/kiswdgindexcolors.cpp --- a/plugins/filters/indexcolors/kiswdgindexcolors.cpp +++ b/plugins/filters/indexcolors/kiswdgindexcolors.cpp @@ -25,6 +25,8 @@ #include "kiswdgindexcolors.h" #include "palettegeneratorconfig.h" #include "ui_kiswdgindexcolors.h" +#include +#include #include "kis_int_parse_spin_box.h" @@ -35,6 +37,14 @@ ui = new Ui::KisWdgIndexColors; ui->setupUi(this); + KoResourceServer* pServer = KoResourceServerProvider::instance()->paletteServer(false); + m_colorSet = pServer->resources().first(); + m_colorsetChoice = new KisColorsetChooser(this); + KoResourceServer* gServer = KoResourceServerProvider::instance()->gradientServer(false); + m_gradient = gServer->resources().first(); + m_gradientChoice = new KisGradientChooser(this); + + connect(ui->diagCheck, SIGNAL(toggled(bool)), SIGNAL(sigConfigurationItemChanged())); connect(ui->inbetweenSpinBox, SIGNAL(valueChanged(int)), SIGNAL(sigConfigurationItemChanged())); connect(ui->alphaStepsSpinBox, SIGNAL(valueChanged(int)), SIGNAL(sigConfigurationItemChanged())); @@ -47,6 +57,9 @@ connect(ui->luminanceSlider, SIGNAL(valueChanged(int)), SIGNAL(sigConfigurationItemChanged())); connect(ui->aSlider, SIGNAL(valueChanged(int)), SIGNAL(sigConfigurationItemChanged())); connect(ui->bSlider, SIGNAL(valueChanged(int)), SIGNAL(sigConfigurationItemChanged())); + connect(ui->tabChoices, SIGNAL(currentChanged(int)), SIGNAL(sigConfigurationItemChanged())); + connect(m_colorsetChoice, SIGNAL(paletteSelected(KoColorSet*)), SIGNAL(sigConfigurationItemChanged())); + connect(m_gradientChoice, SIGNAL(resourceSelected(KoResource*)), SIGNAL(sigConfigurationItemChanged())); } void KisWdgIndexColors::slotColorLimitChanged(int value) @@ -121,6 +134,16 @@ m_colorSelectors[y][x].button = b; m_colorSelectors[y][x].checkbox = c; } + + ui->bnChoosePalette->setText(m_colorSet->name()); + connect(m_colorsetChoice, SIGNAL(paletteSelected(KoColorSet*)), this, SLOT(slotColorSetChanged(KoColorSet*))); + ui->bnChoosePalette->setToolTip(i18n("Choose palette")); + ui->bnChoosePalette->setPopupWidget(m_colorsetChoice); + + ui->bnChooseGradient->setText(m_gradient->name()); + connect(m_gradientChoice, SIGNAL(resourceSelected(KoResource*)), this, SLOT(slotGradientChanged(KoResource*))); + ui->bnChooseGradient->setToolTip(i18n("Choose gradient")); + ui->bnChooseGradient->setPopupWidget(m_gradientChoice); } @@ -130,32 +153,42 @@ PaletteGeneratorConfig palCfg; - for(int y = 0; y < 4; ++y) - for(int x = 0; x < 4; ++x) - { - palCfg.colors[y][x] = m_colorSelectors[y][x].button->color(); - palCfg.colorsEnabled[y][x] = m_colorSelectors[y][x].button->isEnabled(); - } + if (ui->tabChoices->currentIndex()==0) { + for(int y = 0; y < 4; ++y) + for(int x = 0; x < 4; ++x) + { + palCfg.colors[y][x] = m_colorSelectors[y][x].button->color(); + palCfg.colorsEnabled[y][x] = m_colorSelectors[y][x].button->isEnabled(); + } - for(int y = 0; y < 3; ++y) - palCfg.gradientSteps[y] = m_stepSpinners[y]->value(); + for(int y = 0; y < 3; ++y) + palCfg.gradientSteps[y] = m_stepSpinners[y]->value(); - palCfg.diagonalGradients = ui->diagCheck->isChecked(); - palCfg.inbetweenRampSteps = ui->inbetweenSpinBox->value(); - - IndexColorPalette pal = palCfg.generate(); - ui->colorCount->setText(QString::number(pal.numColors())); + palCfg.diagonalGradients = ui->diagCheck->isChecked(); + palCfg.inbetweenRampSteps = ui->inbetweenSpinBox->value(); + + IndexColorPalette pal = palCfg.generate(); + ui->colorCount->setText(QString::number(pal.numColors())); + + } else if (ui->tabChoices->currentIndex()==1) { + config->setProperty("paletteName", m_colorSet->name()); + } else if (ui->tabChoices->currentIndex()==2) { + config->setProperty("gradientName", m_gradient->name()); + } config->setProperty("paletteGen", palCfg.toByteArray()); config->setProperty("LFactor", ui->luminanceSlider->value() / 100.f); config->setProperty("aFactor", ui->aSlider->value() / 100.f); config->setProperty("bFactor", ui->bSlider->value() / 100.f); - + config->setProperty("reduceColorsEnabled", ui->colorLimitCheck->isChecked()); config->setProperty("colorLimit", ui->colorLimit->value()); config->setProperty("alphaSteps", ui->alphaStepsSpinBox->value()); + + config->setProperty("mode", ui->tabChoices->currentIndex()); + return config; } @@ -163,7 +196,20 @@ { PaletteGeneratorConfig palCfg; palCfg.fromByteArray(config->getProperty("paletteGen").toByteArray()); - + + ui->tabChoices->setCurrentIndex(config->getInt("mode", 0)); + KoResourceServer* pServer = KoResourceServerProvider::instance()->paletteServer(false); + m_colorSet = pServer->resourceByName(config->getString("paletteName", "")); + if (!m_colorSet) { + m_colorSet = pServer->resources().first(); + } + KoResourceServer* gServer = KoResourceServerProvider::instance()->gradientServer(false); + m_gradient = gServer->resourceByName(config->getString("paletteName", "")); + if (!m_gradient) { + m_gradient = gServer->resources().first(); + } + ui->bnChooseGradient->setText(config->getString("gradientName", "")); + ui->luminanceSlider->setValue(config->getFloat("LFactor")*100); ui->aSlider->setValue(config->getFloat("aFactor")*100); ui->bSlider->setValue(config->getFloat("bFactor")*100); @@ -188,3 +234,20 @@ IndexColorPalette pal = palCfg.generate(); ui->colorCount->setText(QString::number(pal.numColors())); } + +void KisWdgIndexColors::slotColorSetChanged(KoColorSet *set) +{ + if (set) { + m_colorSet = set; + ui->bnChoosePalette->setText(set->name()); + } +} + +void KisWdgIndexColors::slotGradientChanged(KoResource *resource) +{ + KoAbstractGradient *gradient = dynamic_cast(resource); + if (gradient) { + m_gradient = gradient; + ui->bnChooseGradient->setText(m_gradient->name()); + } +} diff --git a/plugins/filters/indexcolors/kiswdgindexcolors.ui b/plugins/filters/indexcolors/kiswdgindexcolors.ui --- a/plugins/filters/indexcolors/kiswdgindexcolors.ui +++ b/plugins/filters/indexcolors/kiswdgindexcolors.ui @@ -11,68 +11,112 @@ - - 0 - - - 0 - - - 0 - - - 0 - - - - Ramps + + + 0 - - true - - - - - - - 20 - 20 - - - - - QLayout::SetMinimumSize + + + Custom Palette + + + + + + Ramps - - 0 + + true - - 0 + + + + + Diagonal Gradients + + + + + + + + 20 + 20 + + + + + QLayout::SetMinimumSize + + + 0 + + + 0 + + + 0 + + + 0 + + + 6 + + + + + + + + + + + + Palette File + + + + + + Choose Palette: - - 0 + + + + + + PushButton - - 0 + + + + + + + Gradient + + + + + + PushButton - - 6 + + + + + + Choose Gradient - - - - - - - Diagonal Gradients - - - - + + + + - + Gradient Steps @@ -81,10 +125,17 @@ true - - + + - Limit to + Color count: + + + + + + + In-between ramps @@ -104,23 +155,17 @@ - - - - 0 - - - 8 - - - 0 + + + + 0 - - + + - In-between ramps + Limit to @@ -143,24 +188,23 @@ - - - - Color count: + + + + 0 - - - - - - 0 + + 8 + + + 0 - + Indexing Factors @@ -284,7 +328,7 @@ - + Other @@ -320,9 +364,18 @@ + tabChoices + otherBox + indexingBox + gradientStepsBox + KisPopupButton + QPushButton +
kis_popup_button.h
+
+ KisIntParseSpinBox QSpinBox
kis_int_parse_spin_box.h