1 /***************************************************************************
2  *   (C) 2008-2010 Michal Rudolf <mrudolf@kdewebdev.org>                   *
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 
10 #ifndef ANALYSIS_WIDGET_H_INCLUDED
11 #define ANALYSIS_WIDGET_H_INCLUDED
12 
13 #include "enginex.h"
14 #include "movedata.h"
15 #include "ui_analysiswidget.h"
16 #include <QtGui>
17 #include <QPointer>
18 
19 /** @ingroup GUI
20 	The Analysis widget which shows engine output
21 */
22 
23 class Tablebase;
24 class Database;
25 
26 class AnalysisWidget : public QWidget
27 {
28     Q_OBJECT
29 public:
30     AnalysisWidget(QWidget* parent);
31     ~AnalysisWidget();
32 
33     /** Get the main line */
34     Analysis getMainLine() const;
35     /** Analysis has a main line */
36     bool hasMainLine() const;
37     /** Get the name of this widget */
38     QString displayName() const;
39     /** Unpin the analyis (if pinned) */
40     void unPin();
41     /** Is any engine running. */
42     bool isEngineRunning() const;
43     /** Is any engine configured. */
44     bool isEngineConfigured() const;
45 
46     bool onHold() const;
47     void setOnHold(bool onHold);
48 
49     QString engineName() const;
50     void updateBookFile(Database*);
51 
52 public slots:
53     /** Sets new position. If analysis is active, the current content will be cleared and
54     new analysis will be performed. */
55     void setPosition(const BoardX& board, QString line="");
56     /** Called when configuration was changed (either on startup or from Preferences dialog. */
57     void slotReconfigure();
58     /** Store current configuration. */
59     void saveConfig();
60     /** Start currently selected engine. */
61     void startEngine();
62     /** Stop any running  engine. */
63     void stopEngine();
64     /** Stop game analysis when analysis dock is hidden. */
65     void slotVisibilityChanged(bool);
66     /** Change the movetime of the engine */
67     void setMoveTime(EngineParameter mt);
68     /** Change the movetime of the engine */
69     void setMoveTime(int);
70     /** Change the search depth of the engine */
71     void setDepth(int n);
72     /** Must send ucinewgame next time */
73     void slotUciNewGame(const BoardX& b);
74     /** Called when the list of databases changes */
75     void slotUpdateBooks(QStringList);
76     /** Called upon entering or leaving game mode */
77     void setGameMode(bool);
78     /** Restore Book settings */
79     void restoreBook();
80 private slots:
81     /** Stop if analysis is no longer visible. */
82     void toggleAnalysis();
83     /** Displays given analysis received from an engine. */
84     void showAnalysis(Analysis analysis);
85     /** The engine is now ready, as requested */
86     void engineActivated();
87     /** The engine is now deactivated */
88     void engineDeactivated();
89     /** There was an error while running engine. */
90     void engineError(QProcess::ProcessError);
91     /** Add variation. */
92     void slotLinkClicked(const QUrl& link);
93     /** Number of visible lines was changed. */
94     void slotMpvChanged(int mpv);
95     /** Show tablebase move information. */
96     void showTablebaseMove(QList<Move> move, int score);
97     /** The pin button was pressed or released */
98     void slotPinChanged(bool);
99 
100 signals:
101     void addVariation(const Analysis& analysis, const QString&);
102     void addVariation(const QString& san);
103     void requestBoard();
104     void receivedBestMove(const Analysis& analysis);
105     void currentBestMove(const Analysis& analysis);
106     void signalSourceChanged(QString);
107 
108 protected slots:
109     void bookActivated(int);
110     void sendBookMoveTimeout();
111 
112 private:
113     /** Should analysis be running. */
114     bool isAnalysisEnabled() const;
115     /** Update analysis. */
116     void updateAnalysis();
117     /** Update complexity. */
118     void updateComplexity();
119     void updateBookMoves();
120     bool sendBookMove();
121 
122     QList<Analysis> m_analyses;
123     Ui::AnalysisWidget ui;
124     QPointer<EngineX> m_engine;
125     BoardX m_board;
126     QString m_line;
127     BoardX m_NextBoard;
128     QString m_NextLine;
129     BoardX m_startPos;
130     QString m_tablebaseEvaluation;
131     QString m_tablebaseMove;
132     Move m_tb;
133     int m_score_tb;
134     Tablebase* m_tablebase;
135     BoardX m_tbBoard;
136     EngineParameter m_moveTime;
137     bool m_bUciNewGame;
138 
139     double m_complexity;
140     double m_complexity2;
141     Move m_lastBestMove;
142     int m_lastDepthAdded;
143     bool m_onHold;
144 
145     QTime m_lastEngineStart;
146     QPointer<Database> m_pBookDatabase;
147     QList<MoveData> moveList;
148     int games;
149 
150     bool m_gameMode;
151  };
152 
153 #endif // ANALYSIS_WIDGET_H_INCLUDED
154 
155