diff --git a/qt/Makefile.am b/qt/Makefile.am index 0bba6a6..ce3106c 100644 --- a/qt/Makefile.am +++ b/qt/Makefile.am @@ -45,6 +45,7 @@ EXTRA_DIST = \ ui/dic_wizard_letters_def_page.ui \ ui/dic_wizard_conclusion_page.ui \ ui/bag_widget.ui \ + ui/fav_players_dialog.ui \ ui/main_window.ui \ ui/new_game.ui \ ui/player_widget.ui \ @@ -75,6 +76,7 @@ eliot_SOURCES = \ play_word_mediator.cpp play_word_mediator.h \ training_widget.cpp training_widget.h \ player_widget.cpp player_widget.h \ + fav_players_dialog.cpp fav_players_dialog.h \ prefs_dialog.cpp prefs_dialog.h \ aux_window.cpp aux_window.h \ main_window.cpp main_window.h \ @@ -83,6 +85,7 @@ eliot_SOURCES = \ nodist_eliot_SOURCES = \ ui/main_window.ui.h \ ui/bag_widget.ui.h \ + ui/fav_players_dialog.ui.h \ ui/new_game.ui.h \ ui/player_widget.ui.h \ ui/training_widget.ui.h \ @@ -110,6 +113,7 @@ nodist_eliot_SOURCES = \ play_word_mediator.moc.cpp \ player_widget.moc.cpp \ training_widget.moc.cpp \ + fav_players_dialog.moc.cpp \ prefs_dialog.moc.cpp \ aux_window.moc.cpp \ main_window.moc.cpp \ diff --git a/qt/fav_players_dialog.cpp b/qt/fav_players_dialog.cpp new file mode 100644 index 0000000..d031f20 --- /dev/null +++ b/qt/fav_players_dialog.cpp @@ -0,0 +1,67 @@ +/***************************************************************************** + * Eliot + * Copyright (C) 2012 Olivier Teulière + * Authors: Olivier Teulière + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + *****************************************************************************/ + +#include "config.h" + +#include +#include + +#include "fav_players_dialog.h" +#include "players_table_helper.h" + + +INIT_LOGGER(qt, FavPlayersDialog); + + +FavPlayersDialog::FavPlayersDialog(QWidget *iParent) + : QDialog(iParent) +{ + setupUi(this); + + m_helper = new PlayersTableHelper(this, tablePlayers, NULL, buttonRemove); + + QObject::connect(buttonAdd, SIGNAL(clicked()), + this, SLOT(addRow())); + + m_helper->fillWithFavPlayers(); +} + + +void FavPlayersDialog::addRow() +{ + m_helper->addRow(_q("New player"), _q(PlayersTableHelper::kHUMAN), ""); + + // Give focus to the newly created cell containing the player name, + // to allow fast edition + tablePlayers->setFocus(); + tablePlayers->setCurrentCell(tablePlayers->rowCount() - 1, 0, + QItemSelectionModel::ClearAndSelect | + QItemSelectionModel::Current | + QItemSelectionModel::Rows); +} + + +void FavPlayersDialog::accept() +{ + m_helper->saveAsFavPlayers(); + + QDialog::accept(); +} + diff --git a/qt/fav_players_dialog.h b/qt/fav_players_dialog.h new file mode 100644 index 0000000..f586b9c --- /dev/null +++ b/qt/fav_players_dialog.h @@ -0,0 +1,54 @@ +/***************************************************************************** + * Eliot + * Copyright (C) 2012 Olivier Teulière + * Authors: Olivier Teulière + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + *****************************************************************************/ + +#ifndef FAV_PLAYERS_DIALOG_H_ +#define FAV_PLAYERS_DIALOG_H_ + +#include + +#include + +#include "logging.h" + + +class PlayersTableHelper; + +class FavPlayersDialog: public QDialog, private Ui::FavPlayersDialog +{ + Q_OBJECT; + DEFINE_LOGGER(); + +public: + explicit FavPlayersDialog(QWidget *iParent = 0); + +public slots: + /// Update the settings when the user selects "OK" + virtual void accept(); + +private slots: + void addRow(); + +private: + PlayersTableHelper *m_helper; + +}; + +#endif + diff --git a/qt/main_window.cpp b/qt/main_window.cpp index fb4db79..7ce55c1 100644 --- a/qt/main_window.cpp +++ b/qt/main_window.cpp @@ -56,6 +56,7 @@ #include "training_widget.h" #include "history_widget.h" #include "dic_tools_widget.h" +#include "fav_players_dialog.h" #include "timer_widget.h" #include "dic_wizard.h" #include "aux_window.h" @@ -618,6 +619,10 @@ void MainWindow::createMenu() addMenuAction(menuSettings, _q("Create &new dictionary..."), QString(""), _q("Start the wizard for creating a new dictionary " "from an existing word list"), SLOT(onSettingsCreateDic())); + menuSettings->addSeparator(); + addMenuAction(menuSettings, _q("&Favorite players..."), QString(""), + _q("Define frequently used players for faster game creation"), + SLOT(onSettingsFavPlayers())); addMenuAction(menuSettings, _q("&Preferences..."), _q("Ctrl+F"), _q("Edit the preferences"), SLOT(onSettingsPreferences()), false, QIcon(":/images/preferences.png")); @@ -941,6 +946,13 @@ void MainWindow::onSettingsCreateDic() } +void MainWindow::onSettingsFavPlayers() +{ + FavPlayersDialog *favPlayersDialog = new FavPlayersDialog(this); + favPlayersDialog->exec(); +} + + void MainWindow::onWindowsToolbar() { if (m_ui.toolBar->isVisible()) diff --git a/qt/main_window.h b/qt/main_window.h index 146d69c..8531a10 100644 --- a/qt/main_window.h +++ b/qt/main_window.h @@ -75,6 +75,7 @@ private slots: void onGameQuit(); void onSettingsChooseDic(); void onSettingsCreateDic(); + void onSettingsFavPlayers(); void onSettingsPreferences(); void onWindowsToolbar(); void onWindowsBag(); diff --git a/qt/ui/fav_players_dialog.ui b/qt/ui/fav_players_dialog.ui new file mode 100644 index 0000000..17ef057 --- /dev/null +++ b/qt/ui/fav_players_dialog.ui @@ -0,0 +1,121 @@ + + + FavPlayersDialog + + + + 0 + 0 + 400 + 411 + + + + _("Favorite players") + + + + + + _("The favorite players listed below will be used in the "New game" dialog, to add players in a faster way.") + + + true + + + + + + + _("To add or remove a player, use the buttons under the table. You can edit the existing players directly in the table, by double-clicking on them. ") + + + true + + + + + + + + + + + + _("Add player") + + + + + + + false + + + _("Remove player") + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + FavPlayersDialog + accept() + + + 257 + 290 + + + 157 + 274 + + + + + buttonBox + rejected() + FavPlayersDialog + reject() + + + 325 + 290 + + + 286 + 274 + + + + +