add short convenience macros for calling QML functions and setting properties
This commit is contained in:
parent
680f4cf6ed
commit
97feac95d4
15 changed files with 285 additions and 52 deletions
|
|
@ -54,7 +54,7 @@ NOTES
|
|||
|
||||
Try the following:
|
||||
|
||||
(qml-set "game" "difficulty" 8) ; one of: 2, 8, 10
|
||||
(q> |difficulty| "game" 8) ; one of: 2, 8, 10
|
||||
|
||||
Since the logic of the buttons is defined in the QML file, changes to
|
||||
properties will be reflected immediately by the UI.
|
||||
|
|
|
|||
|
|
@ -10,12 +10,12 @@
|
|||
|
||||
(defun cell-state (i)
|
||||
(if (stringp *board*)
|
||||
(qml-get (nth i (children *board*)) "state")
|
||||
(q< |state| (nth i (children *board*)))
|
||||
(svref *board* i)))
|
||||
|
||||
(defun set-cell-state (i state)
|
||||
(if (stringp *board*)
|
||||
(qml-set (nth i (children *board*)) "state" state)
|
||||
(q> |state| (nth i (children *board*)) state)
|
||||
(setf (svref *board* i) state)))
|
||||
|
||||
(defun empty-cell (i)
|
||||
|
|
@ -24,7 +24,7 @@
|
|||
;;; game
|
||||
|
||||
(defun tic-tac-clicked (index)
|
||||
(when (and (qml-get "game" "running")
|
||||
(when (and (q< |running| "game")
|
||||
(can-play-at-pos index))
|
||||
(unless (make-move index "X")
|
||||
(computer-turn))))
|
||||
|
|
@ -47,8 +47,8 @@
|
|||
(return-from winner t)))
|
||||
|
||||
(defun restart-game ()
|
||||
(qml-set "message_display" "visible" nil)
|
||||
(qml-set "game" "running" t)
|
||||
(q> |visible| "message_display" nil)
|
||||
(q> |running| "game" t)
|
||||
(dotimes (i 9)
|
||||
(set-cell-state i "")))
|
||||
|
||||
|
|
@ -66,7 +66,7 @@
|
|||
(defun computer-turn ()
|
||||
(qsleep 1/7)
|
||||
(let ((r (random 10)))
|
||||
(if (< r (qml-get "game" "difficulty"))
|
||||
(if (< r (q< |difficulty| "game"))
|
||||
(smart-ai)
|
||||
(random-ai))))
|
||||
|
||||
|
|
@ -129,6 +129,6 @@
|
|||
(make-move choice "O")))))
|
||||
|
||||
(defun game-finished (message)
|
||||
(qml-set "message_display" "text" message)
|
||||
(qml-set "message_display" "visible" t)
|
||||
(qml-set "game" "running" nil))
|
||||
(q> |text| "message_display" message)
|
||||
(q> |visible| "message_display" t)
|
||||
(q> |running| "game" nil))
|
||||
|
|
|
|||
|
|
@ -14,11 +14,17 @@
|
|||
#:children
|
||||
#:find-quick-item
|
||||
#:js
|
||||
#:js-arg
|
||||
#:qml-call
|
||||
#:qml-get
|
||||
#:qml-set
|
||||
#:qml-set-all
|
||||
#:q!
|
||||
#:q<
|
||||
#:q>
|
||||
#:q>*
|
||||
#:paint
|
||||
#:scale
|
||||
#:reload
|
||||
#:root-context
|
||||
#:root-item))
|
||||
|
|
@ -94,9 +100,11 @@
|
|||
|
||||
(defun find-quick-item (object-name)
|
||||
"Finds the first QQuickItem matching OBJECT-NAME."
|
||||
(if (string= (|objectName| (root-item)) object-name)
|
||||
(root-item)
|
||||
(qt-object-? (qfind-child (root-item) object-name))))
|
||||
(let ((root (root-item)))
|
||||
(unless (qnull root)
|
||||
(if (string= (|objectName| root) object-name)
|
||||
(root-item)
|
||||
(qt-object-? (qfind-child root object-name))))))
|
||||
|
||||
(defun quick-item (item/name)
|
||||
(cond ((stringp item/name)
|
||||
|
|
@ -110,6 +118,10 @@
|
|||
"Like QML function 'children'."
|
||||
(mapcar 'qt-object-? (|childItems| (quick-item item/name))))
|
||||
|
||||
(defun scale ()
|
||||
"Returns the scale factor used on high dpi scaled devices (e.g. phones)."
|
||||
(|effectiveDevicePixelRatio| *quick-view*))
|
||||
|
||||
(defun reload ()
|
||||
"Force reloading of QML file after changes made to it."
|
||||
(|clearComponentCache| (|engine| *quick-view*))
|
||||
|
|
@ -153,6 +165,22 @@
|
|||
(dolist (item (qfind-children (root-item) name))
|
||||
(qml-set item property-name value update)))
|
||||
|
||||
(defmacro q! (method-name item/name &rest arguments)
|
||||
"Convenience macro for QML-CALL. Use symbol instead of string name."
|
||||
`(qml-call ,item/name ,(symbol-name method-name) ,@arguments))
|
||||
|
||||
(defmacro q> (property-name item/name value &optional update)
|
||||
"Convenience macro for QML-SET. Use symbol instead of string name."
|
||||
`(qml-set ,item/name ,(symbol-name property-name) ,value ,update))
|
||||
|
||||
(defmacro q< (property-name item/name)
|
||||
"Convenience macro for QML-GET. Use symbol instead of string name."
|
||||
`(qml-get ,item/name ,(symbol-name property-name)))
|
||||
|
||||
(defmacro q>* (property-name item/name value &optional update)
|
||||
"Convenience macro for QML-SET-ALL. Use symbol instead of string name."
|
||||
`(qml-set-all ,item/name ,(symbol-name property-name) ,value ,update))
|
||||
|
||||
;;; JS
|
||||
|
||||
(defun js (item/name js-format-string &rest arguments)
|
||||
|
|
@ -164,3 +192,8 @@
|
|||
(variant (|evaluate| qml-exp)))
|
||||
(qvariant-value variant)))
|
||||
|
||||
(defun js-arg (object)
|
||||
"To be used for arguments in function JS."
|
||||
(with-output-to-string (*standard-output*)
|
||||
(print-js-readably object)))
|
||||
|
||||
|
|
|
|||
|
|
@ -14,11 +14,17 @@
|
|||
#:children
|
||||
#:find-quick-item
|
||||
#:js
|
||||
#:js-arg
|
||||
#:qml-call
|
||||
#:qml-get
|
||||
#:qml-set
|
||||
#:qml-set-all
|
||||
#:q!
|
||||
#:q<
|
||||
#:q>
|
||||
#:q>*
|
||||
#:paint
|
||||
#:scale
|
||||
#:reload
|
||||
#:root-context
|
||||
#:root-item))
|
||||
|
|
@ -94,9 +100,11 @@
|
|||
|
||||
(defun find-quick-item (object-name)
|
||||
"Finds the first QQuickItem matching OBJECT-NAME."
|
||||
(if (string= (|objectName| (root-item)) object-name)
|
||||
(root-item)
|
||||
(qt-object-? (qfind-child (root-item) object-name))))
|
||||
(let ((root (root-item)))
|
||||
(unless (qnull root)
|
||||
(if (string= (|objectName| root) object-name)
|
||||
(root-item)
|
||||
(qt-object-? (qfind-child root object-name))))))
|
||||
|
||||
(defun quick-item (item/name)
|
||||
(cond ((stringp item/name)
|
||||
|
|
@ -110,6 +118,10 @@
|
|||
"Like QML function 'children'."
|
||||
(mapcar 'qt-object-? (|childItems| (quick-item item/name))))
|
||||
|
||||
(defun scale ()
|
||||
"Returns the scale factor used on high dpi scaled devices (e.g. phones)."
|
||||
(|effectiveDevicePixelRatio| *quick-view*))
|
||||
|
||||
(defun reload ()
|
||||
"Force reloading of QML file after changes made to it."
|
||||
(|clearComponentCache| (|engine| *quick-view*))
|
||||
|
|
@ -153,6 +165,22 @@
|
|||
(dolist (item (qfind-children (root-item) name))
|
||||
(qml-set item property-name value update)))
|
||||
|
||||
(defmacro q! (method-name item/name &rest arguments)
|
||||
"Convenience macro for QML-CALL. Use symbol instead of string name."
|
||||
`(qml-call ,item/name ,(symbol-name method-name) ,@arguments))
|
||||
|
||||
(defmacro q> (property-name item/name value &optional update)
|
||||
"Convenience macro for QML-SET. Use symbol instead of string name."
|
||||
`(qml-set ,item/name ,(symbol-name property-name) ,value ,update))
|
||||
|
||||
(defmacro q< (property-name item/name)
|
||||
"Convenience macro for QML-GET. Use symbol instead of string name."
|
||||
`(qml-get ,item/name ,(symbol-name property-name)))
|
||||
|
||||
(defmacro q>* (property-name item/name value &optional update)
|
||||
"Convenience macro for QML-SET-ALL. Use symbol instead of string name."
|
||||
`(qml-set-all ,item/name ,(symbol-name property-name) ,value ,update))
|
||||
|
||||
;;; JS
|
||||
|
||||
(defun js (item/name js-format-string &rest arguments)
|
||||
|
|
@ -164,3 +192,8 @@
|
|||
(variant (|evaluate| qml-exp)))
|
||||
(qvariant-value variant)))
|
||||
|
||||
(defun js-arg (object)
|
||||
"To be used for arguments in function JS."
|
||||
(with-output-to-string (*standard-output*)
|
||||
(print-js-readably object)))
|
||||
|
||||
|
|
|
|||
|
|
@ -27,9 +27,9 @@ Now changing the QML properties from Lisp will repaint the item:
|
|||
|
||||
Examples:
|
||||
|
||||
(qml-set "left" "color" "transparent")
|
||||
(q> |color| "left" "transparent")
|
||||
|
||||
(qml-set "right" "ellipse" '(40 40 20 20))
|
||||
(q> |ellipse| "right" '(40 40 20 20))
|
||||
|
||||
|
||||
HELP
|
||||
|
|
|
|||
|
|
@ -14,11 +14,17 @@
|
|||
#:children
|
||||
#:find-quick-item
|
||||
#:js
|
||||
#:js-arg
|
||||
#:qml-call
|
||||
#:qml-get
|
||||
#:qml-set
|
||||
#:qml-set-all
|
||||
#:q!
|
||||
#:q<
|
||||
#:q>
|
||||
#:q>*
|
||||
#:paint
|
||||
#:scale
|
||||
#:reload
|
||||
#:root-context
|
||||
#:root-item))
|
||||
|
|
@ -94,9 +100,11 @@
|
|||
|
||||
(defun find-quick-item (object-name)
|
||||
"Finds the first QQuickItem matching OBJECT-NAME."
|
||||
(if (string= (|objectName| (root-item)) object-name)
|
||||
(root-item)
|
||||
(qt-object-? (qfind-child (root-item) object-name))))
|
||||
(let ((root (root-item)))
|
||||
(unless (qnull root)
|
||||
(if (string= (|objectName| root) object-name)
|
||||
(root-item)
|
||||
(qt-object-? (qfind-child root object-name))))))
|
||||
|
||||
(defun quick-item (item/name)
|
||||
(cond ((stringp item/name)
|
||||
|
|
@ -110,6 +118,10 @@
|
|||
"Like QML function 'children'."
|
||||
(mapcar 'qt-object-? (|childItems| (quick-item item/name))))
|
||||
|
||||
(defun scale ()
|
||||
"Returns the scale factor used on high dpi scaled devices (e.g. phones)."
|
||||
(|effectiveDevicePixelRatio| *quick-view*))
|
||||
|
||||
(defun reload ()
|
||||
"Force reloading of QML file after changes made to it."
|
||||
(|clearComponentCache| (|engine| *quick-view*))
|
||||
|
|
@ -153,6 +165,22 @@
|
|||
(dolist (item (qfind-children (root-item) name))
|
||||
(qml-set item property-name value update)))
|
||||
|
||||
(defmacro q! (method-name item/name &rest arguments)
|
||||
"Convenience macro for QML-CALL. Use symbol instead of string name."
|
||||
`(qml-call ,item/name ,(symbol-name method-name) ,@arguments))
|
||||
|
||||
(defmacro q> (property-name item/name value &optional update)
|
||||
"Convenience macro for QML-SET. Use symbol instead of string name."
|
||||
`(qml-set ,item/name ,(symbol-name property-name) ,value ,update))
|
||||
|
||||
(defmacro q< (property-name item/name)
|
||||
"Convenience macro for QML-GET. Use symbol instead of string name."
|
||||
`(qml-get ,item/name ,(symbol-name property-name)))
|
||||
|
||||
(defmacro q>* (property-name item/name value &optional update)
|
||||
"Convenience macro for QML-SET-ALL. Use symbol instead of string name."
|
||||
`(qml-set-all ,item/name ,(symbol-name property-name) ,value ,update))
|
||||
|
||||
;;; JS
|
||||
|
||||
(defun js (item/name js-format-string &rest arguments)
|
||||
|
|
@ -164,3 +192,8 @@
|
|||
(variant (|evaluate| qml-exp)))
|
||||
(qvariant-value variant)))
|
||||
|
||||
(defun js-arg (object)
|
||||
"To be used for arguments in function JS."
|
||||
(with-output-to-string (*standard-output*)
|
||||
(print-js-readably object)))
|
||||
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@
|
|||
(dolist (xy move-to)
|
||||
(incf target)
|
||||
(let ((img (find-quick-item (format nil "img~D" target))))
|
||||
(qml-set img "x" (* 31 (first xy)))
|
||||
(qml-set img "y" (* 31 (second xy)))
|
||||
(q> |x| img (* 31 (first xy)))
|
||||
(q> |y| img (* 31 (second xy)))
|
||||
(qsleep 0.03)))) ; delay between item start (in sec)
|
||||
(qsleep 4)) ; duration of animation + pause (in sec)
|
||||
(qsingle-shot 500 'run-animation)) ; pause (in msec)
|
||||
|
|
|
|||
|
|
@ -14,11 +14,17 @@
|
|||
#:children
|
||||
#:find-quick-item
|
||||
#:js
|
||||
#:js-arg
|
||||
#:qml-call
|
||||
#:qml-get
|
||||
#:qml-set
|
||||
#:qml-set-all
|
||||
#:q!
|
||||
#:q<
|
||||
#:q>
|
||||
#:q>*
|
||||
#:paint
|
||||
#:scale
|
||||
#:reload
|
||||
#:root-context
|
||||
#:root-item))
|
||||
|
|
@ -94,9 +100,11 @@
|
|||
|
||||
(defun find-quick-item (object-name)
|
||||
"Finds the first QQuickItem matching OBJECT-NAME."
|
||||
(if (string= (|objectName| (root-item)) object-name)
|
||||
(root-item)
|
||||
(qt-object-? (qfind-child (root-item) object-name))))
|
||||
(let ((root (root-item)))
|
||||
(unless (qnull root)
|
||||
(if (string= (|objectName| root) object-name)
|
||||
(root-item)
|
||||
(qt-object-? (qfind-child root object-name))))))
|
||||
|
||||
(defun quick-item (item/name)
|
||||
(cond ((stringp item/name)
|
||||
|
|
@ -110,6 +118,10 @@
|
|||
"Like QML function 'children'."
|
||||
(mapcar 'qt-object-? (|childItems| (quick-item item/name))))
|
||||
|
||||
(defun scale ()
|
||||
"Returns the scale factor used on high dpi scaled devices (e.g. phones)."
|
||||
(|effectiveDevicePixelRatio| *quick-view*))
|
||||
|
||||
(defun reload ()
|
||||
"Force reloading of QML file after changes made to it."
|
||||
(|clearComponentCache| (|engine| *quick-view*))
|
||||
|
|
@ -153,6 +165,22 @@
|
|||
(dolist (item (qfind-children (root-item) name))
|
||||
(qml-set item property-name value update)))
|
||||
|
||||
(defmacro q! (method-name item/name &rest arguments)
|
||||
"Convenience macro for QML-CALL. Use symbol instead of string name."
|
||||
`(qml-call ,item/name ,(symbol-name method-name) ,@arguments))
|
||||
|
||||
(defmacro q> (property-name item/name value &optional update)
|
||||
"Convenience macro for QML-SET. Use symbol instead of string name."
|
||||
`(qml-set ,item/name ,(symbol-name property-name) ,value ,update))
|
||||
|
||||
(defmacro q< (property-name item/name)
|
||||
"Convenience macro for QML-GET. Use symbol instead of string name."
|
||||
`(qml-get ,item/name ,(symbol-name property-name)))
|
||||
|
||||
(defmacro q>* (property-name item/name value &optional update)
|
||||
"Convenience macro for QML-SET-ALL. Use symbol instead of string name."
|
||||
`(qml-set-all ,item/name ,(symbol-name property-name) ,value ,update))
|
||||
|
||||
;;; JS
|
||||
|
||||
(defun js (item/name js-format-string &rest arguments)
|
||||
|
|
@ -164,3 +192,8 @@
|
|||
(variant (|evaluate| qml-exp)))
|
||||
(qvariant-value variant)))
|
||||
|
||||
(defun js-arg (object)
|
||||
"To be used for arguments in function JS."
|
||||
(with-output-to-string (*standard-output*)
|
||||
(print-js-readably object)))
|
||||
|
||||
|
|
|
|||
|
|
@ -34,9 +34,9 @@ Examples:
|
|||
|
||||
(in-package :qml)
|
||||
|
||||
(qml-get "label" "text")
|
||||
(qml-set "label" "color" "red")
|
||||
(qml-set "label" "font.pixelSize" 24)
|
||||
(q< |text| "label")
|
||||
(q> |color| "label" "red")
|
||||
(q> |font.pixelSize| "label" 24)
|
||||
|
||||
|
||||
QML FILES
|
||||
|
|
|
|||
|
|
@ -14,11 +14,17 @@
|
|||
#:children
|
||||
#:find-quick-item
|
||||
#:js
|
||||
#:js-arg
|
||||
#:qml-call
|
||||
#:qml-get
|
||||
#:qml-set
|
||||
#:qml-set-all
|
||||
#:q!
|
||||
#:q<
|
||||
#:q>
|
||||
#:q>*
|
||||
#:paint
|
||||
#:scale
|
||||
#:reload
|
||||
#:root-context
|
||||
#:root-item))
|
||||
|
|
@ -94,9 +100,11 @@
|
|||
|
||||
(defun find-quick-item (object-name)
|
||||
"Finds the first QQuickItem matching OBJECT-NAME."
|
||||
(if (string= (|objectName| (root-item)) object-name)
|
||||
(root-item)
|
||||
(qt-object-? (qfind-child (root-item) object-name))))
|
||||
(let ((root (root-item)))
|
||||
(unless (qnull root)
|
||||
(if (string= (|objectName| root) object-name)
|
||||
(root-item)
|
||||
(qt-object-? (qfind-child root object-name))))))
|
||||
|
||||
(defun quick-item (item/name)
|
||||
(cond ((stringp item/name)
|
||||
|
|
@ -110,6 +118,10 @@
|
|||
"Like QML function 'children'."
|
||||
(mapcar 'qt-object-? (|childItems| (quick-item item/name))))
|
||||
|
||||
(defun scale ()
|
||||
"Returns the scale factor used on high dpi scaled devices (e.g. phones)."
|
||||
(|effectiveDevicePixelRatio| *quick-view*))
|
||||
|
||||
(defun reload ()
|
||||
"Force reloading of QML file after changes made to it."
|
||||
(|clearComponentCache| (|engine| *quick-view*))
|
||||
|
|
@ -153,6 +165,22 @@
|
|||
(dolist (item (qfind-children (root-item) name))
|
||||
(qml-set item property-name value update)))
|
||||
|
||||
(defmacro q! (method-name item/name &rest arguments)
|
||||
"Convenience macro for QML-CALL. Use symbol instead of string name."
|
||||
`(qml-call ,item/name ,(symbol-name method-name) ,@arguments))
|
||||
|
||||
(defmacro q> (property-name item/name value &optional update)
|
||||
"Convenience macro for QML-SET. Use symbol instead of string name."
|
||||
`(qml-set ,item/name ,(symbol-name property-name) ,value ,update))
|
||||
|
||||
(defmacro q< (property-name item/name)
|
||||
"Convenience macro for QML-GET. Use symbol instead of string name."
|
||||
`(qml-get ,item/name ,(symbol-name property-name)))
|
||||
|
||||
(defmacro q>* (property-name item/name value &optional update)
|
||||
"Convenience macro for QML-SET-ALL. Use symbol instead of string name."
|
||||
`(qml-set-all ,item/name ,(symbol-name property-name) ,value ,update))
|
||||
|
||||
;;; JS
|
||||
|
||||
(defun js (item/name js-format-string &rest arguments)
|
||||
|
|
@ -164,3 +192,8 @@
|
|||
(variant (|evaluate| qml-exp)))
|
||||
(qvariant-value variant)))
|
||||
|
||||
(defun js-arg (object)
|
||||
"To be used for arguments in function JS."
|
||||
(with-output-to-string (*standard-output*)
|
||||
(print-js-readably object)))
|
||||
|
||||
|
|
|
|||
|
|
@ -30,11 +30,11 @@ See e.g. class:
|
|||
TIP
|
||||
===
|
||||
|
||||
See also function QML-SET-ALL, which is convenient for dynamically created
|
||||
See also function QML-SET-ALL (short Q>*), which is convenient for dynamically created
|
||||
QML items, since many of them may have the same 'objectName'.
|
||||
|
||||
Examples:
|
||||
|
||||
(qml-set-all "wall" "opacity" 1/2)
|
||||
(q>* |opacity| "wall" 1/2)
|
||||
|
||||
(qml-set-all "object" "scale" 2/3)
|
||||
(q>* !scale| "object" 2/3)
|
||||
|
|
|
|||
|
|
@ -14,11 +14,17 @@
|
|||
#:children
|
||||
#:find-quick-item
|
||||
#:js
|
||||
#:js-arg
|
||||
#:qml-call
|
||||
#:qml-get
|
||||
#:qml-set
|
||||
#:qml-set-all
|
||||
#:q!
|
||||
#:q<
|
||||
#:q>
|
||||
#:q>*
|
||||
#:paint
|
||||
#:scale
|
||||
#:reload
|
||||
#:root-context
|
||||
#:root-item))
|
||||
|
|
@ -94,9 +100,11 @@
|
|||
|
||||
(defun find-quick-item (object-name)
|
||||
"Finds the first QQuickItem matching OBJECT-NAME."
|
||||
(if (string= (|objectName| (root-item)) object-name)
|
||||
(root-item)
|
||||
(qt-object-? (qfind-child (root-item) object-name))))
|
||||
(let ((root (root-item)))
|
||||
(unless (qnull root)
|
||||
(if (string= (|objectName| root) object-name)
|
||||
(root-item)
|
||||
(qt-object-? (qfind-child root object-name))))))
|
||||
|
||||
(defun quick-item (item/name)
|
||||
(cond ((stringp item/name)
|
||||
|
|
@ -110,6 +118,10 @@
|
|||
"Like QML function 'children'."
|
||||
(mapcar 'qt-object-? (|childItems| (quick-item item/name))))
|
||||
|
||||
(defun scale ()
|
||||
"Returns the scale factor used on high dpi scaled devices (e.g. phones)."
|
||||
(|effectiveDevicePixelRatio| *quick-view*))
|
||||
|
||||
(defun reload ()
|
||||
"Force reloading of QML file after changes made to it."
|
||||
(|clearComponentCache| (|engine| *quick-view*))
|
||||
|
|
@ -153,6 +165,22 @@
|
|||
(dolist (item (qfind-children (root-item) name))
|
||||
(qml-set item property-name value update)))
|
||||
|
||||
(defmacro q! (method-name item/name &rest arguments)
|
||||
"Convenience macro for QML-CALL. Use symbol instead of string name."
|
||||
`(qml-call ,item/name ,(symbol-name method-name) ,@arguments))
|
||||
|
||||
(defmacro q> (property-name item/name value &optional update)
|
||||
"Convenience macro for QML-SET. Use symbol instead of string name."
|
||||
`(qml-set ,item/name ,(symbol-name property-name) ,value ,update))
|
||||
|
||||
(defmacro q< (property-name item/name)
|
||||
"Convenience macro for QML-GET. Use symbol instead of string name."
|
||||
`(qml-get ,item/name ,(symbol-name property-name)))
|
||||
|
||||
(defmacro q>* (property-name item/name value &optional update)
|
||||
"Convenience macro for QML-SET-ALL. Use symbol instead of string name."
|
||||
`(qml-set-all ,item/name ,(symbol-name property-name) ,value ,update))
|
||||
|
||||
;;; JS
|
||||
|
||||
(defun js (item/name js-format-string &rest arguments)
|
||||
|
|
@ -164,3 +192,8 @@
|
|||
(variant (|evaluate| qml-exp)))
|
||||
(qvariant-value variant)))
|
||||
|
||||
(defun js-arg (object)
|
||||
"To be used for arguments in function JS."
|
||||
(with-output-to-string (*standard-output*)
|
||||
(print-js-readably object)))
|
||||
|
||||
|
|
|
|||
|
|
@ -51,10 +51,10 @@
|
|||
(qml:find-quick-item "board"))
|
||||
|
||||
(defun level ()
|
||||
(floor (qml-get "level" "value")))
|
||||
(floor (q< |value| "level")))
|
||||
|
||||
(defun set-level (index)
|
||||
(qml-set "level" "value" index))
|
||||
(q> |value| "level" index))
|
||||
|
||||
(defun assoc* (item alist)
|
||||
(cdr (assoc item alist)))
|
||||
|
|
@ -98,10 +98,10 @@
|
|||
|
||||
(defun create-item (type)
|
||||
(let ((item (create-item-type type)))
|
||||
(qml-set item "source" (|fromLocalFile.QUrl| (format nil "qml/img/~(~A~).png" type)))
|
||||
(q> |source| item (|fromLocalFile.QUrl| (format nil "qml/img/~(~A~).png" type)))
|
||||
(|setObjectName| item (string-downcase type))
|
||||
(unless *item-size*
|
||||
(setf *item-size* (qml-get item "sourceSize")))
|
||||
(setf *item-size* (q< |sourceSize| item)))
|
||||
item))
|
||||
|
||||
(defun create-items ()
|
||||
|
|
@ -157,9 +157,9 @@
|
|||
(+ (if (eql :next direction/index) 1 -1)
|
||||
(level)))))))
|
||||
(when (/= level (level))
|
||||
(queued (qml-set "zoom_board_out" "running" t)
|
||||
(queued (q> |running| "zoom_board_out" t)
|
||||
(set-level level) ; will call SET-MAZE from QML
|
||||
(qml-set "zoom_board_in" "running" t))))
|
||||
(q> |running| "zoom_board_in" t))))
|
||||
(level))
|
||||
|
||||
(defun key-pressed (object event)
|
||||
|
|
@ -202,13 +202,13 @@
|
|||
(defun set-x (item x &optional animate)
|
||||
(let ((x* (+ x *translate-x*)))
|
||||
(if animate
|
||||
(qml-set item "x" x*)
|
||||
(q> |x| item x*)
|
||||
(|setX| item x*))))
|
||||
|
||||
(defun set-y (item y &optional animate)
|
||||
(let ((y* (+ y *translate-y*)))
|
||||
(if animate
|
||||
(qml-set item "y" y*)
|
||||
(q> |y| item y*)
|
||||
(|setY| item y*))))
|
||||
|
||||
(defun child-at (x y)
|
||||
|
|
@ -283,8 +283,8 @@
|
|||
t)
|
||||
|
||||
(defun final-animation ()
|
||||
(queued (qml-set "rotate_player" "running" t)
|
||||
(qml-set-all "wiggle_box" "running" t)))
|
||||
(queued (q> |running| "rotate_player" t)
|
||||
(q>* |running| "wiggle_box" t)))
|
||||
|
||||
(defun run ()
|
||||
(x:do-with *quick-view*
|
||||
|
|
@ -295,7 +295,7 @@
|
|||
(qadd-event-filter nil |QEvent.KeyPress| 'key-pressed)
|
||||
(setf sokoban:*move-hook* 'move-item
|
||||
sokoban:*undo-hook* 'add-undo-step)
|
||||
(qml-set "level" "maximumValue" (1- (length *my-mazes*)))
|
||||
(q> |maximumValue| "level" (1- (length *my-mazes*)))
|
||||
(set-maze))
|
||||
|
||||
(progn
|
||||
|
|
|
|||
|
|
@ -14,11 +14,17 @@
|
|||
#:children
|
||||
#:find-quick-item
|
||||
#:js
|
||||
#:js-arg
|
||||
#:qml-call
|
||||
#:qml-get
|
||||
#:qml-set
|
||||
#:qml-set-all
|
||||
#:q!
|
||||
#:q<
|
||||
#:q>
|
||||
#:q>*
|
||||
#:paint
|
||||
#:scale
|
||||
#:reload
|
||||
#:root-context
|
||||
#:root-item))
|
||||
|
|
@ -94,9 +100,11 @@
|
|||
|
||||
(defun find-quick-item (object-name)
|
||||
"Finds the first QQuickItem matching OBJECT-NAME."
|
||||
(if (string= (|objectName| (root-item)) object-name)
|
||||
(root-item)
|
||||
(qt-object-? (qfind-child (root-item) object-name))))
|
||||
(let ((root (root-item)))
|
||||
(unless (qnull root)
|
||||
(if (string= (|objectName| root) object-name)
|
||||
(root-item)
|
||||
(qt-object-? (qfind-child root object-name))))))
|
||||
|
||||
(defun quick-item (item/name)
|
||||
(cond ((stringp item/name)
|
||||
|
|
@ -110,6 +118,10 @@
|
|||
"Like QML function 'children'."
|
||||
(mapcar 'qt-object-? (|childItems| (quick-item item/name))))
|
||||
|
||||
(defun scale ()
|
||||
"Returns the scale factor used on high dpi scaled devices (e.g. phones)."
|
||||
(|effectiveDevicePixelRatio| *quick-view*))
|
||||
|
||||
(defun reload ()
|
||||
"Force reloading of QML file after changes made to it."
|
||||
(|clearComponentCache| (|engine| *quick-view*))
|
||||
|
|
@ -153,6 +165,22 @@
|
|||
(dolist (item (qfind-children (root-item) name))
|
||||
(qml-set item property-name value update)))
|
||||
|
||||
(defmacro q! (method-name item/name &rest arguments)
|
||||
"Convenience macro for QML-CALL. Use symbol instead of string name."
|
||||
`(qml-call ,item/name ,(symbol-name method-name) ,@arguments))
|
||||
|
||||
(defmacro q> (property-name item/name value &optional update)
|
||||
"Convenience macro for QML-SET. Use symbol instead of string name."
|
||||
`(qml-set ,item/name ,(symbol-name property-name) ,value ,update))
|
||||
|
||||
(defmacro q< (property-name item/name)
|
||||
"Convenience macro for QML-GET. Use symbol instead of string name."
|
||||
`(qml-get ,item/name ,(symbol-name property-name)))
|
||||
|
||||
(defmacro q>* (property-name item/name value &optional update)
|
||||
"Convenience macro for QML-SET-ALL. Use symbol instead of string name."
|
||||
`(qml-set-all ,item/name ,(symbol-name property-name) ,value ,update))
|
||||
|
||||
;;; JS
|
||||
|
||||
(defun js (item/name js-format-string &rest arguments)
|
||||
|
|
@ -164,3 +192,8 @@
|
|||
(variant (|evaluate| qml-exp)))
|
||||
(qvariant-value variant)))
|
||||
|
||||
(defun js-arg (object)
|
||||
"To be used for arguments in function JS."
|
||||
(with-output-to-string (*standard-output*)
|
||||
(print-js-readably object)))
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
;;; this is (kind of) a simplified port of the "tableview" C++/QML example
|
||||
;;; (see also README.txt)
|
||||
|
||||
(si::trap-fpe t nil) ; ignore floating point overflows
|
||||
|
||||
(qrequire :quick)
|
||||
|
||||
(require :qml-lisp "qml-lisp")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue