mapscene.h 3.51 KB
Newer Older
1
/*
2 3 4 5 6
    Copyright 2003 Russell Steffen <rsteffen@bayarea.net>
    Copyright 2003 Stephan Zehetner <s.zehetner@nevox.org>
    Copyright 2006 Dmitry Suzdalev <dimsuz@gmail.com>
    Copyright 2006 Inge Wallin <inge@lysator.liu.se>
    Copyright 2006 Pierre Ducroquet <pinaraf@gmail.com>
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */
22

23 24
#ifndef KONQUEST_MAPSCENE_H
#define KONQUEST_MAPSCENE_H
Pierre Ducroquet's avatar
Pierre Ducroquet committed
25

Inge Wallin's avatar
Inge Wallin committed
26

Pierre Ducroquet's avatar
Pierre Ducroquet committed
27
#include <QGraphicsScene>
Andrius Štikonas's avatar
Andrius Štikonas committed
28 29
#include <QSvgRenderer>

30
#include <KImageCache>
Andrius Štikonas's avatar
Andrius Štikonas committed
31

32
#include "mapitems.h"
Pierre Ducroquet's avatar
Pierre Ducroquet committed
33
#include "../game.h"
Inge Wallin's avatar
Inge Wallin committed
34

Pierre Ducroquet's avatar
Pierre Ducroquet committed
35
class Planet;
36
class PlanetItem;
37
class PlanetInfoItem;
Pierre Ducroquet's avatar
Pierre Ducroquet committed
38 39
class Map;

Inge Wallin's avatar
Inge Wallin committed
40

Inge Wallin's avatar
Inge Wallin committed
41 42
class MapScene: public QGraphicsScene
{
Pierre Ducroquet's avatar
Pierre Ducroquet committed
43
    Q_OBJECT
Inge Wallin's avatar
Inge Wallin committed
44

Pierre Ducroquet's avatar
Pierre Ducroquet committed
45
    public:
Pierre Ducroquet's avatar
Pierre Ducroquet committed
46
        explicit MapScene(Game *game);
47
        ~MapScene();
Inge Wallin's avatar
Inge Wallin committed
48

49
        QSvgRenderer  *renderer() const  { return m_renderer; }
50
        KImageCache   *imageCache() const  { return m_imageCache; }
Pierre Ducroquet's avatar
Pierre Ducroquet committed
51
        Map           *map()      const  { return m_game->map(); }
Inge Wallin's avatar
Inge Wallin committed
52

53
        void           selectPlanet(Planet *planet);
Inge Wallin's avatar
Inge Wallin committed
54
        void           unselectPlanet();
Alexander Schuch's avatar
Alexander Schuch committed
55 56 57 58 59

    /**
     * Show planet information box.
     *
     * @param planet
60 61
     * planet for which to show planet information or NULL to hide possibly
     * shown planet information
Alexander Schuch's avatar
Alexander Schuch committed
62 63 64
     */

    void displayPlanetInfo(Planet *planet);
65

66
        void           drawBackground( QPainter * painter, const QRectF & rect ) override;
67

68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94

    /**
     * Get size of a sector in pixel.
     *
     * A sector is rendered as a square, so width and height are the same. The
     * size depends on the number of sectors per direction (horizontal and
     * vertical) as well as the dimensions of the board canvas.
     */

    qreal getSectorSize();

    /**
     * Get the horizontal offset.
     *
     * In case the board is tall, it is horizontally centered on the board
     * canvas.
     */

    qreal itemsHorizontalOffset();

    /**
     * Get the vertical offset.
     *
     * In case the board is wide, it is vertically centered on the board canvas.
     */

    qreal itemsVerticalOffset();
95 96

        void           resizeScene(const QRectF& rect);
97

98
        void           clearMap();
99 100
        void           mapUpdate();

Pierre Ducroquet's avatar
Pierre Ducroquet committed
101 102
    signals:
        void  planetSelected( Planet * );
103

Pierre Ducroquet's avatar
Pierre Ducroquet committed
104
    private slots:
Inge Wallin's avatar
Inge Wallin committed
105
        void  planetItemSelected (PlanetItem *);
106

Alexander Schuch's avatar
Alexander Schuch committed
107 108 109 110 111 112
private:

    /**
     * Show planet information box.
     *
     * @param planet
113 114
     * planet for which to show planet information or NULL to hide possibly
     * shown planet information
Alexander Schuch's avatar
Alexander Schuch committed
115 116 117 118 119 120 121
     *
     * @param pos
     * position relative to upper left edge of the board
     */

    void displayPlanetInfo(Planet *planet, const QPointF &pos);

Pierre Ducroquet's avatar
Pierre Ducroquet committed
122
        Game            *m_game;
123

124
        QSvgRenderer    *m_renderer;
125
        KImageCache     *m_imageCache;
Inge Wallin's avatar
Inge Wallin committed
126 127
        PlanetItem      *m_selectedPlanetItem;
        PlanetInfoItem  *m_planetInfoItem;
128
        QVector<PlanetItem*> m_planetItems;
129 130 131

        qreal m_width;
        qreal m_height;
Pierre Ducroquet's avatar
Pierre Ducroquet committed
132 133
};

134
#endif // KONQUEST_MAPSCENE_H