Git commit 4dce98f2489c19797d5d9bc6d6f5d505b1d33be1 by Sven Langkamp Pushed by langkamp into branch master added workspaces M +2 -0 krita/ui/CMakeLists.txt M +9 -2 krita/ui/kis_paintop_box.cc M +1 -0 krita/ui/kis_paintop_box.h M +20 -2 krita/ui/kis_resource_server_provider.cpp M +5 -0 krita/ui/kis_resource_server_provider.h A +102 -0 krita/ui/kis_workspace_resource.cpp [License: LGPL (v2+)] A +43 -0 krita/ui/kis_workspace_resource.h [License: LGPL (v2+)] A +141 -0 krita/ui/widgets/kis_workspace_chooser.cpp [License: LGPL (v2+)] A +48 -0 krita/ui/widgets/kis_workspace_chooser.h [License: LGPL (v2+)] http://commits.kde.org/47e7010d/4dce98f2489c19797d5d9bc6d6f5d505b1d33be1 diff --git a/krita/ui/CMakeLists.txt b/krita/ui/CMakeLists.txt index c7591d1..2a149f0 100644 --- a/krita/ui/CMakeLists.txt +++ b/krita/ui/CMakeLists.txt @@ -95,6 +95,7 @@ set(kritaui_LIB_SRCS kis_view2.cpp kis_zoom_manager.cc ko_favorite_resource_manager.cpp + kis_workspace_resource.cpp kisexiv2/kis_exif_io.cpp kisexiv2/kis_exiv2.cpp kisexiv2/kis_iptc_io.cpp @@ -159,6 +160,7 @@ set(kritaui_LIB_SRCS widgets/kis_tree_view_popup.cc widgets/kis_slider_spin_box.cpp widgets/kis_wdg_generator.cpp + widgets/kis_workspace_chooser.cpp widgets/squeezedcombobox.cpp ) diff --git a/krita/ui/kis_paintop_box.cc b/krita/ui/kis_paintop_box.cc index 63f63a3..d1220e0 100644 --- a/krita/ui/kis_paintop_box.cc +++ b/krita/ui/kis_paintop_box.cc @@ -2,7 +2,7 @@ * kis_paintop_box.cc - part of KImageShop/Krayon/Krita * * 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ý * Copyright (C) 2011 Silvio Heinrich * @@ -67,6 +67,7 @@ #include "widgets/kis_popup_button.h" #include "widgets/kis_paintop_presets_popup.h" #include "widgets/kis_paintop_presets_chooser_popup.h" +#include "widgets/kis_workspace_chooser.h" #include "kis_paintop_settings_widget.h" #include "kis_brushengine_selector.h" #include "ko_favorite_resource_manager.h" @@ -145,6 +146,12 @@ KisPaintopBox::KisPaintopBox(KisView2 * view, QWidget *parent, const char * name //view->actionCollection()->addAction("palette_manager", action); //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->addWidget(m_cmbPaintops); m_layout->addWidget(m_settingsWidget); @@ -154,7 +161,7 @@ KisPaintopBox::KisPaintopBox(KisView2 * view, QWidget *parent, const char * name m_layout->addWidget(m_eraseModeButton); m_layout->addWidget(m_paletteButton); 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_settingsWidget->setPopupWidget(m_presetsPopup); diff --git a/krita/ui/kis_paintop_box.h b/krita/ui/kis_paintop_box.h index e7a7e80..5bc8f23 100644 --- a/krita/ui/kis_paintop_box.h +++ b/krita/ui/kis_paintop_box.h @@ -135,6 +135,7 @@ private: KisBrushEngineSelector* m_brushEngineSelector; KisView2* m_view; QPushButton* m_paletteButton; + KisPopupButton* m_workspaceWidget; QMap m_paintopOptionWidgets; KisPaintOpPresetSP m_activePreset; diff --git a/krita/ui/kis_resource_server_provider.cpp b/krita/ui/kis_resource_server_provider.cpp index 5ee3746..0e76f0d 100644 --- a/krita/ui/kis_resource_server_provider.cpp +++ b/krita/ui/kis_resource_server_provider.cpp @@ -35,6 +35,7 @@ #include #include #include +#include KisResourceServerProvider::KisResourceServerProvider() { @@ -45,7 +46,8 @@ KisResourceServerProvider::KisResourceServerProvider() KGlobal::mainComponent().dirs()->addResourceType("kis_paintoppresets", "data", "krita/paintoppresets/"); 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("kis_patterns", "*.jpg:*.gif:*.png:*.tif:*.xpm:*.bmp:*.pat"); patternThread = new KoResourceLoaderThread(m_patternServer); connect(patternThread, SIGNAL(finished()), this, SLOT(patternThreadDone())); @@ -55,7 +57,11 @@ KisResourceServerProvider::KisResourceServerProvider() paintOpPresetThread = new KoResourceLoaderThread(m_paintOpPresetServer); connect(paintOpPresetThread, SIGNAL(finished()), this, SLOT(paintOpPresetThreadDone())); paintOpPresetThread->start(); - + + m_workspaceServer = new KoResourceServer("kis_workspaces", "*.kws"); + workspaceThread = new KoResourceLoaderThread(m_workspaceServer); + connect(workspaceThread, SIGNAL(finished()), this, SLOT(workspaceThreadDone())); + workspaceThread->start(); } KisResourceServerProvider::~KisResourceServerProvider() @@ -63,6 +69,7 @@ KisResourceServerProvider::~KisResourceServerProvider() dbgRegistry << "deleting KisResourceServerProvider"; delete m_patternServer; delete m_paintOpPresetServer; + delete m_workspaceServer; } KisResourceServerProvider* KisResourceServerProvider::instance() @@ -82,6 +89,11 @@ KoResourceServer* KisResourceServerProvider::paintOpPresetServ return m_paintOpPresetServer; } +KoResourceServer< KisWorkspaceResource >* KisResourceServerProvider::workspaceServer() +{ + return m_workspaceServer; +} + void KisResourceServerProvider::patternThreadDone() { delete patternThread; @@ -94,4 +106,10 @@ void KisResourceServerProvider::paintOpPresetThreadDone() paintOpPresetThread = 0; } +void KisResourceServerProvider::workspaceThreadDone() +{ + delete workspaceThread; + workspaceThread = 0; +} + #include "kis_resource_server_provider.moc" diff --git a/krita/ui/kis_resource_server_provider.h b/krita/ui/kis_resource_server_provider.h index ee65ace..b09b3fe 100644 --- a/krita/ui/kis_resource_server_provider.h +++ b/krita/ui/kis_resource_server_provider.h @@ -34,6 +34,7 @@ class KoResource; class KisPattern; class KisPaintOpPreset; +class KisWorkspaceResource; class KRITAUI_EXPORT KisResourceServerProvider : public QObject { @@ -46,6 +47,7 @@ public: KoResourceServer* patternServer(); KoResourceServer* paintOpPresetServer(); + KoResourceServer* workspaceServer(); private: @@ -55,16 +57,19 @@ private: KoResourceServer* m_patternServer; KoResourceServer* m_paintOpPresetServer; + KoResourceServer* m_workspaceServer; private slots: void patternThreadDone(); void paintOpPresetThreadDone(); + void workspaceThreadDone(); private: QThread * patternThread; QThread * paintOpPresetThread; + QThread * workspaceThread; }; #endif // KIS_RESOURCESERVERPROVIDER_H_ diff --git a/krita/ui/kis_workspace_resource.cpp b/krita/ui/kis_workspace_resource.cpp new file mode 100644 index 0000000..3e7992a --- /dev/null +++ b/krita/ui/kis_workspace_resource.cpp @@ -0,0 +1,102 @@ +/* This file is part of the KDE project + * Copyright (C) 2011 Sven Langkamp + * + * 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 +#include +#include + +#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 diff --git a/krita/ui/kis_workspace_resource.h b/krita/ui/kis_workspace_resource.h new file mode 100644 index 0000000..94c50a7 --- /dev/null +++ b/krita/ui/kis_workspace_resource.h @@ -0,0 +1,43 @@ +/* This file is part of the KDE project + * Copyright (C) 2011 Sven Langkamp + * + * 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 + +/// 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 diff --git a/krita/ui/widgets/kis_workspace_chooser.cpp b/krita/ui/widgets/kis_workspace_chooser.cpp new file mode 100644 index 0000000..1c90d95 --- /dev/null +++ b/krita/ui/widgets/kis_workspace_chooser.cpp @@ -0,0 +1,141 @@ +/* This file is part of the KDE project + * Copyright (C) 2011 Sven Langkamp + * + * 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 +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include "kis_pattern.h" +#include "kis_resource_server_provider.h" +#include "kis_workspace_resource.h" +#include "kis_view2.h" +#include +#include + +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(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 * rserver = KisResourceServerProvider::instance()->workspaceServer(); + KoAbstractResourceServerAdapter* adapter = new KoResourceServerAdapter(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 * 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(resource)->dockerState()); +} diff --git a/krita/ui/widgets/kis_workspace_chooser.h b/krita/ui/widgets/kis_workspace_chooser.h new file mode 100644 index 0000000..3431533 --- /dev/null +++ b/krita/ui/widgets/kis_workspace_chooser.h @@ -0,0 +1,48 @@ +/* This file is part of the KDE project + * Copyright (C) 2011 Sven Langkamp + * + * 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 + +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