1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
|
//vim: ts=8
// File : class_lineedit.cpp
// Creation date : Wed 20 Sep 2000 04:34:40 CEST by Krzysztof Godlewski
//
// This file is part of the KVirc irc client distribution
// Copyright (C) 1999-2000 Szymon Stefanek (pragma at kvirc dot net)
//
// This program is FREE software. You can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your opinion) any later version.
//
// This program is distributed in the HOPE that it will be USEFUL,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, write to the Free Software Foundation,
// Inc. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
#include "kvi_error.h"
#include "kvi_debug.h"
#include "kvi_locale.h"
#include "class_lineedit.h"
static const char * mode_tbl[] = {
"Normal",
"NoEcho",
"Password"
};
static const int mode_cod[] = {
TQLineEdit::Normal,
TQLineEdit::NoEcho,
TQLineEdit::Password
};
#define mode_num (sizeof(mode_tbl) / sizeof(mode_tbl[0]))
/*
@doc: lineedit
@keyterms:
lineedit object class, line editor, input
@title:
lineedit class
@type:
class
@short:
Simple line editor for inputting short text
@inherits:
[class]object[/class]
[class]widget[/class]
@description:
This is a simple, one-line editor usually used for inputting
short text like names, phone numbers etc. It can display text
in three echo modes (see [classfnc]$setEchoMode[/classfnc]()
for details).
@functions:
!fn: <string> $text()
Returns text contained by the widget.[br]
See also [classfnc]$setText[/classfnc]().
!fn: $setText(<text:string>)
Sets editor text to <text>.[br]
See also [classfnc]$text[/classfnc]().
!fn: $setEchoMode(<echo_mode:string>)
Sets the line edit's echo mode. Possible value are:[br]
-Normal: display chars as they entered[br]
-Noecho : do not display anything[br]
-Password : display asterisks instead of the characters actually entered[br]
See also [classfnc]$echoMode[/classfnc]().
!fn: <string> $echoMode()
Return the line edit's echo mode.
See also [classfnc]$setEchoMode[/classfnc]().
!fn: <integer> $maxLength()
Returns the current maximum length of the text that can be typed
in the editor.[br]
See also [classfnc]$setMaxLength[/classfnc]().
!fn: $setMaxLength(<max_lenght:integer>)
Sets maximum length of the text that can be typed in the
editor.[br]
See also [classfnc]$maxLength[/classfnc]().
!fn: <boolean> $frame()
Returns '1' if the editor is drawn inside a frame, which is 2
pixels wide, '0' otherwise.[br]
See also [classfnc]$setFrame[/classfnc]().
!fn: $setFrame(<bframe:boolean>)
Sets editor frame drawing to <bool>.[br]
See also [classfnc]$frame[/classfnc]().
!fn: <integer> $cursorPosition()
Returns current cursor position in the editor.[br]
See also [classfnc]$setCursorPosition[/classfnc]().
!fn: $setCursorPosition(<index:integer>)
Moves the cursor to place pointed by <index>.[br]
See also [classfnc]$cursorPosition[/classfnc]().
!fn: $selectAll()
Selects whole text inside the editor.[br]
See also [classfnc]$setSelection[/classfnc](),
[classfnc]$cut[/classfnc](), [classfnc]$copy[/classfnc](),
[classfnc]$paste[/classfnc]().
!fn: $setSelection(<start:integer>, <length:integer>)
Selects <length> characters in the editor starting at position
<start>.[br]
See also [classfnc]$selectAll[/classfnc](),
[classfnc]$cut[/classfnc](), [classfnc]$copy[/classfnc](),
[classfnc]$paste[/classfnc]().
!fn: $copy()
Copies selected text in the editor to the clipboard.[br]
See also [classfnc]$setSelection[/classfnc](),
[classfnc]$cut[/classfnc](), [classfnc]$paste[/classfnc]().
!fn: $cut()
Cuts selected text from the editor to the clipboard.[br]
See also [classfnc]$setSelection[/classfnc](),
[classfnc]$copy[/classfnc](), [classfnc]$paste[/classfnc]().
!fn: $paste()
Pastes text from the clipboard into the editor. The pasted text
will start at cursor position.[br]
See also [classfnc]$setSelection[/classfnc](),
[classfnc]$copy[/classfnc](), [classfnc]$cut[/classfnc]().
!fn: $clear()
Deletes all text from the editor. Equal to calling [classfnc]$setText[/classfnc]("").
!fn: $setDragEnabled(<bEnabled:bool>)
With this property user can drag text in the lineedit.
!fn: $setReadOnly(<bReadonly:boolean>)
Sets the lineedit to read only mode.
!fn: $setInputMask(<tqmask:string>)
Sets the validation input tqmask to inputMask.[br]
Example:[br]
[br]
%esempio->$setInputMask( "+99 99 99 99 99;_" );[br]
%esempio->$setInputMask( "000.000.000.000;_" );[br]
%esempio->Ip Number Mask.[br]
%esempio->setInputMask( ">AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;#" );[br]
[br]
The tqmask format understands these tqmask characters:[br]
Character Meaning[br]
A ASCII alphabetic character required. A-Z, a-z.[br]
a ASCII alphabetic character permitted but not required.[br]
N ASCII alphanumeric character required. A-Z, a-z, 0-9.[br]
n ASCII alphanumeric character permitted but not required.[br]
X Any character required.[br]
x Any character permitted but not required.[br]
9 ASCII digit required. 0-9.[br]
0 ASCII digit permitted but not required.[br]
D ASCII digit required. 1-9.[br]
d ASCII digit permitted but not required.[br]
# ASCII digit or plus/minus sign permitted but not required.[br]
> All following alphabetic characters are uppercased.[br]
< All following alphabetic characters are lowercased.[br]
! Switch off case conversion.[br]
\ Use \ to escape the special characters listed above to use them as separators.[br]
[br]
The tqmask consists of a string of tqmask characters and separators, optionally[br]
followed by a semi-colon and the character used for blanks: the blank characters [br]
are always removed from the text after editing. The default blank character is space. [br]
!fn: $returnPressedEvent()
This function is called by the framework when the enter key is pressed.
!fn: $lostFocusEvent()
Called when the lineedit lost focus.
!fn: $textChangedEvent(<new text:string>)
This event is called when the text changed, In $0 there is the new text.
@signals:
!sg: $returnPressed()
This signal is emitted by the default implementation of [classfnc]$returnPressedEvent[/classfnc]().
!sg: $lostFocus()
This signal is emitted by the default implementation of [classfnc]$lostFocusEvent[/classfnc]().
!sg: $textChanged()
This signal is emitted by the default implementation of [classfnc]$textChangedEvent[/classfnc]().
*/
KVSO_BEGIN_REGISTERCLASS(KviKvsObject_lineedit,"lineedit","widget")
KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"text", functionText)
KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"setText", functionSetText)
KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"maxLength", functionMaxLength)
KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"setMaxLength", functionSetMaxLength)
KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"frame", functionFrame)
KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"setCursorPosition", functionSetCursorPosition)
KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"cursorPosition", functionCursorPosition)
KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"setFrame", functionSetFrame)
KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"selectAll" , functionSelectAll)
KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"setSelection", functionSetSelection)
KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"copy", functionCopy)
KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"cut", functionCut)
KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"paste", functionPaste)
KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"echoMode", functionEchoMode)
KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"setEchoMode", functionSetEchoMode)
KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"clear", functionClear)
KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"setDragEnabled", functionDragAndDrop)
KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"setInputMask", functionSetInputMask)
KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"setReadOnly", functionSetReadOnly)
KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"returnPressedEvent", functionreturnPressedEvent)
KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"lostFocusEvent", functionlostFocusEvent)
KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"textChangedEvent", functiontextChangedEvent)
KVSO_END_REGISTERCLASS(KviKvsObject_lineedit)
KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_lineedit,KviKvsObject_widget)
KVSO_END_CONSTRUCTOR(KviKvsObject_lineedit)
KVSO_BEGIN_DESTRUCTOR(KviKvsObject_lineedit)
KVSO_END_CONSTRUCTOR(KviKvsObject_lineedit)
bool KviKvsObject_lineedit::init(KviKvsRunTimeContext * pContext,KviKvsVariantList * pParams)
{
setObject(TQT_TQOBJECT(new TQLineEdit(tqparentScriptWidget(),getName())),true);
connect(widget(),TQT_SIGNAL(returnPressed()),this,TQT_SLOT(slotreturnPressed()));
connect(widget(),TQT_SIGNAL(lostFocus()),this,TQT_SLOT(slotlostFocus()));
connect(widget(),TQT_SIGNAL(textChanged(const TQString & )),this,TQT_SLOT(slottextChanged(const TQString & )));
return true;
}
bool KviKvsObject_lineedit::functionText(KviKvsObjectFunctionCall *c)
{
if(widget())
c->returnValue()->setString(((TQLineEdit *)widget())->text());
return true;
}
bool KviKvsObject_lineedit::functionSetText(KviKvsObjectFunctionCall *c)
{
TQString szText;
KVSO_PARAMETERS_BEGIN(c)
KVSO_PARAMETER("text",KVS_PT_STRING,0,szText)
KVSO_PARAMETERS_END(c)
if (widget())
((TQLineEdit *)widget())->setText(szText);
return true;
}
bool KviKvsObject_lineedit::functionMaxLength(KviKvsObjectFunctionCall *c)
{
if(widget())
c->returnValue()->setInteger(((TQLineEdit *)widget())->maxLength());
return true;
}
bool KviKvsObject_lineedit::functionSetMaxLength(KviKvsObjectFunctionCall *c)
{
kvs_uint_t iMaxlen;
KVSO_PARAMETERS_BEGIN(c)
KVSO_PARAMETER("maxlen",KVS_PT_UNSIGNEDINTEGER,0,iMaxlen)
KVSO_PARAMETERS_END(c)
if (widget())
((TQLineEdit *)widget())->setMaxLength(iMaxlen);
return true;
}
bool KviKvsObject_lineedit::functionFrame(KviKvsObjectFunctionCall *c)
{
if(widget())
c->returnValue()->setBoolean(((TQLineEdit *)widget())->frame());
return true;
}
bool KviKvsObject_lineedit::functionSetFrame(KviKvsObjectFunctionCall *c)
{
bool bFrame;
KVSO_PARAMETERS_BEGIN(c)
KVSO_PARAMETER("bframe",KVS_PT_BOOL,0,bFrame)
KVSO_PARAMETERS_END(c)
if(widget())
((TQLineEdit *)widget())->setFrame(bFrame);
return true;
}
bool KviKvsObject_lineedit::functionCursorPosition(KviKvsObjectFunctionCall *c)
{
if(widget())
c->returnValue()->setInteger(((TQLineEdit *)widget())->cursorPosition());
return true;
}
bool KviKvsObject_lineedit::functionSetCursorPosition(KviKvsObjectFunctionCall *c)
{
kvs_uint_t iPos;
KVSO_PARAMETERS_BEGIN(c)
KVSO_PARAMETER("position",KVS_PT_UNSIGNEDINTEGER,0,iPos)
KVSO_PARAMETERS_END(c)
if (widget())
((TQLineEdit *)widget())->setCursorPosition(iPos);
return true;
}
bool KviKvsObject_lineedit::functionSelectAll(KviKvsObjectFunctionCall *c)
{
if(widget())
((TQLineEdit *)widget())->selectAll();
return true;
}
bool KviKvsObject_lineedit::functionSetSelection(KviKvsObjectFunctionCall *c)
{
kvs_uint_t uStart,uLen;
KVSO_PARAMETERS_BEGIN(c)
KVSO_PARAMETER("start",KVS_PT_UNSIGNEDINTEGER,0,uStart)
KVSO_PARAMETER("len",KVS_PT_UNSIGNEDINTEGER,0,uLen)
KVSO_PARAMETERS_END(c)
if (widget())
((TQLineEdit *)widget())->setSelection(uStart, uLen);
return true;
}
bool KviKvsObject_lineedit::functionCopy(KviKvsObjectFunctionCall *c)
{
if(widget())
((TQLineEdit *)widget())->copy();
return true;
}
bool KviKvsObject_lineedit::functionCut(KviKvsObjectFunctionCall *c)
{
if(widget())
((TQLineEdit *)widget())->cut();
return true;
}
bool KviKvsObject_lineedit::functionPaste(KviKvsObjectFunctionCall *c)
{
if(widget())
((TQLineEdit *)widget())->paste();
return true;
}
bool KviKvsObject_lineedit::functionEchoMode(KviKvsObjectFunctionCall *c)
{
int mode = ((TQLineEdit *)widget())->echoMode();
TQString szEchomode="";
for(unsigned int i = 0; i < mode_num; i++)
{
if(mode == mode_cod[i])
{
szEchomode=mode_tbl[i];
break;
}
}
c->returnValue()->setString(szEchomode);
return true;
}
bool KviKvsObject_lineedit::functionSetEchoMode(KviKvsObjectFunctionCall *c)
{
TQString szMode;
KVSO_PARAMETERS_BEGIN(c)
KVSO_PARAMETER("mode",KVS_PT_STRING,0,szMode)
KVSO_PARAMETERS_END(c)
if (!widget()) return true;
for(unsigned int i = 0; i < mode_num; i++)
{
if(KviTQString::equalCI(szMode, mode_tbl[i]))
{
((TQLineEdit *)widget())->setEchoMode( \
((TQLineEdit::EchoMode)mode_cod[i]));
return true;
}
}
c->warning(__tr2qs("Unknown echo mode %Q"),&szMode);
return true;
}
bool KviKvsObject_lineedit::functionClear(KviKvsObjectFunctionCall *c)
{
if(widget())
((TQLineEdit *)widget())->clear();
return true;
}
//-| Grifisx & Noldor |-Start:
bool KviKvsObject_lineedit::functionDragAndDrop(KviKvsObjectFunctionCall *c)
{
bool bEnabled;
KVSO_PARAMETERS_BEGIN(c)
KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled)
KVSO_PARAMETERS_END(c)
if(widget())
((TQLineEdit *)widget())->setDragEnabled(bEnabled);
return true;
}
bool KviKvsObject_lineedit::functionSetReadOnly(KviKvsObjectFunctionCall *c)
{
bool bEnabled;
KVSO_PARAMETERS_BEGIN(c)
KVSO_PARAMETER("bReadonly",KVS_PT_BOOL,0,bEnabled)
KVSO_PARAMETERS_END(c)
if(widget())
((TQLineEdit *)widget())->setReadOnly(bEnabled);
return true;
}
bool KviKvsObject_lineedit::functionSetInputMask(KviKvsObjectFunctionCall *c)
{
TQString szMask;
KVSO_PARAMETERS_BEGIN(c)
KVSO_PARAMETER("tqmask",KVS_PT_STRING,0,szMask)
KVSO_PARAMETERS_END(c)
if (widget())
((TQLineEdit *)widget())->setInputMask(szMask);
return true;
}
bool KviKvsObject_lineedit::functionreturnPressedEvent(KviKvsObjectFunctionCall *c)
{
emitSignal("returnPressed",c);
return true;
}
void KviKvsObject_lineedit::slotreturnPressed()
{
KviKvsVariantList * params = 0;
callFunction(this,"returnPressedEvent",params);
}
// FIND ME
bool KviKvsObject_lineedit::functionlostFocusEvent(KviKvsObjectFunctionCall *c)
{
emitSignal("lostFocus",c);
return true;
}
void KviKvsObject_lineedit::slotlostFocus()
{
KviKvsVariantList * params = 0;
callFunction(this,"lostFocusEvent",params);
}
/////
bool KviKvsObject_lineedit::functiontextChangedEvent(KviKvsObjectFunctionCall *c)
{
emitSignal("textChanged",c,c->params());
return true;
}
void KviKvsObject_lineedit::slottextChanged(const TQString &text)
{
KviKvsVariantList params(new KviKvsVariant(text));
callFunction(this,"textChangedEvent",¶ms);
}
#include "m_class_lineedit.moc"
|