~ubuntu-branches/ubuntu/breezy/koffice/breezy

« back to all changes in this revision

Viewing changes to lib/kscript/kscript_ext_qt.h

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040509113300-vfrdadqsvjfuhn3b
Tags: 1:1.3.1-1
* New upstream bugfix release.
* Built against newer imagemagick (closes: #246623).
* Made koffice-libs/kformula recommend/depend on latex-xft-fonts, which
  provides mathematical fonts that the formula editor can use.  Also
  patched the kformula part to make these fonts the default.
* Changed kword menu hint from "WordProcessors" to "Word processors"
  (closes: #246209).
* Spellchecker configuration is now fixed (closes: #221256, #227568).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef __KSCRIPT_EXT_QT_H__
2
 
#define __KSCRIPT_EXT_QT_H__
3
 
 
4
 
#include "kscript_context.h"
5
 
#include "kscript_object.h"
6
 
#include "kscript_value.h"
7
 
 
8
 
#include <qobject.h>
9
 
#include <qstring.h>
10
 
#include <qcstring.h>
11
 
#include <qvaluelist.h>
12
 
#include <qconnection.h>
13
 
#include <qguardedptr.h>
14
 
 
15
 
class KSClass;
16
 
class KSInterpreter;
17
 
class KS_Qt_Object;
18
 
 
19
 
extern KSModule::Ptr ksCreateModule_Qt( KSInterpreter* );
20
 
 
21
 
/**
22
 
 * There is at all times only one instance of this class
23
 
 * available.
24
 
 */
25
 
class KS_Qt_Callback : public QObject
26
 
{
27
 
  Q_OBJECT
28
 
public:
29
 
  /**
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.
32
 
   */
33
 
  void connect( QObject*, KS_Qt_Object* );
34
 
  /**
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
37
 
   * object r.
38
 
   */
39
 
  void connect( QObject* s, const char* qt_sig, const char* qt_slot,
40
 
                KSObject* r, const char* ks_sig );
41
 
 
42
 
 
43
 
  void disconnect( KSObject* );
44
 
 
45
 
  static KS_Qt_Callback* self();
46
 
 
47
 
protected:
48
 
    KS_Qt_Callback() { }
49
 
    ~KS_Qt_Callback() { }
50
 
 
51
 
    void emitSignal( const QValueList<KSValue::Ptr>& params, const char* name );
52
 
 
53
 
private slots:
54
 
  void slotDestroyed();
55
 
 
56
 
  /**
57
 
   * For every signal that appears in any Qt class
58
 
   * we add a slot here. This is needed to map Qt signals
59
 
   * to KScript signals.
60
 
   */
61
 
  void textChanged( const QString& );
62
 
  void clicked();
63
 
  void activated( int );
64
 
  void activated( const QString& );
65
 
  void selected( int );
66
 
  void selected( const QString & );
67
 
 
68
 
private:
69
 
  struct Connection
70
 
  {
71
 
    QObject* m_sender;
72
 
    QCString m_kscriptSignal;
73
 
    KSObject* m_receiver;
74
 
  };
75
 
 
76
 
  struct DestroyCallback
77
 
  {
78
 
    QObject* m_sender;
79
 
    KS_Qt_Object* m_receiver;
80
 
  };
81
 
 
82
 
  QValueList<Connection> m_connections;
83
 
  QValueList<DestroyCallback> m_callbacks;
84
 
 
85
 
  static KS_Qt_Callback* s_pSelf;
86
 
};
87
 
 
88
 
class KSClass_QObject : public KSScriptClass
89
 
{
90
 
public:
91
 
    KSClass_QObject( KSModule*, const char* name = "QObject" );
92
 
 
93
 
    virtual bool isBuiltin() { return true; }
94
 
    virtual bool hasSignal( const QString& name );
95
 
 
96
 
    void addQtSignal( const QString& str );
97
 
 
98
 
private:
99
 
    QStringList m_signals;
100
 
};
101
 
 
102
 
/**
103
 
 * All objects that use interally some QObject object
104
 
 * must derive from this class.
105
 
 */
106
 
class KS_Qt_Object : public KSScriptObject
107
 
{
108
 
public:
109
 
  enum Type { StringType,
110
 
              IntType,
111
 
              BoolType,
112
 
              DoubleType,
113
 
              RectType,
114
 
              ObjectType,
115
 
              WidgetType,
116
 
              NoType };
117
 
 
118
 
  KS_Qt_Object( KSClass* c );
119
 
  ~KS_Qt_Object();
120
 
 
121
 
  /**
122
 
   * Sets the QObject. If ownership is true, the QObject will be
123
 
   * destroyed when the KS_Qt_Object is destroyed.
124
 
   */
125
 
  void setObject( QObject*, bool ownership = true );
126
 
  QObject* object() { return m_object; }
127
 
 
128
 
  /**
129
 
   * Gets a member of the QObject/KS_Qt_Object. A member is a property or a method.
130
 
   */
131
 
  virtual KSValue::Ptr member( KSContext&, const QString& name );
132
 
  /**
133
 
   * Sets a member of the QObject/KS_Qt_Object.
134
 
   */
135
 
  virtual bool setMember( KSContext&, const QString& name, const KSValue::Ptr& v );
136
 
 
137
 
  bool hasOwnership() { return m_ownership; }
138
 
 
139
 
  /**
140
 
   * Inherited from KSScriptObject
141
 
   */
142
 
  bool inherits( const char* name ) { return ( strcmp( name, "KS_Qt_Object" ) == 0 || KSScriptObject::inherits( name ) ); }
143
 
 
144
 
  /**
145
 
   * Implements the method "destroy"
146
 
   */
147
 
  bool KSQObject_destroy( KSContext& context );
148
 
 
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 );
153
 
  /**
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.
157
 
   */
158
 
  static bool checkType( KSContext& context, KSValue* v, KS_Qt_Object::Type type, bool _fatal = true );
159
 
 
160
 
  static QObject* convert( KSValue* v ) { return ((KS_Qt_Object*)v->objectValue())->m_object; }
161
 
 
162
 
  static bool pack( KSContext& context, QVariant& var, const KSValue::Ptr& v );
163
 
  static KSValue::Ptr unpack( KSContext& context, QVariant& var );
164
 
 
165
 
protected:
166
 
  virtual bool destructor();
167
 
 
168
 
  bool checkDoubleConstructor( KSContext& context, const QString& name );
169
 
  bool checkLive( KSContext& context, const QString& name );
170
 
 
171
 
private:
172
 
  QGuardedPtr<QObject> m_object;
173
 
  bool m_ownership;
174
 
};
175
 
 
176
 
#endif