comparison examples/layouts/dynamiclayouts/dialog.d @ 368:185df9220ea7

Fixed startsWith. Implemented meta-object members as ranges. Freed QMetaObject from stuff that belongs to MetaClass
author Max Samukha <maxter@maxter.com>
date Mon, 28 Jun 2010 21:29:32 +0300
parents 5896535a03cd
children 778ef7374fb5
comparison
equal deleted inserted replaced
367:f69341b40588 368:185df9220ea7
56 56
57 class Dialog : public QDialog 57 class Dialog : public QDialog
58 { 58 {
59 public: 59 public:
60 60
61 this(QWidget parent = null) 61 this(QWidget parent = null)
62 { 62 {
63 super(parent); 63 super(parent);
64 createRotableGroupBox(); 64
65 createOptionsGroupBox(); 65 createRotableGroupBox();
66 createButtonBox(); 66 createOptionsGroupBox();
67 67 createButtonBox();
68 mainLayout = new QGridLayout; 68
69 mainLayout.addWidget(rotableGroupBox, 0, 0); 69 mainLayout = new QGridLayout;
70 mainLayout.addWidget(optionsGroupBox, 1, 0); 70 mainLayout.addWidget(rotableGroupBox, 0, 0);
71 mainLayout.addWidget(buttonBox, 2, 0); 71 mainLayout.addWidget(optionsGroupBox, 1, 0);
72 setLayout(mainLayout); 72 mainLayout.addWidget(buttonBox, 2, 0);
73 73 setLayout(mainLayout);
74 mainLayout.setSizeConstraint(QLayout.SetMinimumSize); 74
75 75 mainLayout.setSizeConstraint(QLayout.SetMinimumSize);
76 setWindowTitle(tr("Dynamic Layouts")); 76
77 } 77 setWindowTitle(tr("Dynamic Layouts"));
78 }
78 79
79 private: // slots 80 private: // slots
80 81
81 void slot_buttonsOrientationChanged(int index) 82 void slot_buttonsOrientationChanged(int index)
82 { 83 {
83 mainLayout.setSizeConstraint(QLayout.SetNoConstraint); 84 mainLayout.setSizeConstraint(QLayout.SetNoConstraint);
84 setMinimumSize(0, 0); 85 setMinimumSize(0, 0);
85 86
86 Qt.Orientation orientation = cast(Qt.Orientation) buttonsOrientationComboBox.itemData(index).toInt(); 87 Qt.Orientation orientation = cast(Qt.Orientation) buttonsOrientationComboBox.itemData(index).toInt();
87 88
88 if (orientation == buttonBox.orientation()) 89 if (orientation == buttonBox.orientation())
89 return; 90 return;
90 91
91 mainLayout.removeWidget(buttonBox); 92 mainLayout.removeWidget(buttonBox);
92 93
93 int spacing = mainLayout.spacing(); 94 int spacing = mainLayout.spacing();
94 95
95 QSize oldSizeHint = buttonBox.sizeHint() + QSize(spacing, spacing); 96 QSize oldSizeHint = buttonBox.sizeHint() + QSize(spacing, spacing);
96 buttonBox.setOrientation(orientation); 97 buttonBox.setOrientation(orientation);
97 QSize newSizeHint = buttonBox.sizeHint() + QSize(spacing, spacing); 98 QSize newSizeHint = buttonBox.sizeHint() + QSize(spacing, spacing);
98 99
99 if (orientation == Qt.Orientation.Horizontal) { 100 if (orientation == Qt.Orientation.Horizontal) {
100 mainLayout.addWidget(buttonBox, 2, 0); 101 mainLayout.addWidget(buttonBox, 2, 0);
101 resize(size() + QSize(-1 * oldSizeHint.width(), newSizeHint.height())); 102 resize(size() + QSize(-1 * oldSizeHint.width(), newSizeHint.height()));
102 } else { 103 } else {
103 mainLayout.addWidget(buttonBox, 0, 3, 2, 1); 104 mainLayout.addWidget(buttonBox, 0, 3, 2, 1);
104 resize(size() + QSize(newSizeHint.width(), -1 * oldSizeHint.height())); 105 resize(size() + QSize(newSizeHint.width(), -1 * oldSizeHint.height()));
105 } 106 }
106 107
107 mainLayout.setSizeConstraint(QLayout.SetDefaultConstraint); 108 mainLayout.setSizeConstraint(QLayout.SetDefaultConstraint);
108 } 109 }
109 110
110 void slot_rotateWidgets() 111 void slot_rotateWidgets()
111 { 112 {
112 assert(rotableWidgets.length % 2 == 0); 113 assert(rotableWidgets.length % 2 == 0);
113 114
114 foreach (QWidget widget; rotableWidgets) 115 foreach (QWidget widget; rotableWidgets)
115 rotableLayout.removeWidget(widget); 116 rotableLayout.removeWidget(widget);
116 117
117 rotableWidgets = rotableWidgets[1..$] ~ rotableWidgets[0]; 118 rotableWidgets = rotableWidgets[1..$] ~ rotableWidgets[0];
118 119
119 int n = rotableWidgets.length; 120 int n = rotableWidgets.length;
120 for (int i = 0; i < n / 2; ++i) { 121 for (int i = 0; i < n / 2; ++i) {
121 rotableLayout.addWidget(rotableWidgets[n - i - 1], 0, i); 122 rotableLayout.addWidget(rotableWidgets[n - i - 1], 0, i);
122 rotableLayout.addWidget(rotableWidgets[i], 1, i); 123 rotableLayout.addWidget(rotableWidgets[i], 1, i);
123 } 124 }
124 } 125 }
125 126
126 void slot_help() 127 void slot_help()
127 { 128 {
128 QMessageBox.information(this, tr("Dynamic Layouts Help"), 129 QMessageBox.information(this, tr("Dynamic Layouts Help"),
129 tr("This example shows how to change layouts dynamically.")); 130 tr("This example shows how to change layouts dynamically."));
130 } 131 }
131 132
132 private: 133 private:
133 134
134 void createRotableGroupBox() 135 void createRotableGroupBox()
135 { 136 {
136 rotableGroupBox = new QGroupBox(tr("Rotable Widgets")); 137 rotableGroupBox = new QGroupBox(tr("Rotable Widgets"));
137 138
138 auto a0 = new QSpinBox; 139 auto a0 = new QSpinBox;
139 auto a1 = new QSlider; 140 auto a1 = new QSlider;
140 auto a2 = new QDial; 141 auto a2 = new QDial;
141 auto a3 = new QProgressBar; 142 auto a3 = new QProgressBar;
142 143
143 rotableWidgets ~= a0; 144 rotableWidgets ~= a0;
144 rotableWidgets ~= a1; 145 rotableWidgets ~= a1;
145 rotableWidgets ~= a2; 146 rotableWidgets ~= a2;
146 rotableWidgets ~= a3; 147 rotableWidgets ~= a3;
147 148
148 int n = rotableWidgets.length; 149 int n = rotableWidgets.length;
149 for (int i = 0; i < n; ++i) 150
150 connect(rotableWidgets[i], "valueChanged", rotableWidgets[(i + 1) % n], "setValue"); 151 for (int i = 0; i < n; ++i)
151 152 connect(rotableWidgets[i], "valueChanged", rotableWidgets[(i + 1) % n], "setValue");
152 153
153 rotableLayout = new QGridLayout; 154 rotableLayout = new QGridLayout;
154 rotableGroupBox.setLayout(rotableLayout); 155 rotableGroupBox.setLayout(rotableLayout);
155 156
156 rotateWidgets(); 157 rotateWidgets();
157 } 158
158 159 }
159 void createOptionsGroupBox() 160
160 { 161 void createOptionsGroupBox()
161 optionsGroupBox = new QGroupBox(tr("Options")); 162 {
162 163 optionsGroupBox = new QGroupBox(tr("Options"));
163 buttonsOrientationLabel = new QLabel(tr("Orientation of buttons:")); 164
164 165 buttonsOrientationLabel = new QLabel(tr("Orientation of buttons:"));
165 buttonsOrientationComboBox = new QComboBox; 166
166 buttonsOrientationComboBox.addItem(tr("Horizontal"), new QVariant(cast(ulong) Qt.Horizontal)); 167 buttonsOrientationComboBox = new QComboBox;
167 buttonsOrientationComboBox.addItem(tr("Vertical"), new QVariant(cast(ulong) Qt.Vertical)); 168 buttonsOrientationComboBox.addItem(tr("Horizontal"), new QVariant(cast(ulong) Qt.Horizontal));
168 169 buttonsOrientationComboBox.addItem(tr("Vertical"), new QVariant(cast(ulong) Qt.Vertical));
169 connect(buttonsOrientationComboBox, "currentIndexChanged", this, "buttonsOrientationChanged"); 170
170 171 connect(buttonsOrientationComboBox, "currentIndexChanged", this, "buttonsOrientationChanged");
171 optionsLayout = new QGridLayout; 172
172 optionsLayout.addWidget(buttonsOrientationLabel, 0, 0); 173 optionsLayout = new QGridLayout;
173 optionsLayout.addWidget(buttonsOrientationComboBox, 0, 1); 174 optionsLayout.addWidget(buttonsOrientationLabel, 0, 0);
174 optionsLayout.setColumnStretch(2, 1); 175 optionsLayout.addWidget(buttonsOrientationComboBox, 0, 1);
175 optionsGroupBox.setLayout(optionsLayout); 176 optionsLayout.setColumnStretch(2, 1);
176 } 177 optionsGroupBox.setLayout(optionsLayout);
177 178 }
178 void createButtonBox() 179
179 { 180 void createButtonBox()
180 buttonBox = new QDialogButtonBox; 181 {
181 182 buttonBox = new QDialogButtonBox;
182 closeButton = buttonBox.addButton(QDialogButtonBox.Close); 183
183 helpButton = buttonBox.addButton(QDialogButtonBox.Help); 184 closeButton = buttonBox.addButton(QDialogButtonBox.Close);
184 rotateWidgetsButton = buttonBox.addButton(tr("Rotate &Widgets"), QDialogButtonBox.ActionRole); 185 helpButton = buttonBox.addButton(QDialogButtonBox.Help);
185 186 rotateWidgetsButton = buttonBox.addButton(tr("Rotate &Widgets"), QDialogButtonBox.ActionRole);
186 connect(rotateWidgetsButton, "clicked", this, "rotateWidgets"); 187
187 connect(closeButton, "clicked", this, "close"); 188 connect(rotateWidgetsButton, "clicked", this, "rotateWidgets");
188 connect(helpButton, "clicked", this, "help"); 189 connect(closeButton, "clicked", this, "close");
189 } 190 connect(helpButton, "clicked", this, "help");
190 191 }
191 QGroupBox rotableGroupBox; 192
192 QWidget[] rotableWidgets; 193 QGroupBox rotableGroupBox;
193 194 QWidget[] rotableWidgets;
194 QGroupBox optionsGroupBox; 195
195 QLabel buttonsOrientationLabel; 196 QGroupBox optionsGroupBox;
196 QComboBox buttonsOrientationComboBox; 197 QLabel buttonsOrientationLabel;
197 198 QComboBox buttonsOrientationComboBox;
198 QDialogButtonBox buttonBox; 199
199 QPushButton closeButton; 200 QDialogButtonBox buttonBox;
200 QPushButton helpButton; 201 QPushButton closeButton;
201 QPushButton rotateWidgetsButton; 202 QPushButton helpButton;
202 203 QPushButton rotateWidgetsButton;
203 QGridLayout mainLayout; 204
204 QGridLayout rotableLayout; 205 QGridLayout mainLayout;
205 QGridLayout optionsLayout; 206 QGridLayout rotableLayout;
207 QGridLayout optionsLayout;
206 208
207 mixin Q_OBJECT; 209 mixin Q_OBJECT;
208 } 210 }