add short convenience macros for calling QML functions and setting properties

This commit is contained in:
polos 2020-06-24 11:59:34 +02:00
parent 680f4cf6ed
commit 97feac95d4
15 changed files with 285 additions and 52 deletions

View file

@ -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)))