annotate examples/layouts/basiclayouts/dialog.d @ 350:31520b2c0b3c

Removed dependency on parent trait and stringof
author Max Samukha <maxter@spambox.com>
date Thu, 20 May 2010 15:49:08 +0300
parents 7a3c43424dca
children
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
350
31520b2c0b3c Removed dependency on parent trait and stringof
Max Samukha <maxter@spambox.com>
parents: 323
diff changeset
59 import std.string : format;
116
1c51d13eef25 add basiclayout example
mandel
parents:
diff changeset
60
323
7a3c43424dca make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents: 282
diff changeset
61 import std.stdio;
7a3c43424dca make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents: 282
diff changeset
62
116
1c51d13eef25 add basiclayout example
mandel
parents:
diff changeset
63 class Dialog : public QDialog
1c51d13eef25 add basiclayout example
mandel
parents:
diff changeset
64 {
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
65 this()
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
66 {
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
67 createMenu();
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
68 createHorizontalGroupBox();
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
69 createGridGroupBox();
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
70 createFormGroupBox();
116
1c51d13eef25 add basiclayout example
mandel
parents:
diff changeset
71
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
72 bigEditor = new QTextEdit;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
73 bigEditor.setPlainText(tr("This widget takes up all the remaining space in the top-level layout."));
116
1c51d13eef25 add basiclayout example
mandel
parents:
diff changeset
74
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
75 buttonBox = new QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel);
116
1c51d13eef25 add basiclayout example
mandel
parents:
diff changeset
76
323
7a3c43424dca make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents: 282
diff changeset
77 connect(buttonBox, "accepted", this, "accept");
7a3c43424dca make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents: 282
diff changeset
78 connect(buttonBox, "rejected", this, "reject");
116
1c51d13eef25 add basiclayout example
mandel
parents:
diff changeset
79
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
80 QVBoxLayout mainLayout = new QVBoxLayout;
116
1c51d13eef25 add basiclayout example
mandel
parents:
diff changeset
81
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
82 mainLayout.setMenuBar(menuBar);
116
1c51d13eef25 add basiclayout example
mandel
parents:
diff changeset
83
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
84 mainLayout.addWidget(horizontalGroupBox);
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
85 mainLayout.addWidget(gridGroupBox);
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
86 mainLayout.addWidget(formGroupBox);
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
87 mainLayout.addWidget(bigEditor);
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
88 mainLayout.addWidget(buttonBox);
116
1c51d13eef25 add basiclayout example
mandel
parents:
diff changeset
89
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
90 setLayout(mainLayout);
116
1c51d13eef25 add basiclayout example
mandel
parents:
diff changeset
91
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
92 setWindowTitle(tr("Basic Layouts"));
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
93 }
116
1c51d13eef25 add basiclayout example
mandel
parents:
diff changeset
94
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
95 void createMenu()
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
96 {
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
97 menuBar = new QMenuBar;
116
1c51d13eef25 add basiclayout example
mandel
parents:
diff changeset
98
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
99 fileMenu = new QMenu(tr("&File"), this);
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
100 exitAction = fileMenu.addAction(tr("E&xit"));
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
101 menuBar.addMenu(fileMenu);
116
1c51d13eef25 add basiclayout example
mandel
parents:
diff changeset
102
323
7a3c43424dca make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents: 282
diff changeset
103 connect(exitAction, "triggered", this, "accept");
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
104 }
116
1c51d13eef25 add basiclayout example
mandel
parents:
diff changeset
105
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
106 void createHorizontalGroupBox()
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
107 {
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
108 horizontalGroupBox = new QGroupBox(tr("Horizontal layout"));
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
109 QHBoxLayout layout = new QHBoxLayout;
116
1c51d13eef25 add basiclayout example
mandel
parents:
diff changeset
110
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
111 for (int i = 0; i < NumButtons; ++i) {
213
26036621830e more D2 examples fixes
SokoL_SD
parents: 204
diff changeset
112 version(Tango)
26036621830e more D2 examples fixes
SokoL_SD
parents: 204
diff changeset
113 const string str = tr("Button {}:");
26036621830e more D2 examples fixes
SokoL_SD
parents: 204
diff changeset
114 else
26036621830e more D2 examples fixes
SokoL_SD
parents: 204
diff changeset
115 const string str = tr("Button %s:");
26036621830e more D2 examples fixes
SokoL_SD
parents: 204
diff changeset
116 buttons[i] = new QPushButton(format(str, i + 1));
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
117 layout.addWidget(buttons[i]);
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
118 }
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
119 horizontalGroupBox.setLayout(layout);
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
120 }
116
1c51d13eef25 add basiclayout example
mandel
parents:
diff changeset
121
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
122 void createGridGroupBox()
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
123 {
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
124 gridGroupBox = new QGroupBox(tr("Grid layout"));
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
125 QGridLayout layout = new QGridLayout;
116
1c51d13eef25 add basiclayout example
mandel
parents:
diff changeset
126
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
127 for (int i = 0; i < NumGridRows; ++i) {
213
26036621830e more D2 examples fixes
SokoL_SD
parents: 204
diff changeset
128 version(Tango)
26036621830e more D2 examples fixes
SokoL_SD
parents: 204
diff changeset
129 const string str = tr("Line {}:");
26036621830e more D2 examples fixes
SokoL_SD
parents: 204
diff changeset
130 else
26036621830e more D2 examples fixes
SokoL_SD
parents: 204
diff changeset
131 const string str = tr("Line %s:");
26036621830e more D2 examples fixes
SokoL_SD
parents: 204
diff changeset
132 labels[i] = new QLabel(format(str, i + 1));
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
133 lineEdits[i] = new QLineEdit;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
134 layout.addWidget(labels[i], i + 1, 0);
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
135 layout.addWidget(lineEdits[i], i + 1, 1);
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
136 }
116
1c51d13eef25 add basiclayout example
mandel
parents:
diff changeset
137
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
138 smallEditor = new QTextEdit;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
139 smallEditor.setPlainText(tr("This widget takes up about two thirds of the grid layout."));
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
140 layout.addWidget(smallEditor, 0, 2, 4, 1);
116
1c51d13eef25 add basiclayout example
mandel
parents:
diff changeset
141
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
142 layout.setColumnStretch(1, 10);
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
143 layout.setColumnStretch(2, 20);
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
144 gridGroupBox.setLayout(layout);
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
145 }
116
1c51d13eef25 add basiclayout example
mandel
parents:
diff changeset
146
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
147 void createFormGroupBox()
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
148 {
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
149 formGroupBox = new QGroupBox(tr("Form layout"));
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
150 QFormLayout layout = new QFormLayout;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
151 layout.addRow(new QLabel(tr("Line 1:")), new QLineEdit);
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
152 layout.addRow(new QLabel(tr("Line 2, long text:")), new QComboBox);
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
153 layout.addRow(new QLabel(tr("Line 3:")), new QSpinBox);
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
154 formGroupBox.setLayout(layout);
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
155 }
116
1c51d13eef25 add basiclayout example
mandel
parents:
diff changeset
156
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
157 enum { NumGridRows = 3, NumButtons = 4 };
116
1c51d13eef25 add basiclayout example
mandel
parents:
diff changeset
158
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
159 QMenuBar menuBar;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
160 QGroupBox horizontalGroupBox;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
161 QGroupBox gridGroupBox;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
162 QGroupBox formGroupBox;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
163 QTextEdit smallEditor;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
164 QTextEdit bigEditor;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
165 QLabel[NumGridRows] labels;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
166 QLineEdit[NumGridRows] lineEdits;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
167 QPushButton[NumButtons] buttons;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
168 QDialogButtonBox buttonBox;
116
1c51d13eef25 add basiclayout example
mandel
parents:
diff changeset
169
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
170 QMenu fileMenu;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 116
diff changeset
171 QAction exitAction;
350
31520b2c0b3c Removed dependency on parent trait and stringof
Max Samukha <maxter@spambox.com>
parents: 323
diff changeset
172
31520b2c0b3c Removed dependency on parent trait and stringof
Max Samukha <maxter@spambox.com>
parents: 323
diff changeset
173 mixin Q_OBJECT;
116
1c51d13eef25 add basiclayout example
mandel
parents:
diff changeset
174 }