Commit 539825d3 authored by Sven Langkamp's avatar Sven Langkamp
Browse files

store palette in workspace

BUG:299033
parent 60faa2a9
......@@ -30,6 +30,10 @@
#include <KoColorSpaceRegistry.h>
#include <KoResourceServerProvider.h>
#include <kis_config.h>
#include <kis_workspace_resource.h>
#include <kis_canvas_resource_provider.h>
#include <kis_view2.h>
#include <kis_canvas2.h>
KisPaletteDocker::KisPaletteDocker()
: QDockWidget(i18n("Palettes"))
......@@ -70,6 +74,12 @@ KisPaletteDocker::~KisPaletteDocker()
void KisPaletteDocker::setCanvas(KoCanvasBase * canvas)
{
m_canvas = canvas;
KisCanvas2* kisCanvas = dynamic_cast<KisCanvas2*>(canvas);
Q_ASSERT(canvas);
KisView2* view = kisCanvas->view();
connect(view->resourceProvider(), SIGNAL(sigSavingWorkspace(KisWorkspaceResource*)), SLOT(saveToWorkspace(KisWorkspaceResource*)));
connect(view->resourceProvider(), SIGNAL(sigLoadingWorkspace(KisWorkspaceResource*)), SLOT(loadFromWorkspace(KisWorkspaceResource*)));
}
void KisPaletteDocker::colorSelected(const KoColor& c, bool final)
......@@ -108,5 +118,25 @@ void KisPaletteDocker::checkForDefaultResource()
}
}
void KisPaletteDocker::saveToWorkspace(KisWorkspaceResource* workspace)
{
KoColorSet* colorSet = m_chooser->colorSet();
if (colorSet) {
workspace->setProperty("palette", colorSet->name());
}
}
void KisPaletteDocker::loadFromWorkspace(KisWorkspaceResource* workspace)
{
if (workspace->hasProperty("palette")) {
KoResourceServer<KoColorSet>* rServer = KoResourceServerProvider::instance()->paletteServer();
KoColorSet* colorSet = rServer->getResourceByName(workspace->getString("palette"));
if (colorSet) {
m_chooser->setColorSet(colorSet);
}
}
}
#include "kis_palette_docker.moc"
......@@ -27,6 +27,7 @@
#include <KoCanvasObserverBase.h>
#include <KoResourceServerAdapter.h>
class KisWorkspaceResource;
class KoColorSetWidget;
class KoColor;
class KisView2;
......@@ -57,6 +58,9 @@ private slots:
void resourceAddedToServer(KoResource* resource);
void checkForDefaultResource();
void saveToWorkspace(KisWorkspaceResource* workspace);
void loadFromWorkspace(KisWorkspaceResource* workspace);
private:
void readNamedColor(void);
......
......@@ -402,4 +402,14 @@ qreal KisCanvasResourceProvider::opacity()
return m_resourceManager->resource(Opacity).toDouble();
}
void KisCanvasResourceProvider::notifyLoadingWorkspace(KisWorkspaceResource* workspace)
{
emit sigLoadingWorkspace(workspace);
}
void KisCanvasResourceProvider::notifySavingWorkspace(KisWorkspaceResource* workspace)
{
emit sigSavingWorkspace(workspace);
}
#include "kis_canvas_resource_provider.moc"
......@@ -28,6 +28,7 @@
#include "kis_types.h"
#include "krita_export.h"
class KisWorkspaceResource;
class KoColorProfile;
class KoAbstractGradient;
class KoResource;
......@@ -117,6 +118,12 @@ public:
void setPaintOpPreset(const KisPaintOpPresetSP preset);
///Notify that the workspace is saved and settings should be saved to it
void notifySavingWorkspace(KisWorkspaceResource* workspace);
///Notify that the workspace is loaded and settings can be read
void notifyLoadingWorkspace(KisWorkspaceResource* workspace);
public slots:
void slotSetFGColor(const KoColor& c);
......@@ -162,6 +169,8 @@ signals:
void sigCompositeOpChanged(const QString &);
void sigOnScreenResolutionChanged(qreal scaleX, qreal scaleY);
void sigOpacityChanged(qreal);
void sigSavingWorkspace(KisWorkspaceResource* workspace);
void sigLoadingWorkspace(KisWorkspaceResource* workspace);
private:
......
......@@ -48,6 +48,11 @@ bool KisWorkspaceResource::save()
QDomElement state = doc.createElement("state");
state.appendChild(doc.createCDATASection(m_dockerState.toBase64()));
root.appendChild(state);
// Save KisPropertiesConfiguration settings
QDomElement settings = doc.createElement("settings");
KisPropertiesConfiguration::toXML(doc, settings);
root.appendChild(settings);
doc.appendChild(root);
QTextStream textStream(&file);
......@@ -82,6 +87,12 @@ bool KisWorkspaceResource::load()
if(!state.isNull()) {
m_dockerState = QByteArray::fromBase64(state.text().toAscii());
}
QDomElement settings = element.firstChildElement("settings");
if(!settings.isNull()) {
KisPropertiesConfiguration::fromXML(settings);
}
setValid(true);
return true;
}
......
......@@ -21,9 +21,10 @@
#define KIS_WORKSPACE_RESOURCE_H
#include <KoResource.h>
#include <kis_properties_configuration.h>
/// Resource for storing of workspaces
class KisWorkspaceResource : public KoResource
class KisWorkspaceResource : public KoResource , public KisPropertiesConfiguration
{
public:
......@@ -32,7 +33,7 @@ public:
virtual bool save();
virtual bool load();
virtual QString defaultFileExtension() const;
void setDockerState(const QByteArray& state);
QByteArray dockerState();
......
......@@ -37,6 +37,7 @@
#include "kis_view2.h"
#include <QGridLayout>
#include <klineedit.h>
#include <kis_canvas_resource_provider.h>
class KisWorkspaceDelegate : public QAbstractItemDelegate
{
......@@ -108,6 +109,7 @@ void KisWorkspaceChooser::slotSave()
KisWorkspaceResource* workspace = new KisWorkspaceResource("");
workspace->setDockerState(m_view->shell()->saveState());
m_view->resourceProvider()->notifySavingWorkspace(workspace);
workspace->setValid(true);
QString saveLocation = rserver->saveLocation();
QString name = m_nameEdit->text();
......@@ -137,5 +139,7 @@ void KisWorkspaceChooser::resourceSelected(KoResource* resource)
if(!m_view->shell()) {
return;
}
m_view->shell()->restoreState(static_cast<KisWorkspaceResource*>(resource)->dockerState());
KisWorkspaceResource* workspace = static_cast<KisWorkspaceResource*>(resource);
m_view->shell()->restoreState(workspace->dockerState());
m_view->resourceProvider()->notifyLoadingWorkspace(workspace);
}
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