1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
|
/*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <tqapplication.h>
#include <tqclipboard.h>
#include <tqobject.h>
#include <tqimage.h>
#include <tqmessagebox.h>
#include <tqbuffer.h>
#include <kmultipledrag.h>
#include <klocale.h>
#include "kdebug.h"
#include "KoStore.h"
#include "KoStoreDrag.h"
#include "kis_types.h"
#include "kis_paint_device.h"
#include "kis_config.h"
#include "kis_colorspace_factory_registry.h"
#include "kis_factory.h"
#include <kis_meta_registry.h>
#include "kis_clipboard.h"
KisClipboard *KisClipboard::m_singleton = 0;
KisClipboard::KisClipboard()
{
Q_ASSERT(KisClipboard::m_singleton == 0);
KisClipboard::m_singleton = this;
m_pushedClipboard = false;
m_hasClip = false;
m_clip = 0;
// Check that we don't already have a clip ready
clipboardDataChanged();
// Make sure we are notified when clipboard changes
connect( TQApplication::clipboard(), TQT_SIGNAL( dataChanged() ),
this, TQT_SLOT( clipboardDataChanged() ) );
}
KisClipboard::~KisClipboard()
{
}
KisClipboard* KisClipboard::instance()
{
if(KisClipboard::m_singleton == 0)
{
KisClipboard::m_singleton = new KisClipboard();
TQ_CHECK_PTR(KisClipboard::m_singleton);
}
return KisClipboard::m_singleton;
}
void KisClipboard::setClip(KisPaintDeviceSP selection)
{
m_clip = selection;
if (!selection)
return;
m_hasClip = true;
// We'll create a store (ZIP format) in memory
TQBuffer buffer;
TQCString mimeType("application/x-chalk-selection");
KoStore* store = KoStore::createStore( TQT_TQIODEVICE(&buffer), KoStore::Write, mimeType );
Q_ASSERT( store );
Q_ASSERT( !store->bad() );
// Layer data
if (store->open("layerdata")) {
if (!selection->write(store)) {
selection->disconnect();
store->close();
return;
}
store->close();
}
// ColorSpace id of layer data
if (store->open("colorspace")) {
TQString csName = selection->colorSpace()->id().id();
store->write(csName.ascii(), strlen(csName.ascii()));
store->close();
}
if (selection->colorSpace()->getProfile()) {
KisAnnotationSP annotation = selection->colorSpace()->getProfile()->annotation();
if (annotation) {
// save layer profile
if (store->open("profile.icc")) {
store->write(annotation->annotation());
store->close();
}
}
}
delete store;
// We also create a TQImage so we can interchange with other applications
TQImage qimg;
KisConfig cfg;
TQString monitorProfileName = cfg.monitorProfile();
KisProfile * monitorProfile = KisMetaRegistry::instance()->csRegistry()->getProfileByName(monitorProfileName);
qimg = selection->convertToTQImage(monitorProfile);
TQImageDrag *qimgDrag = new TQImageDrag(qimg);
KMultipleDrag *multiDrag = new KMultipleDrag();
if ( !qimg.isNull() )
multiDrag->addDragObject( qimgDrag );
KoStoreDrag* storeDrag = new KoStoreDrag( mimeType, 0 );
storeDrag->setEncodedData( buffer.buffer() );
multiDrag->addDragObject( storeDrag );
TQClipboard *cb = TQApplication::clipboard();
cb->setData(multiDrag);
m_pushedClipboard = true;
}
KisPaintDeviceSP KisClipboard::clip()
{
TQClipboard *cb = TQApplication::clipboard();
TQCString mimeType("application/x-chalk-selection");
TQMimeSource *cbData = cb->data();
if(cbData && cbData->provides(mimeType))
{
TQBuffer buffer(cbData->encodedData(mimeType));
KoStore* store = KoStore::createStore( TQT_TQIODEVICE(&buffer), KoStore::Read, mimeType );
KisProfile *profile=0;
if (store->hasFile("profile.icc")) {
TQByteArray data;
store->open("profile.icc");
data = store->read(store->size());
store->close();
profile = new KisProfile(data);
}
TQString csName;
// ColorSpace id of layer data
if (store->hasFile("colorspace")) {
store->open("colorspace");
csName = TQString(store->read(store->size()));
store->close();
}
KisColorSpace *cs = KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID(csName, ""), profile);
m_clip = new KisPaintDevice(cs, "clip");
if (store->hasFile("layerdata")) {
store->open("layerdata");
m_clip->read(store);
store->close();
}
delete store;
}
else
{
TQImage qimg = cb->image();
if (qimg.isNull())
return 0;
KisConfig cfg;
TQ_UINT32 behaviour = cfg.pasteBehaviour();
if(behaviour==2)
{
// Ask user each time
behaviour = TQMessageBox::question(0,i18n("Pasting data from simple source"),i18n("The image data you are trying to paste has no colour profile information.\n\nOn the web and in simple applications the data are supposed to be in sRGB color format.\nImporting as web will show it as it is supposed to look.\nMost monitors are not perfect though so if you made the image yourself\nyou might want to import it as it looked on you monitor.\n\nHow do you want to interpret these data?"),i18n("As &Web"),i18n("As on &Monitor"));
}
KisColorSpace * cs;
TQString profileName("");
if(behaviour==1)
profileName = cfg.monitorProfile();
cs = KisMetaRegistry::instance()->csRegistry() ->getColorSpace(KisID("RGBA",""), profileName);
m_clip = new KisPaintDevice(cs, "from paste");
TQ_CHECK_PTR(m_clip);
m_clip->convertFromTQImage(qimg, profileName);
}
return m_clip;
}
void KisClipboard::clipboardDataChanged()
{
if (!m_pushedClipboard) {
m_hasClip = false;
TQClipboard *cb = TQApplication::clipboard();
TQImage qimg = cb->image();
TQMimeSource *cbData = cb->data();
TQCString mimeType("application/x-chalk-selection");
if(cbData && cbData->provides(mimeType))
m_hasClip = true;
if (!qimg.isNull())
m_hasClip = true;
}
m_pushedClipboard = false;
}
bool KisClipboard::hasClip()
{
return m_hasClip;
}
TQSize KisClipboard::clipSize()
{
TQClipboard *cb = TQApplication::clipboard();
TQCString mimeType("application/x-chalk-selection");
TQMimeSource *cbData = cb->data();
KisPaintDeviceSP clip;
if(cbData && cbData->provides(mimeType)) {
TQBuffer buffer(cbData->encodedData(mimeType));
KoStore* store = KoStore::createStore( TQT_TQIODEVICE(&buffer), KoStore::Read, mimeType );
KisProfile *profile=0;
if (store->hasFile("profile.icc")) {
TQByteArray data;
store->open("profile.icc");
data = store->read(store->size());
store->close();
profile = new KisProfile(data);
}
TQString csName;
// ColorSpace id of layer data
if (store->hasFile("colorspace")) {
store->open("colorspace");
csName = TQString(store->read(store->size()));
store->close();
}
KisColorSpace *cs = KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID(csName, ""), profile);
clip = new KisPaintDevice(cs, "clip");
if (store->hasFile("layerdata")) {
store->open("layerdata");
clip->read(store);
store->close();
}
delete store;
return clip->exactBounds().size();
}
else {
TQImage qimg = cb->image();
return qimg.size();
}
;
}
#include "kis_clipboard.moc"
|