Commit e0dd5ed4 authored by Sven Langkamp's avatar Sven Langkamp

added workspaces

parent dba1c22a
...@@ -95,6 +95,7 @@ set(kritaui_LIB_SRCS ...@@ -95,6 +95,7 @@ set(kritaui_LIB_SRCS
kis_view2.cpp kis_view2.cpp
kis_zoom_manager.cc kis_zoom_manager.cc
ko_favorite_resource_manager.cpp ko_favorite_resource_manager.cpp
kis_workspace_resource.cpp
kisexiv2/kis_exif_io.cpp kisexiv2/kis_exif_io.cpp
kisexiv2/kis_exiv2.cpp kisexiv2/kis_exiv2.cpp
kisexiv2/kis_iptc_io.cpp kisexiv2/kis_iptc_io.cpp
...@@ -159,6 +160,7 @@ set(kritaui_LIB_SRCS ...@@ -159,6 +160,7 @@ set(kritaui_LIB_SRCS
widgets/kis_tree_view_popup.cc widgets/kis_tree_view_popup.cc
widgets/kis_slider_spin_box.cpp widgets/kis_slider_spin_box.cpp
widgets/kis_wdg_generator.cpp widgets/kis_wdg_generator.cpp
widgets/kis_workspace_chooser.cpp
widgets/squeezedcombobox.cpp widgets/squeezedcombobox.cpp
) )
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* kis_paintop_box.cc - part of KImageShop/Krayon/Krita * kis_paintop_box.cc - part of KImageShop/Krayon/Krita
* *
* Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) * Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org)
* Copyright (c) 2009 Sven Langkamp (sven.langkamp@gmail.com) * Copyright (c) 2009-2011 Sven Langkamp (sven.langkamp@gmail.com)
* Copyright (c) 2010 Lukáš Tvrdý <lukast.dev@gmail.com> * Copyright (c) 2010 Lukáš Tvrdý <lukast.dev@gmail.com>
* Copyright (C) 2011 Silvio Heinrich <plassy@web.de> * Copyright (C) 2011 Silvio Heinrich <plassy@web.de>
* *
...@@ -67,6 +67,7 @@ ...@@ -67,6 +67,7 @@
#include "widgets/kis_popup_button.h" #include "widgets/kis_popup_button.h"
#include "widgets/kis_paintop_presets_popup.h" #include "widgets/kis_paintop_presets_popup.h"
#include "widgets/kis_paintop_presets_chooser_popup.h" #include "widgets/kis_paintop_presets_chooser_popup.h"
#include "widgets/kis_workspace_chooser.h"
#include "kis_paintop_settings_widget.h" #include "kis_paintop_settings_widget.h"
#include "kis_brushengine_selector.h" #include "kis_brushengine_selector.h"
#include "ko_favorite_resource_manager.h" #include "ko_favorite_resource_manager.h"
...@@ -145,6 +146,12 @@ KisPaintopBox::KisPaintopBox(KisView2 * view, QWidget *parent, const char * name ...@@ -145,6 +146,12 @@ KisPaintopBox::KisPaintopBox(KisView2 * view, QWidget *parent, const char * name
//view->actionCollection()->addAction("palette_manager", action); //view->actionCollection()->addAction("palette_manager", action);
//action->setDefaultWidget(m_paletteButton); //action->setDefaultWidget(m_paletteButton);
m_workspaceWidget = new KisPopupButton(this);
m_workspaceWidget->setIcon(KIcon("document-multiple"));
m_workspaceWidget->setToolTip(i18n("Choose workspace"));
m_workspaceWidget->setFixedSize(32, 32);
m_workspaceWidget->setPopupWidget(new KisWorkspaceChooser(view));
m_layout = new QHBoxLayout(this); m_layout = new QHBoxLayout(this);
m_layout->addWidget(m_cmbPaintops); m_layout->addWidget(m_cmbPaintops);
m_layout->addWidget(m_settingsWidget); m_layout->addWidget(m_settingsWidget);
...@@ -154,7 +161,7 @@ KisPaintopBox::KisPaintopBox(KisView2 * view, QWidget *parent, const char * name ...@@ -154,7 +161,7 @@ KisPaintopBox::KisPaintopBox(KisView2 * view, QWidget *parent, const char * name
m_layout->addWidget(m_eraseModeButton); m_layout->addWidget(m_eraseModeButton);
m_layout->addWidget(m_paletteButton); m_layout->addWidget(m_paletteButton);
m_layout->addSpacerItem(new QSpacerItem(10, 1, QSizePolicy::Expanding, QSizePolicy::Minimum)); m_layout->addSpacerItem(new QSpacerItem(10, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
// m_layout->addWidget(m_brushChooser); m_layout->addWidget(m_workspaceWidget);
m_presetsPopup = new KisPaintOpPresetsPopup(m_resourceProvider); m_presetsPopup = new KisPaintOpPresetsPopup(m_resourceProvider);
m_settingsWidget->setPopupWidget(m_presetsPopup); m_settingsWidget->setPopupWidget(m_presetsPopup);
......
...@@ -135,6 +135,7 @@ private: ...@@ -135,6 +135,7 @@ private:
KisBrushEngineSelector* m_brushEngineSelector; KisBrushEngineSelector* m_brushEngineSelector;
KisView2* m_view; KisView2* m_view;
QPushButton* m_paletteButton; QPushButton* m_paletteButton;
KisPopupButton* m_workspaceWidget;
QMap<KoID, KisPaintOpSettingsWidget*> m_paintopOptionWidgets; QMap<KoID, KisPaintOpSettingsWidget*> m_paintopOptionWidgets;
KisPaintOpPresetSP m_activePreset; KisPaintOpPresetSP m_activePreset;
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <kis_debug.h> #include <kis_debug.h>
#include <kis_pattern.h> #include <kis_pattern.h>
#include <kis_paintop_preset.h> #include <kis_paintop_preset.h>
#include <kis_workspace_resource.h>
KisResourceServerProvider::KisResourceServerProvider() KisResourceServerProvider::KisResourceServerProvider()
{ {
...@@ -45,7 +46,8 @@ KisResourceServerProvider::KisResourceServerProvider() ...@@ -45,7 +46,8 @@ KisResourceServerProvider::KisResourceServerProvider()
KGlobal::mainComponent().dirs()->addResourceType("kis_paintoppresets", "data", "krita/paintoppresets/"); KGlobal::mainComponent().dirs()->addResourceType("kis_paintoppresets", "data", "krita/paintoppresets/");
KGlobal::mainComponent().dirs()->addResourceDir("kis_paintoppresets", QDir::homePath() + QString("/.create/paintoppresets/krita")); KGlobal::mainComponent().dirs()->addResourceDir("kis_paintoppresets", QDir::homePath() + QString("/.create/paintoppresets/krita"));
KGlobal::mainComponent().dirs()->addResourceType("kis_workspaces", "data", "krita/workspaces/");
m_patternServer = new KoResourceServer<KisPattern>("kis_patterns", "*.jpg:*.gif:*.png:*.tif:*.xpm:*.bmp:*.pat"); m_patternServer = new KoResourceServer<KisPattern>("kis_patterns", "*.jpg:*.gif:*.png:*.tif:*.xpm:*.bmp:*.pat");
patternThread = new KoResourceLoaderThread(m_patternServer); patternThread = new KoResourceLoaderThread(m_patternServer);
connect(patternThread, SIGNAL(finished()), this, SLOT(patternThreadDone())); connect(patternThread, SIGNAL(finished()), this, SLOT(patternThreadDone()));
...@@ -55,7 +57,11 @@ KisResourceServerProvider::KisResourceServerProvider() ...@@ -55,7 +57,11 @@ KisResourceServerProvider::KisResourceServerProvider()
paintOpPresetThread = new KoResourceLoaderThread(m_paintOpPresetServer); paintOpPresetThread = new KoResourceLoaderThread(m_paintOpPresetServer);
connect(paintOpPresetThread, SIGNAL(finished()), this, SLOT(paintOpPresetThreadDone())); connect(paintOpPresetThread, SIGNAL(finished()), this, SLOT(paintOpPresetThreadDone()));
paintOpPresetThread->start(); paintOpPresetThread->start();
m_workspaceServer = new KoResourceServer<KisWorkspaceResource>("kis_workspaces", "*.kws");
workspaceThread = new KoResourceLoaderThread(m_workspaceServer);
connect(workspaceThread, SIGNAL(finished()), this, SLOT(workspaceThreadDone()));
workspaceThread->start();
} }
KisResourceServerProvider::~KisResourceServerProvider() KisResourceServerProvider::~KisResourceServerProvider()
...@@ -63,6 +69,7 @@ KisResourceServerProvider::~KisResourceServerProvider() ...@@ -63,6 +69,7 @@ KisResourceServerProvider::~KisResourceServerProvider()
dbgRegistry << "deleting KisResourceServerProvider"; dbgRegistry << "deleting KisResourceServerProvider";
delete m_patternServer; delete m_patternServer;
delete m_paintOpPresetServer; delete m_paintOpPresetServer;
delete m_workspaceServer;
} }
KisResourceServerProvider* KisResourceServerProvider::instance() KisResourceServerProvider* KisResourceServerProvider::instance()
...@@ -82,6 +89,11 @@ KoResourceServer<KisPaintOpPreset>* KisResourceServerProvider::paintOpPresetServ ...@@ -82,6 +89,11 @@ KoResourceServer<KisPaintOpPreset>* KisResourceServerProvider::paintOpPresetServ
return m_paintOpPresetServer; return m_paintOpPresetServer;
} }
KoResourceServer< KisWorkspaceResource >* KisResourceServerProvider::workspaceServer()
{
return m_workspaceServer;
}
void KisResourceServerProvider::patternThreadDone() void KisResourceServerProvider::patternThreadDone()
{ {
delete patternThread; delete patternThread;
...@@ -94,4 +106,10 @@ void KisResourceServerProvider::paintOpPresetThreadDone() ...@@ -94,4 +106,10 @@ void KisResourceServerProvider::paintOpPresetThreadDone()
paintOpPresetThread = 0; paintOpPresetThread = 0;
} }
void KisResourceServerProvider::workspaceThreadDone()
{
delete workspaceThread;
workspaceThread = 0;
}
#include "kis_resource_server_provider.moc" #include "kis_resource_server_provider.moc"
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
class KoResource; class KoResource;
class KisPattern; class KisPattern;
class KisPaintOpPreset; class KisPaintOpPreset;
class KisWorkspaceResource;
class KRITAUI_EXPORT KisResourceServerProvider : public QObject class KRITAUI_EXPORT KisResourceServerProvider : public QObject
{ {
...@@ -46,6 +47,7 @@ public: ...@@ -46,6 +47,7 @@ public:
KoResourceServer<KisPattern>* patternServer(); KoResourceServer<KisPattern>* patternServer();
KoResourceServer<KisPaintOpPreset>* paintOpPresetServer(); KoResourceServer<KisPaintOpPreset>* paintOpPresetServer();
KoResourceServer<KisWorkspaceResource>* workspaceServer();
private: private:
...@@ -55,16 +57,19 @@ private: ...@@ -55,16 +57,19 @@ private:
KoResourceServer<KisPattern>* m_patternServer; KoResourceServer<KisPattern>* m_patternServer;
KoResourceServer<KisPaintOpPreset>* m_paintOpPresetServer; KoResourceServer<KisPaintOpPreset>* m_paintOpPresetServer;
KoResourceServer<KisWorkspaceResource>* m_workspaceServer;
private slots: private slots:
void patternThreadDone(); void patternThreadDone();
void paintOpPresetThreadDone(); void paintOpPresetThreadDone();
void workspaceThreadDone();
private: private:
QThread * patternThread; QThread * patternThread;
QThread * paintOpPresetThread; QThread * paintOpPresetThread;
QThread * workspaceThread;
}; };
#endif // KIS_RESOURCESERVERPROVIDER_H_ #endif // KIS_RESOURCESERVERPROVIDER_H_
/* This file is part of the KDE project
* Copyright (C) 2011 Sven Langkamp <sven.langkamp@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "kis_workspace_resource.h"
#include <QFile>
#include <QDomDocument>
#include <QTextStream>
#define WORKSPACE_VERSION 1
KisWorkspaceResource::KisWorkspaceResource(const QString& filename): KoResource(filename)
{
}
KisWorkspaceResource::~KisWorkspaceResource()
{
}
bool KisWorkspaceResource::save()
{
if (filename().isEmpty())
return false;
QFile file(filename());
file.open(QIODevice::WriteOnly);
QDomDocument doc;
QDomElement root = doc.createElement("Workspace");
root.setAttribute("name", name() );
root.setAttribute("version", WORKSPACE_VERSION);
QDomElement state = doc.createElement("state");
state.appendChild(doc.createCDATASection(m_dockerState.toBase64()));
root.appendChild(state);
doc.appendChild(root);
QTextStream textStream(&file);
doc.save(textStream, 4);
file.close();
return true;
}
bool KisWorkspaceResource::load()
{
if (filename().isEmpty())
return false;
QFile file(filename());
QDomDocument doc;
if (!file.open(QIODevice::ReadOnly))
return false;
if (!doc.setContent(&file)) {
file.close();
return false;
}
file.close();
QDomElement element = doc.documentElement();
setName(element.attribute("name"));
QDomElement state = element.firstChildElement("state");
if(!state.isNull()) {
m_dockerState = QByteArray::fromBase64(state.text().toAscii());
}
setValid(true);
return true;
}
QString KisWorkspaceResource::defaultFileExtension() const
{
return QString(".kws");
}
void KisWorkspaceResource::setDockerState(const QByteArray& state)
{
m_dockerState = state;
}
QByteArray KisWorkspaceResource::dockerState()
{
return m_dockerState;
}
\ No newline at end of file
/* This file is part of the KDE project
* Copyright (C) 2011 Sven Langkamp <sven.langkamp@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef KIS_WORKSPACE_RESOURCE_H
#define KIS_WORKSPACE_RESOURCE_H
#include <KoResource.h>
/// Resource for storing of workspaces
class KisWorkspaceResource : public KoResource
{
public:
KisWorkspaceResource(const QString& filename);
virtual ~KisWorkspaceResource();
virtual bool save();
virtual bool load();
virtual QString defaultFileExtension() const;
void setDockerState(const QByteArray& state);
QByteArray dockerState();
private:
QByteArray m_dockerState;
};
#endif // KIS_WORKSPACE_RESOURCE_H
/* This file is part of the KDE project
* Copyright (C) 2011 Sven Langkamp <sven.langkamp@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "kis_workspace_chooser.h"
#include <QVBoxLayout>
#include <QAbstractItemDelegate>
#include <QPainter>
#include <QPushButton>
#include <klocale.h>
#include <KoResourceItemChooser.h>
#include <KoResourceServerAdapter.h>
#include <KoMainWindow.h>
#include <KoResource.h>
#include "kis_pattern.h"
#include "kis_resource_server_provider.h"
#include "kis_workspace_resource.h"
#include "kis_view2.h"
#include <QGridLayout>
#include <klineedit.h>
class KisWorkspaceDelegate : public QAbstractItemDelegate
{
public:
KisWorkspaceDelegate(QObject * parent = 0) : QAbstractItemDelegate(parent) {}
virtual ~KisWorkspaceDelegate() {}
/// reimplemented
virtual void paint(QPainter *, const QStyleOptionViewItem &, const QModelIndex &) const;
/// reimplemented
QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex &) const {
return option.decorationSize;
}
};
void KisWorkspaceDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
{
if (! index.isValid())
return;
KisWorkspaceResource* workspace = static_cast<KisWorkspaceResource*>(index.internalPointer());
if (option.state & QStyle::State_Selected) {
painter->setPen(QPen(option.palette.highlight(), 2.0));
painter->fillRect(option.rect, option.palette.highlight());
}
painter->setPen(Qt::black);
painter->drawText(option.rect.x() + 5, option.rect.y() + painter->fontMetrics().ascent() + 5, workspace->name());
}
KisWorkspaceChooser::KisWorkspaceChooser(KisView2 * view, QWidget* parent): QWidget(parent), m_view(view)
{
KoResourceServer<KisWorkspaceResource> * rserver = KisResourceServerProvider::instance()->workspaceServer();
KoAbstractResourceServerAdapter* adapter = new KoResourceServerAdapter<KisWorkspaceResource>(rserver);
m_itemChooser = new KoResourceItemChooser(adapter, this);
m_itemChooser->setItemDelegate(new KisWorkspaceDelegate(this));
m_itemChooser->setFixedSize(250, 250);
m_itemChooser->setRowHeight(30);
m_itemChooser->setColumnCount(1);
connect(m_itemChooser, SIGNAL(resourceSelected(KoResource*)),
this, SLOT(resourceSelected(KoResource*)));
QPushButton* saveButton = new QPushButton(i18n("Save"));
connect(saveButton, SIGNAL(clicked(bool)), this, SLOT(slotSave()));
m_nameEdit = new KLineEdit(this);
m_nameEdit->setClickMessage(i18n("Insert name"));
m_nameEdit->setClearButtonShown(true);
QGridLayout* layout = new QGridLayout(this);
layout->setMargin(0);
layout->addWidget(m_itemChooser, 0, 0, 1, 2);
layout->addWidget(m_nameEdit, 1, 0, 1, 1);
layout->addWidget(saveButton, 1, 1, 1, 1);
}
KisWorkspaceChooser::~KisWorkspaceChooser()
{
}
void KisWorkspaceChooser::slotSave()
{
if(!m_view->shell()) {
return;
}
KoResourceServer<KisWorkspaceResource> * rserver = KisResourceServerProvider::instance()->workspaceServer();
KisWorkspaceResource* workspace = new KisWorkspaceResource("");
workspace->setDockerState(m_view->shell()->saveState());
workspace->setValid(true);
QString saveLocation = rserver->saveLocation();
QString name = m_nameEdit->text();
bool newName = false;
if(name.isEmpty()) {
newName = true;
name = i18n("Workspace");
}
QFileInfo fileInfo(saveLocation + name + workspace->defaultFileExtension());
int i = 1;
while (fileInfo.exists()) {
fileInfo.setFile(saveLocation + name + QString("%1").arg(i) + workspace->defaultFileExtension());
i++;
}
workspace->setFilename(fileInfo.filePath());
if(newName) {
name = i18n("Workspace %1").arg(i);
}
workspace->setName(name);
rserver->addResource(workspace);
}
void KisWorkspaceChooser::resourceSelected(KoResource* resource)
{
if(!m_view->shell()) {
return;
}
m_view->shell()->restoreState(static_cast<KisWorkspaceResource*>(resource)->dockerState());
}
/* This file is part of the KDE project
* Copyright (C) 2011 Sven Langkamp <sven.langkamp@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef KIS_WORKSPACE_CHOOSER_H
#define KIS_WORKSPACE_CHOOSER_H
#include <QWidget>
class KLineEdit;
class KoResourceItemChooser;
class KisView2;
class KoResource;
class KisWorkspaceChooser : public QWidget
{
Q_OBJECT
public:
KisWorkspaceChooser(KisView2 * view, QWidget* parent = 0);
virtual ~KisWorkspaceChooser();
private slots:
void slotSave();
void resourceSelected( KoResource * resource );
private:
KoResourceItemChooser * m_itemChooser;
KisView2* m_view;
KLineEdit* m_nameEdit;
};
#endif // KIS_WORKSPACE_CHOOSER_H
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