Renamed AnimationSettings -> AnimationManager.
[tagua/yd.git] / src / ui.h
blob4a2df1bd26c2222ecd99342ea4bcf172847fc943
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 UI_H
12 #define UI_H
14 #include <boost/shared_ptr.hpp>
15 #include <qobject.h>
16 #include <map>
17 #include <core/state_fwd.h>
18 #include "common.h"
19 #include "controllers/entitytoken.h"
21 class ActionCollection;
22 class ActionStateObserver;
23 class Controller;
24 class Engine;
25 class KActionCollection;
26 class IColor;
28 /**
29 * @brief Utility class to handle GUI actions.
31 * An instance of UI is owned by MainWindow, and every GUI action
32 * is connected to a slot of UI.
33 * A UI instance maintains a correspondence between Tagua tabs and
34 * associated controllers. Besides, UI knows the active tab (hence
35 * controller) and directs all user interaction to it.
36 * Whenever a new tab is created, the corresponding controller is
37 * added to the association, and its setUI member function is called,
38 * so that it can setup all the observers.
40 * To add a new tab <-> controller association, use the addController
41 * member function.
42 * If you want to replace the current controller, use setController.
43 * Both functions assume that the controller is new, hence initialize
44 * it via setUI.
46 class UI : public QObject {
47 Q_OBJECT
48 typedef std::map<QWidget*, boost::shared_ptr<Controller> > ControllerMap;
49 ControllerMap m_controller;
50 QWidget* m_current_tab;
51 boost::shared_ptr<Controller>& controller();
52 boost::shared_ptr<Controller> controller() const;
53 KActionCollection* m_actions;
54 friend class UIActionStateObserver;
55 public:
56 /**
57 * Constructor.
58 * \param actions The action collection associated to this UI instance.
59 * This will be used to enable/disable actions according
60 * to notifications coming from the controller.
62 UI(KActionCollection* actions);
64 /**
65 * Add a new tab <-> controller association.
66 * The controller is assumed to be new, and it is initialized by calling
67 * its setUI member function.
69 void addController(QWidget* tab, const boost::shared_ptr<Controller>&);
70 /**
71 * Just like addController, but replace the current controller instead
72 * of creating a new association. The old controller is no longer referenced
73 * by UI, so it will be destroyed, unless other objects keep it alive.
75 void setController(const boost::shared_ptr<Controller>& controller);
76 /**
77 * Remove a controller. The controller will no longer be referenced by
78 * UI, so it will be destroyed, unless other objects keep it alive.
80 void removeController(QWidget* tab);
82 /**
83 * Create an action state observer that reacts to action state
84 * updates by enabling / disabling the corresponding actions.
85 * \sa ActionStateObserver
87 boost::shared_ptr<ActionStateObserver>
88 createActionStateObserver(const boost::shared_ptr<Controller>&) const;
89 public Q_SLOTS:
90 /**
91 * Change the current tab and associated controller.
93 void setCurrentTab(QWidget* tab);
95 bool undo();
96 bool redo();
97 bool truncate();
98 bool promoteVariation();
99 bool back();
100 bool forward();
101 void gotoFirst();
102 void gotoLast();
103 void setTurn(int);
104 void createCtrlAction();
105 void destroyCtrlAction();
106 ActionCollection* variantActions() const;
108 void pgnCopy();
109 void pgnPaste();
110 void pgnPaste(const QString&);
111 QString currentPGN();
113 // editing
114 void clearBoard();
115 void setStartingPosition();
116 void copyPosition();
117 void pastePosition();
118 StatePtr position() const;
120 EntityToken addPlayingEngine(const IColor* side, const boost::shared_ptr<Engine>& engine);
121 // EntityToken addAnalysingEngine(const boost::shared_ptr<Engine>& engine);
122 void removeEntity(const EntityToken& token);
124 void end();
125 void detach();
127 QString currentVariant() const;
128 void reloadSettings();
131 #endif