1
//=============================================================================
3
// File : class_spinbox.cpp
4
// Creation date : Fri Mar 18 14:30:48 CEST 2005
5
// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor)
7
// This file is part of the KVirc irc client distribution
8
// Copyright (C) 2005-2008 Alessandro Carbone (elfonol at gmail dot com)
10
// This program is FREE software. You can redistribute it and/or
11
// modify it under the terms of the GNU General Public License
12
// as published by the Free Software Foundation; either version 2
13
// of the License, or (at your opinion) any later version.
15
// This program is distributed in the HOPE that it will be USEFUL,
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18
// See the GNU General Public License for more details.
20
// You should have received a copy of the GNU General Public License
21
// along with this program. If not, write to the Free Software Foundation,
22
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24
//=============================================================================
26
#include "class_spinbox.h"
27
#include "kvi_error.h"
28
#include "kvi_debug.h"
29
#include "kvi_locale.h"
30
#include "kvi_iconmanager.h"
42
Provides a simple spin button.
47
This widget allows the user to choose a value either by clicking the up/down buttons
48
to increase/decrease the value currently displayed or by typing the value directly into the spin box.
50
!fn: $setValue(<value:integer>)
51
Sets the value of the spin box.[br]
52
See also [classfnc]$value[/classfnc]()
53
!fn: $setMinValue(<min_value:integer>)
54
Sets the minimum value of the spin box.
55
See also [classfnc]$MinValue[/classfnc]()
56
!fn: $setMaxValue(<max_value:integer>)
57
Sets the maximum value of the spin box.[br]
58
See also [classfnc]$maxValue[/classfnc]()
59
!fn: $setLineStep(<line_step:integer>)
60
Sets the line step: when the user uses the arrows to change the spin box's value the value will be
61
incremented/decremented by the amount of the line step.
62
See also [classfnc]$lineStep[/classfnc]()
63
!fn: $setSpecialValueText(<text:string>)
64
Sets the special-value text.
65
If set, the spin box will display this text instead of a numeric value whenever the current value is equal to [classfnc]$minValue[/classfnc]().
66
See also [classfnc]$setSpecialValueText[/classfnc]()
67
!fn: $setPrefix(<text:string>)
68
This property holds the spin box's prefix.[br]
69
The prefix is prepended to the start of the displayed value.[br]
70
Typical use is to display a unit of measurement or a currency symbol.
71
See also [classfnc]$setSuffix[/classfnc]()
72
!fn: $setSuffix(<text:string>);
73
This property holds the suffix of the spin box.[br]
74
The suffix is appended to the end of the displayed value.[br]
75
See also [classfnc]$setPrefix[/classfnc]()
76
!fn: <integer> $value()
77
Returns the value of the spin box.
78
See also [classfnc]$setValue[/classfnc]()
79
!fn: <integer> $minValue
80
Returns the minimum value of the spin box.
81
See also [classfnc]$setMinValue[/classfnc]()
82
!fn: <integer> $maxValue
83
Returns the maximum value of the spin box.
84
See also [classfnc]$setMaxValue[/classfnc]()
85
!fn: <integer> $lineStep()
87
!fn: <string> $specialValueText()
88
Returns the special-value text.
89
See also [classfnc]$setSpecialValueText[/classfnc]()
90
!fn: $valueChangedEvent(<new value:integer>)
91
This function is called by the framework when the spinbox value is changed and return the new slider value as its argument.[br]
92
The default implementation emits the [classfnc]$valueChanged[/classfnc]() signal,
93
so it is easy to handle the values from many spinboxes without reimplementing
94
the [classfnc]$valueChangedEvent[/classfnc]() for every one.[br]
95
Note: If you reimplement this function to catch the spinbox value, you will have to emit the signal by yourself (if you still need it, obviously).
98
This signal is emitted by the default implementation of [classfnc]valueChangedEvent[/classfnc]().[br]
99
If you reimplement that function you will have to emit the signal manually (if you still need it).
103
KVSO_BEGIN_REGISTERCLASS(KviKvsObject_spinbox,"spinbox","widget")
107
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_spinbox,setValue);
108
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_spinbox,setMinValue);
109
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_spinbox,setMaxValue);
110
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_spinbox,setLineStep);
111
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_spinbox,setSpecialValueText);
112
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_spinbox,value);
113
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_spinbox,minValue);
114
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_spinbox,maxValue);
115
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_spinbox,lineStep);
116
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_spinbox,specialValueText);
118
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_spinbox,setPrefix);
119
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_spinbox,setSuffix);
122
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_spinbox,valueChangedEvent);
123
KVSO_END_REGISTERCLASS(KviKvsObject_spinbox)
125
KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_spinbox,KviKvsObject_widget)
127
KVSO_END_CONSTRUCTOR(KviKvsObject_spinbox)
130
KVSO_BEGIN_DESTRUCTOR(KviKvsObject_spinbox)
132
KVSO_END_CONSTRUCTOR(KviKvsObject_spinbox)
134
bool KviKvsObject_spinbox::init(KviKvsRunTimeContext *,KviKvsVariantList *)
137
connect(widget(),SIGNAL(valueChanged(int)),this,SLOT(valueChanged(int)));
143
KVSO_CLASS_FUNCTION(spinbox,setValue)
145
CHECK_INTERNAL_POINTER(widget())
147
KVSO_PARAMETERS_BEGIN(c)
148
KVSO_PARAMETER("value",KVS_PT_INT,0,iValue)
149
KVSO_PARAMETERS_END(c)
150
((QSpinBox *)widget())->setValue(iValue);
153
KVSO_CLASS_FUNCTION(spinbox,setMinValue)
155
CHECK_INTERNAL_POINTER(widget())
157
KVSO_PARAMETERS_BEGIN(c)
158
KVSO_PARAMETER("min_value",KVS_PT_INT,0,iMinvalue)
159
KVSO_PARAMETERS_END(c)
160
((QSpinBox *)widget())->setMinimum(iMinvalue);
163
KVSO_CLASS_FUNCTION(spinbox,setMaxValue)
165
CHECK_INTERNAL_POINTER(widget())
167
KVSO_PARAMETERS_BEGIN(c)
168
KVSO_PARAMETER("max_value",KVS_PT_INT,0,iMaxvalue)
169
KVSO_PARAMETERS_END(c)
170
((QSpinBox *)widget())->setMaximum(iMaxvalue);
174
KVSO_CLASS_FUNCTION(spinbox,setLineStep)
176
CHECK_INTERNAL_POINTER(widget())
178
KVSO_PARAMETERS_BEGIN(c)
179
KVSO_PARAMETER("line_step",KVS_PT_INT,0,iLinestep)
180
KVSO_PARAMETERS_END(c)
181
((QSpinBox *)widget())->setSingleStep(iLinestep);
186
KVSO_CLASS_FUNCTION(spinbox,value)
188
CHECK_INTERNAL_POINTER(widget())
189
c->returnValue()->setInteger(((QSpinBox *)widget())->value());
193
KVSO_CLASS_FUNCTION(spinbox,minValue)
195
CHECK_INTERNAL_POINTER(widget())
196
c->returnValue()->setInteger(((QSpinBox *)widget())->minimum());
199
KVSO_CLASS_FUNCTION(spinbox,maxValue)
201
CHECK_INTERNAL_POINTER(widget())
202
c->returnValue()->setInteger(((QSpinBox *)widget())->maximum());
205
KVSO_CLASS_FUNCTION(spinbox,lineStep)
207
CHECK_INTERNAL_POINTER(widget())
208
c->returnValue()->setInteger(((QSpinBox *)widget())->singleStep());
213
KVSO_CLASS_FUNCTION(spinbox,specialValueText)
215
CHECK_INTERNAL_POINTER(widget())
216
c->returnValue()->setString(((QSpinBox *)widget())->specialValueText());
221
KVSO_CLASS_FUNCTION(spinbox,setSpecialValueText)
223
CHECK_INTERNAL_POINTER(widget())
225
KVSO_PARAMETERS_BEGIN(c)
226
KVSO_PARAMETER("text",KVS_PT_STRING,0,szText)
227
KVSO_PARAMETERS_END(c)
228
((QSpinBox *)widget())->setSpecialValueText(szText);
231
KVSO_CLASS_FUNCTION(spinbox,setPrefix)
233
CHECK_INTERNAL_POINTER(widget())
235
KVSO_PARAMETERS_BEGIN(c)
236
KVSO_PARAMETER("text",KVS_PT_STRING,0,szPrefix)
237
KVSO_PARAMETERS_END(c)
238
((QSpinBox *)widget())->setPrefix(szPrefix);
241
KVSO_CLASS_FUNCTION(spinbox,setSuffix)
243
CHECK_INTERNAL_POINTER(widget())
245
KVSO_PARAMETERS_BEGIN(c)
246
KVSO_PARAMETER("text",KVS_PT_STRING,0,szSuffix)
247
KVSO_PARAMETERS_END(c)
248
((QSpinBox *)widget())->setSuffix(szSuffix);
252
KVSO_CLASS_FUNCTION(spinbox,valueChangedEvent)
254
emitSignal("valueChanged",c,c->params());
258
void KviKvsObject_spinbox::valueChanged(int value)
260
KviKvsVariantList params(new KviKvsVariant((kvs_int_t)value));
261
callFunction(this,"valueChangedEvent",¶ms);
264
#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES
265
#include "m_class_spinbox.moc"
266
#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES