File indexing completed on 2024-04-28 04:03:30

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_MAPITEMS_H
0012 #define KONQUEST_MAPITEMS_H
0013 
0014 
0015 #include <QGraphicsObject>
0016 #include <QTextDocument>
0017 #include "sector.h"
0018 
0019 class Game;
0020 class MapScene;
0021 
0022 class PlanetItem : public QGraphicsObject
0023 {
0024     Q_OBJECT
0025 
0026 public:
0027     explicit PlanetItem(MapScene *scene, Sector *sector, Game *game);
0028     ~PlanetItem() override {}
0029 
0030     QRectF   boundingRect() const override;
0031     void     paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
0032                    QWidget *widget) override;
0033 
0034     void     hoverEnterEvent ( QGraphicsSceneHoverEvent *event ) override;
0035     void     hoverLeaveEvent ( QGraphicsSceneHoverEvent *event ) override;
0036     void     mousePressEvent ( QGraphicsSceneMouseEvent *event ) override;
0037     void     unselect ();
0038     void     select ();
0039     Sector  *sector () { return m_sector; }
0040 
0041 Q_SIGNALS:
0042     void     planetItemSelected (PlanetItem *);
0043 
0044 private:
0045     void     updatePlanet ();
0046     void     blinkPlanet ();
0047 
0048 private:
0049     QPixmap renderPixmap( const QString& svgId, int width, int height ) const;
0050 
0051     MapScene  *m_scene;
0052     Sector    *m_sector;
0053 
0054     Game      *m_game;
0055 
0056     bool       m_hovered;
0057     bool       m_selected;
0058     bool       m_blinkState;
0059     QTimer    *m_blinkTimer;
0060     QString    m_lookName;
0061 };
0062 
0063 
0064 class PlanetInfoItem : public QGraphicsItem
0065 {
0066 public:
0067     explicit PlanetInfoItem(Game*);
0068     ~PlanetInfoItem() override {}
0069 
0070     QRectF   boundingRect() const override;
0071     void     setPlanet (Planet *planet);
0072     Planet  *planet () { return m_planet; }
0073     void     paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
0074                    QWidget *widget) override;
0075 
0076 private:
0077     Game          *m_game;
0078     QTextDocument  m_textDoc;
0079     Planet        *m_planet;
0080 };
0081 
0082 #endif // KONQUEST_MAPITEMS_H