Compare commits

...

2 Enmetoj

Author SHA1 Message Date
Jaidyn Ann e0fca00772 Add support for QLayout
Including qt:add & qt:find.
2024-02-24 12:27:22 -06:00
Jaidyn Ann 7e19dd1a92 Add qt:inherits; qt:find returns “lowest” type
qt:inherits returns whether or not a QObject
inherits a class of the given name.
Rather than checking equality with qt:classname
internally for qt:add, we now check for
inheritance with qt:inherits.

Now, rather than returning solely <qt-object>,
qt:find will return the most-specific supported
type, i.e. <qt-widget> or <qt-action>.
2024-02-24 12:14:19 -06:00
3 changed files with 33 additions and 5 deletions

View File

@ -3,6 +3,7 @@
#include <QtGui>
#include <QtUiTools>
#include <QLayout>
#include <QOpenGLWidget>
#include <QtMultimedia/QSoundEffect>
#include <chicken.h>
@ -70,6 +71,7 @@ protected:
#define qtsound QSoundEffect *
#define qttextedit QTextEdit *
#define qtaction QAction *
#define qtlayout QLayout *
extern "C" {
#include "prototypes.h"
@ -464,6 +466,7 @@ int qt_propertytype(qtwidget w, char *prop)
const char *qt_classname(qtobject w) { return w->metaObject()->className(); }
___bool qt_inherits(qtobject w, const char *classname) { return w->inherits(classname); }
qtwidget qt_gl(char *name, qtwidget parent, C_word proc) { return new OpenGLWidget(name, parent, proc); }
void qt_update(qtwidget w) { w->update(); }
@ -493,6 +496,8 @@ char *qt_listwidgetitem(qtwidget w, int i) {
return qstrdata(((QListWidget *)w)->item(i)->text());
}
void qt_addlayoutwidget(qtlayout l, qtwidget w) { l->addWidget(w); }
qtsound qt_sound(char *filename) {
QSoundEffect* sound = new QSoundEffect();
sound->setSource(QUrl::fromLocalFile(filename));

View File

@ -19,6 +19,7 @@ qtobject qt_find(qtobject parent, char *name);
qtobject qt_receiver(char *name, C_word proc);
int qt_message(char *caption, char *text, qtwidget parent, char *b0, char *b1, char *b2, int msg_type);
const char *qt_classname(qtobject w);
___bool qt_inherits(qtobject w, const char *classname);
___bool qt_setstringproperty(qtwidget w, char *prop, char *val);
___bool qt_setboolproperty(qtwidget w, char *prop, ___bool val);
___bool qt_setintproperty(qtwidget w, char *prop, int val);
@ -55,6 +56,7 @@ void qt_addcomboboxitem(qtwidget w, char *s);
void qt_addlistwidgetitem(qtwidget w, char *s);
void qt_addtreewidgetitem(qtwidget w, char *s);
char *qt_listwidgetitem(qtwidget w, int i);
void qt_addlayoutwidget(qtlayout l, qtwidget w);
char *qt_getexistingdirectory(qtwidget p, char *cap, char *dir, int opts);
char *qt_getopenfilename(qtwidget p, char *cap, char *dir, char *filter, int opts);
char *qt_getsavefilename(qtwidget p, char *cap, char *dir, char *filter, int opts);

View File

@ -7,7 +7,7 @@
qt:widget qt:receiver qt:pixmap qt:icon qt:theme-icon qt:timer
qt:icon->pixmap qt:pixmap->icon
qt:property qt:gl qt:update qt:start qt:stop
qt:clear qt:add qt:item <qt> qt:classname
qt:clear qt:add qt:item <qt> qt:classname qt:inherits
<qt-object> <qt-widget> <qt-pixmap> <qt-icon> <qt-application>
<qt-receiver> <qt-timer> <qt-sound> <qt-text-edit>
<qt-action>
@ -33,7 +33,7 @@
(define <qt>
(% (current-root-object)
(% (current-root-object)
(class '<qt>)
(pointer #f)
(print (lambda (self #!optional (port (current-output-port)))
@ -49,9 +49,11 @@
(define <qt-timer> (% <qt-object> (class 'qt-timer)))
(define <qt-text-edit> (% <qt-widget> (class 'qt-text-edit)))
(define <qt-action> (% <qt-object> (class 'qt-action)))
(define <qt-layout> (% <qt-object> (class 'qt-layout)))
(define (qt:->pointer i) (and i (? i pointer)))
(define (qt:pointer->widget p) (and p (% <qt-widget> (pointer p))))
(define (qt:pointer->layout p) (and p (% <qt-layout> (pointer p))))
(define (qt:pointer->object p) (and p (% <qt-object> (pointer p))))
(define (qt:pointer->timer p) (and p (% <qt-timer> (pointer p))))
(define (qt:pointer->application p) (and p (% <qt-application> (pointer p))))
@ -68,6 +70,7 @@
(bind-type qtapplication c-pointer qt:->pointer qt:pointer->application)
(bind-type qtpixmap c-pointer qt:->pointer qt:pointer->pixmap)
(bind-type qticon c-pointer qt:->pointer qt:pointer->icon)
(bind-type qtlayout c-pointer qt:->pointer qt:pointer->layout)
(bind-type qtobject c-pointer qt:->pointer qt:pointer->object)
(bind-type qttimer c-pointer qt:->pointer qt:pointer->timer)
(bind-type qtreceiver c-pointer qt:->pointer qt:pointer->receiver)
@ -107,6 +110,23 @@ extern "C" {
(if (procedure? to) (qt:receiver to) to)
(string-append "1" slot)) ) ) )
(define qt:find
(let ((qt:find qt:find))
(lambda (o name)
(let ((result (qt:find o name)))
(if result
(cond ((qt:inherits result "QTextEdit")
(qt:pointer->textedit (qt:->pointer result)))
((qt:inherits result "QWidget")
(qt:pointer->widget (qt:->pointer result)))
((qt:inherits result "QAction")
(qt:pointer->action (qt:->pointer result)))
((qt:inherits result "QLayout")
(qt:pointer->layout (qt:->pointer result)))
(#t
result))
result)))))
(define qt:receiver
(let ((qt:receiver qt:receiver))
(lambda (thunk #!optional (name (gensym "qt:receiver")))
@ -197,9 +217,10 @@ extern "C" {
(qt:run once) ) ) )
(define (qt:add w x)
(cond ((string=? "QComboBox" (qt:classname w)) (qt:addcomboboxitem w x))
((string=? "QListWidget" (qt:classname w)) (qt:addlistwidgetitem w x))
((string=? "QTreeWidget" (qt:classname w)) (qt:addtreewidgetitem w x))
(cond ((qt:inherits w "QComboBox") (qt:addcomboboxitem w x))
((qt:inherits w "QListWidget") (qt:addlistwidgetitem w x))
((qt:inherits w "QTreeWidget") (qt:addtreewidgetitem w x))
((qt:inherits w "QLayout") (qt:addlayoutwidget w x))
(else (error 'qt:add "invalid widget" w x)) ) )
(define (qt:item w i) (and (positive? i) (qt:listwidgetitem w i)))