Commit 45e73705 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Remove copy of KisColorSelectorConfiguration

Now both families of color selectors use the same actual class for
storing the configuration.
parent d5f3bc79
......@@ -31,66 +31,75 @@
#include "kritaui_export.h"
class KRITAUI_EXPORT KisColorSelectorConfiguration {
public:
enum Type {Ring, Square, Wheel, Triangle, Slider};
enum Parameters {H, hsvS, V, hslS, L, SL, SV, SV2, hsvSH, hslSH, VH, LH, SI, SY, hsiSH, hsySH, I, Y, IH, YH, hsiS, hsyS};
Type mainType;
Type subType;
Parameters mainTypeParameter;
Parameters subTypeParameter;
KisColorSelectorConfiguration(Type mainT = Triangle, Type subT = Ring, Parameters mainTP = SL, Parameters subTP = H)
: mainType(mainT)
, subType(subT)
, mainTypeParameter(mainTP)
, subTypeParameter(subTP)
{
}
KisColorSelectorConfiguration(QString string)
{
readString(string);
}
QString toString() const
{
return QString("%1|%2|%3|%4").arg(mainType).arg(subType).arg(mainTypeParameter).arg(subTypeParameter);
}
void readString(QString string)
{
QStringList strili = string.split('|');
if(strili.length()!=4) return;
int imt=strili.at(0).toInt();
int ist=strili.at(1).toInt();
int imtp=strili.at(2).toInt();
int istp=strili.at(3).toInt();
if(imt>Slider || ist>Slider || imtp>hsyS || istp>hsyS)//this was LH before
return;
mainType = Type(imt);
subType = Type(ist);
mainTypeParameter = Parameters(imtp);
subTypeParameter = Parameters(istp);
}
static KisColorSelectorConfiguration fromString(QString string)
{
KisColorSelectorConfiguration ret;
ret.readString(string);
return ret;
}
};
/**
* @brief The KisVisualColorSelector class
* this gives a color selector box that draws gradients and everything.
* Unlike other color selectors, this one draws the full gamut of the given colorspace.
*
* This gives a color selector box that draws gradients and everything.
*
* Unlike other color selectors, this one draws the full gamut of the given
* colorspace.
*/
class KRITAUI_EXPORT KisVisualColorSelector : public QWidget
{
Q_OBJECT
public:
//Copied directly from the advanced color selector:
enum Type {Ring, Square, Wheel, Triangle, Slider};
enum Parameters {H, hsvS, V, hslS, L, SL, SV, SV2, hsvSH, hslSH, VH, LH, SI, SY, hsiSH, hsySH, I, Y, IH, YH, hsiS, hsyS};
struct Configuration {
Type mainType;
Type subType;
Parameters mainTypeParameter;
Parameters subTypeParameter;
Configuration(Type mainT = Triangle,
Type subT = Ring,
Parameters mainTP = SL,
Parameters subTP = H)
: mainType(mainT),
subType(subT),
mainTypeParameter(mainTP),
subTypeParameter(subTP)
{}
Configuration(QString string)
{
readString(string);
}
QString toString() const
{
return QString("%1|%2|%3|%4").arg(mainType).arg(subType).arg(mainTypeParameter).arg(subTypeParameter);
}
void readString(QString string)
{
QStringList strili = string.split('|');
if(strili.length()!=4) return;
int imt=strili.at(0).toInt();
int ist=strili.at(1).toInt();
int imtp=strili.at(2).toInt();
int istp=strili.at(3).toInt();
if(imt>Slider || ist>Slider || imtp>hsyS || istp>hsyS)//this was LH before
return;
mainType = Type(imt);
subType = Type(ist);
mainTypeParameter = Parameters(imtp);
subTypeParameter = Parameters(istp);
}
static Configuration fromString(QString string)
{
Configuration ret;
ret.readString(string);
return ret;
}
};
explicit KisVisualColorSelector(QWidget *parent = 0);
~KisVisualColorSelector();
......@@ -186,6 +195,7 @@ public:
* the pixmap will not change unless 'm_d->setPixmap=true' which is toggled by
* refresh and update functions.
*/
bool imagesNeedUpdate() const;
QImage getImageMap();
/**
* @brief setFullImage
......@@ -334,13 +344,13 @@ class KisVisualRectangleSelectorShape : public KisVisualColorSelectorShape
public:
enum singelDTypes{vertical, horizontal, border, borderMirrored};
explicit KisVisualRectangleSelectorShape(QWidget *parent,
Dimensions dimension,
ColorModel model,
const KoColorSpace *cs,
int channel1, int channel2,
const KoColorDisplayRendererInterface *displayRenderer = KoDumbColorDisplayRenderer::instance(), int width=20,
KisVisualRectangleSelectorShape::singelDTypes d = KisVisualRectangleSelectorShape::vertical
);
Dimensions dimension,
ColorModel model,
const KoColorSpace *cs,
int channel1, int channel2,
const KoColorDisplayRendererInterface *displayRenderer = KoDumbColorDisplayRenderer::instance(), int width=20,
KisVisualRectangleSelectorShape::singelDTypes d = KisVisualRectangleSelectorShape::vertical
);
~KisVisualRectangleSelectorShape();
void setBorderWidth(int width);
......@@ -371,13 +381,13 @@ class KisVisualEllipticalSelectorShape : public KisVisualColorSelectorShape
public:
enum singelDTypes{border, borderMirrored};
explicit KisVisualEllipticalSelectorShape(QWidget *parent,
Dimensions dimension,
ColorModel model,
const KoColorSpace *cs,
int channel1, int channel2,
const KoColorDisplayRendererInterface *displayRenderer = KoDumbColorDisplayRenderer::instance(), int borwidth=20,
KisVisualEllipticalSelectorShape::singelDTypes d = KisVisualEllipticalSelectorShape::border
);
Dimensions dimension,
ColorModel model,
const KoColorSpace *cs,
int channel1, int channel2,
const KoColorDisplayRendererInterface *displayRenderer = KoDumbColorDisplayRenderer::instance(), int borwidth=20,
KisVisualEllipticalSelectorShape::singelDTypes d = KisVisualEllipticalSelectorShape::border
);
~KisVisualEllipticalSelectorShape();
void setBorderWidth(int width);
......@@ -410,13 +420,13 @@ class KisVisualTriangleSelectorShape : public KisVisualColorSelectorShape
public:
enum singelDTypes{border, borderMirrored};
explicit KisVisualTriangleSelectorShape(QWidget *parent,
Dimensions dimension,
ColorModel model,
const KoColorSpace *cs,
int channel1, int channel2,
const KoColorDisplayRendererInterface *displayRenderer = KoDumbColorDisplayRenderer::instance(),
int borwidth=20
);
Dimensions dimension,
ColorModel model,
const KoColorSpace *cs,
int channel1, int channel2,
const KoColorDisplayRendererInterface *displayRenderer = KoDumbColorDisplayRenderer::instance(),
int borwidth=20
);
~KisVisualTriangleSelectorShape();
void setBorderWidth(int width);
......@@ -430,9 +440,12 @@ public:
virtual QRect getSpaceForSquare(QRect geom);
virtual QRect getSpaceForCircle(QRect geom);
virtual QRect getSpaceForTriangle(QRect geom);
protected:
void resizeEvent(QResizeEvent *);
private:
virtual QPointF convertShapeCoordinateToWidgetCoordinate(QPointF coordinate);
virtual QPointF convertWidgetCoordinateToShapeCoordinate(QPoint coordinate);
......
......@@ -44,7 +44,7 @@
#include "kis_signal_compressor.h"
KisColorSelector::KisColorSelector(Configuration conf, QWidget* parent)
KisColorSelector::KisColorSelector(KisColorSelectorConfiguration conf, QWidget* parent)
: KisColorSelectorBase(parent),
m_ring(0),
m_triangle(0),
......@@ -85,7 +85,7 @@ KisColorSelectorBase* KisColorSelector::createPopup() const
return popup;
}
void KisColorSelector::setConfiguration(Configuration conf)
void KisColorSelector::setConfiguration(KisColorSelectorConfiguration conf)
{
m_configuration = conf;
......@@ -99,13 +99,13 @@ void KisColorSelector::setConfiguration(Configuration conf)
}
switch (m_configuration.mainType) {
case Square:
case KisColorSelectorConfiguration::Square:
m_mainComponent=m_square;
break;
case Wheel:
case KisColorSelectorConfiguration::Wheel:
m_mainComponent=m_wheel;
break;
case Triangle:
case KisColorSelectorConfiguration::Triangle:
m_mainComponent=m_triangle;
break;
default:
......@@ -113,10 +113,10 @@ void KisColorSelector::setConfiguration(Configuration conf)
}
switch (m_configuration.subType) {
case Ring:
case KisColorSelectorConfiguration::Ring:
m_subComponent=m_ring;
break;
case Slider:
case KisColorSelectorConfiguration::Slider:
m_subComponent=m_slider;
break;
default:
......@@ -130,7 +130,7 @@ void KisColorSelector::setConfiguration(Configuration conf)
connect(m_mainComponent, SIGNAL(update()), m_signalCompressor, SLOT(start()), Qt::UniqueConnection);
connect(m_subComponent, SIGNAL(update()), m_signalCompressor, SLOT(start()), Qt::UniqueConnection);
m_mainComponent->setConfiguration(m_configuration.mainTypeParameter, m_configuration.mainType);
m_subComponent->setConfiguration(m_configuration.subTypeParameter, m_configuration.subType);
......@@ -138,7 +138,7 @@ void KisColorSelector::setConfiguration(Configuration conf)
resizeEvent(&event);
}
KisColorSelector::Configuration KisColorSelector::configuration() const
KisColorSelectorConfiguration KisColorSelector::configuration() const
{
return m_configuration;
}
......@@ -147,7 +147,7 @@ void KisColorSelector::updateSettings()
{
KisColorSelectorBase::updateSettings();
KConfigGroup cfg = KSharedConfig::openConfig()->group("advancedColorSelector");
setConfiguration(Configuration::fromString(cfg.readEntry("colorSelectorConfiguration", KisColorSelector::Configuration().toString())));
setConfiguration(KisColorSelectorConfiguration::fromString(cfg.readEntry("colorSelectorConfiguration", KisColorSelectorConfiguration().toString())));
}
void KisColorSelector::reset()
......@@ -188,13 +188,16 @@ inline int iconSize(qreal width, qreal height) {
}
void KisColorSelector::resizeEvent(QResizeEvent* e) {
if(m_configuration.subType==Ring) {
if (m_configuration.subType == KisColorSelectorConfiguration::Ring) {
m_ring->setGeometry(0,0,width(), height());
if(displaySettingsButton()) {
if (displaySettingsButton()) {
int size = iconSize(width(), height());
m_button->setGeometry(0, 0, size, size);
}
if(m_configuration.mainType==Triangle) {
if (m_configuration.mainType == KisColorSelectorConfiguration::Triangle) {
m_triangle->setGeometry(width()/2-m_ring->innerRadius(),
height()/2-m_ring->innerRadius(),
m_ring->innerRadius()*2,
......@@ -210,7 +213,7 @@ void KisColorSelector::resizeEvent(QResizeEvent* e) {
}
else {
// type wheel and square
if(m_configuration.mainType==Wheel) {
if (m_configuration.mainType == KisColorSelectorConfiguration::Wheel) {
if(displaySettingsButton()) {
int size = iconSize(width(), height()*0.9);
m_button->setGeometry(0, height()*0.1, size, size);
......
......@@ -19,6 +19,7 @@
#define KIS_COLOR_SELECTOR_H
#include "kis_color_selector_base.h"
#include <kis_visual_color_selector.h>
class KisColorSelectorRing;
class KisColorSelectorComponent;
......@@ -31,68 +32,13 @@ class KisColorSelector : public KisColorSelectorBase
{
Q_OBJECT
public:
enum Type {Ring, Square, Wheel, Triangle, Slider};
enum Parameters {H, hsvS, V, hslS, L, SL, SV, SV2, hsvSH, hslSH, VH, LH, SI, SY, hsiSH, hsySH, I, Y, IH, YH, hsiS, hsyS};
struct Configuration {
Type mainType;
Type subType;
Parameters mainTypeParameter;
Parameters subTypeParameter;
Configuration(Type mainT = Triangle,
Type subT = Ring,
Parameters mainTP = SL,
Parameters subTP = H)
: mainType(mainT),
subType(subT),
mainTypeParameter(mainTP),
subTypeParameter(subTP)
{}
Configuration(QString string)
{
readString(string);
}
QString toString() const
{
return QString("%1|%2|%3|%4").arg(mainType).arg(subType).arg(mainTypeParameter).arg(subTypeParameter);
}
void readString(QString string)
{
QStringList strili = string.split('|');
if(strili.length()!=4) return;
int imt=strili.at(0).toInt();
int ist=strili.at(1).toInt();
int imtp=strili.at(2).toInt();
int istp=strili.at(3).toInt();
if(imt>Slider || ist>Slider || imtp>hsyS || istp>hsyS)//this was LH before
return;
mainType = Type(imt);
subType = Type(ist);
mainTypeParameter = Parameters(imtp);
subTypeParameter = Parameters(istp);
}
static Configuration fromString(QString string)
{
Configuration ret;
ret.readString(string);
return ret;
}
};
// enum MainType {Ring, Square, Wheel};
// enum SubType {Triangle, Square, Slider};
// enum MainTypeParameter {SL, SV, SH, VH, LH, VSV/*experimental*/, SI, SY, YH, IH};
// enum SubTypeParameter {H, S, V, L, I, Y, hsiS, hsyS};
KisColorSelector(Configuration conf, QWidget* parent = 0);
KisColorSelector(KisColorSelectorConfiguration conf, QWidget* parent = 0);
KisColorSelector(QWidget* parent=0);
KisColorSelectorBase* createPopup() const;
void setConfiguration(Configuration conf);
Configuration configuration() const;
void setConfiguration(KisColorSelectorConfiguration conf);
KisColorSelectorConfiguration configuration() const;
void setColor(const KoColor &color);
public Q_SLOTS:
......@@ -127,7 +73,7 @@ private:
KisSignalCompressor *m_signalCompressor;
Configuration m_configuration;
KisColorSelectorConfiguration m_configuration;
KoColor m_lastRealColor;
KoColor m_currentRealColor;
......
......@@ -32,17 +32,17 @@ public:
~KisColorSelectorComboBox();
void hidePopup();
void showPopup();
KisColorSelector::Configuration configuration() const;
KisColorSelectorConfiguration configuration() const;
//int m_model;
protected:
void paintEvent(QPaintEvent *e);
public Q_SLOTS:
void setColorSpace(const KoColorSpace* colorSpace);
void setConfiguration(KisColorSelector::Configuration);
void setConfiguration(KisColorSelectorConfiguration);
void setList(int model);
private:
KisColorSelectorComboBoxPrivate* m_private;
KisColorSelector::Configuration m_configuration;
KisColorSelectorConfiguration m_configuration;
KisColorSelector m_currentSelector;
};
......
......@@ -31,8 +31,8 @@ class KisColorSelectorComponent : public QObject
{
Q_OBJECT
public:
typedef KisColorSelector::Parameters Parameter;
typedef KisColorSelector::Type Type;
typedef KisColorSelectorConfiguration::Parameters Parameter;
typedef KisColorSelectorConfiguration::Type Type;
explicit KisColorSelectorComponent(KisColorSelector* parent);
void setGeometry(int x, int y, int width, int height);
......
......@@ -486,7 +486,7 @@ void KisColorSelectorSettings::loadPreferences()
//color selector
KisColorSelectorComboBox* cstw = dynamic_cast<KisColorSelectorComboBox*>(ui->colorSelectorConfiguration);
cstw->setConfiguration(KisColorSelector::Configuration::fromString(cfg.readEntry("colorSelectorConfiguration", "3|0|5|0"))); // triangle selector
cstw->setConfiguration(KisColorSelectorConfiguration::fromString(cfg.readEntry("colorSelectorConfiguration", "3|0|5|0"))); // triangle selector
//luma values//
ui->l_lumaR->setValue(cfg.readEntry("lumaR", 0.2126));
......@@ -578,7 +578,7 @@ void KisColorSelectorSettings::loadDefaultPreferences()
ui->colorSelectorTypeComboBox->setCurrentIndex(0);
KisColorSelectorComboBox* cstw = dynamic_cast<KisColorSelectorComboBox*>(ui->colorSelectorConfiguration);
cstw->setConfiguration(KisColorSelector::Configuration("3|0|5|0")); // triangle selector
cstw->setConfiguration(KisColorSelectorConfiguration("3|0|5|0")); // triangle selector
//luma//
ui->l_lumaR->setValue(0.2126);
......
......@@ -52,28 +52,28 @@ KoColor KisColorSelectorWheel::selectColor(int x, int y)
angle/=2*M_PI;
switch (m_parameter) {
case KisColorSelector::hsvSH:
case KisColorSelectorConfiguration::hsvSH:
emit paramChanged(angle, radius, -1, -1, -1, -1, -1, -1, -1);
break;
case KisColorSelector::hslSH:
case KisColorSelectorConfiguration::hslSH:
emit paramChanged(angle, -1, -1, radius, -1, -1, -1, -1, -1);
break;
case KisColorSelector::hsiSH:
case KisColorSelectorConfiguration::hsiSH:
emit paramChanged(angle, -1, -1, -1, -1, radius, -1, -1, -1);
break;
case KisColorSelector::hsySH:
case KisColorSelectorConfiguration::hsySH:
emit paramChanged(angle, -1, -1, -1, -1, -1, -1, radius, -1);
break;
case KisColorSelector::VH:
case KisColorSelectorConfiguration::VH:
emit paramChanged(angle, -1, radius, -1, -1, -1, -1, -1, -1);
break;
case KisColorSelector::LH:
case KisColorSelectorConfiguration::LH:
emit paramChanged(angle, -1, -1, -1, radius, -1, -1, -1, -1);
break;
case KisColorSelector::IH:
case KisColorSelectorConfiguration::IH:
emit paramChanged(angle, -1, -1, -1, -1, -1, radius, -1, -1);
break;
case KisColorSelector::YH:
case KisColorSelectorConfiguration::YH:
emit paramChanged(angle, -1, -1, -1, -1, -1, -1, -1, radius);
break;
default:
......@@ -96,10 +96,10 @@ void KisColorSelectorWheel::setColor(const KoColor &color)
{
qreal hsvH, hsvS, hsvV;
qreal hslH, hslS, hslL;
qreal hsiH, hsiS, hsiI;
qreal hsyH, hsyS, hsyY;
KConfigGroup cfg = KSharedConfig::openConfig()->group("advancedColorSelector");
R = cfg.readEntry("lumaR", 0.2126);
qreal hsiH, hsiS, hsiI;
qreal hsyH, hsyS, hsyY;
KConfigGroup cfg = KSharedConfig::openConfig()->group("advancedColorSelector");
R = cfg.readEntry("lumaR", 0.2126);
G = cfg.readEntry("lumaG", 0.7152);
B = cfg.readEntry("lumaB", 0.0722);
Gamma = cfg.readEntry("gamma", 2.2);
......@@ -108,44 +108,44 @@ void KisColorSelectorWheel::setColor(const KoColor &color)
m_parent->converter()->getHsiF(color, &hsiH, &hsiS, &hsiI);
m_parent->converter()->getHsyF(color, &hsyH, &hsyS, &hsyY, R, G, B, Gamma);
//workaround, for some reason the HSI and HSY algorithms are fine, but they don't seem to update the selectors properly.
hsiH=hslH;
hsyH=hslH;
//workaround, for some reason the HSI and HSY algorithms are fine, but they don't seem to update the selectors properly.
hsiH=hslH;
hsyH=hslH;
qreal angle = 0.0, radius = 0.0;
angle = hsvH;
angle *= 2. * M_PI;
angle -= M_PI;
switch (m_parameter) {
case KisColorSelector::LH:
case KisColorSelectorConfiguration::LH:
emit paramChanged(hslH, -1, -1, -1, hslL, -1, -1, -1, -1);
radius = hslL;
break;
case KisColorSelector::VH:
case KisColorSelectorConfiguration::VH:
emit paramChanged(hsvH, -1, hsvV, -1, -1, -1, -1, -1, -1);
radius = hsvV;
break;
case KisColorSelector::IH:
case KisColorSelectorConfiguration::IH:
emit paramChanged(hslH, -1, -1, -1, -1, -1, hsiI, -1, -1);
radius = hsiI;
break;
case KisColorSelector::YH:
case KisColorSelectorConfiguration::YH:
emit paramChanged(hsvH, -1, -1, -1, -1, -1, -1, -1, hsyY);
radius = hsyY;
break;
case KisColorSelector::hsvSH:
case KisColorSelectorConfiguration::hsvSH:
emit paramChanged(hsvH, hsvS, -1, -1, -1, -1, -1, -1, -1);
radius = hsvS;
break;
case KisColorSelector::hslSH:
case KisColorSelectorConfiguration::hslSH:
emit paramChanged(hslH, -1, -1, hslS, -1, -1, -1, -1, -1);
radius = hslS;
break;
case KisColorSelector::hsiSH:
case KisColorSelectorConfiguration::hsiSH:
emit paramChanged(hsiH, -1, -1, -1, -1, hsiS, -1, -1, -1);
radius = hsiS;
break;
case KisColorSelector::hsySH:
case KisColorSelectorConfiguration::hsySH:
emit paramChanged(hsyH, -1, -1, -1, -1, -1, -1, hsyS, -1);
radius = hsyS;
break;
......@@ -195,7 +195,7 @@ void KisColorSelectorWheel::paint(QPainter* painter)
painter->drawImage(m_pixelCacheOffset.x(),m_pixelCacheOffset.y(), m_pixelCache);
// draw blips
if(m_lastClickPos!=QPoint(-1,-1) && m_parent->displayBlip()) {
QPoint pos = (m_lastClickPos*qMin(width(), height())).toPoint();
if(width()<height())
......@@ -235,28 +235,28 @@ KoColor KisColorSelectorWheel::colorAt(int x, int y, bool forceValid)
angle /= 2 * M_PI;
switch(m_parameter) {
case KisColorSelector::hsvSH:
case KisColorSelectorConfiguration::hsvSH:
color = m_parent->converter()->fromHsvF(angle, radius, m_value);
break;
case KisColorSelector::hslSH:
case KisColorSelectorConfiguration::hslSH:
color = m_parent->converter()->fromHslF(angle, radius, m_lightness);
break;
case KisColorSelector::hsiSH:
case KisColorSelectorConfiguration::hsiSH:
color = m_parent->converter()->fromHsiF(angle, radius, m_intensity);
break;
case KisColorSelector::hsySH:
case KisColorSelectorConfiguration::hsySH:
color = m_parent->converter()->fromHsyF(angle, radius, m_luma, R, G, B, Gamma);
break;
case KisColorSelector::VH:
case KisColorSelectorConfiguration::VH:
color = m_parent->converter()->fromHsvF(angle, m_hsvSaturation, radius);
break;
case KisColorSelector::LH:
case KisColorSelectorConfiguration::LH:
color = m_parent->converter()->fromHslF(angle, m_hslSaturation, radius);
break;
case KisColorSelector::IH:
case KisColorSelectorConfiguration::IH:
color = m_parent->converter()->fromHsiF(angle, m_hsiSaturation, radius);
break;
case KisColorSelector::YH:
case KisColorSelectorConfiguration::YH:
color = m_parent->converter()->fromHsyF(angle, m_hsySaturation, radius, R, G, B, Gamma);
break;
default:
......
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