ui/qt/container.cpp

changeset 66
8d490d97aab8
parent 56
87e3a5dc66dd
child 67
f72c4f01bf4a
--- a/ui/qt/container.cpp	Mon Jan 05 18:47:07 2015 +0100
+++ b/ui/qt/container.cpp	Wed Jan 07 17:25:33 2015 +0100
@@ -26,14 +26,75 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <stdio.h>
 #include "container.h"
 
+#include <QSpacerItem>
+
+/* -------------------- UiBoxContainer -------------------- */
+
+UiBoxContainer::UiBoxContainer(QBoxLayout* box) {
+    this->box = box;
+    box->setContentsMargins(QMargins(0,0,0,0));
+    box->setSpacing(0);
+    
+    ui_reset_layout(layout);
+}
+
+void UiBoxContainer::add(QWidget* widget, bool fill) {
+    if(layout.fill != UI_LAYOUT_UNDEFINED) {
+        fill = ui_lb2bool(layout.fill);
+    }
+    
+    if(hasStretchedWidget && fill) {
+        fill = false;
+        fprintf(stderr, "UiError: container has 2 filled widgets");
+    }
+    
+    box->addWidget(widget, fill);
+    
+    if(!hasStretchedWidget) {
+        QSpacerItem *newspace = new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
+        box->removeItem(space);
+        box->addSpacerItem(newspace);
+        space = newspace;
+        
+    }
+    
+    if(fill) {
+        hasStretchedWidget = true;
+    }
+    ui_reset_layout(layout);
+}
+
+UIWIDGET ui_box(UiObject *obj, QBoxLayout::Direction dir) {
+    UiContainer *ct = uic_get_current_container(obj);
+    QWidget *widget = new QWidget();
+    QBoxLayout *box = new QBoxLayout(dir);
+    widget->setLayout(box);
+    ct->add(widget, true);
+    
+    UiObject *newobj = uic_object_new(obj, widget);
+    newobj->container = new UiBoxContainer(box);
+    uic_obj_add(obj, newobj);
+    
+    return widget;
+}
+
+UIWIDGET ui_vbox(UiObject *obj) {
+    return ui_box(obj, QBoxLayout::TopToBottom);
+}
+
+UIWIDGET ui_hbox(UiObject *obj) {
+    return ui_box(obj, QBoxLayout::LeftToRight);
+}
+
 
-UiWindowContainer::UiWindowContainer(QMainWindow* window) {
-    this->window = window;
-}
+
+
+/* -------------------- layout functions -------------------- */
 
-void UiWindowContainer::add(QWidget* widget) {
-    window->setCentralWidget(widget);
+void ui_layout_fill(UiObject *obj, UiBool fill) {
+    UiContainer *ct = uic_get_current_container(obj);
+    ct->layout.fill = ui_bool2lb(fill);
 }
-

mercurial