summaryrefslogtreecommitdiffstats
path: root/src/modules/objects/class_radiobutton.cpp
blob: 204909aed0a0839f07df5a6e024951bccf151696 (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
//
//   File : class_radiobutton.cpp
//   Creation date : Thu Feb 08 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 "class_radiobutton.h"
#include "kvi_error.h"
#include "kvi_debug.h"

#include "kvi_locale.h"
#include "kvi_iconmanager.h"

/*
	@doc: radiobutton
	@keyterms:
		radiobutton widget class
	@title:
		radiobutton class
	@type:
		class
	@short:
		A radiobutton class
	@inherits:
		[class]widget[/class]
	@description:
		The RadioButton widget provides a radio button with a text or pixmap label.
	@functions:
		!fn: $settext(<text:string>)
		Sets the text that will appear in the radiobutton.
		!fn: <boolean> $isChecked()
		Returns 1 (TRUE) if the radio button is checked; otherwise returns 0 (FALSE). 
		!fn: $setChecked(<bChecked:boolean>)
		Sets whether the radio button is checked to check.
		!fn: $setPixmap(<image_id>)
		Sets the pixmap shown on the radiobutton..See the [doc:image_id]image identifier[/doc] documentation for the explaination
		of the <image_id> parameter.
		!fn: <bool>$toggleEvent()
		Called by KVIrc when the radibutton state is toggled.
		The default implementation emits the toggled(<bool>) signal.
		!sg: $toggled()
		This signal is emitted by the default implementation of [classfnc]$toggleEvent[/classfnc]().[br]
		

*/


KVSO_BEGIN_REGISTERCLASS(KviKvsObject_radiobutton,"radiobutton","widget")

	KVSO_REGISTER_HANDLER(KviKvsObject_radiobutton,"setText", functionSetText)
	KVSO_REGISTER_HANDLER(KviKvsObject_radiobutton,"setChecked", functionSetChecked)
	KVSO_REGISTER_HANDLER(KviKvsObject_radiobutton,"isChecked", functionIsChecked)
	KVSO_REGISTER_HANDLER(KviKvsObject_radiobutton,"setImage", functionSetImage)
	KVSO_REGISTER_HANDLER(KviKvsObject_radiobutton,"toggleEvent",function_toggleEvent)

KVSO_END_REGISTERCLASS(KviKvsObject_radiobutton)

KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_radiobutton,KviKvsObject_widget)

KVSO_END_CONSTRUCTOR(KviKvsObject_radiobutton)


KVSO_BEGIN_DESTRUCTOR(KviKvsObject_radiobutton)

KVSO_END_CONSTRUCTOR(KviKvsObject_radiobutton)

bool KviKvsObject_radiobutton::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams)
{
	setObject(TQT_TQOBJECT(new TQRadioButton(parentScriptWidget(),name())),true);
	connect(widget(),TQT_SIGNAL(toggled(bool)),this,TQT_SLOT(toggled(bool)));
	return true;
}
bool KviKvsObject_radiobutton::functionSetText(KviKvsObjectFunctionCall *c)
{
	TQString szText;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("text",KVS_PT_STRING,0,szText)
	KVSO_PARAMETERS_END(c)
	if (widget())
		((TQRadioButton *)widget())->setText(szText);
	return true;
}
bool KviKvsObject_radiobutton::functionIsChecked(KviKvsObjectFunctionCall *c)
{
	if(widget()) c->returnValue()->setBoolean(((TQRadioButton *)widget())->isChecked());
	return true;
}

bool KviKvsObject_radiobutton::functionSetChecked(KviKvsObjectFunctionCall *c)
{
	bool bChecked;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("bChecked",KVS_PT_BOOL,0,bChecked)
	KVSO_PARAMETERS_END(c)
	if(widget()) ((TQRadioButton *)widget())->setChecked(bChecked);
	return true;
}
bool KviKvsObject_radiobutton::functionSetImage(KviKvsObjectFunctionCall *c)
{
	TQString icon;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("icon_id",KVS_PT_STRING,0,icon)
	KVSO_PARAMETERS_END(c)
	if (!widget()) return true;
	TQPixmap * pix = g_pIconManager->getImage(icon);
	if(pix)widget()->setIcon(*pix);
	return true;
}
bool KviKvsObject_radiobutton::function_toggleEvent(KviKvsObjectFunctionCall *c)
{
	emitSignal("toggled",c,c->params());
	return true;
}

void KviKvsObject_radiobutton::toggled(bool b)
{
	KviKvsVariantList params(new KviKvsVariant(b));
	callFunction(this,"toggleEvent",&params);
}


#include "m_class_radiobutton.moc"