Sun, 24 Jan 2016 12:39:05 +0100
added radio buttons and gridwidth layout option (Qt)
application/main.c | file | annotate | diff | comparison | revisions | |
ui/gtk/container.c | file | annotate | diff | comparison | revisions | |
ui/qt/button.cpp | file | annotate | diff | comparison | revisions | |
ui/qt/button.h | file | annotate | diff | comparison | revisions | |
ui/qt/container.cpp | file | annotate | diff | comparison | revisions | |
ui/qt/container.h | file | annotate | diff | comparison | revisions |
--- a/application/main.c Sun Jan 24 12:08:57 2016 +0100 +++ b/application/main.c Sun Jan 24 12:39:05 2016 +0100 @@ -112,7 +112,17 @@ ui_newline(obj); ui_layout_gridwidth(obj, 2); - ui_button(obj, "Test", NULL, NULL); + ui_button(obj, "Test", action_button, NULL); + ui_button(obj, "ABC", action_button2, NULL); + ui_newline(obj); + + ui_radiobutton(obj, "Radio1", &radio); + ui_radiobutton(obj, "Radio2", &radio); + ui_radiobutton(obj, "Radio3", &radio); + + + ui_layout_vexpand(obj, TRUE); + ui_space(obj); ui_end(obj); //*/
--- a/ui/gtk/container.c Sun Jan 24 12:08:57 2016 +0100 +++ b/ui/gtk/container.c Sun Jan 24 12:39:05 2016 +0100 @@ -142,7 +142,7 @@ int gwidth = ct->layout.gridwidth > 0 ? ct->layout.gridwidth : 1; gtk_grid_attach(GTK_GRID(ct->widget), widget, grid->x, grid->y, gwidth, 1); - grid->x++; + grid->x += gwidth; ui_reset_layout(ct->layout); ct->current = widget;
--- a/ui/qt/button.cpp Sun Jan 24 12:08:57 2016 +0100 +++ b/ui/qt/button.cpp Sun Jan 24 12:39:05 2016 +0100 @@ -44,3 +44,47 @@ return button; } + + + +// TODO: checkbox + + +UIWIDGET ui_radiobutton(UiObject *obj, char *label, UiInteger *rgroup) { + QString str = QString::fromUtf8(label); + QRadioButton *button = new QRadioButton(str); + button->setAutoExclusive(false); + + if(rgroup) { + QButtonGroup *buttonGroup = (QButtonGroup*)rgroup->obj; + if(!buttonGroup) { + buttonGroup = new QButtonGroup(); + rgroup->obj = buttonGroup; + button->setChecked(true); + } + buttonGroup->addButton(button, buttonGroup->buttons().size()); + + rgroup->get = ui_radiobutton_get; + rgroup->set = ui_radiobutton_set; + } + + UiContainer *ct = uic_get_current_container(obj); + ct->add(button, false); + + return button; +} + +int ui_radiobutton_get(UiInteger *value) { + QButtonGroup *buttonGroup = (QButtonGroup*)value->obj; + value->value = buttonGroup->checkedId(); + return value->value; +} + +void ui_radiobutton_set(UiInteger *value, int i) { + QButtonGroup *buttonGroup = (QButtonGroup*)value->obj; + QAbstractButton *button = buttonGroup->button(i); + if(button) { + button->setChecked(true); + value->value = i; + } +}
--- a/ui/qt/button.h Sun Jan 24 12:08:57 2016 +0100 +++ b/ui/qt/button.h Sun Jan 24 12:39:05 2016 +0100 @@ -32,6 +32,16 @@ #include "toolkit.h" #include "../ui/button.h" #include <QPushButton> +#include <QRadioButton> +#include <QButtonGroup> + +extern "C" { + +int ui_radiobutton_get(UiInteger *value); + +void ui_radiobutton_set(UiInteger *value, int i); + +} #endif /* BUTTON_H */
--- a/ui/qt/container.cpp Sun Jan 24 12:08:57 2016 +0100 +++ b/ui/qt/container.cpp Sun Jan 24 12:39:05 2016 +0100 @@ -121,8 +121,10 @@ grid->setRowStretch(y, 0); } - grid->addWidget(widget, y, x, alignment); - x++; + int gwidth = layout.gridwidth > 0 ? layout.gridwidth : 1; + + grid->addWidget(widget, y, x, 1, gwidth, alignment); + x += gwidth; ui_reset_layout(layout); current = widget; @@ -211,6 +213,11 @@ ct->layout.vexpand = expand; } +void ui_layout_gridwidth(UiObject *obj, int width) { + UiContainer *ct = uic_get_current_container(obj); + ct->layout.gridwidth = width; +} + void ui_newline(UiObject *obj) { UiContainer *ct = uic_get_current_container(obj); ct->layout.newline = TRUE;