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
|
//
// File : class_groupbox.cpp
// Creation date : Fri Jan 28 14:21:48 CEST 2005
// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor)
//
// This file is part of the KVirc irc client distribution
// Copyright (C) 1999-2005 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_tal_groupbox.h>
#include "class_groupbox.h"
#include "kvi_error.h"
#include "kvi_debug.h"
#include "kvi_locale.h"
#include "kvi_iconmanager.h"
// Tables used in $setAlignment , $alignment and in $setOrientation & $orientation
const char * const align_tbl[] = {
"Left",
"Right",
"HCenter"
};
const int align_cod[] = {
TQt::AlignLeft,
TQt::AlignRight,
TQt::AlignHCenter
};
#define align_num (sizeof(align_tbl) / sizeof(align_tbl[0]))
/*
@doc: groupbox
@keyterms:
groupbox object class,
@title:
groupbox class
@type:
class
@short:
Provides a groupbox bar.
@inherits:
[class]object[/class]
[class]widget[/class]
@description:
This widget can be used to display a groupbox.
It will be usually a parent for other child controls.
You can either use a child layout to manage the children geometries
or use $setColumnLayout to manage the layout automatically.
@functions:
!fn: $setTitle(<text:String>)
Sets the group box title to <text>.
!fn: <string> $title()
Returns the group box title text.
!fn: $setFlat(<bflag:boolean>)
Sets whether the group box is painted flat. Valid Values are 1 or 0.
!fn: <boolean> $isFlat()
Returns 1 (TRUE) if the group box is painted flat; otherwise returns 0 (FALSE).
!fn: <boolean> $isCheckable()
Returns 1 (TRUE) if the group box has a checkbox in its title; otherwise returns 0 (FALSE).
!fn: $setCheckable(<bflag:boolean>)
Sets whether the group box has a checkbox in its title: Valid values are 1 or 0.
!fn: $setInsideMargin(<margin:uint>)
Sets the the width of the inside margin to m pixels.
!fn: <integer> $insideMargin()
Returns the width of the empty space between the items in the group and margin of groupbox.
!fn: $setInsideSpacing(<spacing:uint>)
Sets the width of the empty space between each of the items in the group to m pixels.
!fn: <integer> $insideSpacing()
Returns the width of the empty space between each of the items in the group.
!fn: $setColumns(<columns:uint>)
Sets the number of columns or rows (depending of the orientation) in the group box.
!fn: <integer> $columns()
Returns the number of columns or rows in the groupbox.
!fn: $addSpace()
Adds an empty cell at the next free position.
!fn: <string> $alignment()
Returns the alignment of the group box title.
!fn: $setAlignment(<alignment:string>)
Set the alignment of the groupbox; Valid values are Left,Right,HCenter.
!fn: $setOrientation<orientation:string>
Sets the group box's orientation. Valid values are Horizontal,Vertical.
!fn: $setColumnLayout(<columns:integer>,<orientation:string>)
Enables the automatic layout management. The children are arranged in n columns with the specified orientation.[br]
Valid values for <orientation> are Horizontal,Vertical.
@examples:
[example]
|-Start:[br]
#Let's start.[br]
#first we'll create the main widget.[br]
%widget=$new(widget)[br]
[br]
#then the groupbox [br]
%gb=$new(groupbox,%widget)[br]
%gb->$setTitle(Login)[br]
%gb->$setAlignment("Left")[br]
[br]
#now we create the labels and lineedits.[br]
%labeluser=$new(label,%gb)[br]
%labeluser->$settext(User: )[br]
%labelpass=$new(label,%gb)[br]
%labelpass->$settext(Pass: )[br]
%inputuser=$new(lineedit,%gb)[br]
%inputpass=$new(lineedit,%gb)[br]
%inputpass->$setechomode("password")[br]
[br]
#now lets' layouting the groupbox's element's.[br]
%layoutgb=$new(layout,%gb)[br]
%layoutgb->$setmargin(20)[br]
%layoutgb->$addwidget(%labeluser,0,0)[br]
%layoutgb->$addwidget(%labelpass,1,0)[br]
%layoutgb->$addwidget(%inputuser,0,1)[br]
%layoutgb->$addwidget(%inputpass,1,1)[br]
[br]
# now we create a fake widget and managing the two buttons layout.[br]
%fakewidget=$new(widget,%widget)[br]
%layoutbtn=$new(layout,%fakewidget)[br]
%btnok=$new(button,%fakewidget)[br]
%btnok->$settext("OK")[br]
%btncancel=$new(button,%fakewidget)[br]
%btncancel->$settext("Cancel")[br]
%layoutbtn->$addwidget(%btnok,0,0)[br]
%layoutbtn->$addwidget(%btncancel,0,1)[br]
[br]
#And finally we create a main layout with the groupbox (and its "children")[br]
#and fakewiget (with its buttons children).
%mainlayout=$new(layout,%widget)[br]
%mainlayout->$setspacing(10)[br]
%mainlayout->$setmargin(10)[br]
%mainlayout->$addwidget(%gb,0,0)[br]
%mainlayout->$addwidget(%fakewidget,1,0)[br]
[br]
#Let's show our nice login request =D ! [br]
%widget->$show()[br]
[/example]
*/
KVSO_BEGIN_REGISTERCLASS(KviKvsObject_groupbox,"groupbox","widget")
KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"setTitle", functionSetTitle)
KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"title", functionTitle)
KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"setFlat", functionSetFlat)
KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"isFlat", functionIsFlat)
KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"setCheckable", functionSetCheckable)
KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"isCheckable", functionIsCheckable)
KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"setInsideMargin", functionSetInsideMargin)
KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"insideMargin", functionInsideMargin)
KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"setInsideSpacing", functionSetInsideSpacing)
KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"insideSpacing", functionInsideSpacing)
KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"setColumns", functionSetColumns)
KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"columns", functionColumns)
KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"addSpace", functionAddSpace)
KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"alignment", functionAlignment)
KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"setAlignment", functionSetAlignment)
KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"setOrientation", functionSetOrientation)
KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"isChecked", functionIsChecked)
KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"setChecked", functionSetChecked)
KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"setColumnLayout",functionSetColumnLayout)
KVSO_END_REGISTERCLASS(KviKvsObject_groupbox)
KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_groupbox,KviKvsObject_widget)
KVSO_END_CONSTRUCTOR(KviKvsObject_groupbox)
KVSO_BEGIN_DESTRUCTOR(KviKvsObject_groupbox)
KVSO_END_CONSTRUCTOR(KviKvsObject_groupbox)
bool KviKvsObject_groupbox::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams)
{
setObject(TQT_TQOBJECT(new KviTalGroupBox(name(),parentScriptWidget())), true);
return true;
}
bool KviKvsObject_groupbox::functionSetTitle(KviKvsObjectFunctionCall *c)
{
TQString szTitle;
KVSO_PARAMETERS_BEGIN(c)
KVSO_PARAMETER("title",KVS_PT_STRING,0,szTitle)
KVSO_PARAMETERS_END(c)
if (widget())
((KviTalGroupBox *)widget())->setTitle(szTitle);
return true;
}
bool KviKvsObject_groupbox::functionTitle(KviKvsObjectFunctionCall *c)
{
if (widget()) c->returnValue()->setString(((KviTalGroupBox *)widget())->title());
return true;
}
bool KviKvsObject_groupbox::functionSetFlat(KviKvsObjectFunctionCall *c)
{
bool bEnabled;
KVSO_PARAMETERS_BEGIN(c)
KVSO_PARAMETER("bFlag",KVS_PT_BOOL,0,bEnabled)
KVSO_PARAMETERS_END(c)
if(widget())
((KviTalGroupBox *)widget())->setFlat(bEnabled);
return true;
}
bool KviKvsObject_groupbox::functionIsFlat(KviKvsObjectFunctionCall *c)
{
if (widget()) c->returnValue()->setBoolean(((KviTalGroupBox *)widget())->isFlat());
return true;
}
bool KviKvsObject_groupbox::functionSetCheckable(KviKvsObjectFunctionCall *c)
{
bool bEnabled;
KVSO_PARAMETERS_BEGIN(c)
KVSO_PARAMETER("bFlag",KVS_PT_BOOL,0,bEnabled)
KVSO_PARAMETERS_END(c)
if(widget())
((KviTalGroupBox *)widget())->setCheckable(bEnabled);
return true;
}
bool KviKvsObject_groupbox::functionIsCheckable(KviKvsObjectFunctionCall *c)
{
if (widget()) c->returnValue()->setBoolean(((KviTalGroupBox *)widget())->isCheckable());
return true;
}
bool KviKvsObject_groupbox::functionSetChecked(KviKvsObjectFunctionCall *c)
{
bool bEnabled;
KVSO_PARAMETERS_BEGIN(c)
KVSO_PARAMETER("bFlag",KVS_PT_BOOL,0,bEnabled)
KVSO_PARAMETERS_END(c)
if(widget())
((KviTalGroupBox *)widget())->setChecked(bEnabled);
return true;
}
bool KviKvsObject_groupbox::functionIsChecked(KviKvsObjectFunctionCall *c)
{
if (widget()) c->returnValue()->setBoolean(((KviTalGroupBox *)widget())->isChecked());
return true;
}
bool KviKvsObject_groupbox::functionSetInsideMargin(KviKvsObjectFunctionCall *c)
{
kvs_uint_t uMargin;
KVSO_PARAMETERS_BEGIN(c)
KVSO_PARAMETER("margin",KVS_PT_UNSIGNEDINTEGER,0,uMargin)
KVSO_PARAMETERS_END(c)
if (widget()) ((KviTalGroupBox *)widget())->setInsideMargin(uMargin);
return true;
}
bool KviKvsObject_groupbox::functionInsideMargin(KviKvsObjectFunctionCall *c)
{
if (widget()) c->returnValue()->setInteger(((KviTalGroupBox *)widget())->insideMargin());
return true;
}
bool KviKvsObject_groupbox::functionSetInsideSpacing(KviKvsObjectFunctionCall *c)
{
kvs_uint_t uSpacing;
KVSO_PARAMETERS_BEGIN(c)
KVSO_PARAMETER("spacing",KVS_PT_UNSIGNEDINTEGER,0,uSpacing)
KVSO_PARAMETERS_END(c)
if (widget()) ((KviTalGroupBox *)widget())->setInsideSpacing(uSpacing);
return true;
}
bool KviKvsObject_groupbox::functionInsideSpacing(KviKvsObjectFunctionCall *c)
{
if (widget()) c->returnValue()->setInteger(((KviTalGroupBox *)widget())->insideSpacing());
return true;
}
bool KviKvsObject_groupbox::functionSetColumns(KviKvsObjectFunctionCall *c)
{
kvs_uint_t uColums;
KVSO_PARAMETERS_BEGIN(c)
KVSO_PARAMETER("colums",KVS_PT_UNSIGNEDINTEGER,0,uColums)
KVSO_PARAMETERS_END(c)
if (widget()) ((KviTalGroupBox *)widget())->setColumns(uColums);
return true;
}
bool KviKvsObject_groupbox::functionColumns(KviKvsObjectFunctionCall *c)
{
if (widget()) c->returnValue()->setInteger(((KviTalGroupBox *)widget())->columns());
return true;
}
bool KviKvsObject_groupbox::functionAddSpace(KviKvsObjectFunctionCall *c)
{
kvs_uint_t iSpace;
KVSO_PARAMETERS_BEGIN(c)
KVSO_PARAMETER("colums",KVS_PT_UNSIGNEDINTEGER,0,iSpace)
KVSO_PARAMETERS_END(c)
if (widget()) (((KviTalGroupBox *)widget())->addSpace(iSpace));
return true;
}
bool KviKvsObject_groupbox::functionSetAlignment(KviKvsObjectFunctionCall *c)
{
TQString szAlign;
KVSO_PARAMETERS_BEGIN(c)
KVSO_PARAMETER("alignment",KVS_PT_STRING,0,szAlign)
KVSO_PARAMETERS_END(c)
if (!widget()) return true;
for(unsigned int i = 0; i < align_num; i++)
{
if(KviTQString::equalCI(szAlign, align_tbl[i]))
{
((KviTalGroupBox *)widget())->setAlignment(align_cod[i]);
return true;
}
}
c->warning(__tr2qs("Unknown alignment"));
return true;
}
bool KviKvsObject_groupbox::functionAlignment(KviKvsObjectFunctionCall *c)
{
int mode = ((KviTalGroupBox *)widget())->alignment();
TQString szAlignment="";
for(unsigned int i = 0; i < align_num; i++)
{
if(mode == align_cod[i])
{
szAlignment=align_tbl[i];
break;
}
}
c->returnValue()->setString(szAlignment);
return true;
}
bool KviKvsObject_groupbox::functionSetOrientation(KviKvsObjectFunctionCall *c)
{
TQString szMode;
KVSO_PARAMETERS_BEGIN(c)
KVSO_PARAMETER("orientation",KVS_PT_STRING,0,szMode)
KVSO_PARAMETERS_END(c)
if(!widget())return true;
if(KviTQString::equalCI(szMode, "Horizontal"))
((KviTalGroupBox *)widget())->setOrientation(TQt::Horizontal);
else
if(KviTQString::equalCI(szMode, "Vertical"))
((KviTalGroupBox *)widget())->setOrientation(TQt::Vertical);
else c->warning( __tr2qs("Unknown orientation: "));
return true;
}
bool KviKvsObject_groupbox::functionSetColumnLayout(KviKvsObjectFunctionCall *c)
{
TQString szMode;
kvs_uint_t uCol;
KVSO_PARAMETERS_BEGIN(c)
KVSO_PARAMETER("columns",KVS_PT_UNSIGNEDINTEGER,0,uCol)
KVSO_PARAMETER("orientation",KVS_PT_STRING,0,szMode)
KVSO_PARAMETERS_END(c)
if(!widget())return true;
if(szMode=="Horizontal")
((KviTalGroupBox *)widget())->setColumnLayout(uCol,TQt::Horizontal);
else
if(szMode=="Vertical")
((KviTalGroupBox *)widget())->setColumnLayout(uCol,TQt::Vertical);
else c->warning( __tr2qs("Unknown orientation: "));
return true;
}
|