aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/objects/class_groupbox.cpp
blob: 644f8fa5828d39948cee44642fcb8c7ecc98c3ef (about) (plain) (blame)
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
//=============================================================================
//
//   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) 2005-2009 Alessandro Carbone (elfonol at gmail dot com)
//
//   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[] = {
	Qt::AlignLeft,
	Qt::AlignRight,
	Qt::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: $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.
	@examples:
		[example]
			//Let's start.
			//First we'll create the main widget. as a dialog
			%widget=$new(dialog)
			%layout=$new(layout,%widget)
			//then the groupbox
			%gb=$new(groupbox,%widget)
			%gb->$setTitle(Login)
			%gb->$setAlignment("Left")
			// add the gbox to the main layout
			%layout->$addWidget(%gb,0,0)
			// now we create the user field  (labels + lineedit)
			// in a horizontal box
			%hbox=$new(hbox,%gb)
			%labeluser=$new(label,%hbox)
			%labeluser->$settext(User: )
			%inputuser=$new(lineedit,%hbox)
			//now we create the pass field  (labels + lineedit).
			// in a horizontal box
			%hbox=$new(hbox,%gb)
			%labelpass=$new(label,%hbox)
			%labelpass->$settext(Pass: )
			%inputpass=$new(lineedit,%hbox)
			%inputpass->$setechomode("password")
			// now we create the ok/cancel box buttons
			%hbox=$new(hbox,%gb)
			%btnok=$new(button,%hbox)
			%btnok->$settext("OK")
			%btncancel=$new(button,%hbox)
			%btncancel->$settext("Cancel")

			//Let's show our nice form
			%widget->$show()
		[/example]

*/

KVSO_BEGIN_REGISTERCLASS(KviKvsObject_groupbox,"groupbox","widget")
	KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_groupbox,setTitle)
	KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_groupbox,title)
	KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_groupbox,setFlat)
	KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_groupbox,isFlat)
	KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_groupbox,setCheckable)
	KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_groupbox,isCheckable)
	KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_groupbox,setInsideMargin)
	KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_groupbox,insideMargin)
	KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_groupbox,setInsideSpacing)
	KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_groupbox,insideSpacing)
	KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_groupbox,addSpace)
	KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_groupbox,alignment)
	KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_groupbox,setAlignment)
	KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_groupbox,setOrientation)
	KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_groupbox,isChecked)
	KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_groupbox,setChecked)

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 *,KviKvsVariantList *)
{
	KviTalGroupBox *groupbox=new KviTalGroupBox(getName(),parentScriptWidget());

	groupbox->setOrientation(Qt::Horizontal);
	groupbox->setObjectName(getName());
	setObject(groupbox,true);
	return true;
}

