Cute Chess  0.1
movelist.h
1 /*
2  This file is part of Cute Chess.
3 
4  Cute Chess 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 3 of the License, or
7  (at your option) any later version.
8 
9  Cute Chess 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 Cute Chess. If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #ifndef MOVE_LIST_H
19 #define MOVE_LIST_H
20 
21 #include <QWidget>
22 #include <QPointer>
23 #include <QUrl>
24 #include <QPair>
25 #include <QList>
26 #include <QTextBlockFormat>
27 #include <QTextCharFormat>
28 #include <QTextCursor>
29 #include "movenumbertoken.h"
30 #include "movetoken.h"
31 #include "movecommenttoken.h"
32 
33 class QTextBrowser;
34 class PgnGame;
35 class ChessGame;
36 namespace Chess { class GenericMove; }
37 class QTimer;
38 
39 
40 class MoveList : public QWidget
41 {
42  Q_OBJECT
43 
44  public:
46  MoveList(QWidget* parent = nullptr);
47 
54  void setGame(ChessGame* game, PgnGame* pgn = nullptr);
55 
56  public slots:
63  bool selectMove(int moveNum);
65  void setMove(int ply,
66  const Chess::GenericMove& move,
67  const QString& sanString,
68  const QString& comment);
69 
70  signals:
72  void moveClicked(int num);
74  void commentClicked(int num, const QString& comment);
75 
76  protected:
77  // Reimplemented from QWidget
78  virtual bool eventFilter(QObject* obj, QEvent* event);
79 
80  private slots:
81  void onMoveMade(const Chess::GenericMove& move,
82  const QString& sanString,
83  const QString& comment);
84  void onLinkClicked(const QUrl& url);
85  void selectChosenMove();
86 
87  private:
88  struct Move
89  {
90  MoveNumberToken number;
91  MoveToken move;
92  MoveCommentToken comment;
93  };
94 
95  void insertMove(int ply,
96  const QString& san,
97  const QString& comment,
98  QTextCursor cursor = QTextCursor());
99 
100  QTextBrowser* m_moveList;
101  QPointer<ChessGame> m_game;
102  QList<Move> m_moves;
103  int m_moveCount;
104  int m_startingSide;
105  int m_selectedMove;
106  int m_moveToBeSelected;
107  QTextCharFormat m_defaultTextFormat;
108  QTimer* m_selectionTimer;
109 };
110 
111 #endif // MOVE_LIST_H
MoveList(QWidget *parent=nullptr)
Definition: movelist.cpp:27
A chessmove (usually SAN) token in a PGN game.
Definition: movetoken.h:26
void setGame(ChessGame *game, PgnGame *pgn=nullptr)
Definition: movelist.cpp:102
A game of chess in PGN format.
Definition: pgngame.h:51
Definition: chessgame.h:38
A chess move independent of chess variant or opening book format.
Definition: genericmove.h:33
A fullmove number token in a PGN game.
Definition: movenumbertoken.h:26
Definition: boardscene.h:28
void setMove(int ply, const Chess::GenericMove &move, const QString &sanString, const QString &comment)
Definition: movelist.cpp:197
Definition: movelist.h:40
void commentClicked(int num, const QString &comment)
A comment token for a move in a PGN game.
Definition: movecommenttoken.h:26
void moveClicked(int num)
bool selectMove(int moveNum)
Definition: movelist.cpp:261