removed clock pref widget. clock prefs are definitively part of the lua theme.
[kboard.git] / src / ui.cpp
blobed6857cc69b4e0cd6271a06a4f39edfd13c0dbbd
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"
16 #include "variants/xchess/piecetype.h"
18 using namespace boost;
20 UI::UI()
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) {
47 controller()->end();
48 m_controller.erase(w);
51 void UI::setCurrentTab(QWidget* w) {
52 m_current_tab = w;
55 bool UI::undo() {
56 controller()->undo();
57 return true;
60 bool UI::redo() {
61 controller()->redo();
62 return true;
65 bool UI::truncate() {
66 controller()->truncate();
67 return true;
70 bool UI::promoteVariation() {
71 controller()->promoteVariation();
72 return true;
75 bool UI::back() {
76 return controller()->back();
79 bool UI::forward() {
80 return controller()->forward();
83 void UI::gotoFirst() {
84 controller()->gotoFirst();
87 void UI::gotoLast() {
88 controller()->gotoLast();
91 void UI::pgnCopy() {
92 QClipboard* cb = QApplication::clipboard();
93 cb->setText(controller()->save());
96 void UI::pgnPaste() {
97 QClipboard* cb = QApplication::clipboard();
98 pgnPaste(cb->text());
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);
179 void UI::end() {
180 controller() = controller()->end();
183 void UI::detach() {
184 controller()->detach();