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 void UI::clearBoard() {
105 controller()->clearBoard();
108 void UI::setStartingPosition() {
109 controller()->setStartingPosition();
112 void UI::copyPosition() {
113 QClipboard
* cb
= QApplication::clipboard();
114 cb
->setText(controller()->fen());
117 void UI::pastePosition() {
118 QClipboard
* cb
= QApplication::clipboard();
119 controller()->setFEN(cb
->text());
122 void UI::setTurn(int turn
) {
123 controller()->setTurn(turn
);
126 AbstractPosition::Ptr
UI::position() const {
127 return controller()->currentPosition();
130 void UI::createCtrlAction() {
131 controller()->createCtrlAction();
134 void UI::destroyCtrlAction() {
135 controller()->destroyCtrlAction();
138 ActionCollection
* UI::variantActions() const {
139 return controller()->variantActions();
142 EntityToken
UI::addPlayingEngine(int side
, const shared_ptr
<Engine
>& engine
) {
143 return controller()->addPlayingEngine(side
, engine
);
146 // EntityToken UI::addAnalysingEngine(const shared_ptr<Engine>& engine) {
147 // return controller()->addAnalysingEngine(engine);
150 void UI::removeEntity(const EntityToken
& token
) {
151 controller()->removeEntity(token
);
155 controller() = controller()->end();
159 controller()->detach();
162 QString
UI::currentVariant() const {
163 return controller()->variant();