2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@sns.it>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
11 #ifndef LOADER__IMAGE_H
12 #define LOADER__IMAGE_H
24 * @brief Namespace holding image (and more generally resource) loading functions
33 * @class Image <loader/image.h>
34 * @brief The image class to be used with lua
39 QMatrix m_draw_matrix
;
40 double m_draw_opacity
;
43 void init_painter(QPainter
*);
48 * Creates an image. Image data will be undefined.
49 * @param width The width of the image.
50 * @param height The height of the image.
57 * Creates an image from a file. If the files is not found or could not be
58 * loaded, the resulting image will have width and height equal to 0
59 * @param ctx The current context (theme) reference (should be implicit in lua)
60 * @param file The file name.
66 /** Returns the width of the image */
68 return m_image
.width();
72 /** Returns the height of the image */
74 return m_image
.height();
79 * Sets the transformation matrix
81 void setMatrix(const QMatrix
& m
) {
87 * Resets the transformation matrix
90 m_draw_matrix
.reset();
95 * Scales the transformation matrix
97 void scale(double x
, double y
) {
98 m_draw_matrix
= m_draw_matrix
* QMatrix().scale(x
,y
);
103 * Rotates the transformation matrix
105 void rotate(double angle
) {
106 m_draw_matrix
= m_draw_matrix
* QMatrix().rotate(angle
);
111 * Translates the transformation matrix
113 void translate(double x
, double y
) {
114 m_draw_matrix
= m_draw_matrix
* QMatrix().translate(x
,y
);
119 * Returns the transformation matrix
122 return m_draw_matrix
;
127 * Sets the opacity of the drawing operations
129 void setOpacity(double o
) {
135 * Returns the opacity of the drawing operations
138 return m_draw_opacity
;
143 * Sets the composition mode
144 * @param over If true the painting operations will paint over,
145 * if false will replace the destination color.
147 void setPaintOver(bool over
) {
154 * @param color The color to fill the image with (default transparent)
156 void clear(const QColor
& color
= Qt::transparent
);
161 * @param rect The rectangle
162 * @param brush The fill brush
164 void fillRect(const QRectF
& rect
,
165 const QBrush
& brush
);
170 * @param from The starting point
171 * @param to The end point
172 * @param col The pen color
173 * @param width The pen width
175 void drawLine(const QPointF
& from
,
182 * Draws an image on the over the current one.
183 * @param dest The destination rectangle.
184 * @param src_img The source image.
185 * @param src The source rectangle.
187 void drawImage(const QRectF
& dest
,
188 const Image
& src_img
,
189 const QRectF
& src
= QRectF(0.0,0.0,0.0,0.0));
193 * Draws an image on the over the current one (overload).
194 * @param ctx The current context (theme) reference (should be implicit in lua)
195 * @param dest The destination rectangle.
196 * @param src_img The source image file.
197 * @param src The source rectangle, WITH RELATIVE COORDINATES 0.0 - 1.0 (of course).
198 * @return True if it was possible to load the image file.
200 bool drawImage(Context
* ctx
,
202 const QString
& src_img
,
203 const QRectF
& src
= QRectF(0.0,0.0,0.0,0.0));
207 * Draws an SVG file over the image.
208 * @param ctx The current context (theme) reference (should be implicit in lua)
209 * @param dest The destination rectangle.
210 * @param file The file to load.
211 * @return True if it was possible to load the SVG file.
212 * TODO: add css support (When Qt will support it)
214 bool drawSVG(Context
* ctx
,
216 const QString
& file
);
220 * Draws a font glyph over the image.
221 * @param ctx The current context (theme) reference (should be implicit in lua)
222 * @param dest The destination rectangle.
223 * @param font The font file to load.
224 * @param glyph The unicode glyph code.
225 * @param fg The foreground color.
226 * @param bg The background color.
227 * @param border The background expansion.
228 * @param draw_inner_bg If true the 'inner part' (detected with a flood fill
229 algorithm) will be filled with the background brush.
230 * @return True if it was possible to load the font file and find the glyph.
232 bool drawGlyph(Context
* ctx
,
236 const QBrush
& fg
= Qt::black
,
237 const QBrush
& bg
= Qt::white
,
239 bool draw_inner_bg
= true);
242 * Returns a shadow image for the current image.
243 * @param radius The shadow radius.
244 * @param color The shadow color.
245 * @param grow How bigger the output image will be.
246 * @param offset Position of the shadow (relatively from being centered in the output).
248 Image
createShadow(double radius
,
250 const QPoint
& grow
= QPoint(),
251 const QPointF
& offset
= QPointF() );
255 * @class Glyph <loader/image.h>
256 * @brief A simple class that represents a glyph in a font to be used with lua
264 Glyph(Context
* ctx
, const QString
&, QChar
, int = 0);
265 Glyph(QChar
= QChar());
268 } //end namespace Loader
270 #endif //LOADER__IMAGE_H