ui/qt/container.cpp

Wed, 30 Oct 2024 15:15:36 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 30 Oct 2024 15:15:36 +0100
branch
newapi
changeset 375
af087d0fad9b
parent 130
212b63dd61be
permissions
-rw-r--r--

implement imageviewer (WINUI)

56
87e3a5dc66dd added text widget (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
87e3a5dc66dd added text widget (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
87e3a5dc66dd added text widget (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
87e3a5dc66dd added text widget (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2014 Olaf Wintermann. All rights reserved.
87e3a5dc66dd added text widget (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
87e3a5dc66dd added text widget (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
87e3a5dc66dd added text widget (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
87e3a5dc66dd added text widget (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
87e3a5dc66dd added text widget (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
87e3a5dc66dd added text widget (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
87e3a5dc66dd added text widget (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
87e3a5dc66dd added text widget (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
87e3a5dc66dd added text widget (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
87e3a5dc66dd added text widget (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
87e3a5dc66dd added text widget (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
87e3a5dc66dd added text widget (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
87e3a5dc66dd added text widget (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
87e3a5dc66dd added text widget (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
87e3a5dc66dd added text widget (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
87e3a5dc66dd added text widget (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
87e3a5dc66dd added text widget (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
87e3a5dc66dd added text widget (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
87e3a5dc66dd added text widget (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
87e3a5dc66dd added text widget (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
87e3a5dc66dd added text widget (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
87e3a5dc66dd added text widget (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
87e3a5dc66dd added text widget (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
87e3a5dc66dd added text widget (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
66
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
29 #include <stdio.h>
56
87e3a5dc66dd added text widget (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include "container.h"
87e3a5dc66dd added text widget (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31
66
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
32 #include <QSpacerItem>
68
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
33 #include <QStackedWidget>
66
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
34
130
212b63dd61be adds some qt stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
35
66
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
36 /* -------------------- UiBoxContainer -------------------- */
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
37
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
38 UiBoxContainer::UiBoxContainer(QBoxLayout* box) {
73
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 68
diff changeset
39 this->current = NULL;
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 68
diff changeset
40 this->menu = NULL;
66
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
41 this->box = box;
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
42 box->setContentsMargins(QMargins(0,0,0,0));
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
43 box->setSpacing(0);
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
44
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
45 ui_reset_layout(layout);
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
46 }
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
47
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
48 void UiBoxContainer::add(QWidget* widget, bool fill) {
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
49 if(layout.fill != UI_LAYOUT_UNDEFINED) {
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
50 fill = ui_lb2bool(layout.fill);
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
51 }
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
52
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
53 if(hasStretchedWidget && fill) {
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
54 fill = false;
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
55 fprintf(stderr, "UiError: container has 2 filled widgets");
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
56 }
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
57
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
58 box->addWidget(widget, fill);
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
59
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
60 if(!hasStretchedWidget) {
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
61 QSpacerItem *newspace = new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
62 box->removeItem(space);
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
63 box->addSpacerItem(newspace);
67
f72c4f01bf4a added grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
64 space = newspace;
66
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
65 }
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
66
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
67 if(fill) {
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
68 hasStretchedWidget = true;
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
69 }
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
70 ui_reset_layout(layout);
73
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 68
diff changeset
71 current = widget;
66
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
72 }
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
73
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
74 UIWIDGET ui_box(UiObject *obj, QBoxLayout::Direction dir) {
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
75 UiContainer *ct = uic_get_current_container(obj);
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
76 QWidget *widget = new QWidget();
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
77 QBoxLayout *box = new QBoxLayout(dir);
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
78 widget->setLayout(box);
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
79 ct->add(widget, true);
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
80
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
81 UiObject *newobj = uic_object_new(obj, widget);
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
82 newobj->container = new UiBoxContainer(box);
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
83 uic_obj_add(obj, newobj);
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
84
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
85 return widget;
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
86 }
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
87
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
88 UIWIDGET ui_vbox(UiObject *obj) {
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
89 return ui_box(obj, QBoxLayout::TopToBottom);
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
90 }
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
91
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
92 UIWIDGET ui_hbox(UiObject *obj) {
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
93 return ui_box(obj, QBoxLayout::LeftToRight);
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
94 }
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
95
56
87e3a5dc66dd added text widget (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96
66
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
97
67
f72c4f01bf4a added grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
98 /* -------------------- UiGridContainer -------------------- */
f72c4f01bf4a added grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
99
102
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
100 UiGridContainer::UiGridContainer(QGridLayout* grid, int margin, int columnspacing, int rowspacing) {
73
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 68
diff changeset
101 this->current = NULL;
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 68
diff changeset
102 this->menu = NULL;
67
f72c4f01bf4a added grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
103 this->grid = grid;
102
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
104 grid->setContentsMargins(QMargins(margin, margin, margin, margin));
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
105 grid->setHorizontalSpacing(columnspacing);
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
106 grid->setVerticalSpacing(rowspacing);
67
f72c4f01bf4a added grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
107 ui_reset_layout(layout);
f72c4f01bf4a added grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
108 }
f72c4f01bf4a added grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
109
f72c4f01bf4a added grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
110 void UiGridContainer::add(QWidget* widget, bool fill) {
f72c4f01bf4a added grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
111 if(layout.newline) {
f72c4f01bf4a added grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
112 x = 0;
f72c4f01bf4a added grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
113 y++;
f72c4f01bf4a added grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
114 }
102
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
115
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
116 Qt::Alignment alignment = Qt::AlignTop;
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
117 grid->setColumnStretch(x, layout.hexpand ? 1 : 0);
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
118 if(layout.vexpand) {
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
119 grid->setRowStretch(y, 1);
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
120 alignment = 0;
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
121 } else {
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
122 grid->setRowStretch(y, 0);
67
f72c4f01bf4a added grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
123 }
f72c4f01bf4a added grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
124
110
36f1581b43e2 added radio buttons and gridwidth layout option (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 102
diff changeset
125 int gwidth = layout.gridwidth > 0 ? layout.gridwidth : 1;
36f1581b43e2 added radio buttons and gridwidth layout option (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 102
diff changeset
126
36f1581b43e2 added radio buttons and gridwidth layout option (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 102
diff changeset
127 grid->addWidget(widget, y, x, 1, gwidth, alignment);
36f1581b43e2 added radio buttons and gridwidth layout option (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 102
diff changeset
128 x += gwidth;
67
f72c4f01bf4a added grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
129
f72c4f01bf4a added grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
130 ui_reset_layout(layout);
73
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 68
diff changeset
131 current = widget;
67
f72c4f01bf4a added grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
132 }
f72c4f01bf4a added grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
133
102
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
134 UIWIDGET ui_grid(UiObject *obj) {
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
135 return ui_grid_sp(obj, 0, 0, 0);
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
136 }
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
137
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
138 UIWIDGET ui_grid_sp(UiObject *obj, int margin, int columnspacing, int rowspacing) {
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
139 UiContainer *ct = uic_get_current_container(obj);
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
140 QWidget *widget = new QWidget();
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
141 QGridLayout *grid = new QGridLayout();
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
142 widget->setLayout(grid);
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
143 ct->add(widget, true);
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
144
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
145 UiObject *newobj = uic_object_new(obj, widget);
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
146 newobj->container = new UiGridContainer(grid, margin, columnspacing, rowspacing);
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
147 uic_obj_add(obj, newobj);
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
148
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
149 return widget;
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
150 }
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
151
68
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
152
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
153 /* -------------------- UiTabViewContainer -------------------- */
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
154
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
155 UiTabViewContainer::UiTabViewContainer(QTabWidget* tabwidget) {
73
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 68
diff changeset
156 this->current = NULL;
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 68
diff changeset
157 this->menu = NULL;
68
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
158 this->tabwidget = tabwidget;
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
159 }
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
160
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
161 void UiTabViewContainer::add(QWidget* widget, bool fill) {
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
162 QString str = QString::fromUtf8(layout.label);
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
163 tabwidget->addTab(widget, str);
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
164 }
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
165
130
212b63dd61be adds some qt stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
166
212b63dd61be adds some qt stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
167 /* -------------------- UiStackContainer -------------------- */
212b63dd61be adds some qt stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
168
68
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
169 UiStackContainer::UiStackContainer(QStackedWidget *stack) {
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
170 this->stack = stack;
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
171 }
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
172
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
173 void UiStackContainer::add(QWidget* widget, bool fill) {
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
174 stack->addWidget(widget);
73
473acef47ddd added context menus (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 68
diff changeset
175 current = widget;
68
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
176 }
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
177
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
178 UIWIDGET ui_tabview(UiObject *obj) {
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
179 QStackedWidget *tabwidget = new QStackedWidget();
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
180
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
181 UiContainer *ct = uic_get_current_container(obj);
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
182 ct->add(tabwidget, true);
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
183
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
184 UiObject *tabviewobj = uic_object_new(obj, tabwidget);
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
185 tabviewobj->container = new UiStackContainer(tabwidget);
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
186 uic_obj_add(obj, tabviewobj);
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
187
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
188 return tabwidget;
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
189 }
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
190
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
191 void ui_tab(UiObject *obj, char *title) {
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
192 UiContainer *ct = uic_get_current_container(obj);
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
193 ct->layout.label = title;
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
194 ui_vbox(obj);
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
195 }
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
196
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
197 void ui_select_tab(UIWIDGET tabview, int tab) {
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
198 QStackedWidget *w = (QStackedWidget*)tabview;
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
199 w->setCurrentIndex(tab);
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
200 }
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
201
bd9fb6476b80 added tabview (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
202
130
212b63dd61be adds some qt stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
203 /* -------------------- UiSidebarContainer -------------------- */
212b63dd61be adds some qt stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
204
212b63dd61be adds some qt stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
205 UiSidebarContainer::UiSidebarContainer(QSplitter *splitter) {
212b63dd61be adds some qt stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
206 this->splitter = splitter;
212b63dd61be adds some qt stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
207 }
212b63dd61be adds some qt stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
208
212b63dd61be adds some qt stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
209 UIWIDGET ui_sidebar(UiObject *obj) {
212b63dd61be adds some qt stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
210 QSplitter *splitter = new QSplitter(Qt::Horizontal);
212b63dd61be adds some qt stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
211 UiContainer *ct = uic_get_current_container(obj);
212b63dd61be adds some qt stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
212 ct->add(splitter, true);
212b63dd61be adds some qt stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
213
212b63dd61be adds some qt stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
214 UiObject *left = uic_object_new(obj, splitter);
212b63dd61be adds some qt stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
215 left->container = new UiSidebarContainer(splitter);
212b63dd61be adds some qt stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
216
212b63dd61be adds some qt stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
217 UiObject *right = uic_object_new(obj, splitter);
212b63dd61be adds some qt stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
218 right->container = new UiSidebarContainer(splitter);
212b63dd61be adds some qt stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
219
212b63dd61be adds some qt stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
220 uic_obj_add(obj, right);
212b63dd61be adds some qt stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
221 uic_obj_add(obj, left);
212b63dd61be adds some qt stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
222
212b63dd61be adds some qt stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
223 return splitter;
212b63dd61be adds some qt stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
224 }
212b63dd61be adds some qt stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
225
212b63dd61be adds some qt stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
226 void UiSidebarContainer::add(QWidget *widget, bool fill) {
212b63dd61be adds some qt stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
227 splitter->addWidget(widget);
212b63dd61be adds some qt stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
228 }
212b63dd61be adds some qt stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
229
212b63dd61be adds some qt stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
230
66
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
231 /* -------------------- layout functions -------------------- */
56
87e3a5dc66dd added text widget (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
232
66
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
233 void ui_layout_fill(UiObject *obj, UiBool fill) {
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
234 UiContainer *ct = uic_get_current_container(obj);
8d490d97aab8 added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
235 ct->layout.fill = ui_bool2lb(fill);
56
87e3a5dc66dd added text widget (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
236 }
67
f72c4f01bf4a added grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
237
102
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
238 void ui_layout_hexpand(UiObject *obj, UiBool expand) {
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
239 UiContainer *ct = uic_get_current_container(obj);
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
240 ct->layout.hexpand = expand;
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
241 }
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
242
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
243 void ui_layout_vexpand(UiObject *obj, UiBool expand) {
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
244 UiContainer *ct = uic_get_current_container(obj);
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
245 ct->layout.vexpand = expand;
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
246 }
2988f00ed9d6 improved grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
247
110
36f1581b43e2 added radio buttons and gridwidth layout option (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 102
diff changeset
248 void ui_layout_gridwidth(UiObject *obj, int width) {
36f1581b43e2 added radio buttons and gridwidth layout option (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 102
diff changeset
249 UiContainer *ct = uic_get_current_container(obj);
36f1581b43e2 added radio buttons and gridwidth layout option (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 102
diff changeset
250 ct->layout.gridwidth = width;
36f1581b43e2 added radio buttons and gridwidth layout option (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 102
diff changeset
251 }
36f1581b43e2 added radio buttons and gridwidth layout option (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 102
diff changeset
252
67
f72c4f01bf4a added grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
253 void ui_newline(UiObject *obj) {
f72c4f01bf4a added grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
254 UiContainer *ct = uic_get_current_container(obj);
f72c4f01bf4a added grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
255 ct->layout.newline = TRUE;
f72c4f01bf4a added grid container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
256 }

mercurial