瀏覽代碼

Add QSvgWidget support

Neal Wilson 9 年之前
父節點
當前提交
cc8a914edc
共有 2 個檔案被更改,包括 93 行新增0 行删除
  1. 1
    0
      src/Typica.pro
  2. 92
    0
      src/typica.w

+ 1
- 0
src/Typica.pro 查看文件

@@ -8,6 +8,7 @@ QT += sql
8 8
 QT += xmlpatterns
9 9
 QT += scripttools
10 10
 QT += webkit
11
+QT += svg
11 12
 
12 13
 CONFIG += extserialport
13 14
 

+ 92
- 0
src/typica.w 查看文件

@@ -623,6 +623,7 @@ various Qt modules.
623 623
 #include <QtDebug>
624 624
 #include <QtXmlPatterns>
625 625
 #include <QtWebKit>
626
+#include <QtSvg>
626 627
 
627 628
 @ New code is being written in separate files in a long term effort to improve
628 629
 organization of the code. The result of this is that some additional headers
@@ -1363,6 +1364,93 @@ void setQLabelProperties(QScriptValue value, QScriptEngine *engine)
1363 1364
     setQFrameProperties(value, engine);
1364 1365
 }
1365 1366
 
1367
+@* Scripting QSvgWidget.
1368
+
1369
+\noindent Sometimes it is useful to provide a space for simple drawings without
1370
+the need for all of the other capabilities of a web view. This was introduced
1371
+as a way to draw box plots to help guide the creation of roast specifications.
1372
+
1373
+@<Function prototypes for scripting@>=
1374
+void setQSvgWidgetProperties(QScriptValue value, QScriptEngine *engine);
1375
+QScriptValue constructQSvgWidget(QScriptContext *context,
1376
+                                 QScriptEngine *engine);
1377
+QScriptValue QSvgWidget_loadDevice(QScriptContext *context,
1378
+                                   QScriptEngine *engine);
1379
+void addSvgWidgetToLayout(QDomElement element, QStack<QWidget *> *widgetStack,
1380
+                          QStack<QLayout *> *layoutStack);
1381
+
1382
+@ The constructor must be passed to the scripting engine.
1383
+
1384
+@<Set up the scripting engine@>=
1385
+constructor = engine->newFunction(constructQSvgWidget);
1386
+value = engine->newQMetaObject(&QSvgWidget::staticMetaObject, constructor);
1387
+engine->globalObject().setProperty("QSvgWidget", value);
1388
+
1389
+@ The constructor is trivial.
1390
+
1391
+@<Functions for scripting@>=
1392
+QScriptValue constructQSvgWidget(QScriptContext *context,
1393
+                                 QScriptEngine *engine)
1394
+{
1395
+    QScriptValue object = engine->newQObject(new QSvgWidget);
1396
+    setQSvgWidgetProperties(object, engine);
1397
+    return object;
1398
+}
1399
+
1400
+@ A property is added that allows loading data from a |QIODevice|.
1401
+
1402
+@<Functions for scripting@>=
1403
+void setQSvgWidgetProperties(QScriptValue value, QScriptEngine *engine)
1404
+{
1405
+    setQWidgetProperties(value, engine);
1406
+    value.setProperty("loadDevice",
1407
+                      engine->newFunction(QSvgWidget_loadDevice));
1408
+}
1409
+
1410
+QScriptValue QSvgWidget_loadDevice(QScriptContext *context, QScriptEngine *)
1411
+{
1412
+    if(context->argumentCount() == 1)
1413
+    {
1414
+        QSvgWidget *self = getself<@[QSvgWidget *@]>(context);
1415
+        QIODevice *device = argument<QIODevice *>(0, context);
1416
+        device->reset();
1417
+        QByteArray data = device->readAll();
1418
+        self->load(data);
1419
+    }
1420
+    else
1421
+    {
1422
+        context->throwError("Incorrect number of arguments passed to "@|
1423
+                            "QSvgWidget::loadData(). This method takes one "@|
1424
+                            "QIODevice as an argument.");
1425
+    }
1426
+    return QScriptValue();
1427
+}
1428
+
1429
+@ Additional work is needed to allow including this from the XML description of
1430
+a window.
1431
+
1432
+@<Additional box layout elements@>=
1433
+else if(currentElement.tagName() == "svgwidget")
1434
+{
1435
+    addSvgWidgetToLayout(currentElement, widgetStack, layoutStack);
1436
+}
1437
+
1438
+@ The function used to create this follows the usual pattern.
1439
+
1440
+@<Functions for scripting@>=
1441
+void addSvgWidgetToLayout(QDomElement element, QStack<QWidget *> *,
1442
+                          QStack<QLayout *> *layoutStack)
1443
+{
1444
+    QBoxLayout *layout = qobject_cast<QBoxLayout *>(layoutStack->top());
1445
+    QSvgWidget *widget = new QSvgWidget;
1446
+    layout->addWidget(widget);
1447
+    QString id = element.attribute("id");
1448
+    if(!id.isEmpty())
1449
+    {
1450
+        widget->setObjectName(id);
1451
+    }
1452
+}
1453
+
1366 1454
 @* Scripting QLineEdit.
1367 1455
 
1368 1456
 \noindent Similarly, we may want to allow line edits in interfaces defined
@@ -6116,6 +6204,10 @@ else if(className == "QLineEdit")
6116 6204
 {
6117 6205
     setQLineEditProperties(value, engine);
6118 6206
 }
6207
+else if(className == "QSvgWidget")
6208
+{
6209
+    setQSvgWidgetProperties(value, engine);
6210
+}
6119 6211
 
6120 6212
 @ In the list of classes, the SaltTable entry is for a class which does not
6121 6213
 strictly exist on its own. It is, however, useful to provide some custom

Loading…
取消
儲存