Fri, 09 Jan 2015 14:33:40 +0100
added tabview (Qt)
application/main.c | file | annotate | diff | comparison | revisions | |
ui/qt/button.cpp | 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 Wed Jan 07 20:11:36 2015 +0100 +++ b/application/main.c Fri Jan 09 14:33:40 2015 +0100 @@ -80,11 +80,11 @@ printf("{%s}\n", s); //printf("name: {%s}\n", ui_getval(name)); //printf("mail: {%s}\n", ui_getval(mail)); - //ui_select_tab(tabview, 0); + ui_select_tab(tabview, 1); } void action_test(UiEvent *event, void *data) { - //ui_select_tab(tabview, 1); + ui_select_tab(tabview, 0); } int main(int argc, char** argv) { @@ -105,7 +105,9 @@ printf("create window\n"); UiObject *window = ui_window("Mod0", NULL); - ui_layout_fill(window, FALSE); + tabview = ui_tabview(window); + + ui_tab(window, "1"); ui_grid(window); ui_button(window, "Test1________________", action_button, NULL); ui_button(window, "Test2", action_button, NULL); @@ -113,6 +115,13 @@ ui_button(window, "Test1", action_button, NULL); ui_button(window, "Test2", action_button, NULL); ui_end(window); + ui_end(window); + + ui_tab(window, "2"); + ui_textarea_nv(window, "text"); + ui_button(window, "Zurück", action_test, NULL); + + ui_end(window); ui_show(window); ui_main();
--- a/ui/qt/button.cpp Wed Jan 07 20:11:36 2015 +0100 +++ b/ui/qt/button.cpp Fri Jan 09 14:33:40 2015 +0100 @@ -32,7 +32,7 @@ UIWIDGET ui_button(UiObject *obj, char *label, ui_callback f, void *data) { QString str = QString::fromUtf8(label); - QPushButton *button = new QPushButton(label); + QPushButton *button = new QPushButton(str); if(f) { UiEventWrapper *event = new UiEventWrapper(obj, f, data);
--- a/ui/qt/container.cpp Wed Jan 07 20:11:36 2015 +0100 +++ b/ui/qt/container.cpp Fri Jan 09 14:33:40 2015 +0100 @@ -30,6 +30,7 @@ #include "container.h" #include <QSpacerItem> +#include <QStackedWidget> /* -------------------- UiBoxContainer -------------------- */ @@ -121,6 +122,51 @@ ui_reset_layout(layout); } + +/* -------------------- UiTabViewContainer -------------------- */ + +UiTabViewContainer::UiTabViewContainer(QTabWidget* tabwidget) { + this->tabwidget = tabwidget; +} + +void UiTabViewContainer::add(QWidget* widget, bool fill) { + QString str = QString::fromUtf8(layout.label); + tabwidget->addTab(widget, str); +} + +UiStackContainer::UiStackContainer(QStackedWidget *stack) { + this->stack = stack; +} + +void UiStackContainer::add(QWidget* widget, bool fill) { + stack->addWidget(widget); +} + +UIWIDGET ui_tabview(UiObject *obj) { + QStackedWidget *tabwidget = new QStackedWidget(); + + UiContainer *ct = uic_get_current_container(obj); + ct->add(tabwidget, true); + + UiObject *tabviewobj = uic_object_new(obj, tabwidget); + tabviewobj->container = new UiStackContainer(tabwidget); + uic_obj_add(obj, tabviewobj); + + return tabwidget; +} + +void ui_tab(UiObject *obj, char *title) { + UiContainer *ct = uic_get_current_container(obj); + ct->layout.label = title; + ui_vbox(obj); +} + +void ui_select_tab(UIWIDGET tabview, int tab) { + QStackedWidget *w = (QStackedWidget*)tabview; + w->setCurrentIndex(tab); +} + + UIWIDGET ui_grid(UiObject *obj) { UiContainer *ct = uic_get_current_container(obj); QWidget *widget = new QWidget();
--- a/ui/qt/container.h Wed Jan 07 20:11:36 2015 +0100 +++ b/ui/qt/container.h Fri Jan 09 14:33:40 2015 +0100 @@ -35,6 +35,8 @@ #include <string.h> #include <QBoxLayout> #include <QGridLayout> +#include <QTabWidget> +#include <QStackedWidget> #define ui_lb2bool(b) ((b) == UI_LAYOUT_TRUE ? TRUE : FALSE) #define ui_bool2lb(b) ((b) ? UI_LAYOUT_TRUE : UI_LAYOUT_FALSE) @@ -52,6 +54,7 @@ struct UiLayout { UiLayoutBool fill; bool newline; + char *label; }; struct UiContainer { @@ -83,5 +86,21 @@ virtual void add(QWidget *widget, bool fill); }; +class UiTabViewContainer : public UiContainer { +public: + QTabWidget *tabwidget; + + UiTabViewContainer(QTabWidget *tabwidget); + virtual void add(QWidget *widget, bool fill); +}; + +class UiStackContainer : public UiContainer { +public: + QStackedWidget *stack; + + UiStackContainer(QStackedWidget *stack); + virtual void add(QWidget *widget, bool fill); +}; + #endif /* CONTAINER_H */