summaryrefslogtreecommitdiffstats
path: root/src/modules/objects/class_layout.cpp
blob: b2842a8c5f3e7e33210e5d414a54fee1d0bd2f6a (plain)
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
//
//   File : class_layout.cpp
//   Creation date : Fri Now 22 2002 00:50:01 by Szymon Stefanek
//
//   This file is part of the KVirc irc client distribution
//   Copyright (C) 2002 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.
//
#define _KVI_DEBUG_CHECK_RANGE_
#include "kvi_debug.h"

#include "kvi_locale.h"

#include "class_layout.h"

#ifdef COMPILE_USE_QT4
#define TQLAYOUT_AUTO_CONSTRAINT TQLayout::SetDefaultConstraint
#define TQLAYOUT_FIXED TQLayout::SetFixedSize
#define TQLAYOUT_FREE_RESIZE TQLayout::SetNoConstraint
#define TQLAYOUT_MINIMUM TQLayout::SetMinimumSize
#else
#define TQLAYOUT_AUTO_CONSTRAINT TQLayout::Auto
#define TQLAYOUT_FIXED TQLayout::Fixed
#define TQLAYOUT_FREE_RESIZE TQLayout::FreeResize
#define TQLAYOUT_MINIMUM TQLayout::Minimum
#endif 


/*
	@doc: tqlayout
	@keyterms:
		tqlayout object class, child widgets
	@title:
		tqlayout class
	@type:
		class
	@short:
		Manages child widget tqgeometry
	@inherits:
		[class]object[/class]
	@description:
		The tqlayout is a tqgeometry management tool for child widgets.
		You create a tqlayout , give it some widgets to manage and it will tqlayout them
		automatically.[br]
		The parent of the tqlayout must be the widget for which child widget geometries have to be managed.
		A tqlayout is a grid of NxM cells in which you insert child widgets with [classfnc:tqlayout]$addWidget[/classfnc]().[br]
		Widgets that must span multiple cells can be added to the tqlayout with [classfnc:tqlayout]$addMultiCellWidget[/classfnc]().[br]
	@functions:
		!fn: $addWidget(<widget:object widget>,<row:uint>,<column:uint>)
		Adds a widget to this tqlayout placing it at position <row>,<column> in the grid
		!fn: $addMultiCellWidget(<widget:object widget>,<start_row:uint>,<end_row:uint>,<start_col:uint>,<end_col:uint>)
		Adds a widget to this tqlayout spanning multiple grid cells
		!fn: $setRowStretch(<row:uint>,<stretch:uint>)
		Sets the stretch value for a particular row of this tqlayout. The <stretch_value>
		must be a positive integer. The rows with bigger stretch values will take more space
		in the tqlayout.
		!fn: $setColStretch(<column:uint>,<stretch:uint>)
		Sets the stretch value for a particular column in this tqlayout. The <stretch_value>
		must be a positive integer. The rows with bigger stretch values will take more space
		in the tqlayout.
		!fn: $addRowSpacing(<row:uint>,<spacing:uint>)
		Sets the minimum height of the specified <row> to <spacing> which must be a positive integer
		!fn: $addColSpacing(<column:uint>,<spacing:uint>)
		Sets the minimum width of the specigfied <column> to <spacing> which must be a positive integer
		!fn: $setSpacing(<spacing:uint>)
		Sets the default spacing of the widgets in pixels
		!fn: $setMargin(<margin:uint>)
		Sets the dimension of the tqlayout margin : the distance from the border to the outermost child widget edges.
		!fn: $setResizeMode(<resize_mode:string>)
		Sets the resize mode of the parent widget in relation to this tqlayout.
		<mode> can be one of:[br]
		-Auto: this is the default[br]
		-Fixed: the parent widget of this tqlayout is resized to the "tqsizeHint" value and it cannot be resized by the user.[br]
		-Minimum: the minimum size of the parent widget of this tqlayout is set to tqminimumSize() and it cannot be smaller[br]
		-FreeResize: the parent widget of this tqlayout is not constrained at all[br]
*/


