2014-07-19 18:26:08 +02:00
|
|
|
import std.stdio;
|
2015-04-25 17:11:16 +02:00
|
|
|
import std.format;
|
2014-07-19 18:26:08 +02:00
|
|
|
import std.conv;
|
|
|
|
import std.container;
|
|
|
|
import std.traits;
|
|
|
|
import std.string;
|
2015-04-25 17:11:16 +02:00
|
|
|
import std.algorithm;
|
2014-07-19 18:26:08 +02:00
|
|
|
import dothersideinterface;
|
2014-12-31 12:19:00 +01:00
|
|
|
import qmetatype;
|
2014-12-30 19:11:01 +01:00
|
|
|
import qvariant;
|
2014-07-19 18:26:08 +02:00
|
|
|
|
2014-12-30 19:11:01 +01:00
|
|
|
public class QObject
|
2014-07-19 18:26:08 +02:00
|
|
|
{
|
2015-04-28 23:51:12 +02:00
|
|
|
public this()
|
2015-04-27 19:58:18 +02:00
|
|
|
{
|
2015-04-28 23:51:12 +02:00
|
|
|
this(false);
|
2015-04-27 19:58:18 +02:00
|
|
|
}
|
2015-04-25 17:11:16 +02:00
|
|
|
|
2015-04-28 23:51:12 +02:00
|
|
|
protected this(bool disableDosCalls)
|
2015-04-27 19:58:18 +02:00
|
|
|
{
|
2015-04-28 23:51:12 +02:00
|
|
|
this.disableDosCalls = disableDosCalls;
|
|
|
|
if (!this.disableDosCalls)
|
|
|
|
dos_qobject_create(this.data, cast(void*)this, &staticSlotCallback);
|
2015-04-27 19:58:18 +02:00
|
|
|
}
|
2015-04-25 17:11:16 +02:00
|
|
|
|
2015-04-28 23:51:12 +02:00
|
|
|
~this()
|
2015-04-27 19:58:18 +02:00
|
|
|
{
|
2015-04-28 23:51:12 +02:00
|
|
|
if (!this.disableDosCalls)
|
|
|
|
dos_qobject_delete(this.data);
|
2015-04-27 19:58:18 +02:00
|
|
|
}
|
2015-04-25 17:11:16 +02:00
|
|
|
|
2015-04-28 23:51:12 +02:00
|
|
|
public void* rawData()
|
2015-04-27 19:58:18 +02:00
|
|
|
{
|
2015-04-28 23:51:12 +02:00
|
|
|
return this.data;
|
2015-04-27 19:58:18 +02:00
|
|
|
}
|
2014-07-19 18:26:08 +02:00
|
|
|
|
2015-04-27 19:58:18 +02:00
|
|
|
protected void onSlotCalled(QVariant slotName, QVariant[] parameters)
|
|
|
|
{
|
|
|
|
}
|
2015-04-25 17:11:16 +02:00
|
|
|
|
2015-04-27 19:58:18 +02:00
|
|
|
protected void registerSlot(string name, QMetaType[] types)
|
|
|
|
{
|
|
|
|
int index = -1;
|
|
|
|
int length = cast(int)types.length;
|
|
|
|
int[] array = to!(int[])(types);
|
|
|
|
dos_qobject_slot_create(this.data,
|
|
|
|
name.toStringz(),
|
|
|
|
length,
|
|
|
|
array.ptr,
|
|
|
|
index);
|
|
|
|
}
|
2014-12-31 12:19:00 +01:00
|
|
|
|
2015-04-27 19:58:18 +02:00
|
|
|
protected void registerSignal(string name, QMetaType[] types)
|
|
|
|
{
|
|
|
|
int index = -1;
|
|
|
|
int length = cast(int)types.length;
|
|
|
|
int[] array = length > 0 ? to!(int[])(types) : null;
|
|
|
|
dos_qobject_signal_create(this.data,
|
|
|
|
name.toStringz(),
|
|
|
|
length,
|
|
|
|
array.ptr,
|
|
|
|
index);
|
|
|
|
}
|
2015-04-25 17:11:16 +02:00
|
|
|
|
2015-04-27 19:58:18 +02:00
|
|
|
protected void registerProperty(string name,
|
|
|
|
QMetaType type,
|
|
|
|
string readSlotName,
|
|
|
|
string writeSlotName,
|
|
|
|
string notifySignalName)
|
|
|
|
{
|
|
|
|
dos_qobject_property_create(this.data,
|
|
|
|
name.toStringz(),
|
|
|
|
type,
|
|
|
|
readSlotName.toStringz(),
|
|
|
|
writeSlotName.toStringz(),
|
|
|
|
notifySignalName.toStringz());
|
|
|
|
}
|
2015-04-25 17:11:16 +02:00
|
|
|
|
2015-04-27 19:58:18 +02:00
|
|
|
protected void emit(T)(string signalName, T t)
|
|
|
|
{
|
|
|
|
emit(signalName, new QVariant(t));
|
|
|
|
}
|
2014-07-19 18:26:08 +02:00
|
|
|
|
2015-04-27 19:58:18 +02:00
|
|
|
protected void emit(string signalName, QVariant value)
|
|
|
|
{
|
|
|
|
QVariant[] array = [value];
|
|
|
|
emit(signalName, array);
|
|
|
|
}
|
2014-07-19 18:26:08 +02:00
|
|
|
|
2015-04-27 19:58:18 +02:00
|
|
|
protected void emit(string signalName, QVariant[] arguments = null)
|
|
|
|
{
|
|
|
|
int length = cast(int)arguments.length;
|
|
|
|
void*[] array = null;
|
|
|
|
if (length > 0) {
|
|
|
|
array = new void*[length];
|
|
|
|
foreach (int i, QVariant v; arguments)
|
|
|
|
array[i] = v.rawData();
|
|
|
|
}
|
|
|
|
dos_qobject_signal_emit(this.data,
|
|
|
|
signalName.toStringz(),
|
|
|
|
length,
|
|
|
|
array.ptr);
|
2014-07-19 18:26:08 +02:00
|
|
|
}
|
2015-04-25 17:11:16 +02:00
|
|
|
|
2015-04-28 23:51:12 +02:00
|
|
|
protected extern (C) static void staticSlotCallback(void* qObjectPtr,
|
|
|
|
void* rawSlotName,
|
|
|
|
int numParameters,
|
|
|
|
void** parametersArray)
|
|
|
|
{
|
|
|
|
QVariant[] parameters = new QVariant[numParameters];
|
|
|
|
for (int i = 0; i < numParameters; ++i)
|
|
|
|
parameters[i] = new QVariant(parametersArray[i]);
|
|
|
|
QObject qObject = cast(QObject) qObjectPtr;
|
|
|
|
QVariant slotName = new QVariant(rawSlotName);
|
|
|
|
qObject.onSlotCalled(slotName, parameters);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void* data;
|
|
|
|
private bool disableDosCalls;
|
2014-12-30 19:11:01 +01:00
|
|
|
}
|