1 /*
2  * This file is part of Licq, an instant messaging client for UNIX.
3  * Copyright (C) 2012 Licq developers <licq-dev@googlegroups.com>
4  *
5  * Licq 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; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * Licq is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with Licq; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  */
19 
20 #include "specialspinbox.h"
21 
22 using namespace LicqQtGui;
23 /* TRANSLATOR LicqQtGui::SpecialSpinBox */
24 
SpecialSpinBox(int minimum,int maximum,const QString & specialValueText,QWidget * parent)25 SpecialSpinBox::SpecialSpinBox(int minimum, int maximum, const QString& specialValueText, QWidget* parent)
26   : QSpinBox(parent)
27 {
28   setRange(minimum, maximum);
29   setSpecialValueText(specialValueText);
30   setAccelerated(true);
31 
32   // Values are numeric so aligning right makes more sense
33   setAlignment(Qt::AlignRight);
34 
35   // Let empty value go to special value instead of previous
36   setCorrectionMode(QSpinBox::CorrectToNearestValue);
37   connect(this, SIGNAL(editingFinished()), SLOT(finished()));
38 }
39 
finished()40 void SpecialSpinBox::finished()
41 {
42   // Default to special text if input is bad
43   if (!hasAcceptableInput())
44     setValue(minimum());
45 }
46