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