comparison examples/layouts/basiclayouts/dialog.d @ 116:1c51d13eef25

add basiclayout example
author mandel
date Thu, 04 Jun 2009 14:05:50 +0000
parents
children 6aeaf24018d7
comparison
equal deleted inserted replaced
115:87f833f309d7 116:1c51d13eef25
1 /****************************************************************************
2 **
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: Qt Software Information (qt-info@nokia.com)
5 **
6 ** This file is part of the examples of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial Usage
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Nokia.
14 **
15 ** GNU Lesser General Public License Usage
16 ** Alternatively, this file may be used under the terms of the GNU Lesser
17 ** General Public License version 2.1 as published by the Free Software
18 ** Foundation and appearing in the file LICENSE.LGPL included in the
19 ** packaging of this file. Please review the following information to
20 ** ensure the GNU Lesser General Public License version 2.1 requirements
21 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22 **
23 ** In addition, as a special exception, Nokia gives you certain
24 ** additional rights. These rights are described in the Nokia Qt LGPL
25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26 ** package.
27 **
28 ** GNU General Public License Usage
29 ** Alternatively, this file may be used under the terms of the GNU
30 ** General Public License version 3.0 as published by the Free Software
31 ** Foundation and appearing in the file LICENSE.GPL included in the
32 ** packaging of this file. Please review the following information to
33 ** ensure the GNU General Public License version 3.0 requirements will be
34 ** met: http://www.gnu.org/copyleft/gpl.html.
35 **
36 ** If you are unsure which license is appropriate for your use, please
37 ** contact the sales department at qt-sales@nokia.com.
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 module dialog;
42
43
44 import qt.gui.QDialogButtonBox;
45 import qt.gui.QGroupBox;
46 import qt.gui.QLabel;
47 import qt.gui.QLineEdit;
48 import qt.gui.QMenuBar;
49 import qt.gui.QPushButton;
50 import qt.gui.QTextEdit;
51 import qt.gui.QDialog;
52 import qt.gui.QVBoxLayout;
53 import qt.gui.QHBoxLayout;
54 import qt.gui.QGridLayout;
55 import qt.gui.QFormLayout;
56 import qt.gui.QComboBox;
57 import qt.gui.QSpinBox;
58
59 import tango.text.convert.Format;
60
61
62 class Dialog : public QDialog
63 {
64 this()
65 {
66 createMenu();
67 createHorizontalGroupBox();
68 createGridGroupBox();
69 createFormGroupBox();
70
71 bigEditor = new QTextEdit;
72 bigEditor.setPlainText(tr("This widget takes up all the remaining space in the top-level layout."));
73
74 buttonBox = new QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel);
75
76 buttonBox.accepted.connect(&this.accept);
77 buttonBox.rejected.connect(&this.reject);
78
79 QVBoxLayout mainLayout = new QVBoxLayout;
80
81 mainLayout.setMenuBar(menuBar);
82
83 mainLayout.addWidget(horizontalGroupBox);
84 mainLayout.addWidget(gridGroupBox);
85 mainLayout.addWidget(formGroupBox);
86 mainLayout.addWidget(bigEditor);
87 mainLayout.addWidget(buttonBox);
88
89 setLayout(mainLayout);
90
91 setWindowTitle(tr("Basic Layouts"));
92 }
93
94 void createMenu()
95 {
96 menuBar = new QMenuBar;
97
98 fileMenu = new QMenu(tr("&File"), this);
99 exitAction = fileMenu.addAction(tr("E&xit"));
100 menuBar.addMenu(fileMenu);
101
102 exitAction.triggered.connect(&this.accept);
103 }
104
105 void createHorizontalGroupBox()
106 {
107 horizontalGroupBox = new QGroupBox(tr("Horizontal layout"));
108 QHBoxLayout layout = new QHBoxLayout;
109
110 for (int i = 0; i < NumButtons; ++i) {
111 buttons[i] = new QPushButton(Format(tr("Button {}"), i + 1));
112 layout.addWidget(buttons[i]);
113 }
114 horizontalGroupBox.setLayout(layout);
115 }
116
117 void createGridGroupBox()
118 {
119 gridGroupBox = new QGroupBox(tr("Grid layout"));
120 QGridLayout layout = new QGridLayout;
121
122 for (int i = 0; i < NumGridRows; ++i) {
123 labels[i] = new QLabel(Format(tr("Line {}:"), i + 1));
124 lineEdits[i] = new QLineEdit;
125 layout.addWidget(labels[i], i + 1, 0);
126 layout.addWidget(lineEdits[i], i + 1, 1);
127 }
128
129 smallEditor = new QTextEdit;
130 smallEditor.setPlainText(tr("This widget takes up about two thirds of the grid layout."));
131 layout.addWidget(smallEditor, 0, 2, 4, 1);
132
133 layout.setColumnStretch(1, 10);
134 layout.setColumnStretch(2, 20);
135 gridGroupBox.setLayout(layout);
136 }
137
138 void createFormGroupBox()
139 {
140 formGroupBox = new QGroupBox(tr("Form layout"));
141 QFormLayout layout = new QFormLayout;
142 layout.addRow(new QLabel(tr("Line 1:")), new QLineEdit);
143 layout.addRow(new QLabel(tr("Line 2, long text:")), new QComboBox);
144 layout.addRow(new QLabel(tr("Line 3:")), new QSpinBox);
145 formGroupBox.setLayout(layout);
146 }
147
148 enum { NumGridRows = 3, NumButtons = 4 };
149
150 QMenuBar menuBar;
151 QGroupBox horizontalGroupBox;
152 QGroupBox gridGroupBox;
153 QGroupBox formGroupBox;
154 QTextEdit smallEditor;
155 QTextEdit bigEditor;
156 QLabel[NumGridRows] labels;
157 QLineEdit[NumGridRows] lineEdits;
158 QPushButton[NumButtons] buttons;
159 QDialogButtonBox buttonBox;
160
161 QMenu fileMenu;
162 QAction exitAction;
163 }