~ubuntu-branches/ubuntu/utopic/picmi/utopic

« back to all changes in this revision

Viewing changes to src/gui/graphicsitems/cellitem.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2012-12-03 17:39:47 UTC
  • Revision ID: package-import@ubuntu.com-20121203173947-tt1kk5wp92zk1f2z
Tags: upstream-4.9.90
ImportĀ upstreamĀ versionĀ 4.9.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* *************************************************************************
 
2
 *  Copyright 2012 Jakob Gruber <jakob.gruber@gmail.com>                   *
 
3
 *                                                                         *
 
4
 *  This program is free software: you can redistribute it and/or modify   *
 
5
 *  it under the terms of the GNU General Public License as published by   *
 
6
 *  the Free Software Foundation, either version 2 of the License, or      *
 
7
 *  (at your option) any later version.                                    *
 
8
 *                                                                         *
 
9
 *  This program is distributed in the hope that it will be useful,        *
 
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
 
12
 *  GNU General Public License for more details.                           *
 
13
 *                                                                         *
 
14
 *  You should have received a copy of the GNU General Public License      *
 
15
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.  *
 
16
 ************************************************************************* */
 
17
 
 
18
 
 
19
#ifndef CELLITEM_H
 
20
#define CELLITEM_H
 
21
 
 
22
#include <QGraphicsPixmapItem>
 
23
 
 
24
#include "reloadableitem.h"
 
25
#include "src/logic/picmi.h"
 
26
 
 
27
class Scene;
 
28
class DragManager;
 
29
 
 
30
class CellItem : public QGraphicsPixmapItem, public ReloadableItem
 
31
{
 
32
public:
 
33
    CellItem(int x, int y, QSharedPointer<Picmi> game, QGraphicsItem *parent = 0);
 
34
 
 
35
    /* updates displayed pixmap according to current cell state */
 
36
    virtual void refresh();
 
37
 
 
38
    virtual void reload(const QSize &size);
 
39
 
 
40
protected:
 
41
    virtual int getTilesize() const = 0;
 
42
    virtual QPixmap getPixmap() const = 0;
 
43
 
 
44
    const QSharedPointer<Picmi> m_game;
 
45
};
 
46
 
 
47
class OverviewCellItem : public CellItem
 
48
{
 
49
public:
 
50
    /* creates the item with field coordinates (x,y) and the specified
 
51
      game and scene */
 
52
    OverviewCellItem(int x, int y, QSharedPointer<Picmi> game, QGraphicsItem *parent = 0);
 
53
 
 
54
protected:
 
55
    virtual int getTilesize() const;
 
56
    virtual QPixmap getPixmap() const;
 
57
};
 
58
 
 
59
class GameCellItem : public CellItem
 
60
{
 
61
public:
 
62
    /* creates the item with field coordinates (x,y) and the specified
 
63
      game and scene */
 
64
    GameCellItem(int x, int y, QSharedPointer<Picmi> game, Scene *scene, QGraphicsItem *parent = 0);
 
65
 
 
66
    void keyPressEvent(QKeyEvent *event);
 
67
 
 
68
protected:
 
69
    void mousePressEvent(QGraphicsSceneMouseEvent *event);
 
70
    void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
 
71
    void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
 
72
    void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
 
73
 
 
74
    virtual int getTilesize() const;
 
75
    virtual QPixmap getPixmap() const;
 
76
 
 
77
private:
 
78
 
 
79
    int drag_offset(int pos) const;
 
80
 
 
81
private:
 
82
    Scene *m_scene;
 
83
    QSharedPointer<DragManager> m_dragmanager;
 
84
    Qt::MouseButton m_dragbutton;
 
85
};
 
86
 
 
87
#endif // CELLITEM_H