Initial porting to the new component API.
[tagua/yd.git] / src / controllers / abstract.h
blobe08904cd831a1ffdc175bc7ccad57ec76b6670f1
1 /*
2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@gmail.com>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
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 */
11 #ifndef CONTROLLER_H
12 #define CONTROLLER_H
14 #include <boost/enable_shared_from_this.hpp>
15 #include <QString>
16 #include <core/state_fwd.h>
17 #include "common.h"
18 #include "entitytoken.h"
20 class ActionCollection;
21 class ChessTable;
22 class Engine;
23 class IColor;
24 class PGN;
25 class UI;
26 class UserEntity;
28 /**
29 * @b Controller is the base abstract class for all controllers in Tagua.
30 * Tagua can be used in different modes, such as game editing or position editing.
31 * Each mode corresponds to a concrete subclass of Controller, and defines its behaviour
32 * in response to user events (history navigation, move executions...).
33 * By default, events are routed to the user entity returned by the virtual function
34 * entity.
36 class Controller : public boost::enable_shared_from_this<Controller> {
37 protected:
38 ChessTable* m_view;
39 virtual boost::shared_ptr<UserEntity> entity() const = 0;
40 public:
41 Controller(ChessTable* view);
42 virtual ~Controller();
44 /**
45 * Variant specific actions.
47 virtual ActionCollection* variantActions() const = 0;
49 /**
50 * Variant associated to the controller.
52 virtual QString variant() const = 0;
54 /**
55 * Terminate activity, create another controller and delegate everything to it.
56 * @return The delegate controller, or simply @b this if controller does not need
57 * to be terminated.
59 virtual boost::shared_ptr<Controller> end() { return shared_from_this(); }
61 /**
62 * Detach from resources without disposing them.
64 virtual void detach() { }
66 /**
67 * Clear board. Undefined for almost all controllers.
68 * @return Whether the action has been successfully executed.
70 virtual bool clearBoard() { return false; }
72 /**
73 * Set starting position on the board. Undefined for almost all controllers.
74 * @return Whether the action has been successfully executed.
76 virtual bool setStartingPosition() { return false; }
78 /**
79 * Set a position on the board. Undefined for almost all controllers.
80 * @param fen The position to be set, in FEN notation.
81 * @return Whether the action has been successfully executed.
83 virtual bool setFEN(const QString&) { return false; }
85 /**
86 * Get a FEN string representing the current position on the board.
88 virtual QString fen() { return ""; }
90 /**
91 * @return current position, or a null shared_ptr if no current position
92 * concept is defined for this controller.
94 virtual StatePtr currentPosition() const { return StatePtr(); }
96 /**
97 * Change turn. Used for example in edit position mode.
99 virtual void setTurn(int) { }
102 * Forward a movelist undo call.
104 virtual bool undo();
107 * Forward a movelist redo call.
109 virtual bool redo();
112 * Forward a movelist truncate call.
114 virtual bool truncate();
117 * Forward a movelist promote variation call.
119 virtual bool promoteVariation();
122 * Navigate back in history.
124 virtual bool back();
127 * Navigate forward in history.
129 virtual bool forward();
132 * Warp to the beginning of the history.
134 virtual void gotoFirst();
137 * Warp to the end of the history.
139 virtual void gotoLast();
142 * Save game.
144 virtual QString save();
147 * Load game from a PGN.
149 virtual void loadPGN(const PGN&);
152 * Create a CTRL Action.
153 * @sa UI::createCtrlAction
155 virtual void createCtrlAction() { }
158 * Destroy a CTRL Action.
159 * @sa UI::createCtrlAction.
161 virtual void destroyCtrlAction() { };
164 * Let an engine play as player @a side.
165 * @return a token which uniquely identifies the engine entity
166 * and can be used to remove it from the entity list.
168 virtual EntityToken addPlayingEngine(const IColor* /*side*/,
169 const boost::shared_ptr<Engine>&) { return EntityToken(); }
172 * Remove an entity from the controller list.
174 virtual void removeEntity(const EntityToken&) { }
176 virtual void reloadSettings() = 0;
179 * Set owning user interface.
180 * Used to setup callbacks towards the main window, like action state
181 * change notifications.
183 virtual void setUI(UI& ui) = 0;
186 * Called whenever a controller becomes active in the main window.
188 virtual void activate() = 0;
192 #endif