2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@sns.it>
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 return m_controller
[m_current_tab
];
29 const boost::shared_ptr
<Controller
>& UI::controller() const {
30 Q_ASSERT(m_current_tab
);
32 return m_controller
.find(m_current_tab
)->second
;
35 void UI::addController(QWidget
* w
, const shared_ptr
<Controller
>& controller
) {
36 m_controller
[w
] = controller
;
39 void UI::setController(const shared_ptr
<Controller
>& controller
) {
40 Q_ASSERT(m_current_tab
);
42 m_controller
[m_current_tab
] = controller
;
45 void UI::removeController(QWidget
* w
) {
47 m_controller
.erase(w
);
50 void UI::setCurrentTab(QWidget
* w
) {
65 controller()->truncate();
69 bool UI::promoteVariation() {
70 controller()->promoteVariation();
75 return controller()->back();
79 return controller()->forward();
82 void UI::gotoFirst() {
83 controller()->gotoFirst();
87 controller()->gotoLast();
91 QClipboard
* cb
= QApplication::clipboard();
92 cb
->setText(controller()->save());
96 QClipboard
* cb
= QApplication::clipboard();
100 void UI::pgnPaste(const QString
&) {
101 //controller()->loadPGN(pgn);
104 int UI::promotionType() const {
105 return controller()->promotionType();
108 bool UI::doPromotion() const {
109 return controller()->doPromotion();
112 void UI::setDoPromotion(bool value
) {
113 controller()->setDoPromotion(value
);
116 void UI::clearBoard() {
117 controller()->clearBoard();
120 void UI::setStartingPosition() {
121 controller()->setStartingPosition();
124 void UI::copyPosition() {
125 QClipboard
* cb
= QApplication::clipboard();
126 cb
->setText(controller()->fen());
129 void UI::pastePosition() {
130 QClipboard
* cb
= QApplication::clipboard();
131 controller()->setFEN(cb
->text());
134 void UI::setTurn(int turn
) {
135 controller()->setTurn(turn
);
138 AbstractPosition::Ptr
UI::position() const {
139 return controller()->currentPosition();
142 void UI::createCtrlAction() {
143 controller()->createCtrlAction();
146 void UI::destroyCtrlAction() {
147 controller()->destroyCtrlAction();
150 EntityToken
UI::addPlayingEngine(int side
, const shared_ptr
<Engine
>& engine
) {
151 return controller()->addPlayingEngine(side
, engine
);
154 // EntityToken UI::addAnalysingEngine(const shared_ptr<Engine>& engine) {
155 // return controller()->addAnalysingEngine(engine);
158 void UI::removeEntity(const EntityToken
& token
) {
159 controller()->removeEntity(token
);
163 controller() = controller()->end();
167 controller()->detach();
170 QString
UI::currentVariant() const {
171 return controller()->variant();