1
/***************************************************************************
2
 *   Copyright (c) 2008  Nikolaj Hald Nielsen <nhnFreespirit@gmail.com>    *
3
 *             (c) 2008  Jeff Mitchell <kde-dev@emailgoeshere.com>         *
4
 *                                                                         *
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.                                   *
9
 *                                                                         *
10
 *   This program 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         *
13
 *   GNU General Public License for more details.                          *
14
 *                                                                         *
15
 *   You should have received a copy of the GNU General Public License     *
16
 *   along with this program; if not, write to the                         *
17
 *   Free Software Foundation, Inc.,                                       *
18
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19
 ***************************************************************************/
20
 
21
#ifndef SVGHANDLER_H
22
#define SVGHANDLER_H
23
24
#include "amarok_export.h"
25
26
#include <KPixmapCache>
27
#include <QReadWriteLock>
28
#include <KSvgRenderer>
29
30
#include <QPixmap>
31
#include <QString>
32
33
34
class SvgHandler;
35
36
namespace The {
37
    AMAROK_EXPORT SvgHandler* svgHandler();
38
}
39
40
/**
41
A class to abstract out some common opperations of users of tinted svgs
42
*/
43
class AMAROK_EXPORT SvgHandler : public QObject
44
{
45
    Q_OBJECT
46
47
    friend SvgHandler* The::svgHandler();
48
49
    public:
50
        ~SvgHandler();
51
52
        KSvgRenderer* getRenderer( const QString &name );
53
        KSvgRenderer* getRenderer();
54
        QPixmap renderSvg( const QString &name, const QString& keyname, int width, int height, const QString& element = QString() );
55
56
        /**
57
        * Overloaded function that uses the current theme
58
        * @param keyname the name of the key to save in the cache
59
        * @param width Widht of the resulting pixmap
60
        * @param height Height of the resulting pixmap
61
        * @param element The theme element to render ( if none the entire svg is rendered )
62
        * @return The svg element/file rendered into a pixmap
63
        */
64
        QPixmap renderSvg( const QString& keyname, int width, int height, const QString& element = QString() );
65
66
        
67
        /**
68
         * Yet another oveloaded function. This one renders the svg element and adds half a divider element to the top and the bottom
69
         * so it looks sane when multiple elements with the same widh are stacked.
70
         * @param keyname the name of the key to save in the cache
71
         * @param width Widht of the resulting pixmap
72
         * @param height Height of the resulting pixmap
73
         * @param element The theme element to render ( if none the entire svg is rendered )
74
         * @return The svg element/file rendered into a pixmap
75
         */
76
        QPixmap renderSvgWithDividers( const QString& keyname, int width, int height, const QString& element = QString() );
77
78
79
        QPixmap addBordersToPixmap( QPixmap orgPixmap, int borderWidth, const QString &name, bool skipCache =false );
80
81
        QString themeFile();
82
        void setThemeFile( const QString  & themeFile );
83
84
    public slots:
85
        void reTint();
86
87
    private:
88
        SvgHandler( QObject* parent = 0 );
89
90
        bool loadSvg( const QString& name );
91
92
        KPixmapCache * m_cache;
93
94
        QHash<QString,KSvgRenderer*> m_renderers;
95
        QReadWriteLock m_lock;
96
97
        QString m_themeFile;
98
        bool m_customTheme;
99
};
100
101
#endif