14 #include <QtGui/QStandardItemModel>
15 #include <QtCore/QTimer>
18 #include <KConfigDialog>
19 #include <KActionCollection>
22 #include <KScoreDialog>
24 #include <KStandardGameAction>
41 setCentralWidget(m_view);
52 void KSquaresWindow::initObject()
60 statusBar()->insertPermanentItem(i18n(
"Current Player"), statusplayer);
62 setAutoSaveSettings();
70 KScoreDialog ksdialog(KScoreDialog::Name,
this);
71 ksdialog.addLocalizedConfigGroupName(qMakePair(
QByteArray(
"Easy"), i18n(
"Easy")));
72 ksdialog.addLocalizedConfigGroupName(qMakePair(
QByteArray(
"Medium"), i18n(
"Medium")));
73 ksdialog.addLocalizedConfigGroupName(qMakePair(
QByteArray(
"Hard"), i18n(
"Hard")));
84 nameLineEditList.
append(dialog.playerOneName);
85 nameLineEditList.
append(dialog.playerTwoName);
86 nameLineEditList.
append(dialog.playerThreeName);
87 nameLineEditList.
append(dialog.playerFourName);
89 humanCheckBoxList.
append(dialog.playerOneHuman);
90 humanCheckBoxList.
append(dialog.playerTwoHuman);
91 humanCheckBoxList.
append(dialog.playerThreeHuman);
92 humanCheckBoxList.
append(dialog.playerFourHuman);
102 humanCheckBoxList.
at(i)->setCheckState(Qt::Checked);
104 humanCheckBoxList.
at(i)->setCheckState(Qt::Unchecked);
110 dialog.quickStartCheck->setCheckState(Qt::Checked);
112 dialog.quickStartCheck->setCheckState(Qt::Unchecked);
116 if (dialog.result() == QDialog::Rejected)
return;
122 for(
int i=0; i<=3; i++)
124 tempNames.
append(nameLineEditList.
at(i)->text());
129 for(
int i=0; i<=3; i++)
131 tempHuman.
append(humanCheckBoxList.
at(i)->checkState());
162 color =
QColor(243,195,0);
165 kError() <<
"KSquaresGame::playerSquareComplete(); currentPlayerId() != 0|1|2|3";
181 connect(m_scene, SIGNAL(lineDrawn(
int)), sGame, SLOT(addLineToIndex(
int)));
182 connect(m_scene, SIGNAL(signalMoveRequest(
int,
int,
int,
int)), SLOT(slotMoveRequest(
int,
int,
int,
int)));
183 connect(sGame, SIGNAL(drawLine(
int,
QColor)), m_scene, SLOT(drawLine(
int,
QColor)));
184 connect(sGame, SIGNAL(highlightMove(
int)), m_scene, SLOT(highlightLine(
int)));
185 connect(sGame, SIGNAL(drawSquare(
int,
QColor)), m_scene, SLOT(drawSquare(
int,
QColor)));
204 qSort(playerList.
begin(), playerList.
end(), qGreater<KSquaresPlayer>());
208 scoresDialog.setButtons(KDialog::Close);
209 scoresDialog.setDefaultButton(KDialog::Close);
210 scoresDialog.setCaption(i18n(
"Scores"));
215 scoreTableModel->
setHeaderData(0, Qt::Horizontal, i18n(
"Player Name"));
216 scoreTableModel->
setHeaderData(1, Qt::Horizontal, i18n(
"Completed Squares"));
218 for(
int i = 0; i < playerList.
size(); i++)
224 temp.
setNum(playerList.
at(i).score());
229 scoresDialog.scoreTable->setModel(scoreTableModel);
230 scoresDialog.scoreTable->resizeColumnsToContents();
233 if(playerList.
at(0).isHuman())
237 KScoreDialog ksdialog(KScoreDialog::Name,
this);
241 ksdialog.setConfigGroup(qMakePair(
QByteArray(
"Easy"), i18n(
"Easy")));
242 ksdialog.addLocalizedConfigGroupName(qMakePair(
QByteArray(
"Medium"), i18n(
"Medium")));
243 ksdialog.addLocalizedConfigGroupName(qMakePair(
QByteArray(
"Hard"), i18n(
"Hard")));
246 ksdialog.setConfigGroup(qMakePair(
QByteArray(
"Medium"), i18n(
"Medium")));
247 ksdialog.addLocalizedConfigGroupName(qMakePair(
QByteArray(
"Easy"), i18n(
"Easy")));
248 ksdialog.addLocalizedConfigGroupName(qMakePair(
QByteArray(
"Hard"), i18n(
"Hard")));
251 ksdialog.setConfigGroup(qMakePair(
QByteArray(
"Hard"), i18n(
"Hard")));
252 ksdialog.addLocalizedConfigGroupName(qMakePair(
QByteArray(
"Easy"), i18n(
"Easy")));
253 ksdialog.addLocalizedConfigGroupName(qMakePair(
QByteArray(
"Medium"), i18n(
"Medium")));
256 KScoreDialog::FieldInfo scoreInfo;
257 scoreInfo[KScoreDialog::Name]=playerList.
at(0).name();
258 scoreInfo[KScoreDialog::Score].setNum(score);
260 if(ksdialog.addScore(scoreInfo, KScoreDialog::AskName))
265 void KSquaresWindow::playerTakeTurn(
KSquaresPlayer* currentPlayer)
268 statusBar()->changeItem(
271 .arg(currentPlayer->
name()),
278 setCursor(Qt::ArrowCursor);
284 setCursor(Qt::WaitCursor);
288 setCursor(Qt::ArrowCursor);
293 void KSquaresWindow::aiChooseLine()
299 void KSquaresWindow::setupActions()
301 KStandardGameAction::gameNew(
this, SLOT(
gameNew()), actionCollection());
302 KAction *resetGame = KStandardGameAction::restart(
this, SLOT(
gameReset()), actionCollection());
303 resetGame->setStatusTip(i18n(
"Start a new game with the current settings"));
305 KStandardGameAction::highscores(
this, SLOT(
showHighscores()), actionCollection());
306 KStandardGameAction::quit(
this, SLOT(close()), actionCollection());
309 KStandardAction::preferences(
this, SLOT(optionsPreferences()), actionCollection());
314 void KSquaresWindow::optionsPreferences()
316 KConfigDialog *dialog =
new KConfigDialog(
this,
"settings",
Settings::self());
319 ui_prefs_display.setupUi(displaySettingsDialog);
320 dialog->addPage(displaySettingsDialog, i18n(
"Display"),
"preferences-desktop-display");
323 ui_prefs_ai.setupUi(aiSettingsDialog);
324 dialog->addPage(aiSettingsDialog, i18n(
"Computer Player"),
"games-difficult");
326 connect(dialog, SIGNAL(settingsChanged(
QString)), m_view, SLOT(setBoardSize()));
330 #include "ksquareswindow.moc"
Player class for KSquares.
void disableEvents()
enables mouse events
static int quickStart()
Get Quick start the game.
void createGame(const QVector< KSquaresPlayer > &startPlayers, int startWidth, int startHeight)
Create a new game.
Scene for displaying the game board.
static void setBoardWidth(int v)
Set Width of board.
void append(const T &value)
static void setQuickStart(int v)
Set Quick start the game.
QList< bool > lines() const
static void setNumOfPlayers(int v)
Set Number of Players.
const T & at(int i) const
static void setPlayerNames(const QStringList &v)
Set Player Names.
void start()
Starts the game.
void setFrameStyle(int style)
void setRenderHints(QFlags< QPainter::RenderHint > hints)
void gameReset()
Start a new game with the same settings (read from KConfig Settings)
void addLineToIndex(int index)
void setColumnCount(int columns)
static int numOfPlayers()
Get Number of Players.
void append(const T &value)
void setItem(int row, int column, QStandardItem *item)
static void setBoardHeight(int v)
Set Height of board.
static int boardHeight()
Get Height of board.
void setScene(QGraphicsScene *scene)
QList< int > squares() const
static QStringList playerNames()
Get Player Names.
static int difficulty()
Get Difficulty.
static int boardWidth()
Get Width of board.
virtual bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role)
QStandardItem * item(int row, int column) const
AI Controller for KSquares.
const T & at(int i) const
void gameNew()
Launch the new game dialog and create a new game.
void setBoardSize()
Automatically resizes the board according to the users preferences. Deprecated for a bit...
QString & setNum(short n, int base)
int currentPlayerId() const
KSquaresWindow()
Constructor.
QString fromLatin1(const char *str, int size)
static void setHumanList(const QList< int > &v)
Set Human or AI.
void setRowCount(int rows)
void enableEvents()
disables mouse events
static QList< int > humanList()
Get Human or AI.
void setEditable(bool editable)
Actual game board widget.
QString name() const
Sets the players name.