~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to filters/kword/libexport/Picture.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-09-21 15:36:35 UTC
  • mfrom: (1.4.1 upstream) (60.2.11 maverick)
  • Revision ID: james.westby@ubuntu.com-20100921153635-6tejqkiro2u21ydi
Tags: 1:2.2.2-0ubuntu3
Add kubuntu_03_fix-crash-on-closing-sqlite-connection-2.2.2.diff and
kubuntu_04_support-large-memo-values-for-msaccess-2.2.2.diff as
recommended by upstream http://kexi-
project.org/wiki/wikiview/index.php@Kexi2.2_Patches.html#sqlite_stab
ility

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
   Copyright (c) 2001 Simon Hausmann <hausmann@kde.org>
 
3
   Copyright (C) 2002, 2003 Nicolas GOUTTE <goutte@kde.org>
 
4
 
 
5
   This library is free software; you can redistribute it and/or
 
6
   modify it under the terms of the GNU Library General Public
 
7
   License as published by the Free Software Foundation; either
 
8
   version 2 of the License, or (at your option) any later version.
 
9
 
 
10
   This library is distributed in the hope that it will be useful,
 
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
   Library General Public License for more details.
 
14
 
 
15
   You should have received a copy of the GNU Library General Public License
 
16
   along with this library; see the file COPYING.LIB.  If not, write to
 
17
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
18
 * Boston, MA 02110-1301, USA.
 
19
*/
 
20
 
 
21
#include "Picture.h"
 
22
 
 
23
#include "PictureKey.h"
 
24
#include "PictureShared.h"
 
25
#include "PictureBase.h"
 
26
 
 
27
#include <QPainter>
 
28
#include <QFile>
 
29
//Added by qt3to4:
 
30
#include <QPixmap>
 
31
 
 
32
#include <kdebug.h>
 
33
#include <kurl.h>
 
34
#include <kio/netaccess.h>
 
35
 
 
36
uint Picture::uniqueValue = 0;
 
37
 
 
38
 
 
39
Picture::Picture(void) : m_sharedData(NULL)
 
40
{
 
41
    m_uniqueName = "Pictures" + QString::number(uniqueValue++);
 
42
}
 
43
 
 
44
Picture::~Picture(void)
 
45
{
 
46
    unlinkSharedData();
 
47
}
 
48
 
 
49
QString Picture::uniqueName() const
 
50
{
 
51
    return m_uniqueName;
 
52
}
 
53
 
 
54
Picture::Picture(const Picture &other)
 
55
{
 
56
    m_sharedData = NULL;
 
57
    (*this) = other;
 
58
}
 
59
 
 
60
void Picture::assignPictureId(uint _id)
 
61
{
 
62
    if (m_sharedData)
 
63
        m_sharedData->assignPictureId(_id);
 
64
}
 
65
 
 
66
QString Picture::uniquePictureId() const
 
67
{
 
68
    if (m_sharedData)
 
69
        return m_sharedData->uniquePictureId();
 
70
    else
 
71
        return QString();
 
72
}
 
73
 
 
74
Picture& Picture::operator=(const Picture & other)
 
75
{
 
76
    //kDebug(30508) <<"Picture::= before";
 
77
    if (other.m_sharedData)
 
78
        other.linkSharedData();
 
79
    if (m_sharedData)
 
80
        unlinkSharedData();
 
81
    m_sharedData = other.m_sharedData;
 
82
    m_key = other.m_key;
 
83
    //kDebug(30508) <<"Picture::= after";
 
84
    return *this;
 
85
}
 
86
 
 
87
void Picture::unlinkSharedData(void)
 
88
{
 
89
    if (m_sharedData && m_sharedData->deref())
 
90
        delete m_sharedData;
 
91
 
 
92
    m_sharedData = NULL;
 
93
}
 
94
 
 
95
void Picture::linkSharedData(void) const
 
96
{
 
97
    if (m_sharedData)
 
98
        m_sharedData->ref();
 
99
}
 
100
 
 
101
void Picture::createSharedData(void)
 
102
{
 
103
    if (!m_sharedData) {
 
104
        m_sharedData = new PictureShared();
 
105
        // Do not call m_sharedData->ref()
 
106
    }
 
107
}
 
108
 
 
109
PictureType::Type Picture::getType(void) const
 
110
{
 
111
    if (m_sharedData)
 
112
        return m_sharedData->getType();
 
113
    return PictureType::TypeUnknown;
 
114
}
 
115
 
 
116
PictureKey Picture::getKey(void) const
 
117
{
 
118
    return m_key;
 
119
}
 
120
 
 
121
void Picture::setKey(const PictureKey& key)
 
122
{
 
123
    m_key = key;
 
124
}
 
125
 
 
126
 
 
127
bool Picture::isNull(void) const
 
128
{
 
129
    if (m_sharedData)
 
130
        return m_sharedData->isNull();
 
131
    return true;
 
132
}
 
133
 
 
134
void Picture::draw(QPainter& painter, int x, int y, int width, int height, int sx, int sy, int sw, int sh, bool fastMode)
 
