Added preferences to configure the time

This commit is contained in:
Olivier Teulière 2012-01-26 20:57:43 +01:00
parent 8b33f45dca
commit a7ef1f0f8c
6 changed files with 99 additions and 22 deletions

View file

@ -97,7 +97,10 @@ MainWindow::MainWindow(QWidget *iParent)
// Make it easier to reproduce bugs
LOG_DEBUG("Rand seed: " << val);
m_timerModel = new TimerModel;
QSettings qs(ORGANIZATION, PACKAGE_NAME);
int timerTotal = qs.value(PrefsDialog::kINTF_TIMER_TOTAL_DURATION, 180).toInt();
int timerAlert = qs.value(PrefsDialog::kINTF_TIMER_ALERT_DURATION, 30).toInt();
m_timerModel = new TimerModel(timerTotal, timerAlert);
// TODO: connect to some of the timer signals (alert() and expired())
QObject::connect(this, SIGNAL(gameChangedNonConst(PublicGame*)),
@ -163,7 +166,6 @@ MainWindow::MainWindow(QWidget *iParent)
emit gameChanged(NULL);
// Load dictionary
QSettings qs(ORGANIZATION, PACKAGE_NAME);
QString dicPath = qs.value(PrefsDialog::kINTF_DIC_PATH, "").toString();
if (dicPath != "")
{
@ -280,6 +282,13 @@ void MainWindow::prefsUpdated()
m_newGameDialog->refresh();
}
// Refresh the timer values
QSettings qs(ORGANIZATION, PACKAGE_NAME);
int timerTotal = qs.value(PrefsDialog::kINTF_TIMER_TOTAL_DURATION).toInt();
int timerAlert = qs.value(PrefsDialog::kINTF_TIMER_ALERT_DURATION).toInt();
m_timerModel->setTotalDuration(timerTotal);
m_timerModel->setAlertDuration(timerAlert);
// Probably useless in most cases (currently only used for
// the History alignment)
emit gameUpdated();

View file

@ -38,6 +38,8 @@ const QString PrefsDialog::kINTF_WARN_REPLAY_TURN = "Interface/WarnReplayTurn";
const QString PrefsDialog::kINTF_SHOW_TOOLBAR = "Interface/ShowToolBar";
const QString PrefsDialog::kINTF_LINK_TRAINING_7P1 = "Interface/LinkTrainingRackWith7P1";
const QString PrefsDialog::kINTF_DEFAULT_AI_LEVEL = "Interface/DefaultAiLevel";
const QString PrefsDialog::kINTF_TIMER_TOTAL_DURATION = "Interface/TimerTotalDuration";
const QString PrefsDialog::kINTF_TIMER_ALERT_DURATION = "Interface/TimerAlertDuration";
const QString PrefsDialog::kDEFAULT_DEF_SITE = "http://fr.wiktionary.org/wiki/%w";
@ -45,14 +47,19 @@ PrefsDialog::PrefsDialog(QWidget *iParent)
: QDialog(iParent)
{
setupUi(this);
lineEditDefSite->setToolTip(_("URL of the site used to display word definitions.\n"
"In the URL, %w will be replaced with the word in lower case. Examples:\n"
"\thttp://fr.wiktionary.org/wiki/%w\n"
"\thttp://en.wiktionary.org/wiki/%w\n"
"\thttp://images.google.com/images?q=%w"));
spinBoxDefaultLevel->setToolTip(_("Default level for Eliot, "
"used when creating a new game.\n"
"Accepted range: [0-100]"));
lineEditDefSite->setToolTip(_q("URL of the site used to display word definitions.\n"
"In the URL, %w will be replaced with the word in lower case. Examples:\n"
"\thttp://fr.wiktionary.org/wiki/%w\n"
"\thttp://en.wiktionary.org/wiki/%w\n"
"\thttp://images.google.com/images?q=%w"));
spinBoxDefaultLevel->setToolTip(_q("Default level for Eliot, "
"used when creating a new game.\n"
"Accepted range: [0-100]"));
spinBoxTimerTotal->setToolTip(_q("Total duration of the timer, in seconds.\n"
"Changing this value will reset the timer."));
spinBoxTimerAlert->setToolTip(_q("Number of remaining seconds when an alert is triggered.\n"
"Use a value of -1 to disable the alert.\n"
"Changing this value will reset the timer."));
try
{
@ -70,6 +77,10 @@ PrefsDialog::PrefsDialog(QWidget *iParent)
checkBoxIntfLinkTraining7P1->setChecked(linkTraining7P1);
int defaultAiLevel = qs.value(kINTF_DEFAULT_AI_LEVEL, 100).toInt();
spinBoxDefaultLevel->setValue(defaultAiLevel);
int timerTotal = qs.value(kINTF_TIMER_TOTAL_DURATION, 180).toInt();
spinBoxTimerTotal->setValue(timerTotal);
int timerAlert = qs.value(kINTF_TIMER_ALERT_DURATION, 30).toInt();
spinBoxTimerAlert->setValue(timerAlert);
// Duplicate settings
checkBoxDuplRefuseInvalid->setChecked(Settings::Instance().getBool("duplicate.reject-invalid"));
@ -142,6 +153,18 @@ void PrefsDialog::updateSettings()
shouldEmitUpdate = true;
qs.setValue(kINTF_DEFAULT_AI_LEVEL, spinBoxDefaultLevel->value());
}
if (qs.value(kINTF_TIMER_TOTAL_DURATION, 180).toInt() != spinBoxTimerTotal->value())
{
// We need to change the default AI level
shouldEmitUpdate = true;
qs.setValue(kINTF_TIMER_TOTAL_DURATION, spinBoxTimerTotal->value());
}
if (qs.value(kINTF_TIMER_ALERT_DURATION, 30).toInt() != spinBoxTimerAlert->value())
{
// We need to change the default AI level
shouldEmitUpdate = true;
qs.setValue(kINTF_TIMER_ALERT_DURATION, spinBoxTimerAlert->value());
}
// Duplicate settings
Settings::Instance().setBool("duplicate.reject-invalid",

View file

@ -44,6 +44,8 @@ public:
static const QString kINTF_SHOW_TOOLBAR;
static const QString kINTF_LINK_TRAINING_7P1;
static const QString kINTF_DEFAULT_AI_LEVEL;
static const QString kINTF_TIMER_TOTAL_DURATION;
static const QString kINTF_TIMER_ALERT_DURATION;
static const QString kDEFAULT_DEF_SITE;

View file

@ -99,6 +99,8 @@ bool TimerModel::isActiveTimer() const
void TimerModel::setTotalDuration(int iSeconds)
{
if (iSeconds == m_totalDuration)
return;
m_totalDuration = iSeconds;
if (m_totalDuration < 0)
m_totalDuration = 0;
@ -109,6 +111,8 @@ void TimerModel::setTotalDuration(int iSeconds)
void TimerModel::setAlertDuration(int iSeconds)
{
if (iSeconds == m_alertDuration)
return;
m_alertDuration = iSeconds;
resetTimer();
}

View file

@ -35,7 +35,7 @@ class TimerModel : public QObject
Q_OBJECT;
public:
TimerModel(int iTotalDuration = 8, int iAlertDuration = 3);
TimerModel(int iTotalDuration, int iAlertDuration);
// Accessors
int getValue() const { return m_remaining; }

View file

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>491</width>
<height>563</height>
<width>443</width>
<height>629</height>
</rect>
</property>
<property name="windowTitle">
@ -108,15 +108,29 @@
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>_(&quot;Timer total duration (in seconds):&quot;)</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>_(&quot;Timer alert (in seconds):&quot;)</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>_(&quot;Default computer level:&quot;)</string>
</property>
</widget>
</item>
<item>
<item row="0" column="1">
<widget class="QSpinBox" name="spinBoxDefaultLevel">
<property name="maximum">
<number>100</number>
@ -126,8 +140,8 @@
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<item row="0" column="2">
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@ -139,6 +153,29 @@
</property>
</spacer>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="spinBoxTimerTotal">
<property name="maximum">
<number>999</number>
</property>
<property name="value">
<number>180</number>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="spinBoxTimerAlert">
<property name="minimum">
<number>-1</number>
</property>
<property name="maximum">
<number>999</number>
</property>
<property name="value">
<number>30</number>
</property>
</widget>
</item>
</layout>
</item>
</layout>
@ -311,6 +348,8 @@
<tabstop>checkBoxIntfAlignHistory</tabstop>
<tabstop>checkBoxIntfWarnReplayTurn</tabstop>
<tabstop>spinBoxDefaultLevel</tabstop>
<tabstop>spinBoxTimerTotal</tabstop>
<tabstop>spinBoxTimerAlert</tabstop>
<tabstop>checkBoxDuplRefuseInvalid</tabstop>
<tabstop>spinBoxDuplSoloPlayers</tabstop>
<tabstop>spinBoxDuplSoloValue</tabstop>
@ -328,8 +367,8 @@
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
<x>257</x>
<y>619</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
@ -344,8 +383,8 @@
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
<x>325</x>
<y>619</y>
</hint>
<hint type="destinationlabel">
<x>286</x>