1
//=============================================================================
3
// File : class_combobox.cpp
4
// Creation date : Wed 13 Sep 2000 02:42:05 CEST by Krzysztof Godlewski
6
// This file is part of the KVirc irc client distribution
7
// Copyright (C) 2000 Krzysztof Godlewski
8
// Copyright (C) 2000-2009 Szymon Stefanek (pragma at kvirc dot net)
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
//=============================================================================
27
#include "kvi_error.h"
28
#include "kvi_locale.h"
29
#include "kvi_debug.h"
30
#include "class_list.h"
31
#include "class_combobox.h"
40
combobox object class, selection
46
Combined button and popup list
52
!fn: $insertItem(<text:string>, <index:int>)
53
Inserts a text item at position <index>. If index is negative or
54
not specified the item is appended.
55
!fn: $changeItem(<text:string>, <index:uint>)
56
Changes text of item at <index> to <text>.
57
!fn: $removeItem(<index:uint>)
58
Removes item at given index.
59
!fn: $setMaxCount(<num:uint>)
60
Sets the maximum number of items the combo box can hold to
61
<num>. If <num> is smaller than the current number of items,
62
the list is truncated at the end. There is no limit by default.
63
!fn: <integer> $maxCount()
64
Returns the current maximum number of items in the combo box.
65
!fn: <integer> $count()
66
Returns number of items in the widget.
67
!fn: <string> $current()
68
Returns currently selected item.
69
!fn: <integer> $currentItem()
70
Returns index of currently selected item.
71
!fn: $setEditable(<bflag:boolean>)
72
Make the input field editable, if <bflag>. Otherwise the
73
user may only choose one of the items in the combo box.[br]
74
If the parameter is ommited, it is assumed to be false.
75
!fn: <boolean> $editable()
76
Returns whether the combobox is editable or not.
77
!fn: $setEditText(<text:string>,[<quiet:bool>])
78
Sets the text in the embedded line edit to newText without
79
changing the combo's contents. Does nothing if the combo
80
isn't editable. If the optional quiet parameter is true no warning will be print if text will be empty.
82
Removes all the items from the combo box
83
!fn: $textAt(<index:uint>)
84
Returns item at given index.
85
!fn: $setCurrentItem(<index:uint>)
86
Sets the current combobox item. This is the item to be displayed on the combobox button.
87
!fn: $activatedEvent(<index:integer>)
88
This function is called by the framework when a new item has activated. The index value is the position of the new item.[br]
89
The default implementation emits the [classfnc]$activated[/classfnc]() signal,
90
!fn: $textChangedEvent(<text:string>)
91
This function is called when the text in an editable combobox has changed.[br]
92
The function return the new text in its argument.[br]
93
The default implementation emits the [classfnc]$textChanged[/classfnc]() signal.
96
This signal is emitted by the default implementation of [classfnc]$textChangedEvent[/classfnc]().
98
This signal is emitted by the default implementation of [classfnc]$activatedEvent[/classfnc]().
101
KVSO_BEGIN_REGISTERCLASS(KviKvsObject_combobox,"combobox","widget")
102
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_combobox,insertItem)
103
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_combobox,changeItem)
104
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_combobox,removeItem)
105
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_combobox,clear)
106
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_combobox,setMaxCount)
107
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_combobox,maxCount)
108
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_combobox,count)
109
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_combobox,current)
110
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_combobox,currentItem)
111
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_combobox,setEditable);
112
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_combobox,editable)
113
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_combobox,setEditText)
114
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_combobox,textAt)
115
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_combobox,textLineEdit)
116
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_combobox,setTextLineEdit)
117
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_combobox,setCurrentItem)
118
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_combobox,popup)
119
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_combobox,setInsertionPolicy)
120
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_combobox,textChangedEvent)
121
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_combobox,activatedEvent)
123
KVSO_END_REGISTERCLASS(KviKvsObject_combobox)
125
KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_combobox,KviKvsObject_widget)
127
KVSO_END_CONSTRUCTOR(KviKvsObject_combobox)
130
KVSO_BEGIN_DESTRUCTOR(KviKvsObject_combobox)
132
KVSO_END_CONSTRUCTOR(KviKvsObject_combobox)
134
bool KviKvsObject_combobox::init(KviKvsRunTimeContext *,KviKvsVariantList *)
136
SET_OBJECT(QComboBox);
137
connect (((QComboBox *)widget()),SIGNAL(activated( int )),this,SLOT(slotActivated( int )));
138
connect (((QComboBox *)widget()),SIGNAL(editTextChanged(const QString & )),this,SLOT(editTextChanged(const QString & )));
142
KVSO_CLASS_FUNCTION(combobox,insertItem)
144
CHECK_INTERNAL_POINTER(widget())
147
KVSO_PARAMETERS_BEGIN(c)
148
KVSO_PARAMETER("item",KVS_PT_STRING,0,szItem)
149
KVSO_PARAMETER("index",KVS_PT_INT,KVS_PF_OPTIONAL,iIndex)
150
KVSO_PARAMETERS_END(c)
151
if(c->paramCount()==1)
152
((QComboBox *)widget())->addItem(szItem);
154
((QComboBox *)widget())->insertItem( iIndex,szItem);
157
KVSO_CLASS_FUNCTION(combobox,clear)
159
CHECK_INTERNAL_POINTER(widget())
160
((QComboBox *)widget())->clear();
163
KVSO_CLASS_FUNCTION(combobox,changeItem)
165
CHECK_INTERNAL_POINTER(widget())
166
kvs_uint_t uIndex,cnt;
168
KVSO_PARAMETERS_BEGIN(c)
169
KVSO_PARAMETER("text",KVS_PT_STRING,0,szText)
170
KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,uIndex)
171
KVSO_PARAMETERS_END(c)
172
if (szText.isEmpty()) c->warning(__tr2qs_ctx("No string parameter given - using empty string","objects"));
173
if(uIndex >= (cnt = ((QComboBox *)widget())->count()))
175
c->warning(__tr2qs_ctx("Item index [%d] is too big - defaulting to " \
176
"$count() - 1 [%d]","objects"), uIndex, cnt);
179
((QComboBox *)widget())->setItemText( uIndex,szText);
183
KVSO_CLASS_FUNCTION(combobox,removeItem)
185
CHECK_INTERNAL_POINTER(widget())
186
kvs_uint_t uIndex,cnt;
187
KVSO_PARAMETERS_BEGIN(c)
188
KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,uIndex)
189
KVSO_PARAMETERS_END(c)
190
if(uIndex >= (cnt = ((QComboBox *)widget())->count()))
192
c->warning(__tr2qs_ctx("Item index [%d] is too big - defaulting to " \
193
"$count() - 1 [%d]","objects"), uIndex, cnt);
197
((QComboBox *)widget())->removeItem(uIndex);
202
KVSO_CLASS_FUNCTION(combobox,setMaxCount)
204
CHECK_INTERNAL_POINTER(widget())
207
KVSO_PARAMETERS_BEGIN(c)
208
KVSO_PARAMETER("count",KVS_PT_UNSIGNEDINTEGER,0,iMax)
209
KVSO_PARAMETERS_END(c)
210
((QComboBox *)widget())->setMaxCount(iMax);
213
KVSO_CLASS_FUNCTION(combobox,maxCount)
215
CHECK_INTERNAL_POINTER(widget())
216
c->returnValue()->setInteger(((QComboBox *)widget())->maxCount());
219
KVSO_CLASS_FUNCTION(combobox,count)
221
CHECK_INTERNAL_POINTER(widget())
222
c->returnValue()->setInteger(((QComboBox *)widget())->count());
225
KVSO_CLASS_FUNCTION(combobox,current)
227
CHECK_INTERNAL_POINTER(widget())
228
c->returnValue()->setString(((QComboBox *)widget())->currentText());
231
KVSO_CLASS_FUNCTION(combobox,currentItem)
233
CHECK_INTERNAL_POINTER(widget())
234
c->returnValue()->setInteger(((QComboBox *)widget())->currentIndex());
237
KVSO_CLASS_FUNCTION(combobox,textLineEdit)
239
CHECK_INTERNAL_POINTER(widget())
240
c->returnValue()->setString(((QComboBox *)widget())->lineEdit()->text());
244
KVSO_CLASS_FUNCTION(combobox,setEditable)
246
CHECK_INTERNAL_POINTER(widget())
248
KVSO_PARAMETERS_BEGIN(c)
249
KVSO_PARAMETER("bflag",KVS_PT_BOOLEAN,0,bFlag)
250
KVSO_PARAMETERS_END(c)
251
((QComboBox *)widget())->setEditable(bFlag);
254
KVSO_CLASS_FUNCTION(combobox,setTextLineEdit)
256
CHECK_INTERNAL_POINTER(widget())
258
KVSO_PARAMETERS_BEGIN(c)
259
KVSO_PARAMETER("text",KVS_PT_STRING,0,szText)
260
KVSO_PARAMETERS_END(c)
261
((QComboBox *)widget())->lineEdit()->setText(szText);
265
KVSO_CLASS_FUNCTION(combobox,editable)
267
CHECK_INTERNAL_POINTER(widget())
268
c->returnValue()->setBoolean(((QComboBox *)widget())->isEditable());
271
KVSO_CLASS_FUNCTION(combobox,setEditText)
273
CHECK_INTERNAL_POINTER(widget())
276
KVSO_PARAMETERS_BEGIN(c)
277
KVSO_PARAMETER("text",KVS_PT_STRING,0,szText)
278
KVSO_PARAMETER("quiet",KVS_PT_BOOLEAN,KVS_PF_OPTIONAL,bQuiet)
279
KVSO_PARAMETERS_END(c)
280
if (szText.isEmpty() && !bQuiet) c->warning(__tr2qs_ctx("No string parameter given - using empty string","objects"));
281
((QComboBox *)widget())->setEditText(szText);
284
KVSO_CLASS_FUNCTION(combobox,textAt)
286
CHECK_INTERNAL_POINTER(widget())
288
KVSO_PARAMETERS_BEGIN(c)
289
KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,uIndex)
290
KVSO_PARAMETERS_END(c)
291
c->returnValue()->setString(((QComboBox *)widget())->itemText(uIndex));
294
KVSO_CLASS_FUNCTION(combobox,setCurrentItem)
296
CHECK_INTERNAL_POINTER(widget())
298
KVSO_PARAMETERS_BEGIN(c)
299
KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,uIndex)
300
KVSO_PARAMETERS_END(c)
301
((QComboBox *)widget())->setCurrentIndex(uIndex);
304
KVSO_CLASS_FUNCTION(combobox,popup)
309
((QComboBox *)widget())->showPopup();
312
KVSO_CLASS_FUNCTION(combobox,setInsertionPolicy)
314
CHECK_INTERNAL_POINTER(widget())
316
KVSO_PARAMETERS_BEGIN(c)
317
KVSO_PARAMETER("policy",KVS_PT_STRING,0,szPolicy)
318
KVSO_PARAMETERS_END(c)
319
if(KviQString::equalCI(szPolicy,"NoInsertion"))
320
((QComboBox *)widget())->setInsertPolicy(QComboBox::NoInsert);
321
else if(KviQString::equalCI(szPolicy,"AtTop"))
322
((QComboBox *)widget())->setInsertPolicy(QComboBox::InsertAtTop);
323
else if(KviQString::equalCI(szPolicy,"AtBotton"))
324
((QComboBox *)widget())->setInsertPolicy(QComboBox::InsertAtBottom);
325
else if(KviQString::equalCI(szPolicy,"AtCurrent"))
326
((QComboBox *)widget())->setInsertPolicy(QComboBox::InsertAtCurrent);
327
else if(KviQString::equalCI(szPolicy,"AfterCurrent"))
328
((QComboBox *)widget())->setInsertPolicy(QComboBox::InsertAfterCurrent);
329
else if(KviQString::equalCI(szPolicy,"BeforeCurrent"))
330
((QComboBox *)widget())->setInsertPolicy(QComboBox::InsertBeforeCurrent);
331
else c->warning(__tr2qs_ctx("Invalid insertion Policy '%Q'","objects"),&szPolicy);
335
KVSO_CLASS_FUNCTION(combobox,textChangedEvent)
337
emitSignal("textChanged",c,c->params());
343
KVSO_CLASS_FUNCTION(combobox,activatedEvent)
345
emitSignal("activated",c,c->params());
350
void KviKvsObject_combobox::editTextChanged(const QString &text)
352
KviKvsVariantList params(new KviKvsVariant(text));
353
callFunction(this,"textChangedEvent",¶ms);
356
void KviKvsObject_combobox::slotActivated(int i)
358
KviKvsVariantList params(new KviKvsVariant((kvs_int_t)i));
359
callFunction(this,"activatedEvent",¶ms);
363
#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES
364
#include "m_class_combobox.moc"
365
#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES