2 This file is part of SloppyGUI.
4 SloppyGUI is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 SloppyGUI is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with SloppyGUI. If not, see <http://www.gnu.org/licenses/>.
20 #include <QApplication>
22 #include "mainwindow.h"
24 #include "logmanager.h"
25 #include "guilogger.h"
26 #include "graphicschessboarditem.h"
27 #include "chessboardview.h"
28 #include "chessgame.h"
29 #include "chessplayer.h"
30 #include "xboardengine.h"
32 MainWindow::MainWindow()
34 m_chessboardView
= new ChessboardView(this);
35 m_chessboardScene
= new QGraphicsScene(m_chessboardView
);
36 m_chessboardView
->setScene(m_chessboardScene
);
37 m_chessboardView
->setMinimumSize(400, 400);
39 setCentralWidget(m_chessboardView
);
41 m_visualChessboard
= new GraphicsChessboardItem();
42 m_chessboardScene
->addItem(m_visualChessboard
);
44 setStatusBar(new QStatusBar());
52 void MainWindow::createActions()
54 m_printGameAct
= new QAction(tr("&Print..."), this);
56 m_quitGameAct
= new QAction(tr("&Quit"), this);
57 m_quitGameAct
->setShortcut(QKeySequence(tr("Ctrl+Q")));
60 m_sloppyVersusAct
= new QAction("Sloppy vs. Sloppy", this);
62 connect(m_printGameAct
, SIGNAL(triggered(bool)), this, SLOT(printGame()));
63 connect(m_quitGameAct
, SIGNAL(triggered(bool)), qApp
, SLOT(quit()));
64 connect(m_sloppyVersusAct
, SIGNAL(triggered(bool)), this, SLOT(sloppyVersus()));
67 void MainWindow::createMenus()
69 m_gameMenu
= menuBar()->addMenu(tr("&Game"));
70 m_gameMenu
->addAction(m_printGameAct
);
71 m_gameMenu
->addSeparator();
72 m_gameMenu
->addAction(m_quitGameAct
);
74 m_viewMenu
= menuBar()->addMenu(tr("&View"));
75 m_helpMenu
= menuBar()->addMenu(tr("&Help"));
77 m_debugMenu
= menuBar()->addMenu("&Debug");
78 m_debugMenu
->addAction(m_sloppyVersusAct
);
81 void MainWindow::createToolBars()
83 // Create tool bars here, use actions from createActions()
84 // See: createActions(), QToolBar documentation
87 void MainWindow::createDockWindows()
90 QDockWidget
* logDock
= new QDockWidget(tr("Log"), this);
91 QTextEdit
* logTextEdit
= new QTextEdit(logDock
);
92 logTextEdit
->setReadOnly(true);
93 logDock
->setWidget(logTextEdit
);
95 addDockWidget(Qt::BottomDockWidgetArea
, logDock
);
98 Manager::get()->getLogManager()->addLogger(new GuiLogger(logTextEdit
));
101 QDockWidget
* engineDebugDock
= new QDockWidget(tr("Engine Debug"), this);
102 m_engineDebugTextEdit
= new QTextEdit(engineDebugDock
);
103 m_engineDebugTextEdit
->setReadOnly(true);
104 engineDebugDock
->setWidget(m_engineDebugTextEdit
);
106 addDockWidget(Qt::BottomDockWidgetArea
, engineDebugDock
);
109 void MainWindow::printGame()
111 QPrinter
printer(QPrinter::HighResolution
);
113 QPrintDialog
* printDialog
= new QPrintDialog(&printer
, this);
114 printDialog
->setWindowTitle(tr("Print game"));
116 if (printDialog
->exec() != QDialog::Accepted
)
120 painter
.begin(&printer
);
122 m_chessboardView
->render(&painter
);
127 void MainWindow::sloppyVersus()
129 QProcess
* process1
= new QProcess(this);
130 QProcess
* process2
= new QProcess(this);
132 process1
->setWorkingDirectory("engines/sloppy-020");
133 process2
->setWorkingDirectory("engines/sloppy-020");
135 process1
->start("./sloppy");
136 process2
->start("./sloppy");
138 if (!process1
->waitForStarted() || !process2
->waitForStarted())
140 qDebug() << "Cannot start sloppy process.";
144 ChessGame
* chessgame
= new ChessGame(this);
146 ChessPlayer
* player1
= new XboardEngine(process1
, chessgame
->chessboard(), this);
147 ChessPlayer
* player2
= new XboardEngine(process2
, chessgame
->chessboard(), this);
149 connect(player1
, SIGNAL(debugMessage(const QString
&)),
150 m_engineDebugTextEdit
, SLOT(append(const QString
&)));
151 connect(player2
, SIGNAL(debugMessage(const QString
&)),
152 m_engineDebugTextEdit
, SLOT(append(const QString
&)));
154 chessgame
->newGame(player1
, player2
);