# HG changeset patch # User Olaf Wintermann # Date 1453635545 -3600 # Node ID 36f1581b43e2b5641665a853a952468e39989e48 # Parent b9808f916687924d5337dc44e9e2957206c59abd added radio buttons and gridwidth layout option (Qt) diff -r b9808f916687 -r 36f1581b43e2 application/main.c --- 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); //*/ diff -r b9808f916687 -r 36f1581b43e2 ui/gtk/container.c --- 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; diff -r b9808f916687 -r 36f1581b43e2 ui/qt/button.cpp --- 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; + } +} diff -r b9808f916687 -r 36f1581b43e2 ui/qt/button.h --- 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 +#include +#include + +extern "C" { + +int ui_radiobutton_get(UiInteger *value); + +void ui_radiobutton_set(UiInteger *value, int i); + +} #endif /* BUTTON_H */ diff -r b9808f916687 -r 36f1581b43e2 ui/qt/container.cpp --- 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; diff -r b9808f916687 -r 36f1581b43e2 ui/qt/container.h --- a/ui/qt/container.h Sun Jan 24 12:08:57 2016 +0100 +++ b/ui/qt/container.h Sun Jan 24 12:39:05 2016 +0100 @@ -57,6 +57,7 @@ char *label; bool hexpand; bool vexpand; + int gridwidth; }; struct UiContainer {