1
//=============================================================================
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)
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 "KvsObject_slider.h"
28
#include "kvi_debug.h"
29
#include "KviLocale.h"
30
#include "KviIconManager.h"
44
The slider widget provides a vertical or horizontal slider.
49
The slider is the classic widget for controlling a bounded value.[br]
50
It lets the user move a slider along a horizontal or vertical groove [br]
51
and translates the slider's position into an integer value within the legal range.[/classfnc]()
53
!fn: $setOrientation(<orientation:string>)
54
Sets the slider's orientation.[br]
55
Orientation value can be "Horizontal" or "Vertical".
56
!fn: $setTracking(<bTracking:boolean>)
57
Sets whether slider tracking is enabled to enable.[br]
59
!fn: $setMaxValue(<value:integer>)
60
Sets maximum value for slider's range.
61
!fn: $setMinValue(<minv_value:integer>)
62
Sets minimum value for slider's range.
63
!fn: $setLineStep(<line_step:integer>)
64
Sets the line step to <line_step>.
65
!fn: $setPageStep(<page_step:integer>)
66
Sets the page step to <page_step>.
67
!fn: $setTickmarks(<tick_marks:string>)
68
Sets the tickmark settings for this slider.[br]
70
NoMarks - do not draw any tickmarks.[br]
71
Both - draw tickmarks on both sides of the groove.[br]
72
Above - draw tickmarks above the (horizontal) slider[br]
73
Below - draw tickmarks below the (horizontal) slider[br]
74
Left - draw tickmarks to the left of the (vertical) slider[br]
75
Right - draw tickmarks to the right of the (vertical) slider
76
!fn: $setTickInterval(<value>)
77
Sets the interval between tickmarks.
78
!fn: <integer> $value()
80
!fn: <integer> $minValue()
81
Returns slider minValue.
82
!fn: <integer> $maxValue()
83
Returns slider maxValue.
84
!fn: <integer> $lineStep()
85
Returns slider lineStep value.
86
!fn: <integer>$pageStep()
87
Returns slider pageStep value.
88
!fn: $valueChangedEvent(<new slider value:integer>)
89
This function is called by the framework when the slider value is changed and return the new slider value as its argument.[br]
90
The default implementation emits the [classfnc]$valueChanged[/classfnc]() signal,
91
so it is easy to handle the values from many sliders without reimplementing
92
the [classfnc]$valueChangedEvent[/classfnc]() for every one.[br]
93
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).
96
This signal is emitted by the default implementation of [classfnc]valueChangedEvent[/classfnc]().[br]
97
If you reimplement that function you will have to emit the signal manually (if you still need it).
103
KVSO_BEGIN_REGISTERCLASS(KvsObject_slider,"slider","widget")
106
KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider,setTracking);
107
KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider,setValue);
108
KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider,setMinValue);
109
KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider,setMaxValue);
110
KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider,setLineStep);
111
KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider,setPageStep);
112
KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider,setTickInterval);
113
KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider,value);
114
KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider,minValue);
115
KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider,maxValue);
116
KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider,lineStep);
117
KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider,pageStep);
118
KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider,setTickmarks);
119
KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider,setOrientation);
122
KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider,valueChangedEvent);
123
KVSO_END_REGISTERCLASS(KvsObject_slider)
125
KVSO_BEGIN_CONSTRUCTOR(KvsObject_slider,KvsObject_widget)
127
KVSO_END_CONSTRUCTOR(KvsObject_slider)
130
KVSO_BEGIN_DESTRUCTOR(KvsObject_slider)
132
KVSO_END_CONSTRUCTOR(KvsObject_slider)
134
bool KvsObject_slider::init(KviKvsRunTimeContext *,KviKvsVariantList *)
137
connect(widget(),SIGNAL(valueChanged(int)),this,SLOT(valueChanged(int)));
141
KVSO_CLASS_FUNCTION(slider,setTracking)
143
CHECK_INTERNAL_POINTER(widget())
145
KVSO_PARAMETERS_BEGIN(c)
146
KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled)
147
KVSO_PARAMETERS_END(c)
148
((QSlider *)widget())->setTracking(bEnabled);
153
KVSO_CLASS_FUNCTION(slider,setValue)
155
CHECK_INTERNAL_POINTER(widget())
157
KVSO_PARAMETERS_BEGIN(c)
158
KVSO_PARAMETER("value",KVS_PT_INT,0,iValue)
159
KVSO_PARAMETERS_END(c)
160
((QSlider *)widget())->setValue(iValue);
163
KVSO_CLASS_FUNCTION(slider,setMinValue)
165
CHECK_INTERNAL_POINTER(widget())
167
KVSO_PARAMETERS_BEGIN(c)
168
KVSO_PARAMETER("minimum_value",KVS_PT_INT,0,iMinvalue)
169
KVSO_PARAMETERS_END(c)
170
((QSlider *)widget())->setMinimum(iMinvalue);
173
KVSO_CLASS_FUNCTION(slider,setMaxValue)
175
CHECK_INTERNAL_POINTER(widget())
177
KVSO_PARAMETERS_BEGIN(c)
178
KVSO_PARAMETER("max_value",KVS_PT_INT,0,iMaxvalue)
179
KVSO_PARAMETERS_END(c)
180
((QSlider *)widget())->setMaximum(iMaxvalue);
184
KVSO_CLASS_FUNCTION(slider,setLineStep)
186
CHECK_INTERNAL_POINTER(widget())
188
KVSO_PARAMETERS_BEGIN(c)
189
KVSO_PARAMETER("line_step",KVS_PT_INT,0,iLinestep)
190
KVSO_PARAMETERS_END(c)
191
((QSlider *)widget())->setSingleStep(iLinestep);
194
KVSO_CLASS_FUNCTION(slider,setPageStep)
196
CHECK_INTERNAL_POINTER(widget())
198
KVSO_PARAMETERS_BEGIN(c)
199
KVSO_PARAMETER("page_step",KVS_PT_INT,0,iPagestep)
200
KVSO_PARAMETERS_END(c)
201
if (widget()) ((QSlider *)widget())->setPageStep(iPagestep);
205
KVSO_CLASS_FUNCTION(slider,setTickInterval)
208
KVSO_PARAMETERS_BEGIN(c)
209
KVSO_PARAMETER("tick_interval",KVS_PT_INT,0,iInterval)
210
KVSO_PARAMETERS_END(c)
211
((QSlider *)widget())->setTickInterval(iInterval);
215
KVSO_CLASS_FUNCTION(slider,value)
217
CHECK_INTERNAL_POINTER(widget())
218
c->returnValue()->setInteger(((QSlider *)widget())->value());
222
KVSO_CLASS_FUNCTION(slider,minValue)
224
CHECK_INTERNAL_POINTER(widget())
225
c->returnValue()->setInteger(((QSlider *)widget())->minimum());
228
KVSO_CLASS_FUNCTION(slider,maxValue)
230
CHECK_INTERNAL_POINTER(widget())
231
c->returnValue()->setInteger(((QSlider *)widget())->maximum());
234
KVSO_CLASS_FUNCTION(slider,lineStep)
236
CHECK_INTERNAL_POINTER(widget())
237
c->returnValue()->setInteger(((QSlider *)widget())->singleStep());
241
KVSO_CLASS_FUNCTION(slider,pageStep)
243
CHECK_INTERNAL_POINTER(widget())
244
c->returnValue()->setInteger(((QSlider *)widget())->pageStep());
249
KVSO_CLASS_FUNCTION(slider,setTickmarks)
251
CHECK_INTERNAL_POINTER(widget())
253
KVSO_PARAMETERS_BEGIN(c)
254
KVSO_PARAMETER("tick_marks",KVS_PT_STRING,0,szTick)
255
KVSO_PARAMETERS_END(c)
256
if(KviQString::equalCI(szTick,"NoMarks"))
257
((QSlider *)widget())->setTickPosition(QSlider::NoTicks);
258
else if(KviQString::equalCI(szTick,"Both"))
259
((QSlider *)widget())->setTickPosition(QSlider::TicksBothSides);
260
else if(KviQString::equalCI(szTick,"Above"))
261
((QSlider *)widget())->setTickPosition(QSlider::TicksAbove);
262
else if(KviQString::equalCI(szTick,"Below"))
263
((QSlider *)widget())->setTickPosition(QSlider::TicksBelow);
264
else if(KviQString::equalCI(szTick,"Left"))
265
((QSlider *)widget())->setTickPosition(QSlider::TicksLeft);
266
else if(KviQString::equalCI(szTick,"Right"))
267
((QSlider *)widget())->setTickPosition(QSlider::TicksRight);
268
else c->warning( __tr2qs_ctx("Unknown tickmark '%Q'","objects"),&szTick);
271
KVSO_CLASS_FUNCTION(slider,setOrientation)
273
CHECK_INTERNAL_POINTER(widget())
274
QString szOrientation;
275
KVSO_PARAMETERS_BEGIN(c)
276
KVSO_PARAMETER("orientation",KVS_PT_STRING,0,szOrientation)
277
KVSO_PARAMETERS_END(c)
278
if(KviQString::equalCI(szOrientation,"Horizontal"))
279
((QSlider *)widget())->setOrientation(Qt::Horizontal);
280
else if(KviQString::equalCI(szOrientation,"Vertical"))
281
((QSlider *)widget())->setOrientation(Qt::Vertical);
282
else c->warning( __tr2qs_ctx("Unknown orientation '%Q'","objects"),&szOrientation);
285
KVSO_CLASS_FUNCTION(slider,valueChangedEvent)
287
emitSignal("valueChanged",c,c->params());
291
void KvsObject_slider::valueChanged(int value)
293
KviKvsVariantList params(new KviKvsVariant((kvs_int_t)value));
294
callFunction(this,"valueChangedEvent",¶ms);
298
#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES
299
#include "m_KvsObject_slider.moc"
300
#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES