New dialog to define the favourite players

This commit is contained in:
Olivier Teulière 2012-02-16 22:14:09 +01:00
parent 323344a674
commit 2cf5e29347
6 changed files with 259 additions and 0 deletions

View file

@ -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 \

67
qt/fav_players_dialog.cpp Normal file
View file

@ -0,0 +1,67 @@
/*****************************************************************************
* Eliot
* Copyright (C) 2012 Olivier Teulière
* Authors: Olivier Teulière <ipkiss @@ gmail.com>
*
* 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 <QtGui/QTableWidget>
#include <QtCore/QSettings>
#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();
}

54
qt/fav_players_dialog.h Normal file
View file

@ -0,0 +1,54 @@
/*****************************************************************************
* Eliot
* Copyright (C) 2012 Olivier Teulière
* Authors: Olivier Teulière <ipkiss @@ gmail.com>
*
* 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 <QtGui/QDialog>
#include <ui/fav_players_dialog.ui.h>
#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

View file

@ -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())

View file

@ -75,6 +75,7 @@ private slots:
void onGameQuit();
void onSettingsChooseDic();
void onSettingsCreateDic();
void onSettingsFavPlayers();
void onSettingsPreferences();
void onWindowsToolbar();
void onWindowsBag();

121
qt/ui/fav_players_dialog.ui Normal file
View file

@ -0,0 +1,121 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FavPlayersDialog</class>
<widget class="QDialog" name="FavPlayersDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>411</height>
</rect>
</property>
<property name="windowTitle">
<string>_(&quot;Favorite players&quot;)</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>_(&quot;The favorite players listed below will be used in the &quot;New game&quot; dialog, to add players in a faster way.&quot;)</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>_(&quot;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. &quot;)</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QTableWidget" name="tablePlayers"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="buttonAdd">
<property name="text">
<string>_(&quot;Add player&quot;)</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonRemove">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>_(&quot;Remove player&quot;)</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>FavPlayersDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>257</x>
<y>290</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>FavPlayersDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>325</x>
<y>290</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>