summaryrefslogtreecommitdiffstats
path: root/src/modules/objects/class_button.cpp
blob: 54d1525aa547b025b91e4039ca6cffb3aafc707e (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
//
//   File : class_button.cpp
//   Creation date : Wed 13 Sep 2000 02:42:05 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_debug.h"


#include "kvi_error.h"
#include <qiconset.h>
#include "kvi_iconmanager.h"

#include "class_button.h"

KVSO_BEGIN_REGISTERCLASS(KviKvsObject_button,"button","widget")

	KVSO_REGISTER_HANDLER(KviKvsObject_button,"setText", functionSetText)
	KVSO_REGISTER_HANDLER(KviKvsObject_button,"text", functionText)
	KVSO_REGISTER_HANDLER(KviKvsObject_button,"setAutoDefault", functionSetAutoDefault)
	KVSO_REGISTER_HANDLER(KviKvsObject_button,"setToggleButton", functionSetToggleButton)
	KVSO_REGISTER_HANDLER(KviKvsObject_button,"setOn", functionSetOn)
	KVSO_REGISTER_HANDLER(KviKvsObject_button,"isOn", functionIsOn)
	KVSO_REGISTER_HANDLER(KviKvsObject_button,"toggle", functionToggle)
	KVSO_REGISTER_HANDLER(KviKvsObject_button,"setIsMenuButton", functionSetIsMenuButton)
	KVSO_REGISTER_HANDLER(KviKvsObject_button,"isMenuButton", functionIsMenuButton)
	KVSO_REGISTER_HANDLER(KviKvsObject_button,"clickEvent", functionclickEvent)
	KVSO_REGISTER_HANDLER(KviKvsObject_button,"setImage", functionSetImage)


KVSO_END_REGISTERCLASS(KviKvsObject_button)

KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_button,KviKvsObject_widget)

KVSO_END_CONSTRUCTOR(KviKvsObject_button)


KVSO_BEGIN_DESTRUCTOR(KviKvsObject_button)

KVSO_END_CONSTRUCTOR(KviKvsObject_button)

bool KviKvsObject_button::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams)
{
	setObject(new QPushButton(parentScriptWidget(),name()),true);
	connect(widget(),SIGNAL(clicked()),this,SLOT(slotClicked()));
	return true;
}

bool KviKvsObject_button::functionText(KviKvsObjectFunctionCall *c)
{
	if(widget()) c->returnValue()->setString(((QPushButton *)widget())->text());
	return true;
}

bool KviKvsObject_button::functionSetText(KviKvsObjectFunctionCall *c)
{
	QString szText;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("text",KVS_PT_STRING,0,szText)
	KVSO_PARAMETERS_END(c)
	if (widget())
		((QPushButton *)widget())->setText(szText);
	return true;
}
bool KviKvsObject_button::functionSetAutoDefault(KviKvsObjectFunctionCall *c)
{
	bool bEnabled;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled)
	KVSO_PARAMETERS_END(c)
	if(widget())
		((QPushButton *)widget())->setAutoDefault(bEnabled);
	return true;
}
bool KviKvsObject_button::functionSetToggleButton(KviKvsObjectFunctionCall *c)
{
	bool bEnabled;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled)
	KVSO_PARAMETERS_END(c)
	if(widget())
		((QPushButton *)widget())->setToggleButton(bEnabled);
	return true;
}
bool KviKvsObject_button::functionSetOn(KviKvsObjectFunctionCall *c)
{
	bool bEnabled;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled)
	KVSO_PARAMETERS_END(c)
	if(widget())
		((QPushButton *)widget())->setOn(bEnabled);
	return true;
}
// FIX ME
bool KviKvsObject_button::functionSetIsMenuButton(KviKvsObjectFunctionCall *c)
{
	bool bEnabled;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled)
	KVSO_PARAMETERS_END(c)
	/*if(widget())
		((QPushButton *)widget())->setIsMenuButton(bEnabled);
		*/

	return true;
}
bool KviKvsObject_button::functionIsMenuButton(KviKvsObjectFunctionCall *c)
{
	if (widget()) c->returnValue()->setBoolean(((QPushButton *)widget())->isMenuButton());
	return true;
}
//
bool KviKvsObject_button::functionIsOn(KviKvsObjectFunctionCall *c)
{
	if (widget()) c->returnValue()->setBoolean(((QPushButton *)widget())->isOn());
	return true;
}
bool KviKvsObject_button::functionToggle(KviKvsObjectFunctionCall *c)
{
	if(widget()) ((QPushButton *)widget())->toggle();
	return true;
}
// FIX ME
bool KviKvsObject_button::functionSetImage(KviKvsObjectFunctionCall *c)
{
	QString icon;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("icon",KVS_PT_STRING,0,icon)
	KVSO_PARAMETERS_END(c)
	if (!widget()) return true;
	QPixmap * pix = g_pIconManager->getImage(icon);
	if(pix){
		#ifdef COMPILE_USE_QT4	
		((QPushButton *)widget())->setIconSet(*pix);
		#else
		((QPushButton *)widget())->setIconSet(QIconSet(*pix,QIconSet::Small));
		#endif
	}
	else{
		#ifdef COMPILE_USE_QT4	
		((QPushButton *)widget())->setIcon(QIconSet());
		#else
		((QPushButton *)widget())->setIconSet(QIconSet());
		#endif
	}
	return true;
}
bool KviKvsObject_button::functionclickEvent(KviKvsObjectFunctionCall *c)
{
	emitSignal("clicked",c);
	return true;
}

void KviKvsObject_button::slotClicked()
{
	KviKvsVariantList *params=0;
	callFunction(this,"clickEvent",params);
}


#include "m_class_button.moc"