File indexing completed on 2024-04-21 04:02:36

0001 /*
0002     SPDX-FileCopyrightText: 2019 Christian Krippendorf <Coding@Christian-Krippendorf.de>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef GAMEBACKGROUND_H
0008 #define GAMEBACKGROUND_H
0009 
0010 // Qt
0011 #include <QGraphicsObject>
0012 #include <QBrush>
0013 
0014 // KMahjongg
0015 #include "kmtypes.h"
0016 
0017 
0018 /**
0019  * The background item of the kmahjongg board.
0020  * @author Christian Krippendorf 
0021  */
0022 class GameBackground : public QGraphicsObject
0023 {
0024     Q_OBJECT
0025 
0026 public:
0027     /**
0028      * Constructor
0029      * @param item The parent item
0030      */
0031     explicit GameBackground(QGraphicsObject *item = nullptr);
0032     ~GameBackground() override;
0033 
0034     /**
0035      * Set the background
0036      * @param background The pixmap of the background
0037      */
0038     void setBackground(const QBrush & background);
0039 
0040     /**
0041      * Overrides the paint method of QGraphicsItem
0042      */
0043     void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
0044             QWidget *widget) override;
0045 
0046     /**
0047      * Set size of element
0048      * @param width Width of element in pixels
0049      * @param height Height of element in pixels
0050      */
0051     void setSize(qreal width, qreal height);
0052     
0053     /**
0054      * Overrides the boundingRect method of QGraphicsItem
0055      */
0056     QRectF boundingRect() const override;
0057 
0058     /**
0059      * Returns the rect of the item
0060      * @return The rect of the item
0061      */
0062     QRectF rect() const;
0063 
0064     /**
0065      * Called in GameView::resizeTileset() before reloading the tiles
0066      */
0067     void prepareForGeometryChange();
0068 
0069 private:
0070     QBrush m_background;
0071 
0072     qreal m_width;
0073     qreal m_height;
0074 };
0075 
0076 #endif // GAMEBACKGROUND_H