Wed, 07 Jan 2015 17:25:33 +0100
added button and box container (Qt)
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> |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
33 | |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
34 | /* -------------------- UiBoxContainer -------------------- */ |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
35 | |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
36 | UiBoxContainer::UiBoxContainer(QBoxLayout* box) { |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
37 | this->box = box; |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
38 | box->setContentsMargins(QMargins(0,0,0,0)); |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
39 | box->setSpacing(0); |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
40 | |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
41 | ui_reset_layout(layout); |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
42 | } |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
43 | |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
44 | void UiBoxContainer::add(QWidget* widget, bool fill) { |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
45 | if(layout.fill != UI_LAYOUT_UNDEFINED) { |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
46 | fill = ui_lb2bool(layout.fill); |
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 | |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
49 | if(hasStretchedWidget && fill) { |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
50 | fill = false; |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
51 | 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
|
52 | } |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
53 | |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
54 | box->addWidget(widget, fill); |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
55 | |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
56 | if(!hasStretchedWidget) { |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
57 | 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
|
58 | box->removeItem(space); |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
59 | box->addSpacerItem(newspace); |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
60 | space = newspace; |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
61 | |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
62 | } |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
63 | |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
64 | if(fill) { |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
65 | hasStretchedWidget = true; |
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 | ui_reset_layout(layout); |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
68 | } |
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 | 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
|
71 | UiContainer *ct = uic_get_current_container(obj); |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
72 | QWidget *widget = new QWidget(); |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
73 | QBoxLayout *box = new QBoxLayout(dir); |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
74 | widget->setLayout(box); |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
75 | ct->add(widget, true); |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
76 | |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
77 | UiObject *newobj = uic_object_new(obj, widget); |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
78 | newobj->container = new UiBoxContainer(box); |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
79 | uic_obj_add(obj, newobj); |
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 | return widget; |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
82 | } |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
83 | |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
84 | UIWIDGET ui_vbox(UiObject *obj) { |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
85 | return ui_box(obj, QBoxLayout::TopToBottom); |
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_hbox(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::LeftToRight); |
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 | |
56
87e3a5dc66dd
added text widget (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
92 | |
66
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
93 | |
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 | /* -------------------- layout functions -------------------- */ |
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 | 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
|
98 | UiContainer *ct = uic_get_current_container(obj); |
8d490d97aab8
added button and box container (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
99 | ct->layout.fill = ui_bool2lb(fill); |
56
87e3a5dc66dd
added text widget (Qt)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | } |