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
14 #include <boost/shared_ptr.hpp>
25 * @brief Namespace holding image (and more generally resource) loading functions
34 * @class Image <loader/image.h>
35 * @brief The image class to be used with lua
40 QMatrix m_draw_matrix
;
41 double m_draw_opacity
;
44 void init_painter(QPainter
*);
49 * Creates an image. Image data will be undefined.
50 * @param width The width of the image.
51 * @param height The height of the image.
58 * Creates an image from a file. If the files is not found or could not be
59 * loaded, the resulting image will have width and height equal to 0
60 * @param ctx The current context (theme) reference (should be implicit in lua)
61 * @param file The file name.
65 bool use_cache
= true);
68 /** \return the QImage */
69 QImage
image() { return m_image
; }
71 /** Returns the width of the image */
73 return m_image
.width();
77 /** Returns the height of the image */
79 return m_image
.height();
84 * Sets the transformation matrix
86 void setMatrix(const QMatrix
& m
) {
92 * Resets the transformation matrix
95 m_draw_matrix
.reset();
100 * Scales the transformation matrix
102 void scale(double x
, double y
) {
103 m_draw_matrix
= m_draw_matrix
* QMatrix().scale(x
,y
);
108 * Rotates the transformation matrix
110 void rotate(double angle
) {
111 m_draw_matrix
= m_draw_matrix
* QMatrix().rotate(angle
);
116 * Translates the transformation matrix
118 void translate(double x
, double y
) {
119 m_draw_matrix
= m_draw_matrix
* QMatrix().translate(x
,y
);
124 * Returns the transformation matrix
127 return m_draw_matrix
;
132 * Sets the opacity of the drawing operations
134 void setOpacity(double o
) {
140 * Returns the opacity of the drawing operations
143 return m_draw_opacity
;
148 * Sets the composition mode
149 * @param over If true the painting operations will paint over,
150 * if false will replace the destination color.
152 void setPaintOver(bool over
) {
159 * @param color The color to fill the image with (default transparent)
161 void clear(const QColor
& color
= Qt::transparent
);
166 * @param rect The rectangle
167 * @param brush The fill brush
169 void fillRect(const QRectF
& rect
,
170 const QBrush
& brush
);
175 * @param from The starting point
176 * @param to The end point
177 * @param col The pen color
178 * @param width The pen width
180 void drawLine(const QPointF
& from
,
187 * Draws an image on the over the current one.
188 * @param dest The destination rectangle.
189 * @param src_img The source image.
190 * @param src The source rectangle.
192 void drawImage(const QRectF
& dest
,
193 const Image
& src_img
,
194 const QRectF
& src
= QRectF(0.0,0.0,0.0,0.0));
198 * Draws an image on the over the current one (overload).
199 * @param ctx The current context (theme) reference (should be implicit in lua)
200 * @param dest The destination rectangle.
201 * @param src_img The source image file.
202 * @param src The source rectangle, WITH RELATIVE COORDINATES 0.0 - 1.0 (of course).
203 * @return True if it was possible to load the image file.
205 bool drawImage(Context
* ctx
,
207 const QString
& src_img
,
208 const QRectF
& src
= QRectF(0.0,0.0,0.0,0.0),
209 bool use_cache
= true);
213 * Draws an SVG file over the image.
214 * @param ctx The current context (theme) reference (should be implicit in lua)
215 * @param dest The destination rectangle.
216 * @param file The file to load.
217 * @return True if it was possible to load the SVG file.
218 * TODO: add css support (When Qt will support it)
220 bool drawSVG(Context
* ctx
,
222 const QString
& file
);
226 * Draws a font glyph over the image.
227 * @param ctx The current context (theme) reference (should be implicit in lua)
228 * @param dest The destination rectangle.
229 * @param font The font file to load.
230 * @param glyph The unicode glyph code.
231 * @param fg The foreground color.
232 * @param bg The background color.
233 * @param border The background expansion.
234 * @param draw_inner_bg If true the 'inner part' (detected with a flood fill
235 algorithm) will be filled with the background brush.
236 * @return True if it was possible to load the font file and find the glyph.
238 bool drawGlyph(Context
* ctx
,
242 const QBrush
& fg
= Qt::black
,
243 const QBrush
& bg
= Qt::white
,
245 bool draw_inner_bg
= true);
249 * Blurs the image itself.
251 void expBlur(double radius
);
254 * Returns a shadow image for the current image.
255 * @param radius The shadow radius.
256 * @param color The shadow color.
257 * @param grow How bigger the output image will be.
258 * @param offset Position of the shadow (relatively from being centered in the output).
260 Image
createShadow(double radius
,
262 const QPoint
& grow
= QPoint(),
263 const QPointF
& offset
= QPointF() );
267 * @class Glyph <loader/image.h>
268 * @brief A simple class that represents a glyph in a font to be used with lua
279 Glyph(Context
* ctx
, const QString
&, QChar
, int = 0);
280 Glyph(QChar
= QChar());
282 QFont
font() { return m_font
; }
283 bool fontValid() { return m_font_valid
; }
284 QChar
ch() { return m_char
; }
285 int delta() { return m_delta
; }
289 typedef boost::shared_ptr
<class Font
> FontPtr
;
298 QStringList m_families
;
302 Font(int id
, int size
= 128);
303 Font(const QFont
& font
);
306 QFont
font() { return m_font
; }
307 QStringList
families() { return m_families
; }
309 static FontPtr
create(Context
* ctx
, const QString
& file
);
313 } //end namespace Loader
315 #endif //LOADER__IMAGE_H