File indexing completed on 2024-05-19 04:07:54
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 CELLITEM_H 0008 #define CELLITEM_H 0009 0010 #include <QGraphicsPixmapItem> 0011 0012 #include "reloadableitem.h" 0013 #include "src/logic/picmi.h" 0014 0015 class Scene; 0016 class DragManager; 0017 class QAbstractAnimation; 0018 0019 class CellItem : public QGraphicsPixmapItem, public ReloadableItem 0020 { 0021 public: 0022 CellItem(int x, int y, QSharedPointer<Picmi> game, QGraphicsItem *parent = nullptr); 0023 0024 /* updates displayed pixmap according to current cell state */ 0025 virtual void refresh(); 0026 0027 void reload(const QSize &size) override; 0028 0029 protected: 0030 virtual int getTilesize() const = 0; 0031 virtual QPixmap getPixmap() const = 0; 0032 0033 const QSharedPointer<Picmi> m_game; 0034 }; 0035 0036 class OverviewCellItem : public CellItem 0037 { 0038 public: 0039 /* creates the item with field coordinates (x,y) and the specified 0040 game and scene */ 0041 OverviewCellItem(int x, int y, QSharedPointer<Picmi> game, QGraphicsItem *parent = nullptr); 0042 0043 protected: 0044 int getTilesize() const override; 0045 QPixmap getPixmap() const override; 0046 }; 0047 0048 class GameCellItem : public QObject, public CellItem 0049 { 0050 Q_OBJECT 0051 Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity) 0052 Q_PROPERTY(qreal scale READ scale WRITE setScale) 0053 public: 0054 /* creates the item with field coordinates (x,y) and the specified 0055 game and scene */ 0056 GameCellItem(int x, int y, QSharedPointer<Picmi> game, Scene *scene, QGraphicsItem *parent = nullptr); 0057 0058 void keyPressEvent(QKeyEvent *event) override; 0059 0060 void refresh() override; 0061 void reload(const QSize &size) override; 0062 0063 protected: 0064 void mousePressEvent(QGraphicsSceneMouseEvent *event) override; 0065 void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override; 0066 void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override; 0067 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; 0068 0069 int getTilesize() const override; 0070 QPixmap getPixmap() const override; 0071 0072 private: 0073 /** Converts scene- to game coordinates. */ 0074 QPoint sceneToGame(const QPointF &p) const; 0075 QAbstractAnimation *createAnimation(); 0076 0077 private: 0078 Scene *m_scene; 0079 QSharedPointer<DragManager> m_dragmanager; 0080 Qt::MouseButton m_dragbutton; 0081 QPointF m_sceneorigin; 0082 0083 /* Animation members. */ 0084 Board::State m_state; 0085 QAbstractAnimation *m_anim; 0086 }; 0087 0088 #endif // CELLITEM_H