135
{
 
136
    if (m_sharedData)
 
137
        m_sharedData->draw(painter, x, y, width, height, sx, sy, sw, sh, fastMode);
 
138
    else {
 
139
        // Draw a white box
 
140
        kWarning(30508) << "Drawing white rectangle! (Picture::draw)";
 
141
        painter.save();
 
142
        painter.setBrush(QColor(255, 255, 255));
 
143
        painter.drawRect(x, y, width, height);
 
144
        painter.restore();
 
145
    }
 
146
}
 
147
 
 
148
bool Picture::loadXpm(QIODevice* io)
 
149
{
 
150
    kDebug(30508) << "Picture::loadXpm";
 
151
    if (!io) {
 
152
        kError(30508) << "No QIODevice!" << endl;
 
153
        return false;
 
154
    }
 
155
    createSharedData();
 
156
    return m_sharedData->loadXpm(io);
 
157
}
 
158
 
 
159
bool Picture::save(QIODevice* io) const
 
160
{
 
161
    if (!io)
 
162
        return false;
 
163
    if (m_sharedData)
 
164
        return m_sharedData->save(io);
 
165
    return false;
 
166
}
 
167
 
 
168
bool Picture::saveAsBase64(KoXmlWriter& writer) const
 
169
{
 
170
    if (m_sharedData)
 
171
        return m_sharedData->saveAsBase64(writer);
 
172
    return false;
 
173
}
 
174
 
 
175
void Picture::clear(void)
 
176
{
 
177
    unlinkSharedData();
 
178
}
 
179
 
 
180
void Picture::clearAndSetMode(const QString& newMode)
 
181
{
 
182
    createSharedData();
 
183
    m_sharedData->clearAndSetMode(newMode);
 
184
}
 
185
 
 
186
QString Picture::getExtension(void) const
 
187
{
 
188
    if (m_sharedData)
 
189
        return m_sharedData->getExtension();
 
190
    return "null"; // Just a dummy
 
191
}
 
192
 
 
193
QString Picture::getMimeType(void) const
 
194
{
 
195
    if (m_sharedData)
 
196
        return m_sharedData->getMimeType();
 
197
    return QString(NULL_MIME_TYPE);
 
198
}
 
199
 
 
200
bool Picture::load(QIODevice* io, const QString& extension)
 
201
{
 
202
    kDebug(30508) << "Picture::load(QIODevice*, const QString&)" << extension;
 
203
    createSharedData();
 
204
 
 
205
    return m_sharedData->load(io, extension);
 
206
}
 
207
 
 
208
bool Picture::loadFromFile(const QString& fileName)
 
209
{
 
210
    kDebug(30508) << "Picture::loadFromFile" << fileName;
 
211
    createSharedData();
 
212
    return m_sharedData->loadFromFile(fileName);
 
213
}
 
214
 
 
215
bool Picture::loadFromBase64(const QByteArray& str)
 
216
{
 
217
    createSharedData();
 
218
    return m_sharedData->loadFromBase64(str);
 
219
}
 
220
 
 
221
QSize Picture::getOriginalSize(void) const
 
222
{
 
223
    if (m_sharedData)
 
224
        return m_sharedData->getOriginalSize();
 
225
    return QSize(0, 0);
 
226
}
 
227
 
 
228
QPixmap Picture::generatePixmap(const QSize& size, bool smoothScale)
 
229
{
 
230
    if (m_sharedData)
 
231
        return m_sharedData->generatePixmap(size, smoothScale);
 
232
    return QPixmap();
 
233
}
 
234
 
 
235
bool Picture::setKeyAndDownloadPicture(const KUrl& url, QWidget *window)
 
236
{
 
237
    bool result = false;
 
238
 
 
239
    QString tmpFileName;
 
240
    if (KIO::NetAccess::download(url, tmpFileName, window)) {
 
241
        PictureKey key;
 
242
        key.setKeyFromFile(tmpFileName);
 
243
        setKey(key);
 
244
        result = loadFromFile(tmpFileName);
 
245
        KIO::NetAccess::removeTempFile(tmpFileName);
 
246
    }
 
247
 
 
248
    return result;
 
249
}
 
250
 
 
251
QMimeData* Picture::dragObject(QWidget *dragSource, const char *name)
 
252
{
 
253
    if (m_sharedData)
 
254
        return m_sharedData->dragObject(dragSource, name);
 
255
    return 0;
 
256
}
 
257
 
 
258
QImage Picture::generateImage(const QSize& size)
 
259
{
 
260
    if (m_sharedData)
 
261
        return m_sharedData->generateImage(size);
 
262
    return QImage();
 
263
}
 
264
 
 
265
bool Picture::hasAlphaBuffer() const
 
266
{
 
267
    if (m_sharedData)
 
268
        return m_sharedData->hasAlphaBuffer();
 
269
    return false;
 
270
}
 
271
 
 
272
void Picture::setAlphaBuffer(bool enable)
 
273
{
 
274
    if (m_sharedData)
 
275
        m_sharedData->setAlphaBuffer(enable);
 
276
}
 
277
 
 
278
QImage Picture::createAlphaMask(Qt::ImageConversionFlags flags) const
 
279
{
 
280
    if (m_sharedData)
 
281
        return m_sharedData->createAlphaMask(flags);
 
282
    return QImage();
 
283
}
 
284
 
 
285
void Picture::clearCache(void)
 
286
{
 
287
    if (m_sharedData)
 
288
        m_sharedData->clearCache();
 
289
}