| 1 | /*************************************************************************** |
| 2 | * Copyright (C) 2004-2005 Artur Wiebe * |
| 3 | * [email protected] * |
| 4 | * * |
| 5 | * This program is free software; you can redistribute it and/or modify * |
| 6 | * it under the terms of the GNU General Public License as published by * |
| 7 | * the Free Software Foundation; either version 2 of the License, or * |
| 8 | * (at your option) any later version. * |
| 9 | * * |
| 10 | * This program is distributed in the hope that it will be useful, * |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 13 | * GNU General Public License for more details. * |
| 14 | * * |
| 15 | * You should have received a copy of the GNU General Public License * |
| 16 | * along with this program; if not, write to the * |
| 17 | * Free Software Foundation, Inc., * |
| 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
| 19 | ***************************************************************************/ |
| 20 | |
| 21 | #ifndef _BOARD_H_ |
| 22 | #define _BOARD_H_ |
| 23 | |
| 24 | |
| 25 | #include <QFrame> |
| 26 | |
| 27 | #include "theme.h" |
| 28 | #include "field.h" |
| 29 | #include "checkers.h" |
| 30 | |
| 31 | |
| 32 | class myBoard : public QFrame |
| 33 | { |
| 34 | Q_OBJECT |
| 35 | |
| 36 | public: |
| 37 | myBoard(QWidget* parent); |
| 38 | ~myBoard(); |
| 39 | |
| 40 | QSize sizeHint() const; |
| 41 | void resizeEvent(QResizeEvent*); |
| 42 | |
| 43 | // returns coded move string: from_pos_string?to_pos_string |
| 44 | QString doMove(int from_pos, int to_pos, bool white_player); |
| 45 | // coded move. |
| 46 | bool doMove(const QString& move, bool white_player); |
| 47 | // |
| 48 | void doFreeMove(int from, int to); |
| 49 | |
| 50 | void selectField(int field_num, bool is_on); |
| 51 | |
| 52 | void setTheme(const QString& theme_path, bool set_white); |
| 53 | |
| 54 | void setNotation(bool enabled, bool show_above); |
| 55 | void setNotationFont(const QFont& f); |
| 56 | |
| 57 | void setColorWhite(bool); |
| 58 | void reset(); |
| 59 | void adjustNotation(bool bottom_is_white); |
| 60 | |
| 61 | void setGame(int rules); |
| 62 | |
| 63 | bool whiteIsNext() const; |
| 64 | |
| 65 | int type() const { return m_game->type(); } |
| 66 | // TODO |
| 67 | const Checkers* game() const { return m_game; } |
| 68 | |
| 69 | signals: |
| 70 | void fieldClicked(int); |
| 71 | |
| 72 | protected: |
| 73 | void paintEvent(QPaintEvent*); |
| 74 | void mousePressEvent(QMouseEvent*); |
| 75 | void timerEvent(QTimerEvent*); |
| 76 | |
| 77 | private: |
| 78 | bool convert_move(const QString&, int* from, int* to); |
| 79 | void fieldsSetup(); |
| 80 | void draw(); |
| 81 | void drawField(QPainter&, Field*, int, int); |
| 82 | void invalidate(); |
| 83 | void beginSetup(); |
| 84 | void endSetup(); |
| 85 | int getTargetFieldSize(QSize size); |
| 86 | |
| 87 | void highlight(int, int, bool); |
| 88 | |
| 89 | private: |
| 90 | Field* m_fields[64]; |
| 91 | QPixmap* pixmap = NULL; |
| 92 | bool pixmap_valid; |
| 93 | |
| 94 | Theme* m_theme; |
| 95 | |
| 96 | bool bottom_is_white; |
| 97 | bool animation_in_progress; |
| 98 | QColor m_src_color; |
| 99 | QColor m_dst_color; |
| 100 | Field* m_src_field; |
| 101 | Field* m_dst_field; |
| 102 | |
| 103 | int animation_steps; |
| 104 | int current_step; |
| 105 | int animation_timer; |
| 106 | bool animating_bottom_player; |
| 107 | |
| 108 | Checkers* m_game; |
| 109 | }; |
| 110 | |
| 111 | |
| 112 | #endif |
| 113 |