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

« back to all changes in this revision

Viewing changes to lib/kofficecore/KoPictureShared.h

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2006-04-20 21:38:53 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060420213853-j5lxluqvymxt2zny
Tags: 1:1.5.0-0ubuntu2
UbuntuĀ uploadĀ 

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, 2004 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
#ifndef __koPictureShared_h__
 
21
#define __koPictureShared_h__
 
22
 
 
23
#include <qshared.h>
 
24
#include <qstring.h>
 
25
#include <qiodevice.h>
 
26
#include <qpixmap.h>
 
27
 
 
28
#include "KoPictureKey.h"
 
29
 
 
30
class KoXmlWriter;
 
31
class QPainter;
 
32
class QSize;
 
33
 
 
34
class KURL;
 
35
 
 
36
class KoPictureBase;
 
37
 
 
38
/**
 
39
 * @internal
 
40
 * KoPictureShared is the class that contains the shared part for KoPicture
 
41
 *
 
42
 * @warning As with all QShared objects, the sharing is neither automatic nor transparent!
 
43
 */
 
44
class KoPictureShared : public QShared
 
45
{
 
46
public:
 
47
    /**
 
48
     * Default constructor.
 
49
     */
 
50
    KoPictureShared(void);
 
51
 
 
52
    /**
 
53
     * Destructor.
 
54
     */
 
55
    ~KoPictureShared(void);
 
56
 
 
57
    /**
 
58
     * @brief Copy constructor
 
59
     *
 
60
     * This makes a deep copy. Do not use if you want to share!
 
61
     */
 
62
    KoPictureShared(const KoPictureShared &other);
 
63
 
 
64
    /**
 
65
     * @brief Assignment operator
 
66
     *
 
67
     * This makes a deep copy. Do not use if you want to share!
 
68
     */
 
69
    KoPictureShared& operator=(const KoPictureShared& other);
 
70
 
 
71
    KoPictureType::Type getType(void) const;
 
72
 
 
73
    /**
 
74
     * Returns true if the picture is null.
 
75
     */
 
76
    bool isNull(void) const;
 
77
 
 
78
    /**
 
79
     * @brief Draw the image in a painter.
 
80
     *
 
81
     * The parameter @p fastMode allows the picture to be re-sized and drawn quicker if possible
 
82
     *
 
83
     * The parameters @p width, @p height define the desired size for the picture
 
84
     *
 
85
     * The other parameters are very similar to QPainter::drawPixmap :
 
86
     * (@p x, @p y) define the position in the painter,
 
87
     * (@p sx, @p sy) specify the top-left point in pixmap that is to be drawn. The default is (0, 0).
 
88
     * (@p sw, @p sh) specify the size of the pixmap that is to be drawn. The default, (-1, -1), means all the way to the bottom
 
89
     * right of the pixmap.
 
90
     */
 
91
    void draw(QPainter& painter, int x, int y, int width, int height, int sx = 0, int sy = 0, int sw = -1, int sh = -1, bool fastMode = false);
 
92
 
 
93
    /**
 
94
     * Create a dragobject containing this picture.
 
95
     * @param dragSource must be 0 when copying to the clipboard
 
96
     * @return 0L if the picture is null!
 
97
     */
 
98
    QDragObject* dragObject( QWidget *dragSource = 0L, const char *name = 0L );
 
99
 
 
100
    bool load(QIODevice* io, const QString& extension);
 
101
    bool loadFromBase64( const QCString& str );
 
102
 
 
103
    /**
 
104
     * Save picture into a QIODevice
 
105
     * @param io QIODevice used for saving
 
106
     */
 
107
    bool save(QIODevice* io) const;
 
108
 
 
109
    /**
 
110
     * OASIS FlatXML support:
 
111
     * Save picture as base64-encoded data into an XML writer.
 
112
     */
 
113
    bool saveAsBase64( KoXmlWriter& writer ) const;
 
114
 
 
115
    void setExtension(const QString& extension);
 
116
 
 
117
    QString getExtension(void) const;
 
118
 
 
119
    QSize getOriginalSize(void) const;
 
120
 
 
121
    /**
 
122
     * Clear and set the mode of this KoPictureShared
 
123
     *
 
124
     * @param newMode file extension (like "png") giving the wanted mode
 
125
     */
 
126
    void clearAndSetMode(const QString& newMode);
 
127
 
 
128
    /**
 
129
     * Reset the KoPictureShared (but not the key!)
 
130
     */
 
131
    void clear(void);
 
132
 
 
133
    /**
 
134
     * Load a file
 
135
     *
 
136
     * @param fileName the name of the file to load
 
137
     */
 
138
    bool loadFromFile(const QString& fileName);
 
139
 
 
140
    /**
 
141
     * Load a potentially broken XPM file (for KPresenter)
 
142
     */
 
143
    bool loadXpm(QIODevice* io);
 
144
 
 
145
    /**
 
146
     * @deprecated
 
147
     * Returns a QPixmap from an image
 
148
     *
 
149
     * @param size the wanted size for the QPixmap
 
150
     */
 
151
    QPixmap generatePixmap(const QSize& size, bool smoothScale = false);
 
152
 
 
153
    QString getMimeType(void) const;
 
154
 
 
155
    /**
 
156
     * Generate a QImage
 
157
     *
 
158
     * (always in slow mode)
 
159
     *
 
160
     * @param size the wanted size for the QImage
 
161
     */
 
162
    QImage generateImage(const QSize& size);
 
163
 
 
164
    bool hasAlphaBuffer() const;
 
165
    void setAlphaBuffer(bool enable);
 
166
    QImage createAlphaMask(int conversion_flags = 0) const;
 
167
 
 
168
    /**
 
169
     * Clear any cache
 
170
     *
 
171
     * It is used to avoid using too much memory
 
172
     * especially if the application somehow caches the KoPicture too.
 
173
     */
 
174
    void clearCache(void);
 
175
 
 
176
    QString uniquePictureId() const;
 
177
    void assignPictureId( uint _id);
 
178
 
 
179
protected:
 
180
    /**
 
181
     * @internal
 
182
     * Load a WMF file
 
183
     * \note In %KOffice 1.1, a .wmf file was a QPicture file
 
184
     */
 
185
    bool loadWmf(QIODevice* io);
 
186
 
 
187
    /**
 
188
     * @internal
 
189
     * Loads a temporary file, probably from a downloaded file
 
190
     */
 
191
    bool loadTmp(QIODevice* io);
 
192
 
 
193
    /// Find type of image, create base accordingly, and load data
 
194
    bool identifyAndLoad( QByteArray data );
 
195
 
 
196
    /**
 
197
     * @internal
 
198
     * Loads a compressed file
 
199
     *
 
200
     * @warning risk of endless recurision, be careful when it is called from @see load
 
201
     *
 
202
     * @param io QIODevice of the compressed file/strea,
 
203
     * @param mimeType mimetype of the (de-)compressor
 
204
     * @param extension extension of the uncompressed file
 
205
     */
 
206
    bool loadCompressed( QIODevice* io, const QString& mimeType, const QString& extension );
 
207
 
 
208
protected:
 
209
    KoPictureBase* m_base;
 
210
    QString m_extension;
 
211
    uint m_pictureId;
 
212
};
 
213
 
 
214
#endif /* __koPictureShared_h__ */