80 static const QHash<QString, LayoutPropertyType> namePropertyMap = {
81 {leftMargin, LayoutPropertyLeftMargin},
82 {topMargin, LayoutPropertyTopMargin},
83 {rightMargin, LayoutPropertyRightMargin},
84 {bottomMargin, LayoutPropertyBottomMargin},
85 {horizontalSpacing, LayoutPropertyHorizontalSpacing},
86 {verticalSpacing, LayoutPropertyVerticalSpacing},
87 {spacing, LayoutPropertySpacing},
88 {sizeConstraint, LayoutPropertySizeConstraint},
89 {boxStretchPropertyC, LayoutPropertyBoxStretch},
90 {gridRowStretchPropertyC, LayoutPropertyGridRowStretch},
91 {gridColumnStretchPropertyC, LayoutPropertyGridColumnStretch},
92 {gridRowMinimumHeightPropertyC, LayoutPropertyGridRowMinimumHeight},
93 {gridColumnMinimumWidthPropertyC, LayoutPropertyGridColumnMinimumWidth}
95 return namePropertyMap.value(name, LayoutPropertyNone);
101 int left, top, right, bottom;
102 l->getContentsMargins(&left, &top, &right, &bottom);
104 case LayoutPropertyLeftMargin:
106 case LayoutPropertyTopMargin:
108 case LayoutPropertyRightMargin:
110 case LayoutPropertyBottomMargin:
122 int left, top, right, bottom;
123 l->getContentsMargins(&left, &top, &right, &bottom);
125 case LayoutPropertyLeftMargin:
128 case LayoutPropertyTopMargin:
131 case LayoutPropertyRightMargin:
134 case LayoutPropertyBottomMargin:
141 l->setContentsMargins(left, top, right, bottom);
153 : QDesignerPropertySheet(l, parent), m_layout(l)
155 const QString layoutGroup = u"Layout"_s;
156 int pindex = createFakeProperty(leftMargin, 0);
157 setPropertyGroup(pindex, layoutGroup);
159 pindex = createFakeProperty(topMargin, 0);
160 setPropertyGroup(pindex, layoutGroup);
162 pindex = createFakeProperty(rightMargin, 0);
163 setPropertyGroup(pindex, layoutGroup);
165 pindex = createFakeProperty(bottomMargin, 0);
166 setPropertyGroup(pindex, layoutGroup);
168 const int visibleMask = LayoutProperties::visibleProperties(m_layout);
169 if (visibleMask & LayoutProperties::HorizSpacingProperty) {
170 pindex = createFakeProperty(horizontalSpacing, 0);
171 setPropertyGroup(pindex, layoutGroup);
173 pindex = createFakeProperty(verticalSpacing, 0);
174 setPropertyGroup(pindex, layoutGroup);
176 setAttribute(indexOf(spacing),
true);
180 if (visibleMask & LayoutProperties::BoxStretchProperty) {
181 pindex = createFakeProperty(boxStretchPropertyC, QByteArray());
182 setPropertyGroup(pindex, layoutGroup);
183 setAttribute(pindex,
true);
186 if (visibleMask & LayoutProperties::GridColumnStretchProperty) {
187 const QByteArray empty;
188 pindex = createFakeProperty(gridRowStretchPropertyC, empty);
189 setPropertyGroup(pindex, layoutGroup);
190 setAttribute(pindex,
true);
191 pindex = createFakeProperty(gridColumnStretchPropertyC, empty);
192 setPropertyGroup(pindex, layoutGroup);
193 setAttribute(pindex,
true);
194 pindex = createFakeProperty(gridRowMinimumHeightPropertyC, empty);
195 setPropertyGroup(pindex, layoutGroup);
196 setAttribute(pindex,
true);
197 pindex = createFakeProperty(gridColumnMinimumWidthPropertyC, empty);
198 setPropertyGroup(pindex, layoutGroup);
199 setAttribute(pindex,
true);
207 pindex = createFakeProperty(sizeConstraint);
208 setPropertyGroup(pindex, layoutGroup);
216 const LayoutPropertyType type = layoutPropertyType(propertyName(index));
217 if (QLayoutWidget *lw = qobject_cast<QLayoutWidget *>(m_layout->parent())) {
219 case LayoutPropertyLeftMargin:
220 lw->setLayoutLeftMargin(value.toInt());
222 case LayoutPropertyTopMargin:
223 lw->setLayoutTopMargin(value.toInt());
225 case LayoutPropertyRightMargin:
226 lw->setLayoutRightMargin(value.toInt());
228 case LayoutPropertyBottomMargin:
229 lw->setLayoutBottomMargin(value.toInt());
236 case LayoutPropertyLeftMargin:
237 case LayoutPropertyTopMargin:
238 case LayoutPropertyRightMargin:
239 case LayoutPropertyBottomMargin:
240 setLayoutMargin(m_layout, type, value.toInt());
242 case LayoutPropertyHorizontalSpacing:
243 if (QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout)) {
244 grid->setHorizontalSpacing(value.toInt());
247 if (QFormLayout *form = qobject_cast<QFormLayout *>(m_layout)) {
248 form->setHorizontalSpacing(value.toInt());
252 case LayoutPropertyVerticalSpacing:
253 if (QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout)) {
254 grid->setVerticalSpacing(value.toInt());
257 if (QFormLayout *form = qobject_cast<QFormLayout *>(m_layout)) {
258 form->setVerticalSpacing(value.toInt());
262 case LayoutPropertyBoxStretch:
265 if (QBoxLayout *box = qobject_cast<QBoxLayout *>(m_layout)) {
266 const QString stretch = value.toString();
267 if (isIntegerList(stretch))
268 QFormBuilderExtra::setBoxLayoutStretch(value.toString(), box);
271 case LayoutPropertyGridRowStretch:
272 if (QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout)) {
273 const QString stretch = value.toString();
274 if (isIntegerList(stretch))
275 QFormBuilderExtra::setGridLayoutRowStretch(stretch, grid);
278 case LayoutPropertyGridColumnStretch:
279 if (QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout)) {
280 const QString stretch = value.toString();
281 if (isIntegerList(stretch))
282 QFormBuilderExtra::setGridLayoutColumnStretch(value.toString(), grid);
285 case LayoutPropertyGridRowMinimumHeight:
286 if (QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout)) {
287 const QString minSize = value.toString();
288 if (isIntegerList(minSize))
289 QFormBuilderExtra::setGridLayoutRowMinimumHeight(minSize, grid);
292 case LayoutPropertyGridColumnMinimumWidth:
293 if (QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout)) {
294 const QString minSize = value.toString();
295 if (isIntegerList(minSize))
296 QFormBuilderExtra::setGridLayoutColumnMinimumWidth(minSize, grid);
302 QDesignerPropertySheet::setProperty(index, value);
307 const LayoutPropertyType type = layoutPropertyType(propertyName(index));
308 if (
const QLayoutWidget *lw = qobject_cast<QLayoutWidget *>(m_layout->parent())) {
310 case LayoutPropertyLeftMargin:
311 return lw->layoutLeftMargin();
312 case LayoutPropertyTopMargin:
313 return lw->layoutTopMargin();
314 case LayoutPropertyRightMargin:
315 return lw->layoutRightMargin();
316 case LayoutPropertyBottomMargin:
317 return lw->layoutBottomMargin();
323 case LayoutPropertyLeftMargin:
324 case LayoutPropertyTopMargin:
325 case LayoutPropertyRightMargin:
326 case LayoutPropertyBottomMargin:
327 return getLayoutMargin(m_layout, type);
328 case LayoutPropertyHorizontalSpacing:
329 if (
const QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout))
330 return grid->horizontalSpacing();
331 if (
const QFormLayout *form = qobject_cast<QFormLayout *>(m_layout))
332 return form->horizontalSpacing();
334 case LayoutPropertyVerticalSpacing:
335 if (
const QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout))
336 return grid->verticalSpacing();
337 if (
const QFormLayout *form = qobject_cast<QFormLayout *>(m_layout))
338 return form->verticalSpacing();
340 case LayoutPropertyBoxStretch:
341 if (
const QBoxLayout *box = qobject_cast<QBoxLayout *>(m_layout))
342 return QVariant(QByteArray(QFormBuilderExtra::boxLayoutStretch(box).toUtf8()));
344 case LayoutPropertyGridRowStretch:
345 if (
const QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout))
346 return QVariant(QByteArray(QFormBuilderExtra::gridLayoutRowStretch(grid).toUtf8()));
348 case LayoutPropertyGridColumnStretch:
349 if (
const QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout))
350 return QVariant(QByteArray(QFormBuilderExtra::gridLayoutColumnStretch(grid).toUtf8()));
352 case LayoutPropertyGridRowMinimumHeight:
353 if (
const QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout))
354 return QVariant(QByteArray(QFormBuilderExtra::gridLayoutRowMinimumHeight(grid).toUtf8()));
356 case LayoutPropertyGridColumnMinimumWidth:
357 if (
const QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout))
358 return QVariant(QByteArray(QFormBuilderExtra::gridLayoutColumnMinimumWidth(grid).toUtf8()));
363 return QDesignerPropertySheet::property(index);
368 int left, top, right, bottom;
369 m_layout->getContentsMargins(&left, &top, &right, &bottom);
370 const LayoutPropertyType type = layoutPropertyType(propertyName(index));
373 case LayoutPropertyLeftMargin:
374 m_layout->setContentsMargins(-1, top, right, bottom);
376 case LayoutPropertyTopMargin:
377 m_layout->setContentsMargins(left, -1, right, bottom);
379 case LayoutPropertyRightMargin:
380 m_layout->setContentsMargins(left, top, -1, bottom);
382 case LayoutPropertyBottomMargin:
383 m_layout->setContentsMargins(left, top, right, -1);
385 case LayoutPropertyBoxStretch:
386 if (QBoxLayout *box = qobject_cast<QBoxLayout *>(m_layout))
387 QFormBuilderExtra::clearBoxLayoutStretch(box);
389 case LayoutPropertyGridRowStretch:
390 if (QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout))
391 QFormBuilderExtra::clearGridLayoutRowStretch(grid);
393 case LayoutPropertyGridColumnStretch:
394 if (QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout))
395 QFormBuilderExtra::clearGridLayoutColumnStretch(grid);
397 case LayoutPropertyGridRowMinimumHeight:
398 if (QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout))
399 QFormBuilderExtra::clearGridLayoutRowMinimumHeight(grid);
401 case LayoutPropertyGridColumnMinimumWidth:
402 if (QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout))
403 QFormBuilderExtra::clearGridLayoutColumnMinimumWidth(grid);
406 rc = QDesignerPropertySheet::reset(index);
428void LayoutPropertySheet::stretchAttributesToDom(QDesignerFormEditorInterface *core, QLayout *lt, DomLayout *domLayout)
432 const int visibleMask = LayoutProperties::visibleProperties(lt);
433 if (!(visibleMask & (LayoutProperties::BoxStretchProperty|LayoutProperties::GridColumnStretchProperty|LayoutProperties::GridRowStretchProperty)))
435 const QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core->extensionManager(), lt);
439 if (visibleMask & LayoutProperties::BoxStretchProperty) {
440 const int index = sheet->indexOf(boxStretchPropertyC);
441 Q_ASSERT(index != -1);
442 if (sheet->isChanged(index))
443 domLayout->setAttributeStretch(sheet->property(index).toString());
445 if (visibleMask & LayoutProperties::GridColumnStretchProperty) {
446 const int index = sheet->indexOf(gridColumnStretchPropertyC);
447 Q_ASSERT(index != -1);
448 if (sheet->isChanged(index))
449 domLayout->setAttributeColumnStretch(sheet->property(index).toString());
451 if (visibleMask & LayoutProperties::GridRowStretchProperty) {
452 const int index = sheet->indexOf(gridRowStretchPropertyC);
453 Q_ASSERT(index != -1);
454 if (sheet->isChanged(index))
455 domLayout->setAttributeRowStretch(sheet->property(index).toString());
457 if (visibleMask & LayoutProperties::GridRowMinimumHeightProperty) {
458 const int index = sheet->indexOf(gridRowMinimumHeightPropertyC);
459 Q_ASSERT(index != -1);
460 if (sheet->isChanged(index))
461 domLayout->setAttributeRowMinimumHeight(sheet->property(index).toString());
463 if (visibleMask & LayoutProperties::GridColumnMinimumWidthProperty) {
464 const int index = sheet->indexOf(gridColumnMinimumWidthPropertyC);
465 Q_ASSERT(index != -1);
466 if (sheet->isChanged(index))
467 domLayout->setAttributeColumnMinimumWidth(sheet->property(index).toString());
471void LayoutPropertySheet::markChangedStretchProperties(QDesignerFormEditorInterface *core, QLayout *lt,
const DomLayout *domLayout)
475 QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core->extensionManager(), lt);
477 if (!domLayout->attributeStretch().isEmpty())
478 sheet->setChanged(sheet->indexOf(boxStretchPropertyC),
true);
479 if (!domLayout->attributeRowStretch().isEmpty())
480 sheet->setChanged(sheet->indexOf(gridRowStretchPropertyC),
true);
481 if (!domLayout->attributeColumnStretch().isEmpty())
482 sheet->setChanged(sheet->indexOf(gridColumnStretchPropertyC),
true);
483 if (!domLayout->attributeColumnMinimumWidth().isEmpty())
484 sheet->setChanged(sheet->indexOf(gridColumnMinimumWidthPropertyC),
true);
485 if (!domLayout->attributeRowMinimumHeight().isEmpty())
486 sheet->setChanged(sheet->indexOf(gridRowMinimumHeightPropertyC),
true);