File indexing completed on 2022-09-20 13:02:18

0001 /*
0002     SPDX-FileCopyrightText: 2008-2010 Stefan Majewsky <majewsky@gmx.net>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef KDIAMOND_BOARD_H
0008 #define KDIAMOND_BOARD_H
0009 
0010 class Diamond;
0011 
0012 class QAbstractAnimation;
0013 #include <QGraphicsItem>
0014 class KGameRenderer;
0015 
0016 namespace KDiamond
0017 {
0018 class Board : public QGraphicsObject
0019 {
0020     Q_OBJECT
0021 public:
0022     explicit Board(KGameRenderer *renderer);
0023 
0024     int gridSize() const;
0025     Diamond *diamond(const QPoint &point) const;
0026 
0027     bool hasDiamond(const QPoint &point) const;
0028     bool hasRunningAnimations() const;
0029     QList<QPoint> selections() const;
0030     bool hasSelection(const QPoint &point) const;
0031     void setSelection(const QPoint &point, bool selected);
0032     void clearSelection();
0033 
0034     void removeDiamond(const QPoint &point);
0035     void swapDiamonds(const QPoint &point1, const QPoint &point2);
0036     void fillGaps();
0037 
0038     KGameRenderer *renderer() const;
0039 
0040     QRectF boundingRect() const override;
0041     void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
0042 public Q_SLOTS:
0043     void setPaused(bool paused);
0044 Q_SIGNALS:
0045     void animationsFinished();
0046     void clicked(const QPoint &point);
0047     void dragged(const QPoint &point, const QPoint &direction);
0048 private Q_SLOTS:
0049     void slotAnimationFinished();
0050     void slotClicked();
0051     void slotDragged(const QPoint &direction);
0052 private:
0053     struct MoveAnimSpec {
0054         Diamond *diamond;
0055         QPointF from, to;
0056     };
0057     QPoint findDiamond(Diamond *diamond) const;
0058     Diamond *&rDiamond(const QPoint &point);
0059     Diamond *spawnDiamond(int color);
0060     void spawnMoveAnimations(const QList<MoveAnimSpec> &specs);
0061 
0062     static const int MoveDuration;
0063     static const int RemoveDuration;
0064 
0065     int m_difficultyIndex, m_size, m_colorCount;
0066     QList<QPoint> m_selections;
0067     bool m_paused;
0068 
0069     KGameRenderer *m_renderer;
0070     QVector<Diamond *> m_diamonds;
0071     QList<Diamond *> m_activeSelectors, m_inactiveSelectors;
0072     QList<QAbstractAnimation *> m_runningAnimations;
0073 };
0074 }
0075 
0076 #endif // KDIAMOND_BOARD_H