QTfrontend/ui/widget/SDTimeoutSpinBox.cpp
author Wuzzy <Wuzzy2@mail.ru>
Tue, 07 May 2019 18:45:14 +0200
changeset 14899 4d5df8d35a95
parent 13817 419de2dea82b
permissions -rw-r--r--
Display a warning when the same key is used multiple times
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13817
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     1
/*
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     2
 * Hedgewars, a free turn based strategy game
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     3
 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     4
 *
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     8
 *
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    12
 * GNU General Public License for more details.
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    13
 *
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    17
 */
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    18
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    19
/**
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    20
 * @file
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    21
 * @brief SDTimeoutSpinBox class implementation
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    22
 */
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    23
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    24
#include "SDTimeoutSpinBox.h"
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    25
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    26
SDTimeoutSpinBox::SDTimeoutSpinBox(QWidget* parent) : QSpinBox(parent)
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    27
{
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    28
    // do nothing
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    29
};
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    30
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    31
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    32
QString SDTimeoutSpinBox::textFromValue(int internalValue) const
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    33
{
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    34
    // user-facing value = internal value + 1
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    35
    return QString::number(internalValue + 1);
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    36
}
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    37
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    38
int SDTimeoutSpinBox::valueFromText(const QString & userFacingString) const
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    39
{
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    40
    // internal value = user-facing value - 1
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    41
    bool ok;
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    42
    int value = userFacingString.toInt(&ok);
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    43
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    44
    if (ok)
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    45
        return value - 1;
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    46
    // Fallback
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    47
    else
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    48
        return 15;
419de2dea82b Fix frontend displayed value of Sudden Death timeout being off-by-one
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    49
}