Fix deserialization of shogi promotions.
[tagua/yd.git] / src / ui.cpp
blobe557f46bdf960584b5fd1fc3da074f5b84c6f260
1 /*
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.
9 */
11 #include <iostream>
12 #include <qapplication.h>
13 #include <qclipboard.h>
14 #include "ui.h"
15 #include "controllers/abstract.h"
17 using namespace boost;
19 UI::UI()
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) {
46 controller()->end();
47 m_controller.erase(w);
50 void UI::setCurrentTab(QWidget* w) {
51 m_current_tab = w;
54 bool UI::undo() {
55 controller()->undo();
56 return true;
59 bool UI::redo() {
60 controller()->redo();
61 return true;
64 bool UI::truncate() {
65 controller()->truncate();
66 return true;
69 bool UI::promoteVariation() {
70 controller()->promoteVariation();
71 return true;
74 bool UI::back() {
75 return controller()->back();
78 bool UI::forward() {
79 return controller()->forward();
82 void UI::gotoFirst() {
83 controller()->gotoFirst();
86 void UI::gotoLast() {
87 controller()->gotoLast();
90 void UI::pgnCopy() {
91 QClipboard* cb = QApplication::clipboard();
92 cb->setText(controller()->save());
95 void UI::pgnPaste() {
96 QClipboard* cb = QApplication::clipboard();
97 pgnPaste(cb->text());
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);
156 // }
158 void UI::removeEntity(const EntityToken& token) {
159 controller()->removeEntity(token);
162 void UI::end() {
163 controller() = controller()->end();
166 void UI::detach() {
167 controller()->detach();
170 QString UI::currentVariant() const {
171 return controller()->variant();