1 //=============================================================================
2 //
3 // File : KvsObject_spinBox.cpp
4 // Creation date : Fri Mar 18 14:30:48 CEST 2005
5 // by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor)
6 //
7 // This file is part of the KVIrc IRC client distribution
8 // Copyright (C) 2005-2008 Alessandro Carbone (elfonol at gmail dot com)
9 //
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 option) any later version.
14 //
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.
19 //
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.
23 //
24 //=============================================================================
25
26 #include "KvsObject_spinBox.h"
27 #include "KviError.h"
28 #include "kvi_debug.h"
29 #include "KviLocale.h"
30 #include "KviIconManager.h"
31
32 #include <QSpinBox>
33 /*
34 @doc: spinbox
35 @keyterms:
36 spinbox object class,
37 @title:
38 spinbox class
39 @type:
40 class
41 @short:
42 Provides a simple spin button.
43 @inherits:
44 [class]object[/class]
45 [class]widget[/class]
46 @description:
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.
49 @functions:
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()
86 Return the 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 spin box 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 spin boxes without reimplementing
94 the [classfnc]$valueChangedEvent[/classfnc]() for every one.[br]
95 Note: If you reimplement this function to catch the spin box value, you will have to emit the signal by yourself (if you still need it, obviously).
96 @signals:
97 !sg: $valueChanged()
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).
100 */
101
102 KVSO_BEGIN_REGISTERCLASS(KvsObject_spinBox, "spinbox", "widget")
103
104 KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_spinBox, setValue);
105 KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_spinBox, setMinValue);
106 KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_spinBox, setMaxValue);
107 KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_spinBox, setLineStep);
108 KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_spinBox, setSpecialValueText);
109 KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_spinBox, value);
110 KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_spinBox, minValue);
111 KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_spinBox, maxValue);
112 KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_spinBox, lineStep);
113 KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_spinBox, specialValueText);
114
115 KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_spinBox, setPrefix);
116 KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_spinBox, setSuffix);
117
118 KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_spinBox, valueChangedEvent);
119 KVSO_END_REGISTERCLASS(KvsObject_spinBox)
120
KVSO_BEGIN_CONSTRUCTOR(KvsObject_spinBox,KvsObject_widget)121 KVSO_BEGIN_CONSTRUCTOR(KvsObject_spinBox, KvsObject_widget)
122
123 KVSO_END_CONSTRUCTOR(KvsObject_spinBox)
124
125 KVSO_BEGIN_DESTRUCTOR(KvsObject_spinBox)
126
127 KVSO_END_CONSTRUCTOR(KvsObject_spinBox)
128
129 bool KvsObject_spinBox::init(KviKvsRunTimeContext *, KviKvsVariantList *)
130 {
131 SET_OBJECT(QSpinBox)
132 connect(widget(), SIGNAL(valueChanged(int)), this, SLOT(valueChanged(int)));
133 return true;
134 }
135
KVSO_CLASS_FUNCTION(spinBox,setValue)136 KVSO_CLASS_FUNCTION(spinBox, setValue)
137 {
138 CHECK_INTERNAL_POINTER(widget())
139 kvs_int_t iValue;
140 KVSO_PARAMETERS_BEGIN(c)
141 KVSO_PARAMETER("value", KVS_PT_INT, 0, iValue)
142 KVSO_PARAMETERS_END(c)
143 ((QSpinBox *)widget())->setValue(iValue);
144 return true;
145 }
KVSO_CLASS_FUNCTION(spinBox,setMinValue)146 KVSO_CLASS_FUNCTION(spinBox, setMinValue)
147 {
148 CHECK_INTERNAL_POINTER(widget())
149 kvs_int_t iMinvalue;
150 KVSO_PARAMETERS_BEGIN(c)
151 KVSO_PARAMETER("min_value", KVS_PT_INT, 0, iMinvalue)
152 KVSO_PARAMETERS_END(c)
153 ((QSpinBox *)widget())->setMinimum(iMinvalue);
154 return true;
155 }
KVSO_CLASS_FUNCTION(spinBox,setMaxValue)156 KVSO_CLASS_FUNCTION(spinBox, setMaxValue)
157 {
158 CHECK_INTERNAL_POINTER(widget())
159 kvs_int_t iMaxvalue;
160 KVSO_PARAMETERS_BEGIN(c)
161 KVSO_PARAMETER("max_value", KVS_PT_INT, 0, iMaxvalue)
162 KVSO_PARAMETERS_END(c)
163 ((QSpinBox *)widget())->setMaximum(iMaxvalue);
164 return true;
165 }
166
KVSO_CLASS_FUNCTION(spinBox,setLineStep)167 KVSO_CLASS_FUNCTION(spinBox, setLineStep)
168 {
169 CHECK_INTERNAL_POINTER(widget())
170 kvs_int_t iLinestep;
171 KVSO_PARAMETERS_BEGIN(c)
172 KVSO_PARAMETER("line_step", KVS_PT_INT, 0, iLinestep)
173 KVSO_PARAMETERS_END(c)
174 ((QSpinBox *)widget())->setSingleStep(iLinestep);
175 return true;
176 }
177
KVSO_CLASS_FUNCTION(spinBox,value)178 KVSO_CLASS_FUNCTION(spinBox, value)
179 {
180 CHECK_INTERNAL_POINTER(widget())
181 c->returnValue()->setInteger(((QSpinBox *)widget())->value());
182 return true;
183 }
184
KVSO_CLASS_FUNCTION(spinBox,minValue)185 KVSO_CLASS_FUNCTION(spinBox, minValue)
186 {
187 CHECK_INTERNAL_POINTER(widget())
188 c->returnValue()->setInteger(((QSpinBox *)widget())->minimum());
189 return true;
190 }
KVSO_CLASS_FUNCTION(spinBox,maxValue)191 KVSO_CLASS_FUNCTION(spinBox, maxValue)
192 {
193 CHECK_INTERNAL_POINTER(widget())
194 c->returnValue()->setInteger(((QSpinBox *)widget())->maximum());
195 return true;
196 }
KVSO_CLASS_FUNCTION(spinBox,lineStep)197 KVSO_CLASS_FUNCTION(spinBox, lineStep)
198 {
199 CHECK_INTERNAL_POINTER(widget())
200 c->returnValue()->setInteger(((QSpinBox *)widget())->singleStep());
201 return true;
202 }
203
KVSO_CLASS_FUNCTION(spinBox,specialValueText)204 KVSO_CLASS_FUNCTION(spinBox, specialValueText)
205 {
206 CHECK_INTERNAL_POINTER(widget())
207 c->returnValue()->setString(((QSpinBox *)widget())->specialValueText());
208 return true;
209 }
210
KVSO_CLASS_FUNCTION(spinBox,setSpecialValueText)211 KVSO_CLASS_FUNCTION(spinBox, setSpecialValueText)
212 {
213 CHECK_INTERNAL_POINTER(widget())
214 QString szText;
215 KVSO_PARAMETERS_BEGIN(c)
216 KVSO_PARAMETER("text", KVS_PT_STRING, 0, szText)
217 KVSO_PARAMETERS_END(c)
218 ((QSpinBox *)widget())->setSpecialValueText(szText);
219 return true;
220 }
KVSO_CLASS_FUNCTION(spinBox,setPrefix)221 KVSO_CLASS_FUNCTION(spinBox, setPrefix)
222 {
223 CHECK_INTERNAL_POINTER(widget())
224 QString szPrefix;
225 KVSO_PARAMETERS_BEGIN(c)
226 KVSO_PARAMETER("text", KVS_PT_STRING, 0, szPrefix)
227 KVSO_PARAMETERS_END(c)
228 ((QSpinBox *)widget())->setPrefix(szPrefix);
229 return true;
230 }
KVSO_CLASS_FUNCTION(spinBox,setSuffix)231 KVSO_CLASS_FUNCTION(spinBox, setSuffix)
232 {
233 CHECK_INTERNAL_POINTER(widget())
234 QString szSuffix;
235 KVSO_PARAMETERS_BEGIN(c)
236 KVSO_PARAMETER("text", KVS_PT_STRING, 0, szSuffix)
237 KVSO_PARAMETERS_END(c)
238 ((QSpinBox *)widget())->setSuffix(szSuffix);
239 return true;
240 }
241
KVSO_CLASS_FUNCTION(spinBox,valueChangedEvent)242 KVSO_CLASS_FUNCTION(spinBox, valueChangedEvent)
243 {
244 emitSignal("valueChanged", c, c->params());
245 return true;
246 }
247
valueChanged(int value)248 void KvsObject_spinBox::valueChanged(int value)
249 {
250 KviKvsVariantList params(new KviKvsVariant((kvs_int_t)value));
251 callFunction(this, "valueChangedEvent", ¶ms);
252 }
253