add example "quick/Tic-Tac-Toe"; lots of minor revisions;

This commit is contained in:
polos 2017-01-19 02:02:30 +01:00
parent 43abbe2415
commit c7cefd839c
62 changed files with 1731 additions and 1004 deletions

View file

@ -1,6 +1,7 @@
;;;
;;; * enables QML to call Lisp functions
;;; * allows to get/set any QML property from Lisp (needs 'objectName' to be set)
;;; * allows to evaluate JS code from Lisp (needs 'objectName' to be set)
;;;
;;; (requires a C++ plugin, see "lib/")
@ -9,9 +10,12 @@
(:nicknames :qml)
(:export
#:*quick-view*
#:js
#:root-object
#:qml-get
#:qml-set))
#:qml-set
#:qml-get*
#:qml-set*))
(provide :qml-lisp)
@ -28,6 +32,11 @@
(subseq upper 0 p))
(intern upper))))
(defun qml-error (format-string &rest arguments)
(format *debug-io* "~&[QML] ~A~%" (apply 'format nil format-string arguments)))
;;; function calls from QML
(defun qml-apply (function arguments)
"Every 'Lisp.fun()' or 'Lisp.apply()' function call in QML will call this function."
(let ((value (apply (string-to-symbol function)
@ -42,16 +51,43 @@
(setf root-object (|rootObject| *quick-view*)))
root-object))
(defun find-qml-object (name)
(if (string= (|objectName| (root-object)) name)
(root-object)
(qfind-child (root-object) name)))
(defun find-qml-object (name &optional all)
(or (if (string= (|objectName| (root-object)) name)
(root-object)
(if all
(qfind-children (root-object) name)
(qfind-child (root-object) name)))
(qml-error "No object found with name: ~S." name)))
;;; get/set QML object properties
(defun qml-get (object-name property-name)
"Get QML property. Needs 'objectName' to be set."
"Gets QML property for first object matching 'objectName'."
(qget (find-qml-object object-name) property-name))
(defun qml-set (object-name property-name value)
"Set QML property. Needs 'objectName' to be set."
"Sets QML property for first object matching 'objectName'."
(qset (find-qml-object object-name) property-name value))
(defun qml-get* (object-name property-name)
"Collects QML properties for all objects matching 'objectName'."
(mapcar (lambda (object)
(qget object property-name))
(find-qml-object object-name t)))
(defun qml-set* (object-name property-name value)
"Sets QML property for all objects matching 'objectName'."
(dolist (object (find-qml-object object-name t))
(qset object property-name value)))
;;; JS
(defun js (object-name js-format-string &rest arguments)
"Evaluates a JS string with the element bound to OBJECT-NAME as 'this'."
(qlet ((qml-exp "QQmlExpression(QQmlContext*,QObject*,QString)"
(|rootContext| (|engine| *quick-view*))
(find-qml-object object-name)
(apply 'format nil js-format-string arguments))
(variant (|evaluate| qml-exp)))
(qvariant-value variant)))