| 1 | /*************************************************************************** |
| 2 | * Copyright (C) 2009 by The qGo Project * |
| 3 | * * |
| 4 | * This file is part of qGo. * |
| 5 | * * |
| 6 | * qGo is free software: you can redistribute it and/or modify * |
| 7 | * it under the terms of the GNU General Public License as published by * |
| 8 | * the Free Software Foundation; either version 2 of the License, or * |
| 9 | * (at your option) any later version. * |
| 10 | * * |
| 11 | * This program is distributed in the hope that it will be useful, * |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 | * GNU General Public License for more details. * |
| 15 | * * |
| 16 | * You should have received a copy of the GNU General Public License * |
| 17 | * along with this program; if not, see <http://www.gnu.org/licenses/> * |
| 18 | * or write to the Free Software Foundation, Inc., * |
| 19 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
| 20 | ***************************************************************************/ |
| 21 | |
| 22 | |
| 23 | #ifndef BOARD_H |
| 24 | #define BOARD_H |
| 25 | |
| 26 | #include "defines.h" |
| 27 | |
| 28 | #include <QGraphicsView> |
| 29 | |
| 30 | enum CursorType { cursorIdle, cursorGhostBlack , cursorGhostWhite , cursorWait , cursorNavTo }; |
| 31 | enum CoordType { uninit, sgf, numbertopnoi, numberbottomi }; |
| 32 | |
| 33 | class ImageHandler; |
| 34 | class Move; |
| 35 | class Mark; |
| 36 | class Stone; |
| 37 | class Gatter; |
| 38 | |
| 39 | class Board : public QGraphicsView |
| 40 | { |
| 41 | Q_OBJECT |
| 42 | |
| 43 | public: |
| 44 | Board(QWidget *parent=0, QGraphicsScene *c=0 ); |
| 45 | ~Board(); |
| 46 | void clearData(); |
| 47 | void init(int size); |
| 48 | void setCoordType(CoordType c) { coordType = c; } |
| 49 | void resizeBoard(); |
| 50 | |
| 51 | void removeGhosts(); |
| 52 | void setVarGhost(StoneColor c, int x, int y); |
| 53 | void setMark(int x, int y, MarkType t, bool update=true, QString txt=QString::null, bool overlay=true); |
| 54 | Mark* hasMark(int x, int y); |
| 55 | void removeMark(int x, int y, bool update = false); |
| 56 | void updateLastMove(Move * move); |
| 57 | |
| 58 | // Stone* addStoneSprite(StoneColor c, int x, int y, bool shown=true);//TODO shown ? |
| 59 | void updateStone(StoneColor c, int x, int y, bool dead = false); |
| 60 | void setCursorType(CursorType cur); |
| 61 | // void updateDeadMarks(int &black, int &white); |
| 62 | unsigned int getSize() {return board_size;} |
| 63 | void exportPicture(const QString &fileName, QString *filter, bool toClipboard); |
| 64 | bool updateAll(Move *move); |
| 65 | void updateVariationGhosts(Move *m); |
| 66 | |
| 67 | public: |
| 68 | void setShowCoords(bool b); |
| 69 | |
| 70 | signals: |
| 71 | void signalClicked(bool , int, int, Qt::MouseButton ); |
| 72 | void signalWheelEvent(QWheelEvent *); |
| 73 | |
| 74 | |
| 75 | protected: |
| 76 | void calculateSize(); |
| 77 | void drawBack(); // old drawBackground |
| 78 | void initGatter(); |
| 79 | void drawGatter(); |
| 80 | void setupCoords(void); |
| 81 | void drawCoordinates(); |
| 82 | // void drawStarPoint(int x, int y); |
| 83 | int convertCoordsToPoint(int c, int o); |
| 84 | void resizeEvent(QResizeEvent*); |
| 85 | QHash<int,Stone *> *stones; |
| 86 | QList<Mark*> *marks; |
| 87 | QList<Stone*> *ghosts; |
| 88 | QList<QGraphicsSimpleTextItem*> *hCoords1, *hCoords2 , *vCoords1,*vCoords2 ; |
| 89 | // Accessed by DisplayBoard: |
| 90 | bool isDisplayBoard; |
| 91 | ImageHandler *imageHandler; |
| 92 | bool showCoords; |
| 93 | |
| 94 | private: |
| 95 | |
| 96 | QGraphicsScene *canvas; |
| 97 | QGraphicsRectItem *table; |
| 98 | Gatter *gatter; |
| 99 | // GamePhase gamePhase; |
| 100 | |
| 101 | int board_size, offset, offsetX, offsetY, square_size, board_pixel_size; |
| 102 | bool showSGFCoords; |
| 103 | bool showCursor; |
| 104 | bool antiClicko; |
| 105 | bool lockResize ; |
| 106 | bool localSound; |
| 107 | bool oneColorGo; |
| 108 | |
| 109 | Mark *lastMoveMark; |
| 110 | bool numberPool[400]; |
| 111 | bool letterPool[52]; |
| 112 | Stone *curStone; |
| 113 | CursorType cursor; |
| 114 | CoordType coordType; |
| 115 | short curX, curY; |
| 116 | short downX, downY; //FIXME can we combine safely somehow with curX, curY? |
| 117 | |
| 118 | static long coordsToKey(int x, int y) |
| 119 | { return x * 100 + y; } |
| 120 | static void keyToCoords(long key, int &x, int &y) |
| 121 | { x = key / 100; y = key - x*100; } |
| 122 | |
| 123 | int hasStone(int x, int y); |
| 124 | Stone* getStoneAt(int x, int y) { return stones->find(coordsToKey(x, y)).value(); } |
| 125 | |
| 126 | bool hasVarGhost(StoneColor c, int x, int y); |
| 127 | |
| 128 | void removeLastMoveMark(); |
| 129 | void setMarkText(int x, int y, const QString &txt); |
| 130 | |
| 131 | void mousePressEvent(QMouseEvent *e); |
| 132 | void mouseReleaseEvent(QMouseEvent*); |
| 133 | void mouseMoveEvent ( QMouseEvent * e ) ; |
| 134 | void wheelEvent(QWheelEvent *e); |
| 135 | void leaveEvent(QEvent*); |
| 136 | |
| 137 | QTime clickTime; |
| 138 | Qt::MouseButton mouseState; |
| 139 | }; |
| 140 | |
| 141 | #endif |