瀏覽代碼

Basic QColor scripting support

Neal Wilson 6 年之前
父節點
當前提交
381f48b419
簽署人: neal <neal@typica.us> GPG 金鑰 ID: D6F25C90DD5819DF
共有 1 個檔案被更改,包括 27 行新增3 行删除
  1. 27
    3
      src/typica.w

+ 27
- 3
src/typica.w 查看文件

@@ -3932,6 +3932,30 @@ template<> QTime argument(int arg, QScriptContext *context)
3932 3932
     return qscriptvalue_cast<QTime>(context->argument(arg));
3933 3933
 }
3934 3934
 
3935
+@* Scripting QColor.
3936
+
3937
+\noindent |QColor| support is limited to creating colors from strings to pass
3938
+to objects expecting a color.
3939
+
3940
+@<Function prototypes for scripting@>=
3941
+QScriptValue constructQColor(QScriptContext *context, QScriptEngine *engine);
3942
+
3943
+@ We must tell the script engine about the constructor. This is not done in
3944
+quite the same way as is done for |QObject| derived types.
3945
+
3946
+@<Set up the scripting engine@>=
3947
+constructor = engine->newFunction(constructQColor);
3948
+engine->globalObject().setProperty("QColor", constructor);
3949
+
3950
+@ The constructor is trivial.
3951
+
3952
+@<Functions for scripting@>=
3953
+QScriptValue constructQColor(QScriptContext *context, QScriptEngine *engine)
3954
+{
3955
+    QScriptValue object = engine->toScriptValue<QColor>(QColor(argument<QString>(0, context)));
3956
+    return object;
3957
+}
3958
+
3935 3959
 @* Scripting Item View Classes.
3936 3960
 
3937 3961
 \noindent |QAbstractScrollArea| is a |QFrame| that serves as the base class for
@@ -6737,8 +6761,8 @@ QScriptValue SaltTable_setData(QScriptContext *context, QScriptEngine *)
6737 6761
     QTableView *self = getself<QTableView *>(context);
6738 6762
     int row = argument<int>(0, context);
6739 6763
     int column = argument<int>(1, context);
6740
-    QVariant value = argument<QVariant>(2, context);
6741
-    int role = argument<int>(3, context);
6764
+	QVariant value = argument<QVariant>(2, context);
6765
+	int role = argument<int>(3, context);
6742 6766
     SaltModel *model = qobject_cast<SaltModel *>(self->model());
6743 6767
     QModelIndex cell = model->index(row, column);
6744 6768
     model->setData(cell, value, role);
@@ -13390,7 +13414,7 @@ bool SaltModel::setData(const QModelIndex &index, const QVariant &value,
13390 13414
     }
13391 13415
     QList<QMap<int, QVariant> > row = modelData.at(index.row());
13392 13416
     QMap<int, QVariant> cell = row.at(index.column());
13393
-    cell.insert(role, value);
13417
+	cell.insert(role, value);
13394 13418
     if(role == Qt::EditRole)@/
13395 13419
     {
13396 13420
         cell.insert(Qt::DisplayRole, value);

Loading…
取消
儲存