~ubuntu-branches/ubuntu/trusty/kvirc/trusty

« back to all changes in this revision

Viewing changes to src/modules/objects/class_button.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kai Wasserbäch, Kai Wasserbäch, Raúl Sánchez Siles
  • Date: 2011-02-12 10:40:21 UTC
  • mfrom: (14.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110212104021-5mh4f75jlku20mnt
The combined "Twisted Experiment" and "Nocturnal Raid" release.

[ Kai Wasserbäch ]
* Synced to upstream's SVN revision 5467.
* debian/rules:
  - Added .PHONY line.
  - Resurrect -DMANUAL_REVISION, got lost somewhere and we build SVN
    revisions again.
  - Replace "-DWITH_NO_EMBEDDED_CODE=YES" with "-DWANT_CRYPTOPP=YES".
  - Change the remaining -DWITH/-DWITHOUT to the new -DWANT syntax.
* debian/control:
  - Removed DMUA, I'm a DD now.
  - Changed my e-mail address.
  - Removed unneeded relationships (no upgrades over two releases are
    supported).
  - Fix Suggests for kvirc-dbg.
  - kvirc-data: Make the "Suggests: kvirc" a Recommends, doesn't make much
    sense to install the -data package without the program.
* debian/source/local-options: Added with "unapply-patches".
* debian/kvirc.lintian-overrides: Updated to work for 4.1.1.
* debian/patches/21_make_shared-mime-info_B-D_superfluous.patch: Updated.
* debian/kvirc-data.install: Added .notifyrc.

[ Raúl Sánchez Siles ]
* Stating the right version where kvirc-data break and replace should happen.
* Fixing link to license file.
* Added French and Portuguese man pages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//=============================================================================
2
 
//
3
 
//   File : class_button.cpp
4
 
//   Creation date : Wed 13 Sep 2000 02:42:05 CEST by Krzysztof Godlewski
5
 
//
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)
9
 
//
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.
14
 
//
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.
19
 
//
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.
23
 
//
24
 
//=============================================================================
25
 
 
26
 
#include "kvi_debug.h"
27
 
#include "kvi_locale.h"
28
 
#include "kvi_error.h"
29
 
#include "kvi_iconmanager.h"
30
 
#include "kvi_file.h"
31
 
 
32
 
#include "class_button.h"
33
 
#include "class_pixmap.h"
34
 
 
35
 
#include <QIcon>
36
 
#include <QPushButton>
37
 
 
38
 
/*
39
 
        @doc:button
40
 
        @title:
41
 
                button class
42
 
        @type:
43
 
                class
44
 
        @short:
45
 
                Button widget.
46
 
        @inherits:
47
 
                [class]object[/class]
48
 
                [class]button[/class]
49
 
        @description:
50
 
                This widget provides a push button
51
 
        @functions:
52
 
                !fn: $setText([<text:string>])
53
 
                Set the button text.[br]
54
 
                See also [classfnc]$text[/classfnc]().
55
 
                !fn: <string> $text()
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.
61
 
                !fn: $clickEvent()
62
 
                Called by KVIrc when the mouse button is clicked.
63
 
                The default implementation emits the [classfnc]$clicked[/classfnc]()signal.
64
 
        @signals:
65
 
                !sg: $clicked()
66
 
                This signal is emitted by the default implementation of [classfnc]$clickEvent[/classfnc]().
67
 
        @properties:
68
 
                !pr: $scaledContents()
69
 
                This property holds whether the label will scale its contents to fill all available space.
70
 
*/
71
 
 
72
 
 
73
 
KVSO_BEGIN_REGISTERCLASS(KviKvsObject_button,"button","widget")
74
 
 
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)
79
 
 
80
 
KVSO_END_REGISTERCLASS(KviKvsObject_button)
81
 
 
82
 
KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_button,KviKvsObject_widget)
83
 
 
84
 
KVSO_END_CONSTRUCTOR(KviKvsObject_button)
85
 
 
86
 
 
87
 
KVSO_BEGIN_DESTRUCTOR(KviKvsObject_button)
88
 
 
89
 
KVSO_END_DESTRUCTOR(KviKvsObject_button)
90
 
 
91
 
bool KviKvsObject_button::init(KviKvsRunTimeContext *,KviKvsVariantList *)
92
 
{
93
 
        SET_OBJECT(QPushButton);
94
 
        connect(widget(),SIGNAL(clicked()),this,SLOT(slotClicked()));
95
 
        return true;
96
 
}
97
 
 
98
 
KVSO_CLASS_FUNCTION(button,text)
99
 
{
100
 
        CHECK_INTERNAL_POINTER(widget())
101
 
        c->returnValue()->setString(((QPushButton *)widget())->text());
102
 
        return true;
103
 
}
104
 
 
105
 
KVSO_CLASS_FUNCTION(button,setText)
106
 
{
107
 
        CHECK_INTERNAL_POINTER(widget())
108
 
        QString szText;
109
 
        KVSO_PARAMETERS_BEGIN(c)
110
 
                KVSO_PARAMETER("text",KVS_PT_STRING,0,szText)
111
 
        KVSO_PARAMETERS_END(c)
112
 
        ((QPushButton *)widget())->setText(szText);
113
 
        return true;
114
 
}
115
 
 
116
 
KVSO_CLASS_FUNCTION(button,setImage)
117
 
{
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)
123
 
        if(!pIcon)
124
 
        {
125
 
                c->warning(__tr2qs_ctx("Image parameter missing","object"));
126
 
                return true;
127
 
        }
128
 
        if(pIcon->isHObject())
129
 
        {
130
 
                kvs_hobject_t hObj;
131
 
                pIcon->asHObject(hObj);
132
 
                KviKvsObject *pObject = KviKvsKernel::instance()->objectController()->lookupObject(hObj);
133
 
                if (!pObject)
134
 
                {
135
 
                        c->warning(__tr2qs_ctx("Pixmap parameter is not an object!","objects"));
136
 
                        return true;
137
 
                }
138
 
                if(pObject->inheritsClass("pixmap"))
139
 
                        ((QPushButton *)widget())->setIcon(QIcon(*((KviKvsObject_pixmap *)pObject)->getPixmap()));
140
 
                else
141
 
                        c->warning(__tr2qs_ctx("Object Pixmap required!","object"));
142
 
                return true;
143
 
        }
144
 
        QString szIcon;
145
 
        pIcon->asString(szIcon);
146
 
        QPixmap * pix = g_pIconManager->getImage(szIcon);
147
 
        if(pix) ((QPushButton *)widget())->setIcon(*pix);
148
 
        else((QPushButton *)widget())->setIcon(QIcon());
149
 
        return true;
150
 
}
151
 
KVSO_CLASS_FUNCTION(button,clickEvent)
152
 
{
153
 
        emitSignal("clicked",c);
154
 
        return true;
155
 
}
156
 
 
157
 
// slots
158
 
void KviKvsObject_button::slotClicked()
159
 
{
160
 
        KviKvsVariantList *params=0;
161
 
        callFunction(this,"clickEvent",params);
162
 
}
163
 
 
164
 
 
165
 
#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES
166
 
#include "m_class_button.moc"
167
 
#endif //COMPILE_USE_STANDALONE_MOC_SOURCES