Commit a0ba5835 authored by Sven Langkamp's avatar Sven Langkamp Committed by Halla Rempt
Browse files

restore last used palette in the palette docker after start

CCBUG:299033

Conflicts:
	krita/ui/kis_config.cc
	krita/ui/kis_config.h
parent 6249b7b0
......@@ -20,6 +20,7 @@
#include <QComboBox>
#include <QVBoxLayout>
#include <QTimer>
#include <KoCanvasBase.h>
#include <KoResource.h>
......@@ -27,6 +28,8 @@
#include <KoColorSetWidget.h>
#include <KoCanvasResourceManager.h>
#include <KoColorSpaceRegistry.h>
#include <KoResourceServerProvider.h>
#include <kis_config.h>
KisPaletteDocker::KisPaletteDocker()
: QDockWidget(i18n("Palettes"))
......@@ -39,15 +42,29 @@ KisPaletteDocker::KisPaletteDocker()
QVBoxLayout *layout = new QVBoxLayout(mainWidget);
KoColorSetWidget* chooser = new KoColorSetWidget(this);
layout->addWidget(chooser);
m_chooser = new KoColorSetWidget(this);
layout->addWidget(m_chooser);
mainWidget->setLayout(layout);
connect(chooser, SIGNAL(colorChanged(const KoColor&, bool)), SLOT(colorSelected(const KoColor&, bool)));
connect(m_chooser, SIGNAL(colorChanged(const KoColor&, bool)), SLOT(colorSelected(const KoColor&, bool)));
KisConfig cfg;
m_defaultPalette = cfg.defaultPalette();
KoResourceServer<KoColorSet>* rServer = KoResourceServerProvider::instance()->paletteServer();
m_serverAdapter = new KoResourceServerAdapter<KoColorSet>(rServer, this);
connect(m_serverAdapter, SIGNAL(resourceAdded(KoResource*)), this, SLOT(resourceAddedToServer(KoResource*)));
m_serverAdapter->connectToResourceServer();
checkForDefaultResource();
}
KisPaletteDocker::~KisPaletteDocker()
{
KoColorSet* colorSet = m_chooser->colorSet();
if (colorSet) {
KisConfig cfg;
cfg.setDefaultPalette(colorSet->name());
}
}
void KisPaletteDocker::setCanvas(KoCanvasBase * canvas)
......@@ -75,6 +92,21 @@ QDockWidget* KisPaletteDockerFactory::createDockWidget()
return dockWidget;
}
void KisPaletteDocker::resourceAddedToServer(KoResource* resource)
{
// Avoiding resource mutex deadlock
QTimer::singleShot( 0, this, SLOT( checkForDefaultResource() ) );
}
void KisPaletteDocker::checkForDefaultResource()
{
foreach(KoResource* resource, m_serverAdapter->resources()) {
if (resource->name() == m_defaultPalette) {
KoColorSet* colorSet = static_cast<KoColorSet*>(resource);
m_chooser->setColorSet(colorSet);
}
}
}
#include "kis_palette_docker.moc"
......@@ -25,7 +25,9 @@
#include <KoDockFactoryBase.h>
#include <KoColorSet.h>
#include <KoCanvasObserverBase.h>
#include <KoResourceServerAdapter.h>
class KoColorSetWidget;
class KoColor;
class KisView2;
......@@ -52,6 +54,8 @@ public:
private slots:
void colorSelected(const KoColor& color, bool final);
void resourceAddedToServer(KoResource* resource);
void checkForDefaultResource();
private:
void readNamedColor(void);
......@@ -59,6 +63,9 @@ private:
protected:
KoColorSet* m_currentPalette;
KoCanvasBase* m_canvas;
KoColorSetWidget* m_chooser;
KoResourceServerAdapter<KoColorSet>* m_serverAdapter;
QString m_defaultPalette;
};
class KisPaletteDockerFactory : public KoDockFactoryBase
......
......@@ -837,3 +837,23 @@ void KisConfig::setExportConfiguration(const QString &filterId, const KisPropert
m_cfg.writeEntry("ExportConfiguration-" + filterId, exportConfig);
}
QString KisConfig::defaultPalette()
{
return m_cfg.readEntry("defaultPalette", QString());
}
void KisConfig::setDefaultPalette(const QString& name)
{
m_cfg.writeEntry("defaultPalette", name);
}
bool KisConfig::useSystemMonitorProfile() const
{
return m_cfg.readEntry("ColorManagement/UseSystemMonitorProfile", false);
}
void KisConfig::setUseSystemMonitorProfile(bool _useSystemMonitorProfile)
{
m_cfg.writeEntry("ColorManagement/UseSystemMonitorProfile", _useSystemMonitorProfile);
}
......@@ -265,6 +265,12 @@ public:
QString exportConfiguration(const QString &filterId) const;
void setExportConfiguration(const QString &filterId, const KisPropertiesConfiguration &properties);
bool useSystemMonitorProfile() const;
void setUseSystemMonitorProfile(bool _useSystemMonitorProfile);
QString defaultPalette();
void setDefaultPalette(const QString& name);
template<class T>
void writeEntry(const QString& name, const T& value) {
m_cfg.writeEntry(name, value);
......
......@@ -247,6 +247,11 @@ void KoColorSetWidget::setColorSet(KoColorSet *colorSet)
d->fillColors();
}
KoColorSet* KoColorSetWidget::colorSet()
{
return d->colorSet;
}
void KoColorSetWidget::resizeEvent(QResizeEvent *event)
{
emit widgetSizeChanged(event->size());
......
......@@ -59,6 +59,12 @@ public:
* @param colorSet pointer to the color set
*/
void setColorSet(KoColorSet *colorSet);
/**
* Gets the current color set
* @returns current color set,, 0 if none set
*/
KoColorSet* colorSet();
protected:
virtual void resizeEvent(QResizeEvent *event); ///< reimplemented from QFrame
......
Supports Markdown
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