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