Wed, 20 Jan 2016 16:00:05 +0100
improved grid container (Qt)
application/main.c | file | annotate | diff | comparison | revisions | |
ui/qt/container.cpp | file | annotate | diff | comparison | revisions | |
ui/qt/container.h | file | annotate | diff | comparison | revisions | |
ui/qt/stock.cpp | file | annotate | diff | comparison | revisions | |
ui/qt/toolbar.cpp | file | annotate | diff | comparison | revisions | |
ui/qt/toolbar.h | file | annotate | diff | comparison | revisions |
--- a/application/main.c Wed Jan 20 11:35:01 2016 +0100 +++ b/application/main.c Wed Jan 20 16:00:05 2016 +0100 @@ -92,7 +92,7 @@ //UIWIDGET w = ui_drawingarea(obj, draw, NULL); //ui_mouse_handler(obj, w, click, NULL); - ui_grid_sp(obj, 40, 4, 4); + ui_grid_sp(obj, 8, 4, 4); ui_button(obj, "OK", NULL, NULL); ui_button(obj, "Google", NULL, NULL);
--- a/ui/qt/container.cpp Wed Jan 20 11:35:01 2016 +0100 +++ b/ui/qt/container.cpp Wed Jan 20 16:00:05 2016 +0100 @@ -96,38 +96,56 @@ /* -------------------- UiGridContainer -------------------- */ -UiGridContainer::UiGridContainer(QGridLayout* grid) { +UiGridContainer::UiGridContainer(QGridLayout* grid, int margin, int columnspacing, int rowspacing) { this->current = NULL; this->menu = NULL; this->grid = grid; - grid->setContentsMargins(QMargins(0,0,0,0)); - grid->setSpacing(0); + grid->setContentsMargins(QMargins(margin, margin, margin, margin)); + grid->setHorizontalSpacing(columnspacing); + grid->setVerticalSpacing(rowspacing); ui_reset_layout(layout); } void UiGridContainer::add(QWidget* widget, bool fill) { if(layout.newline) { - QSpacerItem *s = new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::Minimum); - grid->addItem(s, y, x); x = 0; y++; } - if(x == 0) { - if(space) { - grid->removeItem(space); - } - QSpacerItem *s = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding); - grid->addItem(s, y+1, 0); - space = s; + + Qt::Alignment alignment = Qt::AlignTop; + grid->setColumnStretch(x, layout.hexpand ? 1 : 0); + if(layout.vexpand) { + grid->setRowStretch(y, 1); + alignment = 0; + } else { + grid->setRowStretch(y, 0); } - grid->addWidget(widget, y, x); + grid->addWidget(widget, y, x, alignment); x++; ui_reset_layout(layout); current = widget; } +UIWIDGET ui_grid(UiObject *obj) { + return ui_grid_sp(obj, 0, 0, 0); +} + +UIWIDGET ui_grid_sp(UiObject *obj, int margin, int columnspacing, int rowspacing) { + UiContainer *ct = uic_get_current_container(obj); + QWidget *widget = new QWidget(); + QGridLayout *grid = new QGridLayout(); + widget->setLayout(grid); + ct->add(widget, true); + + UiObject *newobj = uic_object_new(obj, widget); + newobj->container = new UiGridContainer(grid, margin, columnspacing, rowspacing); + uic_obj_add(obj, newobj); + + return widget; +} + /* -------------------- UiTabViewContainer -------------------- */ @@ -176,21 +194,6 @@ } -UIWIDGET ui_grid(UiObject *obj) { - UiContainer *ct = uic_get_current_container(obj); - QWidget *widget = new QWidget(); - QGridLayout *grid = new QGridLayout(); - widget->setLayout(grid); - ct->add(widget, true); - - UiObject *newobj = uic_object_new(obj, widget); - newobj->container = new UiGridContainer(grid); - uic_obj_add(obj, newobj); - - return widget; -} - - /* -------------------- layout functions -------------------- */ void ui_layout_fill(UiObject *obj, UiBool fill) { @@ -198,6 +201,16 @@ ct->layout.fill = ui_bool2lb(fill); } +void ui_layout_hexpand(UiObject *obj, UiBool expand) { + UiContainer *ct = uic_get_current_container(obj); + ct->layout.hexpand = expand; +} + +void ui_layout_vexpand(UiObject *obj, UiBool expand) { + UiContainer *ct = uic_get_current_container(obj); + ct->layout.vexpand = expand; +} + void ui_newline(UiObject *obj) { UiContainer *ct = uic_get_current_container(obj); ct->layout.newline = TRUE;
--- a/ui/qt/container.h Wed Jan 20 11:35:01 2016 +0100 +++ b/ui/qt/container.h Wed Jan 20 16:00:05 2016 +0100 @@ -55,6 +55,8 @@ UiLayoutBool fill; bool newline; char *label; + bool hexpand; + bool vexpand; }; struct UiContainer { @@ -81,9 +83,8 @@ QGridLayout *grid; int x = 0; int y = 0; - QSpacerItem *space = NULL; - UiGridContainer(QGridLayout *grid); + UiGridContainer(QGridLayout *grid, int margin, int columnspacing, int rowspacing); virtual void add(QWidget *widget, bool fill); };
--- a/ui/qt/stock.cpp Wed Jan 20 11:35:01 2016 +0100 +++ b/ui/qt/stock.cpp Wed Jan 20 16:00:05 2016 +0100 @@ -26,7 +26,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include <ucx/map.h> +#include "../../ucx/map.h" #include "stock.h" #include "../ui/properties.h"