From 5d32d36bc73a2eeac7601684ed93fce8935d35c3 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Sat, 24 Feb 2024 13:31:03 -0600 Subject: [PATCH] Support for QFormLayouts with qt:add-field --- main.cpp | 16 ++++++++++++++++ prototypes.h | 2 ++ qt-light.scm | 21 +++++++++++++++++---- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/main.cpp b/main.cpp index 5aa683e..bdf5868 100644 --- a/main.cpp +++ b/main.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -72,6 +73,7 @@ protected: #define qttextedit QTextEdit * #define qtaction QAction * #define qtlayout QLayout * +#define qtformlayout QFormLayout * extern "C" { #include "prototypes.h" @@ -498,6 +500,20 @@ char *qt_listwidgetitem(qtwidget w, int i) { void qt_addlayoutwidget(qtlayout l, qtwidget w) { l->addWidget(w); } +void qt_addformlayoutwidget(qtformlayout l, const char* label, qtwidget w, int row) { + if (row < 0) + l->addRow(label, w); + else + l->insertRow(row, label, w); +} + +void qt_addformlayoutlayout(qtformlayout l, const char* label, qtlayout add_l, int row) { + if (row < 0) + l->addRow(label, add_l); + else + l->insertRow(row, label, add_l); +} + qtsound qt_sound(char *filename) { QSoundEffect* sound = new QSoundEffect(); sound->setSource(QUrl::fromLocalFile(filename)); diff --git a/prototypes.h b/prototypes.h index 8d060bb..30baa35 100644 --- a/prototypes.h +++ b/prototypes.h @@ -57,6 +57,8 @@ 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); +void qt_addformlayoutwidget(qtformlayout l, const char* label, qtwidget w, int row); +void qt_addformlayoutlayout(qtformlayout l, const char* label, qtlayout add_l, int row); 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); diff --git a/qt-light.scm b/qt-light.scm index dac2b4e..3cba564 100644 --- a/qt-light.scm +++ b/qt-light.scm @@ -5,10 +5,11 @@ qt:widget qt:show qt:hide qt:run qt:delete qt:message qt:connect qt:find qt:widget qt:receiver qt:pixmap qt:icon qt:theme-icon qt:timer - qt:icon->pixmap qt:pixmap->icon + qt:icon->pixmap qt:pixmap->icon qt:property qt:gl qt:update qt:start qt:stop - qt:clear qt:add qt:item qt:classname qt:inherits - + qt:clear qt:add qt:item qt:add-field + qt:classname qt:inherits + qt:get-open-filename qt:get-save-filename qt:get-directory @@ -50,10 +51,12 @@ (define (% (class 'qt-text-edit))) (define (% (class 'qt-action))) (define (% (class 'qt-layout))) +(define (% (class 'qt-form-layout))) (define (qt:->pointer i) (and i (? i pointer))) (define (qt:pointer->widget p) (and p (% (pointer p)))) (define (qt:pointer->layout p) (and p (% (pointer p)))) +(define (qt:pointer->form-layout p) (and p (% (pointer p)))) (define (qt:pointer->object p) (and p (% (pointer p)))) (define (qt:pointer->timer p) (and p (% (pointer p)))) (define (qt:pointer->application p) (and p (% (pointer p)))) @@ -71,6 +74,7 @@ (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 qtformlayout c-pointer qt:->pointer qt:pointer->form-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) @@ -116,11 +120,13 @@ extern "C" { (let ((result (qt:find o name))) (if result (cond ((qt:inherits result "QTextEdit") - (qt:pointer->textedit (qt:->pointer result))) + (qt:pointer->text-edit (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 "QFormLayout") + (qt:pointer->form-layout (qt:->pointer result))) ((qt:inherits result "QLayout") (qt:pointer->layout (qt:->pointer result))) (#t @@ -223,6 +229,13 @@ extern "C" { ((qt:inherits w "QLayout") (qt:addlayoutwidget w x)) (else (error 'qt:add "invalid widget" w x)) ) ) +(define (qt:add-field layout label item #!optional (row #f)) + (cond ((qt:inherits item "QLayout") + (qt:addformlayoutlayout layout label item (or row -1))) + ((qt:inherits item "QWidget") + (qt:addformlayoutwidget layout label item (or row -1))) + (else (error 'qt:add-field "invalid widget/layout" layout item)))) + (define (qt:item w i) (and (positive? i) (qt:listwidgetitem w i))) (define qt:clear qt:clearlistwidget)