~ubuntu-branches/ubuntu/trusty/kvirc/trusty

« back to all changes in this revision

Viewing changes to src/modules/objects/class_combobox.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kai Wasserbäch, Kai Wasserbäch, Raúl Sánchez Siles
  • Date: 2011-02-12 10:40:21 UTC
  • mfrom: (14.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110212104021-5mh4f75jlku20mnt
The combined "Twisted Experiment" and "Nocturnal Raid" release.

[ Kai Wasserbäch ]
* Synced to upstream's SVN revision 5467.
* debian/rules:
  - Added .PHONY line.
  - Resurrect -DMANUAL_REVISION, got lost somewhere and we build SVN
    revisions again.
  - Replace "-DWITH_NO_EMBEDDED_CODE=YES" with "-DWANT_CRYPTOPP=YES".
  - Change the remaining -DWITH/-DWITHOUT to the new -DWANT syntax.
* debian/control:
  - Removed DMUA, I'm a DD now.
  - Changed my e-mail address.
  - Removed unneeded relationships (no upgrades over two releases are
    supported).
  - Fix Suggests for kvirc-dbg.
  - kvirc-data: Make the "Suggests: kvirc" a Recommends, doesn't make much
    sense to install the -data package without the program.
* debian/source/local-options: Added with "unapply-patches".
* debian/kvirc.lintian-overrides: Updated to work for 4.1.1.
* debian/patches/21_make_shared-mime-info_B-D_superfluous.patch: Updated.
* debian/kvirc-data.install: Added .notifyrc.

[ Raúl Sánchez Siles ]
* Stating the right version where kvirc-data break and replace should happen.
* Fixing link to license file.
* Added French and Portuguese man pages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//=============================================================================
2
 
//
3
 
//   File : class_combobox.cpp
4
 
//   Creation date : Wed 13 Sep 2000 02:42:05 CEST by Krzysztof Godlewski
5
 
//
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)
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 opinion) 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
 
 
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"
32
 
 
33
 
#include <QLineEdit>
34
 
#include <QString>
35
 
#include <QComboBox>
36
 
 
37
 
/*
38
 
        @doc:   combobox
39
 
        @keyterms:
40
 
                combobox object class, selection
41
 
        @title:
42
 
                combobox class
43
 
        @type:
44
 
                class
45
 
        @short:
46
 
                Combined button and popup list
47
 
        @inherits:
48
 
                [class]object[/class]
49
 
                [class]widget[/class]
50
 
        @description:
51
 
        @functions:
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.
81
 
                !fn: $clear()
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.
94
 
                @signals:
95
 
                !sg: $textChanged()
96
 
                This signal is emitted by the default implementation of [classfnc]$textChangedEvent[/classfnc]().
97
 
                !sg: $activated()
98
 
                This signal is emitted by the default implementation of [classfnc]$activatedEvent[/classfnc]().
99
 
 
100
 
*/
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)
122
 
 
123
 
KVSO_END_REGISTERCLASS(KviKvsObject_combobox)
124
 
 
125
 
KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_combobox,KviKvsObject_widget)
126
 
 
127
 
KVSO_END_CONSTRUCTOR(KviKvsObject_combobox)
128
 
 
129
 
 
130
 
KVSO_BEGIN_DESTRUCTOR(KviKvsObject_combobox)
131
 
 
132
 
KVSO_END_CONSTRUCTOR(KviKvsObject_combobox)
133
 
 
134
 
bool KviKvsObject_combobox::init(KviKvsRunTimeContext *,KviKvsVariantList *)
135
 
{
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 & )));
139
 
        return true;
140
 
}
141
 
 
142
 
KVSO_CLASS_FUNCTION(combobox,insertItem)
143
 
{
144
 
        CHECK_INTERNAL_POINTER(widget())
145
 
        kvs_int_t iIndex;
146
 
        QString szItem;
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);
153
 
        else
154
 
                ((QComboBox *)widget())->insertItem( iIndex,szItem);
155
 
        return true;
156
 
}
157
 
KVSO_CLASS_FUNCTION(combobox,clear)
158
 
{
159
 
        CHECK_INTERNAL_POINTER(widget())
160
 
        ((QComboBox *)widget())->clear();
161
 
        return true;
162
 
}
163
 
KVSO_CLASS_FUNCTION(combobox,changeItem)
164
 
{
165
 
        CHECK_INTERNAL_POINTER(widget())
166
 
        kvs_uint_t uIndex,cnt;
167
 
        QString szText;
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()))
174
 
        {
175
 
                c->warning(__tr2qs_ctx("Item index [%d] is too big - defaulting to " \
176
 
                        "$count() - 1 [%d]","objects"), uIndex, cnt);
177
 
                uIndex = cnt - 1;
178
 
        }
179
 
        ((QComboBox *)widget())->setItemText( uIndex,szText);
180
 
        return true;
181
 
 
182
 
}
183
 
KVSO_CLASS_FUNCTION(combobox,removeItem)
184
 
{
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()))
191
 
        {
192
 
                c->warning(__tr2qs_ctx("Item index [%d] is too big - defaulting to " \
193
 
                        "$count() - 1 [%d]","objects"), uIndex, cnt);
194
 
                uIndex = cnt - 1;
195
 
        }
196
 
 
197
 
        ((QComboBox *)widget())->removeItem(uIndex);
198
 
 
199
 
        return true;
200
 
 
201
 
}
202
 
KVSO_CLASS_FUNCTION(combobox,setMaxCount)
203
 
