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

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