1
#ifndef __KSCRIPT_EXT_QT_H__
2
#define __KSCRIPT_EXT_QT_H__
4
#include "kscript_context.h"
5
#include "kscript_object.h"
6
#include "kscript_value.h"
11
#include <qvaluelist.h>
12
#include <qconnection.h>
13
#include <qguardedptr.h>
19
extern KSModule::Ptr ksCreateModule_Qt( KSInterpreter* );
22
* There is at all times only one instance of this class
25
class KS_Qt_Callback : public QObject
30
* Use this function to connect to the destroyed signal of the QObject.
31
* So we become informed if the QObject is about to die.
33
void connect( QObject*, KS_Qt_Object* );
35
* Connect a qt_signal of the QObject to a qt_slot of KS_Qt_Callback.
36
* KS_Qt_Callback in turn triggers the signal ks_sig of the KScript
39
void connect( QObject* s, const char* qt_sig, const char* qt_slot,
40
KSObject* r, const char* ks_sig );
43
void disconnect( KSObject* );
45
static KS_Qt_Callback* self();
51
void emitSignal( const QValueList<KSValue::Ptr>& params, const char* name );
57
* For every signal that appears in any Qt class
58
* we add a slot here. This is needed to map Qt signals
61
void textChanged( const QString& );
63
void activated( int );
64
void activated( const QString& );
66
void selected( const QString & );
72
QCString m_kscriptSignal;
76
struct DestroyCallback
79
KS_Qt_Object* m_receiver;
82
QValueList<Connection> m_connections;
83
QValueList<DestroyCallback> m_callbacks;
85
static KS_Qt_Callback* s_pSelf;
88
class KSClass_QObject : public KSScriptClass
91
KSClass_QObject( KSModule*, const char* name = "QObject" );
93
virtual bool isBuiltin() { return true; }
94
virtual bool hasSignal( const QString& name );
96
void addQtSignal( const QString& str );
99
QStringList m_signals;
103
* All objects that use interally some QObject object
104
* must derive from this class.
106
class KS_Qt_Object : public KSScriptObject
109
enum Type { StringType,
118
KS_Qt_Object( KSClass* c );
122
* Sets the QObject. If ownership is true, the QObject will be
123
* destroyed when the KS_Qt_Object is destroyed.
125
void setObject( QObject*, bool ownership = true );
126
QObject* object() { return m_object; }
129
* Gets a member of the QObject/KS_Qt_Object. A member is a property or a method.
131
virtual KSValue::Ptr member( KSContext&, const QString& name );
133
* Sets a member of the QObject/KS_Qt_Object.
135
virtual bool setMember( KSContext&, const QString& name, const KSValue::Ptr& v );
137
bool hasOwnership() { return m_ownership; }
140
* Inherited from KSScriptObject
142
bool inherits( const char* name ) { return ( strcmp( name, "KS_Qt_Object" ) == 0 || KSScriptObject::inherits( name ) ); }
145
* Implements the method "destroy"
147
bool KSQObject_destroy( KSContext& context );
149
static bool checkArguments( KSContext& context, KSValue* v, const QString& name, Type t1 = NoType, Type t2 = NoType,
150
Type t3 = NoType, Type t4 = NoType, Type t5 = NoType, Type t6 = NoType );
151
static bool tryArguments( KSContext& context, KSValue* v, Type t1 = NoType, Type t2 = NoType,
152
Type t3 = NoType, Type t4 = NoType, Type t5 = NoType, Type t6 = NoType );
154
* If parameter v can not be casted to the Qt type then an exception
155
* is set in the context if _fatal is TRUE and FALSE is returned.
156
* If the parameter has correct type, then TRUE is returned.
158
static bool checkType( KSContext& context, KSValue* v, KS_Qt_Object::Type type, bool _fatal = true );
160
static QObject* convert( KSValue* v ) { return ((KS_Qt_Object*)v->objectValue())->m_object; }
162
static bool pack( KSContext& context, QVariant& var, const KSValue::Ptr& v );
163
static KSValue::Ptr unpack( KSContext& context, QVariant& var );
166
virtual bool destructor();
168
bool checkDoubleConstructor( KSContext& context, const QString& name );
169
bool checkLive( KSContext& context, const QString& name );
172
QGuardedPtr<QObject> m_object;