1 //=============================================================================
2 //
3 // File : KvsObject_slider.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_slider.h"
27 #include "KviError.h"
28 #include "kvi_debug.h"
29 #include "KviLocale.h"
30 #include "KviIconManager.h"
31
32 #include <QSlider>
33
34 /*
35 @doc: slider
36 @keyterms:
37 slider object class
38 @title:
39 slider class
40 @type:
41 class
42 @short:
43 The slider widget provides a vertical or horizontal slider.
44 @inherits:
45 [class]object[/class]
46 [class]widget[/class]
47 @description:
48 The slider is the classic widget for controlling a bounded value.[br]
49 It lets the user move a slider along a horizontal or vertical groove[br]
50 and translates the slider's position into an integer value within the legal range.[/classfnc]()
51 @functions:
52 !fn: $setOrientation(<orientation:string>)
53 Sets the slider's orientation.[br]
54 Orientation value can be "Horizontal" or "Vertical".
55 !fn: $setTracking(<bTracking:boolean>)
56 Sets whether slider tracking is enabled to enable.[br]
57 Value can be 1 or 0.
58 !fn: $setMaxValue(<value:integer>)
59 Sets maximum value for slider's range.
60 !fn: $setMinValue(<minv_value:integer>)
61 Sets minimum value for slider's range.
62 !fn: $setLineStep(<line_step:integer>)
63 Sets the line step to <line_step>.
64 !fn: $setPageStep(<page_step:integer>)
65 Sets the page step to <page_step>.
66 !fn: $setTickmarks(<tick_marks:string>)
67 Sets the tickmark settings for this slider.[br]
68 Values are:[br]
69 [pre]
70 NoMarks - do not draw any tickmarks.
71 Both - draw tickmarks on both sides of the groove.
72 Above - draw tickmarks above the (horizontal) slider
73 Below - draw tickmarks below the (horizontal) slider
74 Left - draw tickmarks to the left of the (vertical) slider
75 Right - draw tickmarks to the right of the (vertical) slider
76 [/pre]
77 !fn: $setTickInterval(<value>)
78 Sets the interval between tickmarks.
79 !fn: <integer> $value()
80 Returns slider value.
81 !fn: <integer> $minValue()
82 Returns slider minValue.
83 !fn: <integer> $maxValue()
84 Returns slider maxValue.
85 !fn: <integer> $lineStep()
86 Returns slider lineStep value.
87 !fn: <integer>$pageStep()
88 Returns slider pageStep value.
89 !fn: $valueChangedEvent(<new slider value:integer>)
90 This function is called by the framework when the slider value is changed and return the new slider value as its argument.[br]
91 The default implementation emits the [classfnc]$valueChanged[/classfnc]() signal,
92 so it is easy to handle the values from many sliders without reimplementing
93 the [classfnc]$valueChangedEvent[/classfnc]() for every one.[br]
94 Note: If you reimplement this function to catch the slider value, you will have to emit the signal by yourself (if you still need it, obviously).
95 @signals:
96 !sg: $valueChanged()
97 This signal is emitted by the default implementation of [classfnc]valueChangedEvent[/classfnc]().[br]
98 If you reimplement that function you will have to emit the signal manually (if you still need it).
99 */
100
101 KVSO_BEGIN_REGISTERCLASS(KvsObject_slider, "slider", "widget")
102
103 KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider, setTracking);
104 KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider, setValue);
105 KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider, setMinValue);
106 KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider, setMaxValue);
107 KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider, setLineStep);
108 KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider, setPageStep);
109 KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider, setTickInterval);
110 KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider, value);
111 KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider, minValue);
112 KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider, maxValue);
113 KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider, lineStep);
114 KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider, pageStep);
115 KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider, setTickmarks);
116 KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider, setOrientation);
117
118 KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider, valueChangedEvent);
119 KVSO_END_REGISTERCLASS(KvsObject_slider)
120
KVSO_BEGIN_CONSTRUCTOR(KvsObject_slider,KvsObject_widget)121 KVSO_BEGIN_CONSTRUCTOR(KvsObject_slider, KvsObject_widget)
122
123 KVSO_END_CONSTRUCTOR(KvsObject_slider)
124
125 KVSO_BEGIN_DESTRUCTOR(KvsObject_slider)
126
127 KVSO_END_CONSTRUCTOR(KvsObject_slider)
128
129 bool KvsObject_slider::init(KviKvsRunTimeContext *, KviKvsVariantList *)
130 {
131 SET_OBJECT(QSlider)
132 connect(widget(), SIGNAL(valueChanged(int)), this, SLOT(valueChanged(int)));
133 return true;
134 }
135
KVSO_CLASS_FUNCTION(slider,setTracking)136 KVSO_CLASS_FUNCTION(slider, setTracking)
137 {
138 CHECK_INTERNAL_POINTER(widget())
139 bool bEnabled;
140 KVSO_PARAMETERS_BEGIN(c)
141 KVSO_PARAMETER("bEnabled", KVS_PT_BOOL, 0, bEnabled)
142 KVSO_PARAMETERS_END(c)
143 ((QSlider *)widget())->setTracking(bEnabled);
144 return true;
145 }
146
KVSO_CLASS_FUNCTION(slider,setValue)147 KVSO_CLASS_FUNCTION(slider, setValue)
148 {
149 CHECK_INTERNAL_POINTER(widget())
150 kvs_int_t iValue;
151 KVSO_PARAMETERS_BEGIN(c)
152 KVSO_PARAMETER("value", KVS_PT_INT, 0, iValue)
153 KVSO_PARAMETERS_END(c)
154 ((QSlider *)widget())->setValue(iValue);
155 return true;
156 }
KVSO_CLASS_FUNCTION(slider,setMinValue)157 KVSO_CLASS_FUNCTION(slider, setMinValue)
158 {
159 CHECK_INTERNAL_POINTER(widget())
160 kvs_int_t iMinvalue;
161 KVSO_PARAMETERS_BEGIN(c)
162 KVSO_PARAMETER("minimum_value", KVS_PT_INT, 0, iMinvalue)
163 KVSO_PARAMETERS_END(c)
164 ((QSlider *)widget())->setMinimum(iMinvalue);
165 return true;
166 }
KVSO_CLASS_FUNCTION(slider,setMaxValue)167 KVSO_CLASS_FUNCTION(slider, setMaxValue)
168 {
169 CHECK_INTERNAL_POINTER(widget())
170 kvs_int_t iMaxvalue;
171 KVSO_PARAMETERS_BEGIN(c)
172 KVSO_PARAMETER("max_value", KVS_PT_INT, 0, iMaxvalue)
173 KVSO_PARAMETERS_END(c)
174 ((QSlider *)widget())->setMaximum(iMaxvalue);
175 return true;
176 }
177
KVSO_CLASS_FUNCTION(slider,setLineStep)178 KVSO_CLASS_FUNCTION(slider, setLineStep)
179 {
180 CHECK_INTERNAL_POINTER(widget())
181 kvs_int_t iLinestep;
182 KVSO_PARAMETERS_BEGIN(c)
183 KVSO_PARAMETER("line_step", KVS_PT_INT, 0, iLinestep)
184 KVSO_PARAMETERS_END(c)
185 ((QSlider *)widget())->setSingleStep(iLinestep);
186 return true;
187 }
KVSO_CLASS_FUNCTION(slider,setPageStep)188 KVSO_CLASS_FUNCTION(slider, setPageStep)
189 {
190 CHECK_INTERNAL_POINTER(widget())
191 kvs_int_t iPagestep;
192 KVSO_PARAMETERS_BEGIN(c)
193 KVSO_PARAMETER("page_step", KVS_PT_INT, 0, iPagestep)
194 KVSO_PARAMETERS_END(c)
195 if(widget())
196 ((QSlider *)widget())->setPageStep(iPagestep);
197 return true;
198 }
199
KVSO_CLASS_FUNCTION(slider,setTickInterval)200 KVSO_CLASS_FUNCTION(slider, setTickInterval)
201 {
202 kvs_int_t iInterval;
203 KVSO_PARAMETERS_BEGIN(c)
204 KVSO_PARAMETER("tick_interval", KVS_PT_INT, 0, iInterval)
205 KVSO_PARAMETERS_END(c)
206 ((QSlider *)widget())->setTickInterval(iInterval);
207 return true;
208 }
209
KVSO_CLASS_FUNCTION(slider,value)210 KVSO_CLASS_FUNCTION(slider, value)
211 {
212 CHECK_INTERNAL_POINTER(widget())
213 c->returnValue()->setInteger(((QSlider *)widget())->value());
214 return true;
215 }
216
KVSO_CLASS_FUNCTION(slider,minValue)217 KVSO_CLASS_FUNCTION(slider, minValue)
218 {
219 CHECK_INTERNAL_POINTER(widget())
220 c->returnValue()->setInteger(((QSlider *)widget())->minimum());
221 return true;
222 }
KVSO_CLASS_FUNCTION(slider,maxValue)223 KVSO_CLASS_FUNCTION(slider, maxValue)
224 {
225 CHECK_INTERNAL_POINTER(widget())
226 c->returnValue()->setInteger(((QSlider *)widget())->maximum());
227 return true;
228 }
KVSO_CLASS_FUNCTION(slider,lineStep)229 KVSO_CLASS_FUNCTION(slider, lineStep)
230 {
231 CHECK_INTERNAL_POINTER(widget())
232 c->returnValue()->setInteger(((QSlider *)widget())->singleStep());
233 return true;
234 }
235
KVSO_CLASS_FUNCTION(slider,pageStep)236 KVSO_CLASS_FUNCTION(slider, pageStep)
237 {
238 CHECK_INTERNAL_POINTER(widget())
239 c->returnValue()->setInteger(((QSlider *)widget())->pageStep());
240 return true;
241 }
242
KVSO_CLASS_FUNCTION(slider,setTickmarks)243 KVSO_CLASS_FUNCTION(slider, setTickmarks)
244 {
245 CHECK_INTERNAL_POINTER(widget())
246 QString szTick;
247 KVSO_PARAMETERS_BEGIN(c)
248 KVSO_PARAMETER("tick_marks", KVS_PT_STRING, 0, szTick)
249 KVSO_PARAMETERS_END(c)
250 if(KviQString::equalCI(szTick, "NoMarks"))
251 ((QSlider *)widget())->setTickPosition(QSlider::NoTicks);
252 else if(KviQString::equalCI(szTick, "Both"))
253 ((QSlider *)widget())->setTickPosition(QSlider::TicksBothSides);
254 else if(KviQString::equalCI(szTick, "Above"))
255 ((QSlider *)widget())->setTickPosition(QSlider::TicksAbove);
256 else if(KviQString::equalCI(szTick, "Below"))
257 ((QSlider *)widget())->setTickPosition(QSlider::TicksBelow);
258 else if(KviQString::equalCI(szTick, "Left"))
259 ((QSlider *)widget())->setTickPosition(QSlider::TicksLeft);
260 else if(KviQString::equalCI(szTick, "Right"))
261 ((QSlider *)widget())->setTickPosition(QSlider::TicksRight);
262 else
263 c->warning(__tr2qs_ctx("Unknown tickmark '%Q'", "objects"), &szTick);
264 return true;
265 }
KVSO_CLASS_FUNCTION(slider,setOrientation)266 KVSO_CLASS_FUNCTION(slider, setOrientation)
267 {
268 CHECK_INTERNAL_POINTER(widget())
269 QString szOrientation;
270 KVSO_PARAMETERS_BEGIN(c)
271 KVSO_PARAMETER("orientation", KVS_PT_STRING, 0, szOrientation)
272 KVSO_PARAMETERS_END(c)
273 if(KviQString::equalCI(szOrientation, "Horizontal"))
274 ((QSlider *)widget())->setOrientation(Qt::Horizontal);
275 else if(KviQString::equalCI(szOrientation, "Vertical"))
276 ((QSlider *)widget())->setOrientation(Qt::Vertical);
277 else
278 c->warning(__tr2qs_ctx("Unknown orientation '%Q'", "objects"), &szOrientation);
279 return true;
280 }
KVSO_CLASS_FUNCTION(slider,valueChangedEvent)281 KVSO_CLASS_FUNCTION(slider, valueChangedEvent)
282 {
283 emitSignal("valueChanged", c, c->params());
284 return true;
285 }
286
valueChanged(int value)287 void KvsObject_slider::valueChanged(int value)
288 {
289 KviKvsVariantList params(new KviKvsVariant((kvs_int_t)value));
290 callFunction(this, "valueChangedEvent", ¶ms);
291 }
292