Commit 1851f3d4 authored by Silvio Heinrich's avatar Silvio Heinrich
Browse files

Save the settings of the Artistic Color Selector before closing.

And after opening the selector the settings will be loaded.
parent 13c29aa4
......@@ -58,8 +58,10 @@ ArtisticColorSelectorDock::ArtisticColorSelectorDock():
m_resetMenu->addAction(i18n("Reset Light"))->setData(ACTION_RESET_LIGHT);
m_resetMenu->addAction(i18n("Reset Everything"))->setData(ACTION_RESET_EVERYTHING);
m_selectorUI->colorSelector->loadSettings();
m_selectorUI->bnColorPrefs->setPopupWidget(m_preferencesUI);
m_selectorUI->bnReset->setMenu(m_resetMenu);
m_selectorUI->bnAbsLight->setChecked(!m_selectorUI->colorSelector->islightRelative());
m_hsxButtons->addButton(m_preferencesUI->bnHsy, KisColor::HSY);
m_hsxButtons->addButton(m_preferencesUI->bnHsi, KisColor::HSI);
......@@ -67,12 +69,21 @@ ArtisticColorSelectorDock::ArtisticColorSelectorDock():
m_hsxButtons->addButton(m_preferencesUI->bnHsv, KisColor::HSV);
m_preferencesUI->numPiecesSlider->setRange(1, 48);
m_preferencesUI->numPiecesSlider->setValue(12);
m_preferencesUI->numRingsSlider->setRange(1, 20);
m_preferencesUI->numRingsSlider->setValue(11);
m_preferencesUI->numLightPiecesSlider->setRange(1, 30);
m_preferencesUI->numLightPiecesSlider->setValue(19);
m_preferencesUI->numPiecesSlider->setValue(m_selectorUI->colorSelector->getNumPieces());
m_preferencesUI->numRingsSlider->setValue(m_selectorUI->colorSelector->getNumRings());
m_preferencesUI->numLightPiecesSlider->setValue(m_selectorUI->colorSelector->getNumLightPieces());
m_preferencesUI->bnInverseSat->setChecked(m_selectorUI->colorSelector->isSaturationInverted());
switch(m_selectorUI->colorSelector->getColorSpace())
{
case KisColor::HSV: { m_preferencesUI->bnHsv->setChecked(true); } break;
case KisColor::HSI: { m_preferencesUI->bnHsi->setChecked(true); } break;
case KisColor::HSL: { m_preferencesUI->bnHsl->setChecked(true); } break;
case KisColor::HSY: { m_preferencesUI->bnHsy->setChecked(true); } break;
}
connect(m_preferencesUI->numLightPiecesSlider, SIGNAL(valueChanged(int)) , SLOT(slotPreferenceChanged()));
connect(m_preferencesUI->numPiecesSlider , SIGNAL(valueChanged(int)) , SLOT(slotPreferenceChanged()));
connect(m_preferencesUI->numRingsSlider , SIGNAL(valueChanged(int)) , SLOT(slotPreferenceChanged()));
......@@ -85,14 +96,13 @@ ArtisticColorSelectorDock::ArtisticColorSelectorDock():
connect(m_resetMenu , SIGNAL(triggered(QAction*)) , SLOT(slotMenuActionTriggered(QAction*)));
connect(this , SIGNAL(topLevelChanged(bool)) , SLOT(slotTopLevelChanged(bool)));
connect(this , SIGNAL(dockLocationChanged(Qt::DockWidgetArea)), SLOT(slotDockLocationChanged(Qt::DockWidgetArea)));
setWidget(m_selectorUI);
slotColorSpaceSelected(KisColor::HSY);
slotPreferenceChanged();
}
ArtisticColorSelectorDock::~ArtisticColorSelectorDock()
{
m_selectorUI->colorSelector->saveSettings();
delete m_hsxButtons;
delete m_resetMenu;
}
......
......@@ -26,8 +26,11 @@
#include <QMouseEvent>
#include <QResizeEvent>
#include <QTransform>
#include <QList>
#include <cmath>
#include <kis_config.h>
#include "kis_color_selector.h"
static const int MIN_NUM_HUE_PIECES = 1;
......@@ -353,14 +356,14 @@ void KisColorSelector::createRing(ColorRing& ring, quint8 numPieces, qreal inner
void KisColorSelector::setSelectedColor(const KisColor& color, bool selectAsFgColor, bool emitSignal)
{
if (selectAsFgColor) { m_fgColor = color; }
else { m_bgColor = color; }
else { m_bgColor = color; }
m_selectedColor = color;
m_selectedColorIsFgColor = selectAsFgColor;
if (emitSignal) {
if (selectAsFgColor) { emit sigFgColorChanged(m_selectedColor); }
else { emit sigBgColorChanged(m_selectedColor); }
else { emit sigBgColorChanged(m_selectedColor); }
}
}
......@@ -682,3 +685,57 @@ void KisColorSelector::resizeEvent(QResizeEvent* /*event*/)
{
recalculateAreas(quint8(getNumLightPieces()));
}
void KisColorSelector::saveSettings()
{
KisConfig cfg;
cfg.writeEntry("ArtColorSel.ColorSpace" , qint32(m_colorSpace));
cfg.writeEntry("ArtColorSel.NumRings" , m_colorRings.size());
cfg.writeEntry("ArtColorSel.RingPieces" , qint32(m_numPieces));
cfg.writeEntry("ArtColorSel.LightPieces", qint32(m_numLightPieces));
cfg.writeEntry("ArtColorSel.InversedSaturation", m_inverseSaturation);
cfg.writeEntry("ArtColorSel.RelativeLight" , m_relativeLight);
cfg.writeEntry("ArtColorSel.Light" , m_light);
cfg.writeEntry("ArtColorSel.SelColorH", m_selectedColor.getH());
cfg.writeEntry("ArtColorSel.SelColorS", m_selectedColor.getS());
cfg.writeEntry("ArtColorSel.SelColorX", m_selectedColor.getX());
cfg.writeEntry("ArtColorSel.SelColorA", m_selectedColor.getA());
QList<float> angles;
for(int i=0; i<m_colorRings.size(); ++i)
angles.push_back(m_colorRings[i].angle.value());
cfg.writeList("ArtColorSel.RingAngles", angles);
}
void KisColorSelector::loadSettings()
{
KisConfig cfg;
setColorSpace(KisColor::Type(cfg.readEntry<qint32>("ArtColorSel.ColorSpace" , KisColor::HSY)));
setNumLightPieces(cfg.readEntry("ArtColorSel.LightPieces", 19));
m_selectedColor.setH(cfg.readEntry<float>("ArtColorSel.SelColorH", 0.0f));
m_selectedColor.setS(cfg.readEntry<float>("ArtColorSel.SelColorS", 0.0f));
m_selectedColor.setX(cfg.readEntry<float>("ArtColorSel.SelColorX", 0.0f));
m_selectedColor.setA(cfg.readEntry<float>("ArtColorSel.SelColorA", 0.0f));
setInverseSaturation(cfg.readEntry<bool>("ArtColorSel.InversedSaturation", false));
setLight(cfg.readEntry<float>("ArtColorSel.Light", 0.5f), cfg.readEntry<bool>("ArtColorSel.RelativeLight", false));
recalculateRings(
cfg.readEntry("ArtColorSel.NumRings" , 11),
cfg.readEntry("ArtColorSel.RingPieces", 12)
);
QList<float> angles = cfg.readList<float>("ArtColorSel.RingAngles");
for(int i=0; i<m_colorRings.size(); ++i)
m_colorRings[i].angle = angles[i];
selectColor(m_selectedColor);
update();
}
......@@ -42,8 +42,8 @@ class KisColorSelector: public QWidget
ColorRing(): angle(0) { }
Radian getPieceAngle() const { return RAD_360 / float(pieced.size()); }
Radian getShift () const { return angle % getPieceAngle(); }
Radian getMovedAngel() const { return angle - tmpAngle; }
Radian getShift () const { return angle % getPieceAngle(); }
Radian getMovedAngel() const { return angle - tmpAngle; }
void setTemporaries(const KisColor& color) {
tmpAngle = angle;
......@@ -78,10 +78,16 @@ public:
void setFgColor(const KisColor& fgColor);
void setBgColor(const KisColor& bgColor);
qint32 getNumRings () const { return m_colorRings.size(); }
qint32 getNumPieces () const { return m_numPieces; }
qint32 getNumLightPieces() const { return m_numLightPieces; }
qreal getLight () const { return m_light; }
void saveSettings();
void loadSettings();
KisColor::Type getColorSpace () const { return m_colorSpace; }
qint32 getNumRings () const { return m_colorRings.size(); }
qint32 getNumPieces () const { return m_numPieces; }
qint32 getNumLightPieces () const { return m_numLightPieces; }
qreal getLight () const { return m_light; }
bool isSaturationInverted() const { return m_inverseSaturation; }
bool islightRelative () const { return m_relativeLight; }
signals:
void sigFgColorChanged(const KisColor& color);
......
......@@ -20,6 +20,7 @@
#include <QString>
#include <QStringList>
#include <QList>
#include <QColor>
#include <ksharedconfig.h>
......@@ -260,7 +261,27 @@ public:
QString exportConfiguration(const QString &filterId) const;
void setExportConfiguration(const QString &filterId, const KisPropertiesConfiguration &properties);
template<class T>
void writeEntry(const QString& name, const T& value) {
m_cfg.writeEntry(name, value);
}
template<class T>
void writeList(const QString& name, const QList<T>& value) {
m_cfg.writeEntry(name, value);
}
template<class T>
T readEntry(const QString& name, const T& defaultValue=T()) {
return m_cfg.readEntry(name, defaultValue);
}
template<class T>
QList<T> readList(const QString& name, const QList<T>& defaultValue=QList<T>()) {
return m_cfg.readEntry(name, defaultValue);
}
private:
KisConfig(const KisConfig&);
KisConfig& operator=(const KisConfig&);
......
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