File indexing completed on 2024-11-24 03:43:19

0001 /*******************************************************************
0002  *
0003  * This file is part of the KDE project "Bovo"
0004  *
0005  * Bovo is free software; you can redistribute it and/or modify
0006  * it under the terms of the GNU General Public License as published by
0007  * the Free Software Foundation; either version 2, or (at your option)
0008  * any later version.
0009  *
0010  * Bovo is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013  * GNU General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU General Public License
0016  * along with Bovo; see the file COPYING.  If not, write to
0017  * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
0018  * Boston, MA 02110-1301, USA.
0019  *
0020  ********************************************************************/
0021 
0022 #ifndef BOVO_SCENE_H
0023 #define BOVO_SCENE_H
0024 
0025 #include <QGraphicsScene>
0026 #include <QList>
0027 
0028 #include "common.h"
0029 
0030 class QSvgRenderer;
0031 class QPainter;
0032 class QTimer;
0033 
0034 namespace bovo
0035 {
0036 class Move;
0037 class Game;
0038 }
0039 
0040 using namespace bovo;
0041 
0042 namespace gui
0043 {
0044 class HintItem;
0045 class Mark;
0046 class Theme;
0047 
0048 class Scene : public QGraphicsScene
0049 {
0050     Q_OBJECT
0051 
0052 public:
0053     explicit Scene(const Theme &theme, bool animation = true);
0054     ~Scene() override;
0055     void activate(bool activate);
0056     void setGame(Game *game);
0057     bool isBusy() const;
0058     void setTheme(const Theme &theme);
0059     qreal squareSize() const;
0060     QPointF cellCenter(int x, int y) const;
0061     QPointF cellTopLeft(int x, int y) const;
0062 
0063 public Q_SLOTS:
0064     void updateBoard(const Move &move);
0065     void slotPlayerTurn();
0066     void slotOposerTurn();
0067     void slotGameOver(const QList<Move> &winningMoves);
0068     void hint(const Move &hint);
0069     void hintTimeout();
0070     void destroyHint();
0071     void enableAnimation(bool enabled);
0072     void setWin();
0073     void replay();
0074     void killMark(Mark *);
0075 
0076 protected:
0077     bool event(QEvent *event) override;
0078 
0079 Q_SIGNALS:
0080     void move(const Move &);
0081 
0082 private:
0083     void drawBackground(QPainter *p, const QRectF &rect) override;
0084     void drawForeground(QPainter *p, const QRectF &rect) override;
0085     void mousePressEvent(QGraphicsSceneMouseEvent *) override;
0086     void mouseMoveEvent(QGraphicsSceneMouseEvent *) override;
0087     void killAnimations();
0088     bool m_activate;
0089     Game *m_game;
0090     QSvgRenderer *m_bkgndRenderer;
0091     QSvgRenderer *m_renderer;
0092     qreal m_curCellSize;
0093     QList<Move>::const_iterator m_replayEnd;
0094     QList<Move>::const_iterator m_replayIterator;
0095     QTimer *m_replayTimer;
0096     QTimer *m_hintTimer;
0097     //    int m_hintCounter;
0098     HintItem *m_hintItem;
0099     Player m_player;
0100     bool m_animation;
0101     QList<Move> m_winningMoves;
0102     uint m_row;
0103     uint m_col;
0104     bool m_paintMarker;
0105     uint m_lastRow;
0106     uint m_lastCol;
0107     bool m_showLast;
0108     void removePaintMarker();
0109     void setPaintMarker(uint col, uint row);
0110     void removeShowLast();
0111     void setShowLast(uint col, uint row);
0112     qreal m_fill;
0113     void loadTheme(const Theme &theme);
0114 };
0115 
0116 } /* namespace gui */
0117 
0118 #endif // BOVO_SCENE_H