File indexing completed on 2024-04-21 04:03:43

0001 /*
0002     SPDX-FileCopyrightText: 2003 Russell Steffen <rsteffen@bayarea.net>
0003     SPDX-FileCopyrightText: 2003 Stephan Zehetner <s.zehetner@nevox.org>
0004     SPDX-FileCopyrightText: 2006 Dmitry Suzdalev <dimsuz@gmail.com>
0005     SPDX-FileCopyrightText: 2006 Inge Wallin <inge@lysator.liu.se>
0006     SPDX-FileCopyrightText: 2006 Pierre Ducroquet <pinaraf@gmail.com>
0007 
0008     SPDX-License-Identifier: GPL-2.0-or-later
0009 */
0010 
0011 #ifndef KONQUEST_MAPSCENE_H
0012 #define KONQUEST_MAPSCENE_H
0013 
0014 
0015 #include <QGraphicsScene>
0016 #include <QSvgRenderer>
0017 
0018 #include <KImageCache>
0019 
0020 #include "mapitems.h"
0021 #include "../game.h"
0022 
0023 class Planet;
0024 class PlanetItem;
0025 class PlanetInfoItem;
0026 class Map;
0027 
0028 
0029 class MapScene: public QGraphicsScene
0030 {
0031     Q_OBJECT
0032 
0033     public:
0034         explicit MapScene(Game *game);
0035         ~MapScene() override;
0036 
0037         QSvgRenderer  *renderer() const  { return m_renderer; }
0038         KImageCache   *imageCache() const  { return m_imageCache; }
0039         Map           *map()      const  { return m_game->map(); }
0040 
0041         void           selectPlanet(Planet *planet);
0042         void           unselectPlanet();
0043 
0044     /**
0045      * Show planet information box.
0046      *
0047      * @param planet
0048      * planet for which to show planet information or NULL to hide possibly
0049      * shown planet information
0050      */
0051 
0052     void displayPlanetInfo(Planet *planet);
0053 
0054         void           drawBackground( QPainter * painter, const QRectF & rect ) override;
0055 
0056 
0057     /**
0058      * Get size of a sector in pixel.
0059      *
0060      * A sector is rendered as a square, so width and height are the same. The
0061      * size depends on the number of sectors per direction (horizontal and
0062      * vertical) as well as the dimensions of the board canvas.
0063      */
0064 
0065     qreal getSectorSize();
0066 
0067     /**
0068      * Get the horizontal offset.
0069      *
0070      * In case the board is tall, it is horizontally centered on the board
0071      * canvas.
0072      */
0073 
0074     qreal itemsHorizontalOffset();
0075 
0076     /**
0077      * Get the vertical offset.
0078      *
0079      * In case the board is wide, it is vertically centered on the board canvas.
0080      */
0081 
0082     qreal itemsVerticalOffset();
0083 
0084         void           resizeScene(const QRectF& rect);
0085 
0086         void           clearMap();
0087         void           mapUpdate();
0088 
0089     Q_SIGNALS:
0090         void  planetSelected( Planet * );
0091 
0092     private:
0093         void  planetItemSelected (PlanetItem *);
0094 
0095 private:
0096 
0097     /**
0098      * Show planet information box.
0099      *
0100      * @param planet
0101      * planet for which to show planet information or NULL to hide possibly
0102      * shown planet information
0103      *
0104      * @param pos
0105      * position relative to upper left edge of the board
0106      */
0107 
0108     void displayPlanetInfo(Planet *planet, const QPointF &pos);
0109 
0110         Game            *m_game;
0111 
0112         QSvgRenderer    *m_renderer;
0113         KImageCache     *m_imageCache;
0114         PlanetItem      *m_selectedPlanetItem;
0115         PlanetInfoItem  *m_planetInfoItem;
0116         QList<PlanetItem*> m_planetItems;
0117 
0118         qreal m_width;
0119         qreal m_height;
0120 };
0121 
0122 #endif // KONQUEST_MAPSCENE_H