From fb4ea0e5597e09ea5cc6656b27746c9afcde3cba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Teuli=C3=A8re?= Date: Sat, 29 Nov 2008 16:40:59 +0000 Subject: [PATCH] - The actions on the game history are now available in the menu and the toolbar - The toolbar can be shown/hidden via a menu entry - Added icons for all the history actions - Ask for confirmation before replaying a turn --- qt/eliot.qrc | 5 ++ qt/images/first.xpm | 36 ++++++++++++++ qt/images/last.xpm | 36 ++++++++++++++ qt/images/next.xpm | 36 ++++++++++++++ qt/images/prev.xpm | 36 ++++++++++++++ qt/images/replay.xpm | 37 ++++++++++++++ qt/main_window.cpp | 116 +++++++++++++++++++++++++++++++------------ qt/main_window.h | 18 +++++-- qt/ui/main_window.ui | 66 ++++++------------------ 9 files changed, 296 insertions(+), 90 deletions(-) create mode 100644 qt/images/first.xpm create mode 100644 qt/images/last.xpm create mode 100644 qt/images/next.xpm create mode 100644 qt/images/prev.xpm create mode 100644 qt/images/replay.xpm diff --git a/qt/eliot.qrc b/qt/eliot.qrc index 580163b..a860562 100644 --- a/qt/eliot.qrc +++ b/qt/eliot.qrc @@ -1,5 +1,10 @@ images/eliot.xpm + images/first.xpm + images/last.xpm + images/prev.xpm + images/next.xpm + images/replay.xpm diff --git a/qt/images/first.xpm b/qt/images/first.xpm new file mode 100644 index 0000000..44479bd --- /dev/null +++ b/qt/images/first.xpm @@ -0,0 +1,36 @@ +/* XPM */ +static char * prev_xpm[] = { +"16 16 17 1", +"* c None", +". c #000000", +"+ c #800000", +"@ c #008000", +"# c #808000", +"$ c #000080", +"% c #800080", +"& c #008080", +" c #C0C0C0", +"= c #808080", +"- c #FF0000", +"; c #00FF00", +"> c #FFFF00", +", c #0000FF", +"' c #FF00FF", +") c #00FFFF", +"! c #FFFFFF", +"****************", +"****************", +"****************", +"****************", +"**.****.****.***", +"**.***..***..***", +"**.**...**...***", +"**.*....*....***", +"**.**...**...***", +"**.***..***..***", +"**.****.****.***", +"****************", +"****************", +"****************", +"****************", +"****************"}; diff --git a/qt/images/last.xpm b/qt/images/last.xpm new file mode 100644 index 0000000..cf39b0f --- /dev/null +++ b/qt/images/last.xpm @@ -0,0 +1,36 @@ +/* XPM */ +static char * next_xpm[] = { +"16 16 17 1", +"* c None", +". c #000000", +"+ c #800000", +"@ c #008000", +"# c #808000", +"$ c #000080", +"% c #800080", +"& c #008080", +" c #C0C0C0", +"= c #808080", +"- c #FF0000", +"; c #00FF00", +"> c #FFFF00", +", c #0000FF", +"' c #FF00FF", +") c #00FFFF", +"! c #FFFFFF", +"****************", +"****************", +"****************", +"****************", +"**.****.****.***", +"**..***..***.***", +"**...**...**.***", +"**....*....*.***", +"**...**...**.***", +"**..***..***.***", +"**.****.****.***", +"****************", +"****************", +"****************", +"****************", +"****************"}; diff --git a/qt/images/next.xpm b/qt/images/next.xpm new file mode 100644 index 0000000..f078ec7 --- /dev/null +++ b/qt/images/next.xpm @@ -0,0 +1,36 @@ +/* XPM */ +static char * play_xpm[] = { +"16 16 17 1", +"* c None", +". c #000000", +"+ c #800000", +"@ c #008000", +"# c #808000", +"$ c #000080", +"% c #800080", +"& c #008080", +" c #C0C0C0", +"= c #808080", +"- c #FF0000", +"; c #00FF00", +"> c #FFFF00", +", c #0000FF", +"' c #FF00FF", +") c #00FFFF", +"! c #FFFFFF", +"****************", +"****************", +"***..***********", +"***....*********", +"***......*******", +"***........*****", +"***..........***", +"***...........**", +"***..........***", +"***........*****", +"***......*******", +"***....*********", +"***..***********", +"****************", +"****************", +"****************"}; diff --git a/qt/images/prev.xpm b/qt/images/prev.xpm new file mode 100644 index 0000000..b239950 --- /dev/null +++ b/qt/images/prev.xpm @@ -0,0 +1,36 @@ +/* XPM */ +static char * play_xpm[] = { +"16 16 17 1", +"* c None", +". c #000000", +"+ c #800000", +"@ c #008000", +"# c #808000", +"$ c #000080", +"% c #800080", +"& c #008080", +" c #C0C0C0", +"= c #808080", +"- c #FF0000", +"; c #00FF00", +"> c #FFFF00", +", c #0000FF", +"' c #FF00FF", +") c #00FFFF", +"! c #FFFFFF", +"****************", +"****************", +"***********..***", +"*********....***", +"*******......***", +"*****........***", +"***..........***", +"**...........***", +"***..........***", +"*****........***", +"*******......***", +"*********....***", +"***********..***", +"****************", +"****************", +"****************"}; diff --git a/qt/images/replay.xpm b/qt/images/replay.xpm new file mode 100644 index 0000000..d068fde --- /dev/null +++ b/qt/images/replay.xpm @@ -0,0 +1,37 @@ +/* XPM */ +static char *replay_xpm[] = { +"16 16 17 1", +" c None", +"B c #000000", +"C c #800000", +"D c #008000", +"E c #808000", +"F c #000080", +"G c #800080", +"H c #008080", +"I c #C0C0C0", +"J c #808080", +"K c #FF0000", +"L c #00FF00", +"M c #FFFF00", +"N c #0000FF", +"O c #FF00FF", +"P c #00FFFF", +"Q c #FFFFFF", +" ", +" B ", +" BB ", +"BBB BB BB BBBBB ", +"BBB BB BB BBBBB ", +" BB BB ", +" BB B ", +" BB ", +" BB ", +" BB B ", +" BB BB ", +" BBBBBBBBBBBBBB ", +" BBBBBBBBBBBBBB ", +" BB ", +" B ", +" " +}; diff --git a/qt/main_window.cpp b/qt/main_window.cpp index ede1778..1edc4e3 100644 --- a/qt/main_window.cpp +++ b/qt/main_window.cpp @@ -153,15 +153,6 @@ MainWindow::MainWindow(QWidget *iParent) emit gameChangedNonConst(NULL); emit gameChanged(NULL); - QObject::connect(m_ui.buttonFirst, SIGNAL(clicked()), - this, SLOT(onGameFirst())); - QObject::connect(m_ui.buttonPrev, SIGNAL(clicked()), - this, SLOT(onGamePrev())); - QObject::connect(m_ui.buttonNext, SIGNAL(clicked()), - this, SLOT(onGameNext())); - QObject::connect(m_ui.buttonLast, SIGNAL(clicked()), - this, SLOT(onGameLast())); - // Load dictionary QSettings qs(ORGANIZATION, PACKAGE_NAME); QString dicPath = qs.value(PrefsDialog::kINTF_DIC_PATH, "").toString(); @@ -211,25 +202,19 @@ void MainWindow::destroyCurrentGame() void MainWindow::refresh() { - if (m_game == NULL) - { - m_ui.buttonFirst->setEnabled(false); - m_ui.buttonPrev->setEnabled(false); - m_ui.buttonNext->setEnabled(false); - m_ui.buttonLast->setEnabled(false); - // XXX: tmp - m_ui.labelTurnNb->setText(""); - } - else + if (m_game != NULL) { bool isFirstTurn = m_game->getNavigation().isFirstTurn(); bool isLastTurn = m_game->getNavigation().isLastTurn(); - m_ui.buttonFirst->setEnabled(!isFirstTurn); - m_ui.buttonPrev->setEnabled(!isFirstTurn); - m_ui.buttonNext->setEnabled(!isLastTurn); - m_ui.buttonLast->setEnabled(!isLastTurn); - // XXX: tmp - m_ui.labelTurnNb->setText(QString("Turn: %1").arg(m_game->getNavigation().getCurrTurn())); + m_actionHistoryFirstTurn->setEnabled(!isFirstTurn); + m_actionHistoryPrevTurn->setEnabled(!isFirstTurn); + m_actionHistoryNextTurn->setEnabled(!isLastTurn); + m_actionHistoryLastTurn->setEnabled(!isLastTurn); + m_actionHistoryReplayTurn->setEnabled(!isLastTurn); +#ifdef DEBUG + cout << endl << endl; + m_game->getNavigation().print(); +#endif } } @@ -240,6 +225,11 @@ void MainWindow::updateForGame(const Game *iGame) { m_actionGameSaveAs->setEnabled(false); m_actionGamePrint->setEnabled(false); + m_actionHistoryFirstTurn->setEnabled(false); + m_actionHistoryPrevTurn->setEnabled(false); + m_actionHistoryNextTurn->setEnabled(false); + m_actionHistoryLastTurn->setEnabled(false); + m_actionHistoryReplayTurn->setEnabled(false); setWindowTitle(_q("No game") + " - Eliot"); } else @@ -332,12 +322,13 @@ void MainWindow::readSettings() QAction * MainWindow::addMenuAction(QMenu *menu, QString iText, const QKeySequence &iShortcut, QString iStatusTip, const char *iMember, - bool iCheckable) + bool iCheckable, QIcon icon) { QAction *action = new QAction(iText, this); action->setShortcut(iShortcut); action->setStatusTip(iStatusTip); action->setCheckable(iCheckable); + action->setIcon(icon); QObject::connect(action, SIGNAL(triggered()), this, iMember); menu->addAction(action); return action; @@ -363,6 +354,32 @@ void MainWindow::createMenu() addMenuAction(menuFile, _q("&Quit"), _q("Ctrl+Q"), _q("Quit Eliot"), SLOT(close())); + QMenu *menuHistory = new QMenu(m_ui.menubar); + m_ui.menubar->addAction(menuHistory->menuAction()); + menuHistory->setTitle(_q("&History")); + m_actionHistoryFirstTurn = addMenuAction(menuHistory, _q("&First turn"), _q("Ctrl+Home"), + _q("Go to the first turn of the game"), SLOT(onHistoryFirstTurn()), + false, QIcon(":/images/first.xpm")); + m_actionHistoryPrevTurn = addMenuAction(menuHistory, _q("&Previous turn"), _q("Ctrl+Left"), + _q("Go to the previous turn of the game"), SLOT(onHistoryPrevTurn()), + false, QIcon(":/images/prev.xpm")); + m_actionHistoryNextTurn = addMenuAction(menuHistory, _q("&Next turn"), _q("Ctrl+Right"), + _q("Go to the next turn of the game"), SLOT(onHistoryNextTurn()), + false, QIcon(":/images/next.xpm")); + m_actionHistoryLastTurn = addMenuAction(menuHistory, _q("&Last turn"), _q("Ctrl+End"), + _q("Go to the last turn of the game"), SLOT(onHistoryLastTurn()), + false, QIcon(":/images/last.xpm")); + m_actionHistoryReplayTurn = addMenuAction(menuHistory, _q("&Replay turn"), _q("Ctrl+R"), + _q("Play the game from the current position, " + "replacing what was really played"), SLOT(onHistoryReplayTurn()), + false, QIcon(":/images/replay.xpm")); + // Add actions to the toolbar + m_ui.toolBar->addAction(m_actionHistoryFirstTurn); + m_ui.toolBar->addAction(m_actionHistoryPrevTurn); + m_ui.toolBar->addAction(m_actionHistoryNextTurn); + m_ui.toolBar->addAction(m_actionHistoryLastTurn); + m_ui.toolBar->addAction(m_actionHistoryReplayTurn); + QMenu *menuSettings = new QMenu(m_ui.menubar); m_ui.menubar->addAction(menuSettings->menuAction()); menuSettings->setTitle(_q("&Settings")); @@ -374,6 +391,9 @@ void MainWindow::createMenu() QMenu *menuWindows = new QMenu(m_ui.menubar); m_ui.menubar->addAction(menuWindows->menuAction()); menuWindows->setTitle(_q("&Windows")); + m_actionWindowsToolbar = addMenuAction(menuWindows, _q("&Toolbar"), _q("Ctrl+T"), + _q("Show/hide the toolbar"), SLOT(onWindowsToolbar()), true); + m_actionWindowsToolbar->setChecked(true); m_actionWindowsBag = addMenuAction(menuWindows, _q("&Bag"), _q("Ctrl+B"), _q("Show/hide the remaining tiles in the bag"), SLOT(onWindowsBag()), true); m_actionWindowsBoard = addMenuAction(menuWindows, _q("&External board"), _q("Ctrl+E"), @@ -663,6 +683,15 @@ void MainWindow::onSettingsChooseDic() } +void MainWindow::onWindowsToolbar() +{ + if (m_ui.toolBar->isVisible()) + m_ui.toolBar->hide(); + else + m_ui.toolBar->show(); +} + + void MainWindow::onWindowsBag() { if (m_bagWindow == NULL) @@ -747,13 +776,13 @@ void MainWindow::onHelpAbout() "the License, or (at your option) any later version."); // QMessageBox::about() doesn't add the nice information icon, so we create // the box manually (not much work...) - QMessageBox *aboutBox = new QMessageBox(QMessageBox::Information, - _q("About Eliot"), msg, QMessageBox::Ok, this); - aboutBox->exec(); + QMessageBox aboutBox(QMessageBox::Information, _q("About Eliot"), + msg, QMessageBox::Ok, this); + aboutBox.exec(); } -void MainWindow::onGameFirst() +void MainWindow::onHistoryFirstTurn() { if (m_game == NULL) return; @@ -763,7 +792,7 @@ void MainWindow::onGameFirst() } -void MainWindow::onGamePrev() +void MainWindow::onHistoryPrevTurn() { if (m_game == NULL) return; @@ -773,7 +802,7 @@ void MainWindow::onGamePrev() } -void MainWindow::onGameNext() +void MainWindow::onHistoryNextTurn() { if (m_game == NULL) return; @@ -783,7 +812,7 @@ void MainWindow::onGameNext() } -void MainWindow::onGameLast() +void MainWindow::onHistoryLastTurn() { if (m_game == NULL) return; @@ -792,3 +821,24 @@ void MainWindow::onGameLast() emit gameUpdated(); } + +void MainWindow::onHistoryReplayTurn() +{ + if (m_game == NULL) + return; + + // Ask for a confirmation, because this may lead to data loss + QString msg = _q("Replaying this turn will modify the game history " + "by deleting the turns \"in the future\"."); + QMessageBox confirmationBox(QMessageBox::Question, _q("Eliot"), msg, + QMessageBox::Ok | QMessageBox::Cancel, this); + confirmationBox.setInformativeText(_q("Do you want to continue?")); + int ret = confirmationBox.exec(); + if (ret != QMessageBox::Ok) + return; + + m_game->accessNavigation().clearFuture(); + emit gameUpdated(); + displayInfoMsg(_q("Future turns deleted")); +} + diff --git a/qt/main_window.h b/qt/main_window.h index f6bd274..a2c2cce 100644 --- a/qt/main_window.h +++ b/qt/main_window.h @@ -67,16 +67,18 @@ private slots: void onGamePrint(); void onSettingsChooseDic(); void onSettingsPreferences(); + void onWindowsToolbar(); void onWindowsBag(); void onWindowsBoard(); void onWindowsHistory(); void onWindowsDicTools(); void onHelpAbout(); - void onGameFirst(); - void onGamePrev(); - void onGameNext(); - void onGameLast(); + void onHistoryFirstTurn(); + void onHistoryPrevTurn(); + void onHistoryNextTurn(); + void onHistoryLastTurn(); + void onHistoryReplayTurn(); /** Perform some updates when the game is updated */ void refresh(); @@ -109,6 +111,12 @@ private: /// Actions enabled or disabled depending on the game state QAction *m_actionGamePrint; QAction *m_actionGameSaveAs; + QAction *m_actionHistoryPrevTurn; + QAction *m_actionHistoryNextTurn; + QAction *m_actionHistoryFirstTurn; + QAction *m_actionHistoryLastTurn; + QAction *m_actionHistoryReplayTurn; + QAction *m_actionWindowsToolbar; static const char * m_windowName; @@ -136,7 +144,7 @@ private: QAction * addMenuAction(QMenu *menu, QString iText, const QKeySequence &iShortcut, QString iStatusTip, const char *iMember, - bool iCheckable = false); + bool iCheckable = false, QIcon icon = QIcon()); /// Create the menu bar and the actions void createMenu(); diff --git a/qt/ui/main_window.ui b/qt/ui/main_window.ui index 9848ace..837b951 100644 --- a/qt/ui/main_window.ui +++ b/qt/ui/main_window.ui @@ -18,58 +18,6 @@ - - - - - - First - - - - - - - Prev - - - - - - - Next - - - - - - - Last - - - - - - - Turn: - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - @@ -121,6 +69,20 @@ + + + Qt::ActionsContextMenu + + + toolBar + + + TopToolBarArea + + + false + + true