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.
12 #include <qapplication.h>
13 #include <qclipboard.h>
15 #include "controllers/abstract.h"
17 using namespace boost
;
20 : m_current_tab(NULL
) {
23 boost::shared_ptr
<Controller
>& UI::controller() {
24 Q_ASSERT(m_current_tab
);
26 boost::shared_ptr
<Controller
>& res
= m_controller
[m_current_tab
];
32 boost::shared_ptr
<Controller
> UI::controller() const {
33 Q_ASSERT(m_current_tab
);
35 ControllerMap::const_iterator it
= m_controller
.find(m_current_tab
);
36 Q_ASSERT(it
!= m_controller
.end());
40 void UI::addController(QWidget
* w
, const shared_ptr
<Controller
>& controller
) {
41 m_controller
[w
] = controller
;
44 void UI::setController(const shared_ptr
<Controller
>& controller
) {
45 Q_ASSERT(m_current_tab
);
47 m_controller
[m_current_tab
] = controller
;
50 void UI::removeController(QWidget
* w
) {
52 std::cout
<< "removing controller " << w
<< std::endl
;
53 m_controller
.erase(w
);
56 void UI::setCurrentTab(QWidget
* w
) {
71 controller()->truncate();
75 bool UI::promoteVariation() {
76 controller()->promoteVariation();
81 return controller()->back();
85 return controller()->forward();
88 void UI::gotoFirst() {
89 controller()->gotoFirst();
93 controller()->gotoLast();
97 QClipboard
* cb
= QApplication::clipboard();
98 cb
->setText(controller()->save());
101 void UI::pgnPaste() {
102 QClipboard
* cb
= QApplication::clipboard();
103 pgnPaste(cb
->text());
106 void UI::pgnPaste(const QString
&) {
107 //controller()->loadPGN(pgn);
110 void UI::clearBoard() {
111 controller()->clearBoard();
114 void UI::setStartingPosition() {
115 controller()->setStartingPosition();
118 void UI::copyPosition() {
119 QClipboard
* cb
= QApplication::clipboard();
120 cb
->setText(controller()->fen());
123 void UI::pastePosition() {
124 QClipboard
* cb
= QApplication::clipboard();
125 controller()->setFEN(cb
->text());
128 void UI::setTurn(int turn
) {
129 controller()->setTurn(turn
);
132 AbstractPosition::Ptr
UI::position() const {
133 return controller()->currentPosition();
136 void UI::createCtrlAction() {
137 controller()->createCtrlAction();
140 void UI::destroyCtrlAction() {
141 controller()->destroyCtrlAction();
144 ActionCollection
* UI::variantActions() const {
145 return controller()->variantActions();
148 EntityToken
UI::addPlayingEngine(int side
, const shared_ptr
<Engine
>& engine
) {
149 return controller()->addPlayingEngine(side
, engine
);
152 // EntityToken UI::addAnalysingEngine(const shared_ptr<Engine>& engine) {
153 // return controller()->addAnalysingEngine(engine);
156 void UI::removeEntity(const EntityToken
& token
) {
157 controller()->removeEntity(token
);
161 controller() = controller()->end();
165 controller()->detach();
168 QString
UI::currentVariant() const {
169 return controller()->variant();
172 void UI::reloadSettings() {
173 for (ControllerMap::iterator it
= m_controller
.begin(),
174 end
= m_controller
.end();
177 it
->second
->reloadSettings();