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
|
|
60 public:
|
|
61
|
|
62 this(QWidget parent = null)
|
|
63 {
|
|
64 super(parent);
|
|
65 createRotableGroupBox();
|
|
66 createOptionsGroupBox();
|
|
67 createButtonBox();
|
|
68
|
|
69 mainLayout = new QGridLayout;
|
|
70 mainLayout.addWidget(rotableGroupBox, 0, 0);
|
|
71 mainLayout.addWidget(optionsGroupBox, 1, 0);
|
|
72 mainLayout.addWidget(buttonBox, 2, 0);
|
|
73 setLayout(mainLayout);
|
|
74
|
|
75 mainLayout.setSizeConstraint(QLayout.SetMinimumSize);
|
|
76
|
|
77 setWindowTitle(tr("Dynamic Layouts"));
|
|
78 }
|
|
79
|
|
80 private:
|
|
81
|
|
82 void buttonsOrientationChanged(int index)
|
|
83 {
|
|
84 mainLayout.setSizeConstraint(QLayout.SetNoConstraint);
|
|
85 setMinimumSize(0, 0);
|
|
86
|
103
|
87 Qt.Orientation orientation = cast(Qt.Orientation) buttonsOrientationComboBox.itemData(index).toInt();
|
101
|
88
|
|
89 if (orientation == buttonBox.orientation())
|
|
90 return;
|
|
91
|
|
92 mainLayout.removeWidget(buttonBox);
|
|
93
|
|
94 int spacing = mainLayout.spacing();
|
|
95
|
|
96 QSize oldSizeHint = buttonBox.sizeHint() + QSize(spacing, spacing);
|
|
97 buttonBox.setOrientation(orientation);
|
|
98 QSize newSizeHint = buttonBox.sizeHint() + QSize(spacing, spacing);
|
|
99
|
|
100 if (orientation == Qt_Orientation.Horizontal) {
|
|
101 mainLayout.addWidget(buttonBox, 2, 0);
|
|
102 resize(size() + QSize(-1 * oldSizeHint.width(), newSizeHint.height()));
|
|
103 } else {
|
|
104 mainLayout.addWidget(buttonBox, 0, 3, 2, 1);
|
|
105 resize(size() + QSize(newSizeHint.width(), -1 * oldSizeHint.height()));
|
|
106 }
|
|
107
|
|
108 mainLayout.setSizeConstraint(QLayout.SetDefaultConstraint);
|
|
109 }
|
|
110
|
|
111 void rotateWidgets()
|
|
112 {
|
|
113 assert(rotableWidgets.length % 2 == 0);
|
|
114
|
|
115 foreach (QWidget widget; rotableWidgets)
|
|
116 rotableLayout.removeWidget(widget);
|
|
117
|
|
118 rotableWidgets = rotableWidgets[1..$] ~ rotableWidgets[0];
|
|
119
|
|
120 int n = rotableWidgets.length;
|
|
121 for (int i = 0; i < n / 2; ++i) {
|
|
122 rotableLayout.addWidget(rotableWidgets[n - i - 1], 0, i);
|
|
123 rotableLayout.addWidget(rotableWidgets[i], 1, i);
|
|
124 }
|
|
125 }
|
|
126
|
|
127 void help()
|
|
128 {
|
|
129 QMessageBox.information(this, tr("Dynamic Layouts Help"),
|
|
130 tr("This example shows how to change layouts dynamically."));
|
|
131 }
|
|
132
|
|
133 private:
|
|
134
|
|
135 void createRotableGroupBox()
|
|
136 {
|
|
137 rotableGroupBox = new QGroupBox(tr("Rotable Widgets"));
|
|
138
|
103
|
139 a0 = new QSpinBox;
|
|
140 a1 = new QSlider;
|
|
141 a2 = new QDial;
|
|
142 a3 = new QProgressBar;
|
|
143
|
|
144 rotableWidgets ~= a0;
|
|
145 rotableWidgets ~= a1;
|
|
146 rotableWidgets ~= a2;
|
|
147 rotableWidgets ~= a3;
|
|
148
|
|
149 a0.valueChanged.connect(&a1.setValue);
|
|
150 a1.valueChanged.connect(&a2.setValue);
|
|
151 a2.valueChanged.connect(&a3.setValue);
|
|
152 a3.valueChanged.connect(&a0.setValue);
|
|
153
|
|
154 /*
|
101
|
155 int n = rotableWidgets.length;
|
|
156 for (int i = 0; i < n; ++i) {
|
|
157 rotableWidgets[i].valueChanged.connect(&rotableWidgets[(i + 1) % n].setValue);
|
103
|
158 }*/
|
101
|
159
|
|
160 rotableLayout = new QGridLayout;
|
|
161 rotableGroupBox.setLayout(rotableLayout);
|
|
162
|
|
163 rotateWidgets();
|
|
164 }
|
|
165
|
|
166 void createOptionsGroupBox()
|
|
167 {
|
|
168 optionsGroupBox = new QGroupBox(tr("Options"));
|
|
169
|
|
170 buttonsOrientationLabel = new QLabel(tr("Orientation of buttons:"));
|
|
171
|
|
172 buttonsOrientationComboBox = new QComboBox;
|
|
173 buttonsOrientationComboBox.addItem(tr("Horizontal"), new QVariant(cast(ulong) Qt.Horizontal));
|
|
174 buttonsOrientationComboBox.addItem(tr("Vertical"), new QVariant(cast(ulong) Qt.Vertical));
|
|
175
|
|
176 buttonsOrientationComboBox.currentIndexChanged.connect(&this.buttonsOrientationChanged);
|
|
177
|
|
178 optionsLayout = new QGridLayout;
|
|
179 optionsLayout.addWidget(buttonsOrientationLabel, 0, 0);
|
|
180 optionsLayout.addWidget(buttonsOrientationComboBox, 0, 1);
|
|
181 optionsLayout.setColumnStretch(2, 1);
|
|
182 optionsGroupBox.setLayout(optionsLayout);
|
|
183 }
|
|
184
|
|
185 void createButtonBox()
|
|
186 {
|
|
187 buttonBox = new QDialogButtonBox;
|
|
188
|
|
189 closeButton = buttonBox.addButton(QDialogButtonBox.Close);
|
|
190 helpButton = buttonBox.addButton(QDialogButtonBox.Help);
|
|
191 rotateWidgetsButton = buttonBox.addButton(tr("Rotate &Widgets"), QDialogButtonBox.ActionRole);
|
|
192
|
|
193 rotateWidgetsButton.clicked.connect(&this.rotateWidgets);
|
|
194 closeButton.clicked.connect(&this.close);
|
|
195 helpButton.clicked.connect(&this.help);
|
|
196 }
|
|
197
|
|
198 QGroupBox rotableGroupBox;
|
|
199 QWidget[] rotableWidgets;
|
103
|
200
|
|
201 // qtd
|
|
202 QSpinBox a0;
|
|
203 QSlider a1;
|
|
204 QDial a2;
|
|
205 QProgressBar a3;
|
101
|
206
|
|
207 QGroupBox optionsGroupBox;
|
|
208 QLabel buttonsOrientationLabel;
|
|
209 QComboBox buttonsOrientationComboBox;
|
|
210
|
|
211 QDialogButtonBox buttonBox;
|
|
212 QPushButton closeButton;
|
|
213 QPushButton helpButton;
|
|
214 QPushButton rotateWidgetsButton;
|
|
215
|
|
216 QGridLayout mainLayout;
|
|
217 QGridLayout rotableLayout;
|
|
218 QGridLayout optionsLayout;
|
|
219 }
|