KVSO_BEGIN_REGISTERCLASS(KviKvsObject_layout,"tqlayout","object")
	KVSO_REGISTER_HANDLER(KviKvsObject_layout,"addWidget", functionAddWidget)
	KVSO_REGISTER_HANDLER(KviKvsObject_layout,"addMultiCellWidget", functionAddMultiCellWidget)
	KVSO_REGISTER_HANDLER(KviKvsObject_layout,"setRowStretch", functionSetRowStretch)
	KVSO_REGISTER_HANDLER(KviKvsObject_layout,"setColStretch", functionSetColStretch)
	KVSO_REGISTER_HANDLER(KviKvsObject_layout,"addRowSpacing", functionAddRowSpacing)
	KVSO_REGISTER_HANDLER(KviKvsObject_layout,"addColSpacing", functionAddColSpacing)
	KVSO_REGISTER_HANDLER(KviKvsObject_layout,"setMargin", functionSetMargin)
	KVSO_REGISTER_HANDLER(KviKvsObject_layout,"setSpacing", functionSetSpacing)
	KVSO_REGISTER_HANDLER(KviKvsObject_layout,"setResizeMode", functionSetResizeMode)
KVSO_END_REGISTERCLASS(KviKvsObject_layout)

KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_layout,KviKvsObject)

KVSO_END_CONSTRUCTOR(KviKvsObject_layout)


KVSO_BEGIN_DESTRUCTOR(KviKvsObject_layout)

KVSO_END_CONSTRUCTOR(KviKvsObject_layout)

bool KviKvsObject_layout::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams)
{
	TQWidget * w = parentScriptWidget();

	if(!w)
	{
		pContext->warning(__tr2qs("The parent of a tqlayout must be a widget!"));
		return false;
	}
	setObject(TQT_TQOBJECT(new TQGridLayout(w)));
	return true;
}

bool KviKvsObject_layout::functionAddWidget(KviKvsObjectFunctionCall *c)
{
	KviKvsObject * pObject;
	kvs_hobject_t hObject;
	kvs_uint_t uCol,uRow;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("widget",KVS_PT_HOBJECT,0,hObject)
		KVSO_PARAMETER("row",KVS_PT_UNSIGNEDINTEGER,0,uRow)
		KVSO_PARAMETER("col",KVS_PT_UNSIGNEDINTEGER,0,uCol)
	KVSO_PARAMETERS_END(c)
	pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject);
	if(!widget())return true;
	if (!pObject)
	{
		c->warning(__tr2qs("Widget parameter is not an object"));
		return true;
	}
	if (!pObject->object())
	{
		c->warning(__tr2qs("Widget parameter is not a valid object"));
		return true;
	}
	if(!pObject->object()->isWidgetType())
	{
		c->warning(__tr2qs("Can't add a non-widget object"));
		return true;
	}
	((TQGridLayout *)object())->addWidget(((TQWidget *)(pObject->object())),uRow,uCol);
	return true;
}
bool KviKvsObject_layout::functionAddMultiCellWidget(KviKvsObjectFunctionCall *c)
{
	KviKvsObject * pObject;
	kvs_hobject_t hObject;
	kvs_uint_t uStartCol,uStartRow,uEndCol,uEndRow;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("widget",KVS_PT_HOBJECT,0,hObject)
		KVSO_PARAMETER("start_row",KVS_PT_UNSIGNEDINTEGER,0,uStartRow)
		KVSO_PARAMETER("end_row",KVS_PT_UNSIGNEDINTEGER,0,uEndRow)
		KVSO_PARAMETER("start_column",KVS_PT_UNSIGNEDINTEGER,0,uStartCol)
		KVSO_PARAMETER("end_column",KVS_PT_UNSIGNEDINTEGER,0,uEndCol)
	KVSO_PARAMETERS_END(c)
	pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject);
	if(!widget())return true;
	if (!pObject)
	{
		c->warning(__tr2qs("Widget parameter is not an object"));
		return true;
	}
	if (!pObject->object())
	{
		c->warning(__tr2qs("Widget parameter is not a valid object"));
		return true;
	}
	if(!pObject->object()->isWidgetType())
	{
		c->warning(__tr2qs("Can't add a non-widget object"));
		return true;
	}
	((TQGridLayout *)object())->addMultiCellWidget(((TQWidget *)(pObject->object())),uStartRow,uEndRow,uStartCol,uEndCol);
	return true;
}
bool KviKvsObject_layout::functionSetRowStretch(KviKvsObjectFunctionCall *c)
{
	kvs_uint_t uRow,uStretch;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("row",KVS_PT_UNSIGNEDINTEGER,0,uRow)
		KVSO_PARAMETER("stretch",KVS_PT_UNSIGNEDINTEGER,0,uStretch)
	KVSO_PARAMETERS_END(c)
	if(!widget())return true;
	((TQGridLayout *)object())->setRowStretch(uRow,uStretch);
	return true;
}
bool KviKvsObject_layout::functionSetColStretch(KviKvsObjectFunctionCall *c)
{
	kvs_uint_t uCol,uStretch;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("column",KVS_PT_UNSIGNEDINTEGER,0,uCol)
		KVSO_PARAMETER("stretch",KVS_PT_UNSIGNEDINTEGER,0,uStretch)
	KVSO_PARAMETERS_END(c)
	if(!widget())return true;
	((TQGridLayout *)object())->setColStretch(uCol,uStretch);
	return true;
}

