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