Mercurial > projects > qtd
annotate examples/layouts/dynamiclayouts/dialog.d @ 282:256ab6cb8e85
Signals look-up andNew syntax for connect. The old one will not work from now on. This will allow for the signals overload. Although changes are done for both D1 and D2 versions, D1 won't work because of compiler bugs. I am tired of waiting for fixes.
author | eldar |
---|---|
date | Fri, 16 Oct 2009 02:43:59 +0000 |
parents | 9fa74f0e3fb6 |
children | 7a3c43424dca |
rev | line source |
---|---|
101 | 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.QDialog; | |
45 import qt.gui.QGroupBox; | |
46 import qt.gui.QGridLayout; | |
47 import qt.gui.QLabel; | |
48 import qt.gui.QComboBox; | |
49 import qt.gui.QDialogButtonBox; | |
50 import qt.gui.QPushButton; | |
51 import qt.gui.QMessageBox; | |
52 import qt.gui.QSpinBox; | |
53 import qt.gui.QDial; | |
54 import qt.gui.QProgressBar; | |
55 | |
56 | |
57 class Dialog : public QDialog | |
58 { | |
59 public: | |
60 | |
61 this(QWidget parent = null) | |
62 { | |
63 super(parent); | |
64 createRotableGroupBox(); | |
65 createOptionsGroupBox(); | |
66 createButtonBox(); | |
67 | |
68 mainLayout = new QGridLayout; | |
69 mainLayout.addWidget(rotableGroupBox, 0, 0); | |
70 mainLayout.addWidget(optionsGroupBox, 1, 0); | |
71 mainLayout.addWidget(buttonBox, 2, 0); | |
72 setLayout(mainLayout); | |
73 | |
74 mainLayout.setSizeConstraint(QLayout.SetMinimumSize); | |
75 | |
76 setWindowTitle(tr("Dynamic Layouts")); | |
77 } | |
78 | |
79 private: | |
80 | |
81 void buttonsOrientationChanged(int index) | |
82 { | |
83 mainLayout.setSizeConstraint(QLayout.SetNoConstraint); | |
84 setMinimumSize(0, 0); | |
85 | |
103 | 86 Qt.Orientation orientation = cast(Qt.Orientation) buttonsOrientationComboBox.itemData(index).toInt(); |
101 | 87 |
88 if (orientation == buttonBox.orientation()) | |
89 return; | |
90 | |
91 mainLayout.removeWidget(buttonBox); | |
92 | |
93 int spacing = mainLayout.spacing(); | |
94 | |
95 QSize oldSizeHint = buttonBox.sizeHint() + QSize(spacing, spacing); | |
96 buttonBox.setOrientation(orientation); | |
97 QSize newSizeHint = buttonBox.sizeHint() + QSize(spacing, spacing); | |
98 | |
99 if (orientation == Qt_Orientation.Horizontal) { | |
100 mainLayout.addWidget(buttonBox, 2, 0); | |
101 resize(size() + QSize(-1 * oldSizeHint.width(), newSizeHint.height())); | |
102 } else { | |
103 mainLayout.addWidget(buttonBox, 0, 3, 2, 1); | |
104 resize(size() + QSize(newSizeHint.width(), -1 * oldSizeHint.height())); | |
105 } | |
106 | |
107 mainLayout.setSizeConstraint(QLayout.SetDefaultConstraint); | |
108 } | |
109 | |
110 void rotateWidgets() | |
111 { | |
112 assert(rotableWidgets.length % 2 == 0); | |
113 | |
114 foreach (QWidget widget; rotableWidgets) | |
115 rotableLayout.removeWidget(widget); | |
116 | |
117 rotableWidgets = rotableWidgets[1..$] ~ rotableWidgets[0]; | |
108 | 118 |
101 | 119 int n = rotableWidgets.length; |
120 for (int i = 0; i < n / 2; ++i) { | |
121 rotableLayout.addWidget(rotableWidgets[n - i - 1], 0, i); | |
122 rotableLayout.addWidget(rotableWidgets[i], 1, i); | |
123 } | |
124 } | |
125 | |
126 void help() | |
127 { | |
128 QMessageBox.information(this, tr("Dynamic Layouts Help"), | |
129 tr("This example shows how to change layouts dynamically.")); | |
130 } | |
131 | |
132 private: | |
133 | |
134 void createRotableGroupBox() | |
135 { | |
136 rotableGroupBox = new QGroupBox(tr("Rotable Widgets")); | |
137 | |
108 | 138 auto a0 = new QSpinBox; |
139 auto a1 = new QSlider; | |
140 auto a2 = new QDial; | |
141 auto a3 = new QProgressBar; | |
142 | |
143 rotableWidgets ~= a0; | |
144 rotableWidgets ~= a1; | |
145 rotableWidgets ~= a2; | |
146 rotableWidgets ~= a3; | |
147 | |
282
256ab6cb8e85
Signals look-up andNew syntax for connect. The old one will not work from now on. This will allow for the signals overload. Although changes are done for both D1 and D2 versions, D1 won't work because of compiler bugs. I am tired of waiting for fixes.
eldar
parents:
108
diff
changeset
|
148 connect!("valueChanged")(a0, &a1.setValue); |
256ab6cb8e85
Signals look-up andNew syntax for connect. The old one will not work from now on. This will allow for the signals overload. Although changes are done for both D1 and D2 versions, D1 won't work because of compiler bugs. I am tired of waiting for fixes.
eldar
parents:
108
diff
changeset
|
149 connect!("valueChanged")(a1, &a2.setValue); |
256ab6cb8e85
Signals look-up andNew syntax for connect. The old one will not work from now on. This will allow for the signals overload. Although changes are done for both D1 and D2 versions, D1 won't work because of compiler bugs. I am tired of waiting for fixes.
eldar
parents:
108
diff
changeset
|
150 connect!("valueChanged")(a2, &a3.setValue); |
256ab6cb8e85
Signals look-up andNew syntax for connect. The old one will not work from now on. This will allow for the signals overload. Although changes are done for both D1 and D2 versions, D1 won't work because of compiler bugs. I am tired of waiting for fixes.
eldar
parents:
108
diff
changeset
|
151 connect!("valueChanged")(a3, &a0.setValue); |
108 | 152 |
153 /* | |
101 | 154 int n = rotableWidgets.length; |
155 for (int i = 0; i < n; ++i) { | |
156 rotableWidgets[i].valueChanged.connect(&rotableWidgets[(i + 1) % n].setValue); | |
103 | 157 }*/ |
101 | 158 |
159 rotableLayout = new QGridLayout; | |
160 rotableGroupBox.setLayout(rotableLayout); | |
161 | |
162 rotateWidgets(); | |
163 } | |
164 | |
165 void createOptionsGroupBox() | |
166 { | |
167 optionsGroupBox = new QGroupBox(tr("Options")); | |
168 | |
169 buttonsOrientationLabel = new QLabel(tr("Orientation of buttons:")); | |
170 | |
171 buttonsOrientationComboBox = new QComboBox; | |
172 buttonsOrientationComboBox.addItem(tr("Horizontal"), new QVariant(cast(ulong) Qt.Horizontal)); | |
173 buttonsOrientationComboBox.addItem(tr("Vertical"), new QVariant(cast(ulong) Qt.Vertical)); | |
174 | |
282
256ab6cb8e85
Signals look-up andNew syntax for connect. The old one will not work from now on. This will allow for the signals overload. Although changes are done for both D1 and D2 versions, D1 won't work because of compiler bugs. I am tired of waiting for fixes.
eldar
parents:
108
diff
changeset
|
175 connect!("currentIndexChanged")(buttonsOrientationComboBox, &this.buttonsOrientationChanged); |
101 | 176 |
177 optionsLayout = new QGridLayout; | |
178 optionsLayout.addWidget(buttonsOrientationLabel, 0, 0); | |
179 optionsLayout.addWidget(buttonsOrientationComboBox, 0, 1); | |
180 optionsLayout.setColumnStretch(2, 1); | |
181 optionsGroupBox.setLayout(optionsLayout); | |
182 } | |
183 | |
184 void createButtonBox() | |
185 { | |
186 buttonBox = new QDialogButtonBox; | |
187 | |
188 closeButton = buttonBox.addButton(QDialogButtonBox.Close); | |
189 helpButton = buttonBox.addButton(QDialogButtonBox.Help); | |
190 rotateWidgetsButton = buttonBox.addButton(tr("Rotate &Widgets"), QDialogButtonBox.ActionRole); | |
191 | |
282
256ab6cb8e85
Signals look-up andNew syntax for connect. The old one will not work from now on. This will allow for the signals overload. Although changes are done for both D1 and D2 versions, D1 won't work because of compiler bugs. I am tired of waiting for fixes.
eldar
parents:
108
diff
changeset
|
192 connect!("clicked")(rotateWidgetsButton, &this.rotateWidgets); |
256ab6cb8e85
Signals look-up andNew syntax for connect. The old one will not work from now on. This will allow for the signals overload. Although changes are done for both D1 and D2 versions, D1 won't work because of compiler bugs. I am tired of waiting for fixes.
eldar
parents:
108
diff
changeset
|
193 connect!("clicked")(closeButton, &this.close); |
256ab6cb8e85
Signals look-up andNew syntax for connect. The old one will not work from now on. This will allow for the signals overload. Although changes are done for both D1 and D2 versions, D1 won't work because of compiler bugs. I am tired of waiting for fixes.
eldar
parents:
108
diff
changeset
|
194 connect!("clicked")(helpButton, &this.help); |
101 | 195 } |
196 | |
197 QGroupBox rotableGroupBox; | |
198 QWidget[] rotableWidgets; | |
103 | 199 |
101 | 200 QGroupBox optionsGroupBox; |
201 QLabel buttonsOrientationLabel; | |
202 QComboBox buttonsOrientationComboBox; | |
203 | |
204 QDialogButtonBox buttonBox; | |
205 QPushButton closeButton; | |
206 QPushButton helpButton; | |
207 QPushButton rotateWidgetsButton; | |
208 | |
209 QGridLayout mainLayout; | |
210 QGridLayout rotableLayout; | |
211 QGridLayout optionsLayout; | |
212 } |