bool KviKvsObject_layout::functionSetMargin(KviKvsObjectFunctionCall *c)
{
	kvs_uint_t uMargin;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("margin",KVS_PT_UNSIGNEDINTEGER,0,uMargin)
	KVSO_PARAMETERS_END(c)
    if (widget()) ((TQGridLayout *)object())->setMargin(uMargin);
	return true;
}

bool KviKvsObject_layout::functionSetSpacing(KviKvsObjectFunctionCall *c)
{
	kvs_uint_t uSpacing;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("spacing",KVS_PT_UNSIGNEDINTEGER,0,uSpacing)
	KVSO_PARAMETERS_END(c)
    if (widget()) ((TQGridLayout *)object())->setSpacing(uSpacing);
	return true;
}


bool KviKvsObject_layout::functionAddRowSpacing(KviKvsObjectFunctionCall *c)
{
	kvs_uint_t uSpacing,uRow;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("row",KVS_PT_UNSIGNEDINTEGER,0,uRow)
		KVSO_PARAMETER("spacing",KVS_PT_UNSIGNEDINTEGER,0,uSpacing)
	KVSO_PARAMETERS_END(c)
    if (widget()) ((TQGridLayout *)object())->addRowSpacing(uRow,uSpacing);
	return true;
}

bool KviKvsObject_layout::functionAddColSpacing(KviKvsObjectFunctionCall *c)
{
	kvs_uint_t uSpacing,uCol;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("column",KVS_PT_UNSIGNEDINTEGER,0,uCol)
		KVSO_PARAMETER("spacing",KVS_PT_UNSIGNEDINTEGER,0,uSpacing)
	KVSO_PARAMETERS_END(c)
    if (widget()) ((TQGridLayout *)object())->addColSpacing(uCol,uSpacing);
	return true;
}

bool KviKvsObject_layout::functionSetResizeMode(KviKvsObjectFunctionCall *c)
{
	TQString szMode;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("resize_mode",KVS_PT_STRING,0,szMode)
	KVSO_PARAMETERS_END(c)
	if(!widget())return true;
#ifdef COMPILE_USE_QT4
	TQLayout::SizeConstraint r = TQLAYOUT_AUTO_CONSTRAINT;
#else
	TQLayout::ResizeMode r = TQLAYOUT_AUTO_CONSTRAINT;
#endif
	if(KviTQString::equalCI(szMode,"FreeResize")) r = TQLAYOUT_FREE_RESIZE;
	else if(KviTQString::equalCI(szMode,"Minimum")) r = TQLAYOUT_MINIMUM;
	else if(KviTQString::equalCI(szMode,"Fixed"))r = TQLAYOUT_FIXED;
	else c->warning(__tr2qs("Invalid resize mode defaulting to Auto"));
	((TQGridLayout *)object())->setResizeMode(r);
	return true;

}