1
//=============================================================================
3
// File : class_button.cpp
4
// Creation date : Wed 13 Sep 2000 02:42:05 CEST by Krzysztof Godlewski
6
// This file is part of the KVirc irc client distribution
7
// Copyright (C) 2000 Krzysztof Godlewski
8
// Copyright (C) 2000-2009 Szymon Stefanek (pragma at kvirc dot net)
10
// This program is FREE software. You can redistribute it and/or
11
// modify it under the terms of the GNU General Public License
12
// as published by the Free Software Foundation; either version 2
13
// of the License, or (at your opinion) any later version.
15
// This program is distributed in the HOPE that it will be USEFUL,
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18
// See the GNU General Public License for more details.
20
// You should have received a copy of the GNU General Public License
21
// along with this program. If not, write to the Free Software Foundation,
22
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24
//=============================================================================
26
#include "kvi_debug.h"
27
#include "kvi_locale.h"
28
#include "kvi_error.h"
29
#include "kvi_iconmanager.h"
32
#include "class_button.h"
33
#include "class_pixmap.h"
36
#include <QPushButton>
50
This widget provides a push button
52
!fn: $setText([<text:string>])
53
Set the button text.[br]
54
See also [classfnc]$text[/classfnc]().
56
Return the button text.[br]
57
See also [classfnc]$setText[/classfnc]().
58
!fn: $setImage(<image_id_or_pixmap_object>)
59
Sets the icon for this button.
60
See the [doc:image_id]image identifier[/doc] documentation for the explaination of the <image_id> parameter.
62
Called by KVIrc when the mouse button is clicked.
63
The default implementation emits the [classfnc]$clicked[/classfnc]()signal.
66
This signal is emitted by the default implementation of [classfnc]$clickEvent[/classfnc]().
68
!pr: $scaledContents()
69
This property holds whether the label will scale its contents to fill all available space.
73
KVSO_BEGIN_REGISTERCLASS(KviKvsObject_button,"button","widget")
75
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_button,setText)
76
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_button,text)
77
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_button,clickEvent)
78
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_button,setImage)
80
KVSO_END_REGISTERCLASS(KviKvsObject_button)
82
KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_button,KviKvsObject_widget)
84
KVSO_END_CONSTRUCTOR(KviKvsObject_button)
87
KVSO_BEGIN_DESTRUCTOR(KviKvsObject_button)
89
KVSO_END_DESTRUCTOR(KviKvsObject_button)
91
bool KviKvsObject_button::init(KviKvsRunTimeContext *,KviKvsVariantList *)
93
SET_OBJECT(QPushButton);
94
connect(widget(),SIGNAL(clicked()),this,SLOT(slotClicked()));
98
KVSO_CLASS_FUNCTION(button,text)
100
CHECK_INTERNAL_POINTER(widget())
101
c->returnValue()->setString(((QPushButton *)widget())->text());
105
KVSO_CLASS_FUNCTION(button,setText)
107
CHECK_INTERNAL_POINTER(widget())
109
KVSO_PARAMETERS_BEGIN(c)
110
KVSO_PARAMETER("text",KVS_PT_STRING,0,szText)
111
KVSO_PARAMETERS_END(c)
112
((QPushButton *)widget())->setText(szText);
116
KVSO_CLASS_FUNCTION(button,setImage)
118
CHECK_INTERNAL_POINTER(widget())
119
KviKvsVariant * pIcon;
120
KVSO_PARAMETERS_BEGIN(c)
121
KVSO_PARAMETER("icon_or_hobject",KVS_PT_VARIANT,0,pIcon)
122
KVSO_PARAMETERS_END(c)
125
c->warning(__tr2qs_ctx("Image parameter missing","object"));
128
if(pIcon->isHObject())
131
pIcon->asHObject(hObj);
132
KviKvsObject *pObject = KviKvsKernel::instance()->objectController()->lookupObject(hObj);
135
c->warning(__tr2qs_ctx("Pixmap parameter is not an object!","objects"));
138
if(pObject->inheritsClass("pixmap"))
139
((QPushButton *)widget())->setIcon(QIcon(*((KviKvsObject_pixmap *)pObject)->getPixmap()));
141
c->warning(__tr2qs_ctx("Object Pixmap required!","object"));
145
pIcon->asString(szIcon);
146
QPixmap * pix = g_pIconManager->getImage(szIcon);
147
if(pix) ((QPushButton *)widget())->setIcon(*pix);
148
else((QPushButton *)widget())->setIcon(QIcon());
151
KVSO_CLASS_FUNCTION(button,clickEvent)
153
emitSignal("clicked",c);
158
void KviKvsObject_button::slotClicked()
160
KviKvsVariantList *params=0;
161
callFunction(this,"clickEvent",params);
165
#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES
166
#include "m_class_button.moc"
167
#endif //COMPILE_USE_STANDALONE_MOC_SOURCES