Mercurial > projects > qtd
annotate examples/layouts/dynamiclayouts/dialog.d @ 337:5896535a03cd
moved enums back to classes
author | maxter <spambox@d-coding.com> |
---|---|
date | Sat, 13 Mar 2010 00:38:42 +0200 |
parents | 7a3c43424dca |
children | 185df9220ea7 |
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 | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
79 private: // slots |
101 | 80 |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
81 void slot_buttonsOrientationChanged(int index) |
101 | 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 | |
337 | 99 if (orientation == Qt.Orientation.Horizontal) { |
101 | 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 | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
110 void slot_rotateWidgets() |
101 | 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 | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
126 void slot_help() |
101 | 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 | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
148 int n = rotableWidgets.length; |
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
149 for (int i = 0; i < n; ++i) |
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
150 connect(rotableWidgets[i], "valueChanged", rotableWidgets[(i + 1) % n], "setValue"); |
108 | 151 |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
152 |
101 | 153 rotableLayout = new QGridLayout; |
154 rotableGroupBox.setLayout(rotableLayout); | |
155 | |
156 rotateWidgets(); | |
157 } | |
158 | |
159 void createOptionsGroupBox() | |
160 { | |
161 optionsGroupBox = new QGroupBox(tr("Options")); | |
162 | |
163 buttonsOrientationLabel = new QLabel(tr("Orientation of buttons:")); | |
164 | |
165 buttonsOrientationComboBox = new QComboBox; | |
166 buttonsOrientationComboBox.addItem(tr("Horizontal"), new QVariant(cast(ulong) Qt.Horizontal)); | |
167 buttonsOrientationComboBox.addItem(tr("Vertical"), new QVariant(cast(ulong) Qt.Vertical)); | |
168 | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
169 connect(buttonsOrientationComboBox, "currentIndexChanged", this, "buttonsOrientationChanged"); |
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
170 |
101 | 171 optionsLayout = new QGridLayout; |
172 optionsLayout.addWidget(buttonsOrientationLabel, 0, 0); | |
173 optionsLayout.addWidget(buttonsOrientationComboBox, 0, 1); | |
174 optionsLayout.setColumnStretch(2, 1); | |
175 optionsGroupBox.setLayout(optionsLayout); | |
176 } | |
177 | |
178 void createButtonBox() | |
179 { | |
180 buttonBox = new QDialogButtonBox; | |
181 | |
182 closeButton = buttonBox.addButton(QDialogButtonBox.Close); | |
183 helpButton = buttonBox.addButton(QDialogButtonBox.Help); | |
184 rotateWidgetsButton = buttonBox.addButton(tr("Rotate &Widgets"), QDialogButtonBox.ActionRole); | |
185 | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
186 connect(rotateWidgetsButton, "clicked", this, "rotateWidgets"); |
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
187 connect(closeButton, "clicked", this, "close"); |
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
188 connect(helpButton, "clicked", this, "help"); |
101 | 189 } |
190 | |
191 QGroupBox rotableGroupBox; | |
192 QWidget[] rotableWidgets; | |
103 | 193 |
101 | 194 QGroupBox optionsGroupBox; |
195 QLabel buttonsOrientationLabel; | |
196 QComboBox buttonsOrientationComboBox; | |
197 | |
198 QDialogButtonBox buttonBox; | |
199 QPushButton closeButton; | |
200 QPushButton helpButton; | |
201 QPushButton rotateWidgetsButton; | |
202 | |
203 QGridLayout mainLayout; | |
204 QGridLayout rotableLayout; | |
205 QGridLayout optionsLayout; | |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
206 |
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
282
diff
changeset
|
207 mixin Q_OBJECT; |
101 | 208 } |