File indexing completed on 2024-04-28 04:05:20

0001 /*
0002     SPDX-FileCopyrightText: 2015 Jakob Gruber <jakob.gruber@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef SCENE_H
0008 #define SCENE_H
0009 
0010 #include <QGraphicsPixmapItem>
0011 #include <QGraphicsScene>
0012 #include <QList>
0013 
0014 #include "graphicsitems/cellitem.h"
0015 #include "graphicsitems/highlightitem.h"
0016 #include "graphicsitems/pixmapitem.h"
0017 #include "graphicsitems/streakitem.h"
0018 #include "graphicsitems/textbanneritem.h"
0019 #include "renderer.h"
0020 #include "src/logic/picmi.h"
0021 
0022 class Scene : public QGraphicsScene
0023 {
0024     Q_OBJECT
0025 public:
0026     explicit Scene(QSharedPointer<Picmi> game, QObject *parent = nullptr);
0027 
0028     /* 0 <= x < m_game.width(); 0 <= y < m_game.height()
0029       handles a request to (un)mark (x,y) as a box or cross */
0030     void press(int x, int y, Board::State state);
0031     /* sets focus and highlights to a specific cell,
0032       either specified using absolute coordinates (x,y)
0033       or relative coordinates (dx,dy) */
0034     void hover(int x, int y);
0035     void move(int dx, int dy);
0036 
0037     /* resize scene to view size */
0038     void resize(const QSize &size);
0039 
0040     /* refresh display of all dynamic graphics elements
0041        related to p. */
0042     void refresh(const QPoint &p);
0043     /* refresh display of all dynamic graphics elements */
0044     void refresh();
0045 
0046     void setPaused(bool paused);
0047 
0048     void forwardKeyPressEvent(QKeyEvent *event);
0049 
0050 private Q_SLOTS:
0051     void onGameCompleted();
0052 
0053 private:
0054 
0055     void init();
0056     void loadBackground();
0057     void loadStreaks();
0058     void loadCells();
0059     void loadDividers();
0060     void loadBanners();
0061     void loadOverView();
0062     void setGroupPos(const QSize &size);
0063     void setOverviewPos();
0064 
0065     void updateHighlights();
0066     void hideHighlights();
0067     int xy_to_i(int x, int y) const;
0068 
0069     QSharedPointer<Picmi> m_game;
0070 
0071     /* The scene automatically deletes registered items */
0072     PauseBannerItem *m_pause_banner;
0073     QList<ReloadableItem*> m_items;
0074     QList<GameCellItem*> m_cells;
0075     QList<OverviewCellItem*> m_overview_cells;
0076     QList<StreakItem*> m_row_streaks;
0077     QList<StreakItem*> m_col_streaks;
0078     QList<HighlightItem*> m_highlights;
0079     QGraphicsItemGroup *m_group;
0080     QGraphicsItemGroup *m_overview_group;
0081 
0082     /* All streaks as strings. Needed for calculation of streak
0083        area dimensions. */
0084     QStringList m_streak_strings;
0085 
0086     /* current position on board */
0087     QPoint m_position;
0088 };
0089 
0090 #endif // SCENE_H