ui/qt/container.cpp

changeset 66
8d490d97aab8
parent 56
87e3a5dc66dd
child 67
f72c4f01bf4a
equal deleted inserted replaced
65:4697592e24ba 66:8d490d97aab8
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include <stdio.h>
29 #include "container.h" 30 #include "container.h"
30 31
32 #include <QSpacerItem>
31 33
32 UiWindowContainer::UiWindowContainer(QMainWindow* window) { 34 /* -------------------- UiBoxContainer -------------------- */
33 this->window = window; 35
36 UiBoxContainer::UiBoxContainer(QBoxLayout* box) {
37 this->box = box;
38 box->setContentsMargins(QMargins(0,0,0,0));
39 box->setSpacing(0);
40
41 ui_reset_layout(layout);
34 } 42 }
35 43
36 void UiWindowContainer::add(QWidget* widget) { 44 void UiBoxContainer::add(QWidget* widget, bool fill) {
37 window->setCentralWidget(widget); 45 if(layout.fill != UI_LAYOUT_UNDEFINED) {
46 fill = ui_lb2bool(layout.fill);
47 }
48
49 if(hasStretchedWidget && fill) {
50 fill = false;
51 fprintf(stderr, "UiError: container has 2 filled widgets");
52 }
53
54 box->addWidget(widget, fill);
55
56 if(!hasStretchedWidget) {
57 QSpacerItem *newspace = new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
58 box->removeItem(space);
59 box->addSpacerItem(newspace);
60 space = newspace;
61
62 }
63
64 if(fill) {
65 hasStretchedWidget = true;
66 }
67 ui_reset_layout(layout);
38 } 68 }
39 69
70 UIWIDGET ui_box(UiObject *obj, QBoxLayout::Direction dir) {
71 UiContainer *ct = uic_get_current_container(obj);
72 QWidget *widget = new QWidget();
73 QBoxLayout *box = new QBoxLayout(dir);
74 widget->setLayout(box);
75 ct->add(widget, true);
76
77 UiObject *newobj = uic_object_new(obj, widget);
78 newobj->container = new UiBoxContainer(box);
79 uic_obj_add(obj, newobj);
80
81 return widget;
82 }
83
84 UIWIDGET ui_vbox(UiObject *obj) {
85 return ui_box(obj, QBoxLayout::TopToBottom);
86 }
87
88 UIWIDGET ui_hbox(UiObject *obj) {
89 return ui_box(obj, QBoxLayout::LeftToRight);
90 }
91
92
93
94
95 /* -------------------- layout functions -------------------- */
96
97 void ui_layout_fill(UiObject *obj, UiBool fill) {
98 UiContainer *ct = uic_get_current_container(obj);
99 ct->layout.fill = ui_bool2lb(fill);
100 }

mercurial