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