|
@@ -56,6 +56,46 @@ void DragLabel::mousePressEvent(QMouseEvent *event)
|
56
|
56
|
}
|
57
|
57
|
}
|
58
|
58
|
|
|
59
|
+@ We require the ability to create these labels from the host environment.
|
|
60
|
+First we include the appropriate header.
|
|
61
|
+
|
|
62
|
+@<Header files to include@>=
|
|
63
|
+#include "draglabel.h"
|
|
64
|
+
|
|
65
|
+@ Next, a pair of function prototypes.
|
|
66
|
+
|
|
67
|
+@<Function prototypes for scripting@>=
|
|
68
|
+QScriptValue constructDragLabel(QScriptContext *context, QScriptEngine *engine);
|
|
69
|
+void setDragLabelProperties(QScriptValue value, QScriptEngine *engine);
|
|
70
|
+
|
|
71
|
+@ These are made known to the host environment as usual.
|
|
72
|
+
|
|
73
|
+@<Set up the scripting engine@>=
|
|
74
|
+constructor = engine->newFunction(constructDragLabel);
|
|
75
|
+value = engine->newQMetaObject(&DragLabel::staticMetaObject, constructor);
|
|
76
|
+engine->globalObject().setProperty("DragLabel", value);
|
|
77
|
+
|
|
78
|
+@ The implementation is trivial.
|
|
79
|
+
|
|
80
|
+@<Functions for scripting@>=
|
|
81
|
+QScriptValue constructDragLabel(QScriptContext *context, QScriptEngine *engine)
|
|
82
|
+{
|
|
83
|
+ QScriptValue object;
|
|
84
|
+ QString labelText = "";
|
|
85
|
+ if(context->argumentCount() == 1)
|
|
86
|
+ {
|
|
87
|
+ labelText = argument<QString>(0, context);
|
|
88
|
+ }
|
|
89
|
+ object = engine->newQObject(new DragLabel(labelText));
|
|
90
|
+ setDragLabelProperties(object, engine);
|
|
91
|
+ return object;
|
|
92
|
+}
|
|
93
|
+
|
|
94
|
+void setDragLabelProperties(QScriptValue value, QScriptEngine *engine)
|
|
95
|
+{
|
|
96
|
+ setQLabelProperties(value, engine);
|
|
97
|
+}
|
|
98
|
+
|
59
|
99
|
@ An object is also required to communicate with a scale. This is responsible
|
60
|
100
|
for setting up a connection over a serial port, sending commands out to the
|
61
|
101
|
scale, buffering and interpreting the response, and signaling new measurements.
|