KVSO_CLASS_FUNCTION(groupbox,setTitle)
{
	CHECK_INTERNAL_POINTER(widget())
	QString szTitle;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("title",KVS_PT_STRING,0,szTitle)
	KVSO_PARAMETERS_END(c)
	((KviTalGroupBox *)widget())->setTitle(szTitle);
	return true;
}
KVSO_CLASS_FUNCTION(groupbox,title)
{
	CHECK_INTERNAL_POINTER(widget())
	c->returnValue()->setString(((KviTalGroupBox *)widget())->title());
	return true;
}
KVSO_CLASS_FUNCTION(groupbox,setFlat)
{
	CHECK_INTERNAL_POINTER(widget())
	bool bEnabled;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("bFlag",KVS_PT_BOOL,0,bEnabled)
	KVSO_PARAMETERS_END(c)
	((KviTalGroupBox *)widget())->setFlat(bEnabled);
	return true;
}
KVSO_CLASS_FUNCTION(groupbox,isFlat)
{
	CHECK_INTERNAL_POINTER(widget())
	c->returnValue()->setBoolean(((KviTalGroupBox *)widget())->isFlat());
	return true;
}
KVSO_CLASS_FUNCTION(groupbox,setCheckable)
{
	CHECK_INTERNAL_POINTER(widget())
	bool bEnabled;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("bFlag",KVS_PT_BOOL,0,bEnabled)
	KVSO_PARAMETERS_END(c)
	((KviTalGroupBox *)widget())->setCheckable(bEnabled);
	return true;
}
KVSO_CLASS_FUNCTION(groupbox,isCheckable)
{
	CHECK_INTERNAL_POINTER(widget())
	c->returnValue()->setBoolean(((KviTalGroupBox *)widget())->isCheckable());
	return true;
}
KVSO_CLASS_FUNCTION(groupbox,setChecked)
{
	CHECK_INTERNAL_POINTER(widget())
	bool bEnabled;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("bFlag",KVS_PT_BOOL,0,bEnabled)
	KVSO_PARAMETERS_END(c)
	((KviTalGroupBox *)widget())->setChecked(bEnabled);
	return true;
}
KVSO_CLASS_FUNCTION(groupbox,isChecked)
{
	CHECK_INTERNAL_POINTER(widget())
	c->returnValue()->setBoolean(((KviTalGroupBox *)widget())->isChecked());
	return true;
}
KVSO_CLASS_FUNCTION(groupbox,setInsideMargin)
{
	CHECK_INTERNAL_POINTER(widget())
	kvs_uint_t uMargin;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("margin",KVS_PT_UNSIGNEDINTEGER,0,uMargin)
	KVSO_PARAMETERS_END(c)
	((KviTalGroupBox *)widget())->setInsideMargin(uMargin);
	return true;
}
KVSO_CLASS_FUNCTION(groupbox,insideMargin)
{
	CHECK_INTERNAL_POINTER(widget())
	c->returnValue()->setInteger(((KviTalGroupBox *)widget())->insideMargin());
	return true;
}
KVSO_CLASS_FUNCTION(groupbox,setInsideSpacing)
{
	CHECK_INTERNAL_POINTER(widget())
	kvs_uint_t uSpacing;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("spacing",KVS_PT_UNSIGNEDINTEGER,0,uSpacing)
	KVSO_PARAMETERS_END(c)
    ((KviTalGroupBox *)widget())->setInsideSpacing(uSpacing);
	return true;
}
KVSO_CLASS_FUNCTION(groupbox,insideSpacing)
{
	CHECK_INTERNAL_POINTER(widget())
	c->returnValue()->setInteger(((KviTalGroupBox *)widget())->insideSpacing());
	return true;
}

KVSO_CLASS_FUNCTION(groupbox,addSpace)
{
	CHECK_INTERNAL_POINTER(widget())
	kvs_uint_t iSpace;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("colums",KVS_PT_UNSIGNEDINTEGER,0,iSpace)
	KVSO_PARAMETERS_END(c)
	(((KviTalGroupBox *)widget())->addSpace(iSpace));
	return true;
}

KVSO_CLASS_FUNCTION(groupbox,setAlignment)
{
	CHECK_INTERNAL_POINTER(widget())
	QString szAlign;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("alignment",KVS_PT_STRING,0,szAlign)
	KVSO_PARAMETERS_END(c)
	for(unsigned int i = 0; i < align_num; i++)
	{
		if(KviQString::equalCI(szAlign, align_tbl[i]))
		{
			((KviTalGroupBox *)widget())->setAlignment(align_cod[i]);
			return true;
		}
	}
	c->warning(__tr2qs_ctx("Unknown alignment '%Q'","objets"),&szAlign);
	return true;
}

KVSO_CLASS_FUNCTION(groupbox,alignment)
{
	CHECK_INTERNAL_POINTER(widget())
	int mode = ((KviTalGroupBox *)widget())->alignment();
	QString 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;
}

KVSO_CLASS_FUNCTION(groupbox,setOrientation)
{
	CHECK_INTERNAL_POINTER(widget())
	QString szMode;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("orientation",KVS_PT_STRING,0,szMode)
	KVSO_PARAMETERS_END(c)
	if(KviQString::equalCI(szMode, "Horizontal"))
		((KviTalGroupBox *)widget())->setOrientation(Qt::Vertical);
	else
	if(KviQString::equalCI(szMode, "Vertical"))
		((KviTalGroupBox *)widget())->setOrientation(Qt::Horizontal);
	else c->warning( __tr2qs_ctx("Unknown orientation '%Q'","objects"),&szMode);

	return true;
}