Commit 1fa358fd authored by Boudewijn Rempt's avatar Boudewijn Rempt

* Pasting from Kolourpaint (and probably others) into Krita now works

* Profile used on copy
* more work with display profiles.

svn path=/trunk/koffice/; revision=373738
parent adafa57a
......@@ -76,7 +76,8 @@ libkritacore_la_SOURCES = kis_paint_device.cc \
kis_rotate_visitor.cc \
kis_cms.cc \
kis_quantum_operations.cc \
kis_pixel.h
kis_clipboard.cc \
kis_pixel.cc
noinst_HEADERS = kis_paint_device.h \
kis_layer.h \
......
......@@ -48,3 +48,14 @@ QStringList KisColorSpaceRegistry::listColorSpaceNames() const
{
return listKeys();
}
KisProfileSP KisColorSpaceRegistry::getProfileByName(const QString & name) const
{
KisProfileSP profile = 0;
QStringList keys = listKeys();
for ( QStringList::Iterator it = keys.begin(); it != keys.end(); ++it ) {
profile = get(*it) -> getProfileByName(name);
if (profile != 0) return profile;
}
return profile;
}
......@@ -32,6 +32,8 @@ public:
QStringList listColorSpaceNames() const;
static KisColorSpaceRegistry* instance();
KisProfileSP getProfileByName(const QString & name) const;
private:
KisColorSpaceRegistry();
......
/*
* Copyright (c) 2004 Boudewijn Rempt <boud@valdyas.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <qapplication.h>
#include <qclipboard.h>
#include "qobject.h"
#include "kdebug.h"
#include "kis_types.h"
#include "kis_paint_device.h"
#include "kis_config.h"
#include "kis_colorspace_registry.h"
#include "kis_clipboard.h"
KisClipboard *KisClipboard::m_singleton = 0;
KisClipboard::KisClipboard()
{
// kdDebug() << " creating a KisClipboard" << endl;
Q_ASSERT(KisClipboard::m_singleton == 0);
KisClipboard::m_singleton = this;
m_pushedClipboard = false;
m_clip = 0;
connect( QApplication::clipboard(), SIGNAL( dataChanged() ),
this, SLOT( clipboardDataChanged() ) );
}
KisClipboard::~KisClipboard()
{
}
KisClipboard* KisClipboard::instance()
{
if(KisClipboard::m_singleton == 0)
{
KisClipboard::m_singleton = new KisClipboard();
}
return KisClipboard::m_singleton;
}
void KisClipboard::setClip(KisPaintDeviceSP selection)
{
m_clip = selection;
if (selection) {
KisConfig cfg;
QImage qimg;
if (cfg.applyMonitorProfileOnCopy()) {
// XXX: Is this a performance problem?
KisConfig cfg;
QString monitorProfileName = cfg.monitorProfile();
KisProfileSP monitorProfile = KisColorSpaceRegistry::instance() -> getProfileByName(monitorProfileName);
qimg = selection -> convertToQImage(monitorProfile);
}
else {
qimg = selection -> convertToQImage(0);
}
QClipboard *cb = QApplication::clipboard();
cb -> setImage(qimg);
m_pushedClipboard = true;
}
}
KisPaintDeviceSP KisClipboard::clip()
{
return m_clip;
}
void KisClipboard::clipboardDataChanged()
{
if (!m_pushedClipboard) {
QClipboard *cb = QApplication::clipboard();
QImage qimg = cb -> image();
if (!qimg.isNull()) {
KisStrategyColorSpaceSP cs = KisColorSpaceRegistry::instance()->get("RGBA");
m_clip =
new KisPaintDevice(qimg.width(), qimg.height(),
cs,
"KisClipboard created clipboard selection");
m_clip -> convertFromImage(qimg);
}
}
m_pushedClipboard = false;
}
bool KisClipboard::hasClip()
{
if (m_clip != 0) {
return true;
}
return false;
}
#include "kis_clipboard.moc"
/*
* kis_clipboard.h - part of Krayon
*
* Copyright (c) 2004 Boudewijn Rempt <boud@valdyas.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __KIS_CLIPBOARD_H_
#define __KIS_CLIPBOARD_H_
#include "kis_types.h"
class QImage;
/**
* The Krita clipboard is a clipboard that can store paint devices
* instead of just qimage's.
*/
class KisClipboard : public QObject {
Q_OBJECT
public:
virtual KisClipboard::~KisClipboard();
static KisClipboard* instance();
/**
* Sets the clipboard to the contents of the specified paint device; also
* set the system clipboard to a QImage representation of the specified
* paint device.
*/
void setClip(KisPaintDeviceSP layer);
/**
* Get the contents of the clipboard in the form of a paint device.
*/
KisPaintDeviceSP clip();
bool hasClip();
private slots:
void clipboardDataChanged();
private:
KisClipboard();
KisClipboard(const KisClipboard &);
KisClipboard operator=(const KisClipboard &);
static KisClipboard * m_singleton;
KisPaintDeviceSP m_clip;
bool m_pushedClipboard;
};
#endif // __KIS_CLIPBOARD_H_
......@@ -21,7 +21,6 @@
// Qt
#include <qapplication.h>
#include <qclipboard.h>
#include <qdom.h>
#include <qimage.h>
#include <qpainter.h>
......@@ -29,7 +28,6 @@
#include <qstringlist.h>
#include <qwidget.h>
#include <qpaintdevicemetrics.h>
#include <qmessagebox.h>
// KDE
#include <dcopobject.h>
......@@ -39,7 +37,6 @@
#include <kimageio.h>
#include <kfiledialog.h>
#include <kglobal.h>
#include <kmessagebox.h>
#include <kmimetype.h>
#include <knotifyclient.h>
#include <klocale.h>
......@@ -341,7 +338,6 @@ KisDoc::KisDoc(QWidget *parentWidget, const char *widgetName, QObject *parent, c
m_dcop = 0;
m_cmdHistory = 0;
m_nserver = 0;
m_pushedClipboard = false;
m_currentMacro = 0;
m_macroNestDepth = 0;
m_ioProgressBase = 0;
......@@ -350,9 +346,6 @@ KisDoc::KisDoc(QWidget *parentWidget, const char *widgetName, QObject *parent, c
if (name)
dcopObject();
connect( QApplication::clipboard(), SIGNAL( dataChanged() ),
this, SLOT( clipboardDataChanged() ) );
}
KisDoc::~KisDoc()
......@@ -1423,43 +1416,6 @@ void KisDoc::setLayerProperties(KisImageSP img,
}
}
void KisDoc::setClipboard(KisPaintDeviceSP selection)
{
m_clipboard = selection;
if (selection) {
QImage qimg = selection -> convertToQImage();
QClipboard *cb = QApplication::clipboard();
cb -> setImage(qimg);
m_pushedClipboard = true;
}
}
KisPaintDeviceSP KisDoc::clipboard()
{
return m_clipboard;
}
void KisDoc::clipboardDataChanged()
{
if (!m_pushedClipboard) {
QClipboard *cb = QApplication::clipboard();
QImage qimg = cb -> image();
if (!qimg.isNull()) {
m_clipboard =
new KisPaintDevice(qimg.width(), qimg.height(),
KisColorSpaceRegistry::instance()->get( qimg.hasAlphaBuffer() ? "RGBA" : "RGB" ),
"KisDoc created clipboard selection");
m_clipboard -> convertFromImage(qimg);
}
}
m_pushedClipboard = false;
}
bool KisDoc::undo() const
{
return m_undo;
......
......@@ -131,17 +131,6 @@ public:
QString nextImageName() const;
void setCurrentImage(KisImageSP img);
/**
* Sets the clipboard to the contents of the specified paint device; also
* set the system clipboard to a QImage representation of the specified
* paint device.
*/
void setClipboard(KisPaintDeviceSP layer);
/**
* Get the contents of the clipboard in the form of a paint device.
*/
KisPaintDeviceSP clipboard();
bool importImage(const QString& filename);
......@@ -165,7 +154,6 @@ protected:
private slots:
void slotUpdate(KisImageSP img, Q_UINT32 x, Q_UINT32 y, Q_UINT32 w, Q_UINT32 h);
void clipboardDataChanged();
void slotIOProgress(Q_INT8 percentage);
private:
......@@ -185,10 +173,6 @@ private:
KoCommandHistory *m_cmdHistory;
vKisImageSP m_images;
KisImageSP m_currentImage;
KisPaintDeviceSP m_clipboard;
bool m_pushedClipboard;
DCOPObject *m_dcop;
KisNameServer *m_nserver;
KMacroCommand *m_currentMacro;
......
......@@ -66,7 +66,7 @@ public:
return list;
}
private:
protected:
KisGenericRegistry(const KisGenericRegistry&) { };
KisGenericRegistry operator=(const KisGenericRegistry&) { };
storageMap m_storage;
......
......@@ -51,6 +51,8 @@
#include "visitors/kis_merge.h"
#include "kis_scale_visitor.h"
#include "kis_profile.h"
#include "kis_config.h"
#include "kis_colorspace_registry.h"
#define DEBUG_IMAGES 0
......@@ -308,6 +310,11 @@ void KisImage::init(KisUndoAdapter *adapter, Q_INT32 width, Q_INT32 height, Kis
m_undoHistory = 0;
m_ntileCols = (width + TILE_WIDTH - 1) / TILE_WIDTH;
m_ntileRows = (height + TILE_HEIGHT - 1) / TILE_HEIGHT;
KisConfig cfg;
QString monitorProfileName = cfg.monitorProfile();
m_monitorProfile = KisColorSpaceRegistry::instance() -> getProfileByName(monitorProfileName);
}
void KisImage::resize(Q_INT32 w, Q_INT32 h)
......@@ -1064,7 +1071,9 @@ void KisImage::renderToPainter(Q_INT32 x1,
continue;
renderToProjection(tileno);
QImage img = projection() -> convertToQImage(x, y, TILE_WIDTH, TILE_HEIGHT);
QImage img = projection() -> convertToQImage(m_monitorProfile, x, y, TILE_WIDTH, TILE_HEIGHT);
if (!img.isNull()) {
// XXX: made obosolete by qt-copy patch 0005
// m_pixio.putImage(&m_pixmap, 0, 0, &img);
......
......@@ -91,6 +91,11 @@ public:
// Set the profile associated with this image
void setProfile(const KisProfileSP& profile);
// Get the profile that this image uses to display itself on
// the monitor
KisProfileSP monitorProfile() const { return m_monitorProfile; }
void enableUndo(KoCommandHistory *history);
KisStrategyColorSpaceSP colorStrategy() const;
......@@ -193,6 +198,7 @@ private:
QString m_description;
KisProfileSP m_profile;
KisProfileSP m_monitorProfile;
Q_UINT32 m_depth;
......@@ -226,6 +232,7 @@ private:
QPixmap m_pixmap;
};
#endif // KIS_IMAGE_H_
......@@ -664,7 +664,7 @@ void KisPaintDevice::setProfile(KisProfileSP profile)
}
QImage KisPaintDevice::convertToQImage(Q_INT32 x, Q_INT32 y, Q_INT32 w, Q_INT32 h, KisProfileSP dstProfile)
QImage KisPaintDevice::convertToQImage(KisProfileSP dstProfile, Q_INT32 x, Q_INT32 y, Q_INT32 w, Q_INT32 h)
{
if (w < 0) {
w = width();
......
......@@ -119,7 +119,7 @@ public:
* case it's up to the colour strategy to choose a profile (most
* like sRGB).
*/
virtual QImage convertToQImage(Q_INT32 x = 0, Q_INT32 y = 0, Q_INT32 w = -1, Q_INT32 h = -1, KisProfileSP dstProfile = 0);
virtual QImage convertToQImage(KisProfileSP dstProfile, Q_INT32 x = 0, Q_INT32 y = 0, Q_INT32 w = -1, Q_INT32 h = -1);
virtual QString name() const;
virtual void setName(const QString& name);
......@@ -192,6 +192,8 @@ public:
void resize(Q_INT32 w, Q_INT32 h);
void resize(const QSize& size);
void resize();
// XXX: Do all rotations etc. use the visitor instead of the QMatrix-based code by now?
void scale(double sx, double sy, KisProgressDisplayInterface *m_progress, enumFilterType ftype=MITCHELL_FILTER);
void rotate(double angle, KisProgressDisplayInterface *m_progress);
void shear(double angleX, double angleY, KisProgressDisplayInterface *m_progress);
......@@ -496,7 +498,7 @@ inline bool KisPaintDevice::pixel(Q_INT32 x, Q_INT32 y, QColor *c, QUANTUM *opac
if (!pix) return false;
colorStrategy() -> toQColor(pix, c, opacity);
colorStrategy() -> toQColor(pix, c, opacity); //profile
return true;
}
......@@ -513,7 +515,7 @@ inline bool KisPaintDevice::setPixel(Q_INT32 x, Q_INT32 y, const QColor& c, QUAN
pix = pd -> data;
Q_ASSERT(pix);
colorStrategy() -> nativeColor(c, opacity, pix);
colorStrategy() -> nativeColor(c, opacity, pix); //profile
tm -> releasePixelData(pd);
......
/*
* Copyright (c) 2004 Cyrille Berger <cberger@cberger.net>
* Copyright (c) 2004 Boudewijn Rempt <boud@valdyas.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "qcolor.h"
#include "kis_global.h"
#include "kis_types.h"
#include "kis_profile.h"
#include "kis_quantum.h"
#include "kis_pixel.h"
......@@ -19,10 +19,13 @@
#ifndef _KIS_PIXEL_H_
#define _KIS_PIXEL_H_
#include "ksharedptr.h"
#include "kis_global.h"
#include "kis_types.h"
#include "kis_profile.h"
#include "kis_quantum.h"
#include "kis_strategy_colorspace.h"
class QColor;
......@@ -152,7 +155,7 @@ class KisColor {
public:
KisColor(QColor c, KisStrategyColorSpaceSP colorStrategy, KisProfileSP profile);
KisColor(QColor c, KisStrategyColorSpaceSP colorStrategy, KisProfileSP profile) {};
KisColor(QUANTUM * channels, QUANTUM* alpha, KisStrategyColorSpaceSP colorStrategy, KisProfileSP profile)
: m_channels(channels),
......@@ -173,7 +176,6 @@ public:
QUANTUM* channels() { return m_channels; }
QColor toQColor();
private:
QUANTUM* m_channels;
......
......@@ -15,9 +15,10 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <qobject.h>
#include <qclipboard.h>
#include <qapplication.h>
#include <qclipboard.h>
#include <kdebug.h>
#include <kaction.h>
......@@ -26,6 +27,7 @@
#include <qcolor.h>
#include "kis_clipboard.h"
#include "kis_types.h"
#include "kis_view.h"
#include "kis_doc.h"
......@@ -44,7 +46,6 @@ KisSelectionManager::KisSelectionManager(KisView * parent, KisDoc * doc)
: m_parent(parent),
m_doc(doc),
m_previousSelection(0),
m_clipboardHasImage(false),
m_copy(0),
m_cut(0),
m_paste(0),
......@@ -64,9 +65,9 @@ KisSelectionManager::KisSelectionManager(KisView * parent, KisDoc * doc)
m_transform(0),
m_load(0),
m_save(0)
{
m_pluginActions.setAutoDelete(true);
m_clipboard = KisClipboard::instance();
}
KisSelectionManager::~KisSelectionManager()
......@@ -200,9 +201,14 @@ void KisSelectionManager::setup(KActionCollection * collection)
this, SLOT(save()),
collection, "save_selection");
QClipboard *cb = QApplication::clipboard();
connect(cb, SIGNAL(dataChanged()), SLOT(clipboardDataChanged()));
}
void KisSelectionManager::clipboardDataChanged()
{
updateGUI();
}
......@@ -211,11 +217,6 @@ void KisSelectionManager::addSelectionAction(KAction * action)
m_pluginActions.append(action);
}
void KisSelectionManager::clipboardDataChanged()
{
m_clipboardHasImage = !QApplication::clipboard() -> image().isNull();
}
void KisSelectionManager::updateGUI()
{
......@@ -225,7 +226,7 @@ void KisSelectionManager::updateGUI()
m_copy -> setEnabled(enable);
m_cut -> setEnabled(enable);
m_paste -> setEnabled(img != 0 && m_clipboardHasImage);
m_paste -> setEnabled(img != 0 && m_clipboard -> hasClip());
m_selectAll -> setEnabled(img != 0);
m_deselect -> setEnabled(enable);
m_clear -> setEnabled(enable);
......@@ -310,7 +311,7 @@ void KisSelectionManager::copy()
// << r.height() << "\n";
m_doc -> setClipboard(s);
m_clipboard -> setClip(s);
imgSelectionChanged(m_parent -> currentImg());
}
......@@ -324,7 +325,7 @@ KisLayerSP KisSelectionManager::paste()
KisLayerSP layer = img -> activeLayer();
if (!layer) return 0;
KisPaintDeviceSP clip = m_doc -> clipboard();
KisPaintDeviceSP clip = m_clipboard -> clip();
if (clip) {
KisLayerSP layer = new KisLayer(img, clip -> width(), clip -> height(), img -> nextLayerName() + "(pasted)", OPACITY_OPAQUE);
......@@ -340,24 +341,7 @@ KisLayerSP KisSelectionManager::paste()
return layer;
}
else {
QClipboard *cb = QApplication::clipboard();
QImage qimg = cb -> image();
if (!qimg.isNull()) {
KisLayerSP layer =
new KisLayer(qimg.width(), qimg.height(),
KisColorSpaceRegistry::instance()->get( qimg.hasAlphaBuffer() ? "RGBA" : "RGB" ),
"KisDoc created clipboard selection");
layer -> convertFromImage(qimg);
m_doc -> layerAdd(img, layer, img -> index(layer));
layer -> move(0,0);
img -> notify();
return layer;
}
}
return 0;
}
......
......@@ -27,6 +27,7 @@
class KAction;
class KisView;
class KisDoc;
class KisClipboard;
/**
* The selection manager is responsible selections
......@@ -47,9 +48,9 @@ public:
public slots:
void clipboardDataChanged();
void updateGUI();
void imgSelectionChanged(KisImageSP img);
void clipboardDataChanged();