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