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.
14 #include <boost/enable_shared_from_this.hpp>
18 #include "entitytoken.h"
25 class ActionCollection
;
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
36 class Controller
: public boost::enable_shared_from_this
<Controller
> {
39 virtual boost::shared_ptr
<UserEntity
> entity() const = 0;
42 Controller(ChessTable
* view
);
43 virtual ~Controller();
46 * Variant specific actions.
48 virtual ActionCollection
* variantActions() const = 0;
51 * Variant associated to the controller.
53 virtual QString
variant() const = 0;
56 * Terminate activity, create another controller and delegate everything to it.
57 * @return The delegate controller, or simply @b this if controller does not need
60 virtual boost::shared_ptr
<Controller
> end() { return shared_from_this(); }
63 * Detach from resources without disposing them.
65 virtual void detach() { }
68 * Clear board. Undefined for almost all controllers.
69 * @return Whether the action has been successfully executed.
71 virtual bool clearBoard() { return false; }
74 * Set starting position on the board. Undefined for almost all controllers.
75 * @return Whether the action has been successfully executed.
77 virtual bool setStartingPosition() { return false; }
80 * Set a position on the board. Undefined for almost all controllers.
81 * @param fen The position to be set, in FEN notation.
82 * @return Whether the action has been successfully executed.
84 virtual bool setFEN(const QString
&) { return false; }
87 * Get a FEN string representing the current position on the board.
89 virtual QString
fen() { return ""; }
92 * @return current position, or a null shared_ptr if no current position
93 * concept is defined for this controller.
95 virtual PositionPtr
currentPosition() const { return PositionPtr(); }
98 * Change turn. Used for example in edit position mode.
100 virtual void setTurn(int) { }
103 * Forward a movelist undo call.
108 * Forward a movelist redo call.
113 * Forward a movelist truncate call.
115 virtual bool truncate();
118 * Forward a movelist promote variation call.
120 virtual bool promoteVariation();
123 * Navigate back in history.
128 * Navigate forward in history.
130 virtual bool forward();
133 * Warp to the beginning of the history.
135 virtual void gotoFirst();
138 * Warp to the end of the history.
140 virtual void gotoLast();
145 virtual QString
save();
148 * Load game from a PGN.
150 virtual void loadPGN(const PGN
&);
153 * Create a CTRL Action.
154 * @sa UI::createCtrlAction
156 virtual void createCtrlAction() { }
159 * Destroy a CTRL Action.
160 * @sa UI::createCtrlAction.
162 virtual void destroyCtrlAction() { };
165 * Let an engine play as player @a side.
166 * @return a token which uniquely identifies the engine entity
167 * and can be used to remove it from the entity list.
169 virtual EntityToken
addPlayingEngine(int /*side*/, 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;
191 * Each controller has an associated URL that will be used for saving
193 * @return The URL associated with this controller.
195 virtual KUrl
url() const;
198 * Set this controller's URL.
201 virtual void setUrl(const KUrl
& url
);