Fix mines time displaying "1 seconds" in frontend
authorWuzzy <almikes@aol.com>
Fri, 06 May 2016 18:33:54 +0200
changeset 11815 68bc5ebce319
parent 11814 8eccc307ca1e
child 11816 f73a299c7884
Fix mines time displaying "1 seconds" in frontend
QTfrontend/ui/page/pagescheme.cpp
QTfrontend/ui/page/pagescheme.h
QTfrontend/ui/widget/MinesTimeSpinBox.cpp
QTfrontend/ui/widget/MinesTimeSpinBox.h
share/hedgewars/Data/Locale/hedgewars_en.ts
--- a/QTfrontend/ui/page/pagescheme.cpp	Fri May 06 17:26:06 2016 +0200
+++ b/QTfrontend/ui/page/pagescheme.cpp	Fri May 06 18:33:54 2016 +0200
@@ -30,6 +30,7 @@
 #include "ammoSchemeModel.h"
 #include "pagescheme.h"
 #include "FreqSpinBox.h"
+#include "MinesTimeSpinBox.h"
 
 
 QLayout * PageScheme::bodyLayoutDefinition()
@@ -368,13 +369,11 @@
     l->setFixedSize(32,32);
     l->setPixmap(QPixmap(":/res/iconMineTime.png"));
     glBSLayout->addWidget(l,10,1,1,1);
-    SB_MinesTime = new QSpinBox(gbBasicSettings);
+    SB_MinesTime = new MinesTimeSpinBox(gbBasicSettings);
     SB_MinesTime->setWhatsThis(wtMinesTime);
     SB_MinesTime->setRange(-1, 5);
     SB_MinesTime->setValue(3);
     SB_MinesTime->setSingleStep(1);
-    SB_MinesTime->setSpecialValueText(tr("Random"));
-    SB_MinesTime->setSuffix(" "+ tr("Seconds"));
     glBSLayout->addWidget(SB_MinesTime,10,2,1,1);
 
     l = new QLabel(gbBasicSettings);
--- a/QTfrontend/ui/page/pagescheme.h	Fri May 06 17:26:06 2016 +0200
+++ b/QTfrontend/ui/page/pagescheme.h	Fri May 06 18:33:54 2016 +0200
@@ -23,6 +23,7 @@
 #include "togglebutton.h"
 
 class FreqSpinBox;
+class MinesTimeSpinBox;
 
 class PageScheme : public AbstractPage
 {
@@ -85,7 +86,7 @@
         FreqSpinBox * SB_CaseProb;
         QSpinBox * SB_HealthCrates;
         QSpinBox * SB_CrateHealth;
-        QSpinBox * SB_MinesTime;
+        MinesTimeSpinBox * SB_MinesTime;
         QSpinBox * SB_Mines;
         QSpinBox * SB_AirMines;
         QSpinBox * SB_MineDuds;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/ui/widget/MinesTimeSpinBox.cpp	Fri May 06 18:33:54 2016 +0200
@@ -0,0 +1,40 @@
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@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; version 2 of the License
+ *
+ * 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
+ */
+
+/**
+ * @file
+ * @brief MinesTimeSpinBox class implementation
+ */
+
+#include "MinesTimeSpinBox.h"
+
+
+MinesTimeSpinBox::MinesTimeSpinBox(QWidget* parent) : QSpinBox(parent)
+{
+    // do nothing
+};
+
+
+QString MinesTimeSpinBox::textFromValue(int value) const
+{
+    switch (value)
+    {
+        case -1: return tr("Random");
+        default: return tr("%1 seconds", "", value).arg(value);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/ui/widget/MinesTimeSpinBox.h	Fri May 06 18:33:54 2016 +0200
@@ -0,0 +1,55 @@
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@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; version 2 of the License
+ *
+ * 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
+ */
+
+/**
+ * @file
+ * @brief MinesTimeSpinBox class definition
+ */
+
+#ifndef HEDGEWARS_MINESTIMESPINBOX_H
+#define HEDGEWARS_MINESTIMESPINBOX_H
+
+#include <QObject>
+#include <QSpinBox>
+
+/**
+ * <code>SpinBox</code> that returns its value as localized mines time.
+ * @since  0.9.23
+ */
+class MinesTimeSpinBox : public QSpinBox
+{
+        Q_OBJECT
+
+    public:
+        /**
+         * @brief Class constructor.
+         * @param parent parent widget.
+         */
+        MinesTimeSpinBox(QWidget * parent);
+
+    protected:
+        /**
+         * Returns it's value localized.
+         * @param value integer value to be representing as string.
+         * @return string representation
+         */
+        QString textFromValue(int value) const;
+};
+
+
+#endif // HEDGEWARS_MINESTIMESPINBOX_H
--- a/share/hedgewars/Data/Locale/hedgewars_en.ts	Fri May 06 17:26:06 2016 +0200
+++ b/share/hedgewars/Data/Locale/hedgewars_en.ts	Fri May 06 18:33:54 2016 +0200
@@ -138,6 +138,20 @@
     </message>
 </context>
 <context>
+    <name>MinesTimeSpinBox</name>
+    <message>
+        <source>Random</source>
+        <translation>Random</translation>
+    </message>
+    <message numerus="yes">
+        <source>%1 seconds</source>
+        <translation>
+            <numerusform>%1 second</numerusform>
+            <numerusform>%1 seconds</numerusform>
+        </translation>
+    </message>
+</context>
+<context>
     <name>GameCFGWidget</name>
     <message>
         <source>Edit weapons</source>
@@ -1440,14 +1454,6 @@
         <translation>Your hogs are unable to move, put your artillery skills to the test</translation>
     </message>
     <message>
-        <source>Random</source>
-        <translation>Random</translation>
-    </message>
-    <message>
-        <source>Seconds</source>
-        <translation>Seconds</translation>
-    </message>
-    <message>
         <source>New</source>
         <translation>New</translation>
     </message>