# HG changeset patch # User Olaf Wintermann # Date 1453302005 -3600 # Node ID 2988f00ed9d6778660c596bf069d27187b150147 # Parent 1c943d43fa813e4f55815419c6e7550b73bc64e5 improved grid container (Qt) diff -r 1c943d43fa81 -r 2988f00ed9d6 application/main.c --- 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); diff -r 1c943d43fa81 -r 2988f00ed9d6 ui/qt/container.cpp --- 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; diff -r 1c943d43fa81 -r 2988f00ed9d6 ui/qt/container.h --- 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); }; diff -r 1c943d43fa81 -r 2988f00ed9d6 ui/qt/stock.cpp --- 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 +#include "../../ucx/map.h" #include "stock.h" #include "../ui/properties.h" diff -r 1c943d43fa81 -r 2988f00ed9d6 ui/qt/toolbar.cpp --- a/ui/qt/toolbar.cpp Wed Jan 20 11:35:01 2016 +0100 +++ b/ui/qt/toolbar.cpp Wed Jan 20 16:00:05 2016 +0100 @@ -26,7 +26,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include +#include "../../ucx/map.h" #include #include "toolbar.h" diff -r 1c943d43fa81 -r 2988f00ed9d6 ui/qt/toolbar.h --- a/ui/qt/toolbar.h Wed Jan 20 11:35:01 2016 +0100 +++ b/ui/qt/toolbar.h Wed Jan 20 16:00:05 2016 +0100 @@ -31,7 +31,7 @@ #include "toolkit.h" #include "../ui/toolbar.h" -#include +#include "../../ucx/list.h" #include class UiToolItemI {