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