revision of "quick" examples

This commit is contained in:
polos 2017-02-12 17:06:25 +01:00
parent b221fb1014
commit 27289c1166
12 changed files with 41 additions and 36 deletions

View file

@ -24,11 +24,10 @@ static QVariant qmlApply(QObject* caller, const QString& function, const QVarian
Q_ARG(QObject*, caller),
Q_ARG(QString, function),
Q_ARG(QVariantList, arguments));
if(var.type() == QVariant::String) {
QString str(var.toString());
if(str.startsWith("#<>")) { // prepared in Lisp for JS eval
QQmlExpression exp(rootContext(), caller, str.mid(3));
return exp.evaluate(); }}
QString str(var.toString());
if(str.startsWith("#<>")) { // prepared in Lisp for JS eval
QQmlExpression exp(rootContext(), caller, str.mid(3));
return exp.evaluate(); }
return var; }
QVariant Lisp::call(const QJSValue& caller_or_function, const QJSValue& function_or_arg0,

View file

@ -81,7 +81,7 @@
(defun root-item ()
(when *quick-view*
(|rootObject| *quick-view*)))
(qt-object-? (|rootObject| *quick-view*))))
(defun root-context ()
(when *quick-view*

View file

@ -39,7 +39,7 @@
;; advanced note on QOVERRIDE:
;;
;; in overridden function "data(QModelIndex,int)", new QVariants are constructed,
;; in overridden function "data(QModelIndex,int)", new QVariants are constructed
;; (here: using QVARIANT-FROM-VALUE); they will be garbage collected (like return
;; values from any Qt function, and from QGET)

View file

@ -24,11 +24,10 @@ static QVariant qmlApply(QObject* caller, const QString& function, const QVarian
Q_ARG(QObject*, caller),
Q_ARG(QString, function),
Q_ARG(QVariantList, arguments));
if(var.type() == QVariant::String) {
QString str(var.toString());
if(str.startsWith("#<>")) { // prepared in Lisp for JS eval
QQmlExpression exp(rootContext(), caller, str.mid(3));
return exp.evaluate(); }}
QString str(var.toString());
if(str.startsWith("#<>")) { // prepared in Lisp for JS eval
QQmlExpression exp(rootContext(), caller, str.mid(3));
return exp.evaluate(); }
return var; }
QVariant Lisp::call(const QJSValue& caller_or_function, const QJSValue& function_or_arg0,

View file

@ -81,7 +81,7 @@
(defun root-item ()
(when *quick-view*
(|rootObject| *quick-view*)))
(qt-object-? (|rootObject| *quick-view*))))
(defun root-context ()
(when *quick-view*

View file

@ -22,4 +22,4 @@ Only in this exceptional case there is no way to do it implicitly using QML.
Example:
(qml-set "left" "fillColor" "orange" t) ; pass T for repainting
(qml-set "left" "color" "orange" t) ; pass T for repainting

View file

@ -24,11 +24,10 @@ static QVariant qmlApply(QObject* caller, const QString& function, const QVarian
Q_ARG(QObject*, caller),
Q_ARG(QString, function),
Q_ARG(QVariantList, arguments));
if(var.type() == QVariant::String) {
QString str(var.toString());
if(str.startsWith("#<>")) { // prepared in Lisp for JS eval
QQmlExpression exp(rootContext(), caller, str.mid(3));
return exp.evaluate(); }}
QString str(var.toString());
if(str.startsWith("#<>")) { // prepared in Lisp for JS eval
QQmlExpression exp(rootContext(), caller, str.mid(3));
return exp.evaluate(); }
return var; }
QVariant Lisp::call(const QJSValue& caller_or_function, const QJSValue& function_or_arg0,

View file

@ -1,7 +1,8 @@
;;;
;;; Use of PaintedItem (a QQuickPaintedItem) and QPainter
;;; (meant as an alternative to Canvas in QML).
;;;
;;; (meant as an alternative to Canvas in QML)
;;; See also "lib/qml_lisp.*" for PaintedItem.
;;;
#-qt-wrapper-functions ; see README-OPTIONAL.txt
@ -27,18 +28,22 @@
(cond ((qeql (clock) item)
(clock:paint item painter))
(t
(|fillRect| painter (|contentsBoundingRect| item)
(qml-get item "fillColor"))))) ; QML property
(qlet ((pen "QPen(QColor)" "white")
(brush "QBrush(QColor)" (qml-get item "color"))) ; QML property
(|setWidth| pen 5)
(|setPen| painter pen)
(|setBrush| painter brush)
(|drawEllipse| painter (qml-get item "ellipse")))))) ; QML property
(defun run ()
(setf qml:*quick-view* (qnew "QQuickWidget")) ; QQuickView would crash on Windows
(setf qml:*quick-view* (qnew "QQuickWidget")) ; QQuickView would crash on Windows
(x:do-with qml:*quick-view*
(|setSource| (|fromLocalFile.QUrl| "qml/painted-item.qml"))
(|setResizeMode| |QQuickView.SizeRootObjectToView|)
(|resize| '(340 340)))
(let ((timer (qnew "QTimer")))
(qconnect timer "timeout()" (lambda () (|update| (clock)))) ; repaint
(|start| timer (* 60 1000))) ; once a minute
(qconnect timer "timeout()" (lambda () (|update| (clock)))) ; repaint
(|start| timer (* 60 1000))) ; once a minute
(|show| qml:*quick-view*))
(run)

View file

@ -81,7 +81,7 @@
(defun root-item ()
(when *quick-view*
(|rootObject| *quick-view*)))
(qt-object-? (|rootObject| *quick-view*))))
(defun root-context ()
(when *quick-view*

View file

@ -7,7 +7,9 @@ Rectangle {
PaintedItem {
x: 10; y: 10; width: 100; height: 100
objectName: "left"
property string fillColor: "coral"
property rect ellipse: Qt.rect(10, 10, 80, 80)
property string color: "coral"
}
PaintedItem {
@ -21,14 +23,14 @@ Rectangle {
ScaleAnimator {
target: clock
from: 0.95; to: 1.0
from: 0.9; to: 1.0
duration: 500
easing.type: Easing.InOutSine
}
ScaleAnimator {
target: clock
from: 1.0; to: 0.95
from: 1.0; to: 0.9
duration: 500
easing.type: Easing.InOutSine
}
@ -38,6 +40,8 @@ Rectangle {
PaintedItem {
x: 230; y: 10; width: 100; height: 100
objectName: "right"
property string fillColor: "cornflowerblue"
property rect ellipse: Qt.rect(10, 10, 80, 80)
property string color: "cornflowerblue"
}
}

View file

@ -24,11 +24,10 @@ static QVariant qmlApply(QObject* caller, const QString& function, const QVarian
Q_ARG(QObject*, caller),
Q_ARG(QString, function),
Q_ARG(QVariantList, arguments));
if(var.type() == QVariant::String) {
QString str(var.toString());
if(str.startsWith("#<>")) { // prepared in Lisp for JS eval
QQmlExpression exp(rootContext(), caller, str.mid(3));
return exp.evaluate(); }}
QString str(var.toString());
if(str.startsWith("#<>")) { // prepared in Lisp for JS eval
QQmlExpression exp(rootContext(), caller, str.mid(3));
return exp.evaluate(); }
return var; }
QVariant Lisp::call(const QJSValue& caller_or_function, const QJSValue& function_or_arg0,

View file

@ -81,7 +81,7 @@
(defun root-item ()
(when *quick-view*
(|rootObject| *quick-view*)))
(qt-object-? (|rootObject| *quick-view*))))
(defun root-context ()
(when *quick-view*