File indexing completed on 2024-11-10 06:45:25

0001 /*
0002     This file is part of the KDE project "KBounce"
0003 
0004     SPDX-FileCopyrightText: 2006 Dmitry Suzdalev <dimsuz@gmail.com>
0005     SPDX-FileCopyrightText: 2007 Tomasz Boczkowski <tboczkowski@onet.pl>
0006 
0007     SPDX-License-Identifier: LGPL-2.0-or-later
0008 */
0009 
0010 #ifndef RENDERER_H
0011 #define RENDERER_H
0012 
0013 #include <QSvgRenderer>
0014 #include <KGameRenderer>
0015 
0016 #include <QSize>
0017 #include <QHash>
0018 #include <QPixmap>
0019 
0020 
0021 /**
0022  * Class for rendering elements of game SVG to QPixmap
0023  */
0024 
0025 class KBounceRenderer : public KGameRenderer
0026 {
0027     Q_OBJECT
0028     public:
0029         /**
0030          * Constructor.
0031          * @param fileName path to SVG containing game graphics
0032          */
0033         explicit KBounceRenderer();
0034         /**
0035          * Destructor.
0036          */
0037         ~KBounceRenderer() override;
0038         /**
0039          * Sets Background size and invalidates background cache
0040          */
0041         void setBackgroundSize(QSize size);
0042         /**
0043          * Renders background to QPixmap of size set by setBachgroundSize
0044          * Background pixmap is cached (setBackgroundSize() invalidates the cache)
0045          */
0046         QPixmap renderBackground();
0047         /**
0048          * Set s the path were custom background pictures are located.
0049          */
0050         void setCustomBackgroundPath(const QString &path);
0051         /**
0052          * Returns a random pixmap from the custom background path.
0053          * If no picture is located in this path the pixmap is null.
0054          */
0055         QPixmap getRandomBackgroundPixmap(const QString& path);
0056         bool loadNewBackgroundPixmap();
0057 
0058     private:
0059         QSvgRenderer m_svgRenderer;
0060         QSize m_backgroundSize;
0061         QPixmap m_cachedBackground;
0062         QPixmap m_randomBackground;
0063 
0064         QString m_customBackgroundPath;
0065         bool m_useRandomBackgrounds;
0066 };
0067 
0068 #endif //RENDERER_H
0069