{
204
 
        CHECK_INTERNAL_POINTER(widget())
205
 
        kvs_uint_t iMax;
206
 
        QString szText;
207
 
        KVSO_PARAMETERS_BEGIN(c)
208
 
                KVSO_PARAMETER("count",KVS_PT_UNSIGNEDINTEGER,0,iMax)
209
 
        KVSO_PARAMETERS_END(c)
210
 
        ((QComboBox *)widget())->setMaxCount(iMax);
211
 
        return true;
212
 
}
213
 
KVSO_CLASS_FUNCTION(combobox,maxCount)
214
 
{
215
 
        CHECK_INTERNAL_POINTER(widget())
216
 
        c->returnValue()->setInteger(((QComboBox *)widget())->maxCount());
217
 
        return true;
218
 
}
219
 
KVSO_CLASS_FUNCTION(combobox,count)
220
 
{
221
 
        CHECK_INTERNAL_POINTER(widget())
222
 
        c->returnValue()->setInteger(((QComboBox *)widget())->count());
223
 
        return true;
224
 
}
225
 
KVSO_CLASS_FUNCTION(combobox,current)
226
 
{
227
 
        CHECK_INTERNAL_POINTER(widget())
228
 
        c->returnValue()->setString(((QComboBox *)widget())->currentText());
229
 
        return true;
230
 
}
231
 
KVSO_CLASS_FUNCTION(combobox,currentItem)
232
 
{
233
 
        CHECK_INTERNAL_POINTER(widget())
234
 
        c->returnValue()->setInteger(((QComboBox *)widget())->currentIndex());
235
 
        return true;
236
 
}
237
 
KVSO_CLASS_FUNCTION(combobox,textLineEdit)
238
 
{
239
 
        CHECK_INTERNAL_POINTER(widget())
240
 
        c->returnValue()->setString(((QComboBox *)widget())->lineEdit()->text());
241
 
        return true;
242
 
}
243
 
 
244
 
KVSO_CLASS_FUNCTION(combobox,setEditable)
245
 
{
246
 
        CHECK_INTERNAL_POINTER(widget())
247
 
        bool bFlag;
248
 
        KVSO_PARAMETERS_BEGIN(c)
249
 
                KVSO_PARAMETER("bflag",KVS_PT_BOOLEAN,0,bFlag)
250
 
        KVSO_PARAMETERS_END(c)
251
 
        ((QComboBox *)widget())->setEditable(bFlag);
252
 
        return true;
253
 
}
254
 
KVSO_CLASS_FUNCTION(combobox,setTextLineEdit)
255
 
{
256
 
        CHECK_INTERNAL_POINTER(widget())
257
 
        QString szText;
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);
262
 
        return true;
263
 
}
264
 
 
265
 
KVSO_CLASS_FUNCTION(combobox,editable)
266
 
{
267
 
        CHECK_INTERNAL_POINTER(widget())
268
 
        c->returnValue()->setBoolean(((QComboBox *)widget())->isEditable());
269
 
        return true;
270
 
}
271
 
KVSO_CLASS_FUNCTION(combobox,setEditText)
272
 
{
273
 
        CHECK_INTERNAL_POINTER(widget())
274
 
        QString szText;
275
 
        bool bQuiet=false;
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);
282
 
        return true;
283
 
}
284
 
KVSO_CLASS_FUNCTION(combobox,textAt)
285
 
{
286
 
        CHECK_INTERNAL_POINTER(widget())
287
 
        kvs_uint_t uIndex;
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));
292
 
        return true;
293
 
}
294
 
KVSO_CLASS_FUNCTION(combobox,setCurrentItem)
295
 
{
296
 
        CHECK_INTERNAL_POINTER(widget())
297
 
        kvs_uint_t uIndex;
298
 
        KVSO_PARAMETERS_BEGIN(c)
299
 
                KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,uIndex)
300
 
        KVSO_PARAMETERS_END(c)
301
 
        ((QComboBox *)widget())->setCurrentIndex(uIndex);
302
 
        return true;
303
 
}
304
 
KVSO_CLASS_FUNCTION(combobox,popup)
305
 
{
306
 
        Q_UNUSED(c);
307
 
 
308
 
        if(widget())
309
 
           ((QComboBox *)widget())->showPopup();
310
 
        return true;
311
 
}
312
 
KVSO_CLASS_FUNCTION(combobox,setInsertionPolicy)
313
 
{
314
 
        CHECK_INTERNAL_POINTER(widget())
315
 
        QString szPolicy;
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);
332
 
        return true;
333
 
}
334
 
 
335
 
KVSO_CLASS_FUNCTION(combobox,textChangedEvent)
336
 
{
337
 
        emitSignal("textChanged",c,c->params());
338
 
        return true;
339
 
}
340
 
 
341
 
 
342
 
 
343
 
KVSO_CLASS_FUNCTION(combobox,activatedEvent)
344
 
{
345
 
        emitSignal("activated",c,c->params());
346
 
        return true;
347
 
}
348
 
 
349
 
//slots
350
 
void KviKvsObject_combobox::editTextChanged(const QString &text)
351
 
{
352
 
        KviKvsVariantList params(new KviKvsVariant(text));
353
 
        callFunction(this,"textChangedEvent",&params);
354
 
}
355
 
 
356
 
void KviKvsObject_combobox::slotActivated(int i)
357
 
{
358
 
        KviKvsVariantList params(new KviKvsVariant((kvs_int_t)i));
359
 
        callFunction(this,"activatedEvent",&params);
360
 
}
361
 
 
362
 
 
363
 
#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES
364
 
#include "m_class_combobox.moc"
365
 
#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES
366