00001 /*************************************************************************** 00002 * qtobject.h 00003 * This file is part of the KDE project 00004 * copyright (C)2004-2005 by Sebastian Sauer (mail@dipe.org) 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Library General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2 of the License, or (at your option) any later version. 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Library General Public License for more details. 00014 * You should have received a copy of the GNU Library General Public License 00015 * along with this program; see the file COPYING. If not, write to 00016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 * Boston, MA 02110-1301, USA. 00018 ***************************************************************************/ 00019 00020 #ifndef KROSS_API_QTOBJECT_H 00021 #define KROSS_API_QTOBJECT_H 00022 00023 #include "class.h" 00024 00025 #include <qstring.h> 00026 #include <qobject.h> 00027 00028 // Forward-declaration of the builtin Qt QUObject struct. 00029 struct QUObject; 00030 00031 namespace Kross { namespace Api { 00032 00033 // Forward declarations. 00034 class Object; 00035 class Variant; 00036 class ScriptContainer; 00037 class ScriptContrainer; 00038 00039 /** 00040 * Class to wrap \a QObject or inherited instances. 00041 * 00042 * This class publishs all SIGNAL's, SLOT's and Q_PROPERTY's 00043 * the QObject has. 00044 */ 00045 class QtObject : public Kross::Api::Class<QtObject> 00046 { 00047 public: 00048 00049 /** 00050 * Shared pointer to implement reference-counting. 00051 */ 00052 typedef KSharedPtr<QtObject> Ptr; 00053 00054 /** 00055 * Constructor. 00056 * 00057 * \param parent The \a QObject instance this 00058 * class is children of. 00059 * \param object The \a QObject instance this 00060 * class wraps. 00061 * \param name The unique name this \a QtObject 00062 * instance has. If not defined then the 00063 * \a QObject::name() will be used. 00064 */ 00065 QtObject(Object::Ptr parent, QObject* object, const QString& name = QString::null); 00066 00067 /** 00068 * Destructor. 00069 */ 00070 virtual ~QtObject(); 00071 00072 /// \see Kross::Api::Object::getClassName() 00073 virtual const QString getClassName() const; 00074 00075 /** 00076 * Return the \a QObject instance this class wraps. 00077 * 00078 * \return The wrapped QObject. 00079 */ 00080 QObject* getObject(); 00081 00082 /** 00083 * Build a Qt QUObject struct out of the Qt signal or 00084 * slot signature and the passed \a List arguments. 00085 * 00086 * \throw RuntimeException If the try to translate \p arguments 00087 * failed. 00088 * \param signature The Qt signal or slot signature. 00089 * \param arguments The optional \a List of arguments. 00090 * \return A QUObject array. 00091 */ 00092 static QUObject* toQUObject(const QString& signature, List::Ptr arguments); 00093 00094 private: 00095 /// The wrapped QObject. 00096 QObject* m_object; 00097 00098 // QProperty's 00099 00100 /// Return a list of property names. 00101 Kross::Api::Object::Ptr propertyNames(Kross::Api::List::Ptr); 00102 /// Return true if the property exists else false. 00103 Kross::Api::Object::Ptr hasProperty(Kross::Api::List::Ptr); 00104 /// Return a property. 00105 Kross::Api::Object::Ptr getProperty(Kross::Api::List::Ptr); 00106 /// Set a property. 00107 Kross::Api::Object::Ptr setProperty(Kross::Api::List::Ptr); 00108 00109 // Slots 00110 00111 /// Return a list of slot names. 00112 Kross::Api::Object::Ptr slotNames(Kross::Api::List::Ptr); 00113 /// Return true if the slot exists else false. 00114 Kross::Api::Object::Ptr hasSlot(Kross::Api::List::Ptr); 00115 /// Call a slot. 00116 Kross::Api::Object::Ptr callSlot(Kross::Api::List::Ptr); 00117 00118 // Signals 00119 00120 /// Return a list of signal names. 00121 Kross::Api::Object::Ptr signalNames(Kross::Api::List::Ptr); 00122 /// Return true if the signal exists else false. 00123 Kross::Api::Object::Ptr hasSignal(Kross::Api::List::Ptr); 00124 /// Emit a signal. 00125 Kross::Api::Object::Ptr emitSignal(Kross::Api::List::Ptr); 00126 00127 /// Connect signal with a QObject slot. 00128 Kross::Api::Object::Ptr connectSignal(Kross::Api::List::Ptr); 00129 /// Disconnect signal from QObject slot. 00130 Kross::Api::Object::Ptr disconnectSignal(Kross::Api::List::Ptr); 00131 00132 }; 00133 00134 }} 00135 00136 #endif 00137
1.4.6