File indexing completed on 2024-12-15 03:48:05

0001 /*
0002     SPDX-FileCopyrightText: 2008 Sascha Peilicke <sasch.pe@gmx.de>
0003 
0004     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #ifndef KIGO_GAMESCENE_H
0008 #define KIGO_GAMESCENE_H
0009 
0010 #include <KGamePopupItem>
0011 
0012 #include <QGraphicsScene>
0013 
0014 class QTimer;
0015 
0016 namespace Kigo {
0017 
0018 class Game;
0019 
0020 /**
0021  * This class provides a graphical representation of the go game using
0022  * QGraphicsScene.
0023  *
0024  * It displays the go board in its current state, receives mouse events,
0025  * translates them and interacts with the Game. It also drives the game
0026  * flow, i.e. tells game when to make the next move.
0027  *
0028  * @author Sascha Peilicke <sasch.pe@gmx.de>
0029  * @since 0.1
0030  */
0031 class GameScene : public QGraphicsScene
0032 {
0033     Q_OBJECT
0034 
0035 public:
0036     explicit GameScene(Game *game, QObject *parent = nullptr);
0037 
0038 Q_SIGNALS:
0039     void cursorPixmapChanged(const QPixmap &);
0040 
0041 public Q_SLOTS:
0042     void resizeScene(int width, int height);
0043     void showLabels(bool show);
0044     void showHint(bool show);
0045     void showMoveNumbers(bool show);
0046     void showMessage(const QString &message, int msecs = 2000);
0047     void showPlacementMarker(bool show);
0048     void showTerritory(bool show);
0049 
0050 private Q_SLOTS:
0051     void updateStoneItems();
0052     void updateHintItems();
0053     void updateTerritoryItems();
0054     void changeBoardSize(int size);
0055     void hideHint() { showHint(false); }
0056     void themeChanged();
0057 
0058 private:
0059     void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
0060     void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
0061     void drawBackground(QPainter *painter, const QRectF &) override;
0062 
0063     Game *m_game;                           ///< Go game
0064 
0065     KGamePopupItem m_gamePopup;
0066     bool m_showLabels;                      ///< Show board labels or not
0067     bool m_showHint;
0068     QTimer *m_hintTimer;
0069     bool m_showMoveNumbers;
0070     bool m_showPlacementMarker;
0071     bool m_showTerritory;
0072     QRectF m_boardRect;                     ///< Position of board in the scene
0073     QRectF m_mouseRect;                     ///< Board mouse interaction rect
0074     QRectF m_gridRect;                      ///< Board grid rect
0075     int m_cellSize;                         ///< Width of board grid cell
0076     QSize m_stonePixmapSize;                ///< Size of Go stone pixmap
0077     QSize m_placementMarkerPixmapSize;
0078     int m_boardSize;                        ///< Go board size (9, 13, 19, ..)
0079     QGraphicsPixmapItem *m_placementMarkerItem;
0080 
0081     QList<QGraphicsPixmapItem *> m_stoneItems;
0082     QList<QGraphicsPixmapItem *> m_hintItems;
0083     QList<QGraphicsPixmapItem *> m_territoryItems;
0084 };
0085 
0086 } // End of namespace Kigo
0087 
0088 #endif