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"
16 #include "variants/xchess/piecetype.h"
18 using namespace boost
;
21 : m_current_tab(NULL
) {
24 boost::shared_ptr
<Controller
>& UI::controller() {
25 Q_ASSERT(m_current_tab
);
27 return m_controller
[m_current_tab
];
30 const boost::shared_ptr
<Controller
>& UI::controller() const {
31 Q_ASSERT(m_current_tab
);
33 return m_controller
.find(m_current_tab
)->second
;
36 void UI::addController(QWidget
* w
, const shared_ptr
<Controller
>& controller
) {
37 m_controller
[w
] = controller
;
40 void UI::setController(const shared_ptr
<Controller
>& controller
) {
41 Q_ASSERT(m_current_tab
);
43 m_controller
[m_current_tab
] = controller
;
46 void UI::removeController(QWidget
* w
) {
48 m_controller
.erase(w
);
51 void UI::setCurrentTab(QWidget
* w
) {
66 controller()->truncate();
70 bool UI::promoteVariation() {
71 controller()->promoteVariation();
76 return controller()->back();
80 return controller()->forward();
83 void UI::gotoFirst() {
84 controller()->gotoFirst();
88 controller()->gotoLast();
92 QClipboard
* cb
= QApplication::clipboard();
93 cb
->setText(controller()->save());
97 QClipboard
* cb
= QApplication::clipboard();
101 void UI::pgnPaste(const QString
&) {
102 //controller()->loadPGN(pgn);
105 void UI::promoteToQueen() {
106 controller()->setPromotionType(QUEEN
);
109 void UI::promoteToRook() {
110 controller()->setPromotionType(ROOK
);
113 void UI::promoteToBishop() {
114 controller()->setPromotionType(BISHOP
);
117 void UI::promoteToKnight() {
118 controller()->setPromotionType(KNIGHT
);
121 int UI::promotionType() const {
122 return controller()->promotionType();
125 bool UI::doPromotion() const {
126 return controller()->doPromotion();
129 void UI::setDoPromotion(bool value
) {
130 controller()->setDoPromotion(value
);
133 void UI::clearBoard() {
134 controller()->clearBoard();
137 void UI::setStartingPosition() {
138 controller()->setStartingPosition();
141 void UI::copyPosition() {
142 QClipboard
* cb
= QApplication::clipboard();
143 cb
->setText(controller()->fen());
146 void UI::pastePosition() {
147 QClipboard
* cb
= QApplication::clipboard();
148 controller()->setFEN(cb
->text());
151 void UI::setTurn(int turn
) {
152 controller()->setTurn(turn
);
155 AbstractPosition::Ptr
UI::position() const {
156 return controller()->currentPosition();
159 void UI::createCtrlAction() {
160 controller()->createCtrlAction();
163 void UI::destroyCtrlAction() {
164 controller()->destroyCtrlAction();
167 void UI::addPlayingEngine(int side
, const shared_ptr
<Engine
>& engine
) {
168 controller()->addPlayingEngine(side
, engine
);
171 EntityToken
UI::addAnalysingEngine(const shared_ptr
<Engine
>& engine
) {
172 return controller()->addAnalysingEngine(engine
);
175 void UI::removeAnalysingEngine(const EntityToken
& token
) {
176 controller()->removeAnalysingEngine(token
);
180 controller() = controller()->end();
184 controller()->detach();