86void QQuickMenuItemIconLabelPrivate::updateImplicitSize()
88 Q_Q(QQuickMenuItemIconLabel);
89 const bool showIcon = image && hasIcon();
90 const bool showText = label && hasText();
91#if QT_CONFIG(shortcut)
92 const bool showShortcutText = shortcutLabel && !shortcut().isEmpty();
94 const bool showShortcutText =
false;
96 const qreal horizontalPadding = leftPadding + rightPadding;
97 const qreal verticalPadding = topPadding + bottomPadding;
98 const qreal iconImplicitWidth = showIcon ? image->implicitWidth() : 0;
99 const qreal iconImplicitHeight = showIcon ? image->implicitHeight() : 0;
100 const qreal textImplicitWidth = showText ? label->implicitWidth() : 0;
101 const qreal textImplicitHeight = showText ? label->implicitHeight() : 0;
102 const qreal shortcutTextImplicitWidth = showShortcutText ? shortcutLabel->implicitWidth() : 0;
103 const qreal shortcutTextImplicitHeight = showShortcutText ? shortcutLabel->implicitHeight() : 0;
104 qreal effectiveSpacing = showText && showIcon && image->implicitWidth() > 0 ? spacing : 0;
105 if (showShortcutText && shortcutLabel->implicitWidth() > 0)
106 effectiveSpacing += spacing;
107 const qreal implicitWidth = display == QQuickIconLabel::TextBesideIcon
108 ? iconImplicitWidth + textImplicitWidth + shortcutTextImplicitHeight + effectiveSpacing
109 : qMax(qMax(iconImplicitWidth, textImplicitWidth), shortcutTextImplicitWidth);
110 const qreal implicitHeight = display == QQuickIconLabel::TextUnderIcon
111 ? iconImplicitHeight + textImplicitHeight + shortcutTextImplicitHeight + effectiveSpacing
112 : qMax(qMax(iconImplicitHeight, textImplicitHeight), shortcutTextImplicitHeight);
113 q->setImplicitSize(implicitWidth + horizontalPadding, implicitHeight + verticalPadding);
116void QQuickMenuItemIconLabelPrivate::layout()
118 Q_Q(QQuickIconLabel);
119 if (!componentComplete)
122 const qreal availableWidth = width - leftPadding - rightPadding;
123 const qreal availableHeight = height - topPadding - bottomPadding;
125 auto layoutShortcutLabel = [
this, availableWidth, availableHeight](
const qreal availableWidthForShortcut){
126 if (availableWidthForShortcut - spacing - shortcutLabel->implicitWidth() > 0) {
128 shortcutLabel->setVisible(
true);
131 const QRectF shortcutTextRect = alignedRect(mirrored, Qt::AlignRight | Qt::AlignVCenter, QSizeF(
132 qMin(shortcutLabel->implicitWidth(), availableWidth),
133 qMin(shortcutLabel->implicitHeight(), availableHeight)),
134 QRectF(leftPadding, topPadding, availableWidth, availableHeight));
135 shortcutLabel->setSize(shortcutTextRect.size());
136 shortcutLabel->setPosition(shortcutTextRect.topLeft());
141 shortcutLabel->setVisible(
false);
146 case QQuickIconLabel::IconOnly:
147 QQuickIconLabelPrivate::layout();
149 case QQuickIconLabel::TextOnly: {
151 const QRectF textRect = alignedRect(mirrored, alignment, QSizeF(
152 qMin(label->implicitWidth(), availableWidth),
153 qMin(label->implicitHeight(), availableHeight)),
154 QRectF(leftPadding, topPadding, availableWidth, availableHeight));
155 label->setSize(textRect.size());
156 label->setPosition(textRect.topLeft());
160 layoutShortcutLabel(availableWidth - (label->width() + spacing));
162 }
case QQuickIconLabel::TextUnderIcon: {
166 QQuickIconLabelPrivate::layout();
169 case QQuickIconLabel::TextBesideIcon:
171 QSizeF iconSize(0, 0);
172 QSizeF textSize(0, 0);
173 QSizeF shortcutLabelSize(0, 0);
175 iconSize.setWidth(qMin(image->implicitWidth(), availableWidth));
176 iconSize.setHeight(qMin(image->implicitHeight(), availableHeight));
178 qreal spacingBetweenIconAndLabel = 0;
180 if (!iconSize.isEmpty())
181 spacingBetweenIconAndLabel = spacing;
182 textSize.setWidth(qMin(label->implicitWidth(), availableWidth - iconSize.width()
183 - spacingBetweenIconAndLabel));
184 textSize.setHeight(qMin(label->implicitHeight(), availableHeight));
187 qreal spacingBetweenLabelAndShortcutLabel = 0;
189 if (!textSize.isEmpty())
190 spacingBetweenLabelAndShortcutLabel = spacing;
191 shortcutLabelSize.setWidth(qMin(shortcutLabel->implicitWidth(), availableWidth - iconSize.width()
192 - spacingBetweenIconAndLabel - textSize.width() - spacingBetweenLabelAndShortcutLabel));
193 shortcutLabelSize.setHeight(qMin(shortcutLabel->implicitHeight(), availableHeight));
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213 const QRectF combinedImageAndLabelRect = alignedRect(mirrored, alignment, QSizeF(
214 iconSize.width() + spacingBetweenIconAndLabel + textSize.width(),
215 qMax(iconSize.height(), textSize.height())),
216 QRectF(leftPadding, topPadding, availableWidth, availableHeight));
218 const QRectF iconRect = alignedRect(mirrored, Qt::AlignLeft | Qt::AlignVCenter, iconSize, combinedImageAndLabelRect);
219 image->setSize(iconRect.size());
220 image->snapPositionTo(iconRect.topLeft());
223 const QRectF textRect = alignedRect(mirrored, Qt::AlignRight | Qt::AlignVCenter, textSize, combinedImageAndLabelRect);
224 label->setSize(textRect.size());
225 label->setPosition(textRect.topLeft());
228 layoutShortcutLabel(availableWidth - combinedImageAndLabelRect.width());
232 q->setBaselineOffset(label ? label->y() + label->baselineOffset() : 0);
299void QQuickMenuItemIconLabel::componentComplete()
301 Q_D(QQuickMenuItemIconLabel);
302 if (d->shortcutLabel)
303 QQuickIconLabelPrivate::completeComponent(d->shortcutLabel);
305 QQuickIconLabel::componentComplete();
308 const auto paintOrderChildItems = QQuickItemPrivate::get(
this)->paintOrderChildItems();
309 const auto bottomMostFosterChildIt = std::find_if(paintOrderChildItems.constBegin(),
310 paintOrderChildItems.constEnd(), [d](QQuickItem *item) {
311 return item != d->label && item != d->image && item != d->shortcutLabel;
313 if (bottomMostFosterChildIt != paintOrderChildItems.constEnd()) {
314 const QQuickItem *bottomMostFosterChild = *bottomMostFosterChildIt;
315 if (d->shortcutLabel)
316 d->shortcutLabel->stackBefore(bottomMostFosterChild);