24 Horizontal = Left | Right,
25 Vertical = Top | Bottom,
34 void calculateImplicitSize();
35 void signalPaddings(
const QMarginsF &oldPaddings, Paddings paddings);
43 std::optional<qreal> m_horizontalPadding;
44 std::optional<qreal> m_verticalPadding;
46 std::optional<qreal> m_leftPadding;
47 std::optional<qreal> m_topPadding;
48 std::optional<qreal> m_rightPadding;
49 std::optional<qreal> m_bottomPadding;
52void PaddingPrivate::calculateImplicitSize()
58 impWidth += m_contentItem->implicitWidth();
59 impHeight += m_contentItem->implicitHeight();
65 q->setImplicitSize(impWidth, impHeight);
73void PaddingPrivate::signalPaddings(
const QMarginsF &oldPaddings, Paddings which)
75 if ((which & Left) && !qFuzzyCompare(q->
leftPadding(), oldPaddings.
left())) {
76 Q_EMIT q->leftPaddingChanged();
78 if ((which & Top) && !qFuzzyCompare(q->
topPadding(), oldPaddings.
top())) {
79 Q_EMIT q->topPaddingChanged();
82 Q_EMIT q->rightPaddingChanged();
85 Q_EMIT q->bottomPaddingChanged();
87 if ((which == Horizontal || which == All)
89 Q_EMIT q->horizontalPaddingChanged();
91 if ((which == Vertical || which == All)
93 Q_EMIT q->verticalPaddingChanged();
96 Q_EMIT q->availableWidthChanged();
99 Q_EMIT q->availableHeightChanged();
103void PaddingPrivate::disconnect()
116 , d(std::make_unique<PaddingPrivate>(this))
127 if (d->m_contentItem == item) {
133 if (d->m_contentItem) {
138 d->m_contentItem->setParentItem(
nullptr);
141 d->m_contentItem = item;
143 if (d->m_contentItem) {
144 d->m_contentItem->setParentItem(
this);
154 Q_EMIT contentItemChanged();
155 Q_EMIT implicitContentWidthChanged();
156 Q_EMIT implicitContentWidthChanged();
161 return d->m_contentItem;
164void Padding::setPadding(qreal padding)
166 if (qFuzzyCompare(
padding, d->m_padding)) {
170 const QMarginsF oldPadding = d->paddings();
175 d->signalPaddings(oldPadding, PaddingPrivate::All);
180void Padding::resetPadding()
182 if (qFuzzyCompare(d->m_padding, 0)) {
186 const QMarginsF oldPadding = d->paddings();
191 d->signalPaddings(oldPadding, PaddingPrivate::All);
201void Padding::setHorizontalPadding(qreal padding)
207 const QMarginsF oldPadding = d->paddings();
208 d->m_horizontalPadding =
padding;
210 d->signalPaddings(oldPadding, PaddingPrivate::Horizontal);
215void Padding::resetHorizontalPadding()
217 if (!d->m_horizontalPadding.has_value()) {
221 const QMarginsF oldPadding = d->paddings();
222 d->m_horizontalPadding.reset();
224 d->signalPaddings(oldPadding, PaddingPrivate::Horizontal);
231 return d->m_horizontalPadding.value_or(d->m_padding);
234void Padding::setVerticalPadding(qreal padding)
240 const QMarginsF oldPadding = d->paddings();
241 d->m_verticalPadding =
padding;
243 d->signalPaddings(oldPadding, PaddingPrivate::Vertical);
248void Padding::resetVerticalPadding()
250 if (!d->m_verticalPadding.has_value()) {
254 const QMarginsF oldPadding = d->paddings();
255 d->m_verticalPadding.reset();
257 d->signalPaddings(oldPadding, PaddingPrivate::Vertical);
264 return d->m_verticalPadding.value_or(d->m_padding);
267void Padding::setLeftPadding(qreal padding)
269 const QMarginsF oldPadding = d->paddings();
270 if (qFuzzyCompare(
padding, oldPadding.
left()) && d->m_leftPadding.has_value()) {
276 d->signalPaddings(oldPadding, PaddingPrivate::Left);
281void Padding::resetLeftPadding()
283 if (!d->m_leftPadding.has_value()) {
287 const QMarginsF oldPadding = d->paddings();
288 d->m_leftPadding.reset();
290 d->signalPaddings(oldPadding, PaddingPrivate::Left);
297 if (d->m_leftPadding.has_value()) {
298 return d->m_leftPadding.value();
304void Padding::setTopPadding(qreal padding)
306 const QMarginsF oldPadding = d->paddings();
307 if (qFuzzyCompare(
padding, oldPadding.
top()) && d->m_topPadding.has_value()) {
313 d->signalPaddings(oldPadding, PaddingPrivate::Top);
318void Padding::resetTopPadding()
320 if (!d->m_topPadding.has_value()) {
324 const QMarginsF oldPadding = d->paddings();
325 d->m_topPadding.reset();
327 d->signalPaddings(oldPadding, PaddingPrivate::Top);
334 if (d->m_topPadding.has_value()) {
335 return d->m_topPadding.value();
341void Padding::setRightPadding(qreal padding)
343 const QMarginsF oldPadding = d->paddings();
344 if (qFuzzyCompare(
padding, oldPadding.
right()) && d->m_rightPadding.has_value()) {
350 d->signalPaddings(oldPadding, PaddingPrivate::Right);
355void Padding::resetRightPadding()
357 if (!d->m_rightPadding.has_value()) {
361 const QMarginsF oldPadding = d->paddings();
362 d->m_rightPadding.reset();
364 d->signalPaddings(oldPadding, PaddingPrivate::Right);
371 if (d->m_rightPadding.has_value()) {
372 return d->m_rightPadding.value();
378void Padding::setBottomPadding(qreal padding)
380 const QMarginsF oldPadding = d->paddings();
381 if (qFuzzyCompare(
padding, oldPadding.
bottom()) && d->m_bottomPadding.has_value()) {
387 d->signalPaddings(oldPadding, PaddingPrivate::Bottom);
392void Padding::resetBottomPadding()
394 if (!d->m_bottomPadding.has_value()) {
398 const QMarginsF oldPadding = d->paddings();
399 d->m_bottomPadding.reset();
401 d->signalPaddings(oldPadding, PaddingPrivate::Bottom);
408 if (d->m_bottomPadding.has_value()) {
409 return d->m_bottomPadding.value();
427 if (d->m_contentItem) {
428 return d->m_contentItem->implicitWidth();
436 if (d->m_contentItem) {
437 return d->m_contentItem->implicitHeight();
443void Padding::geometryChange(
const QRectF &newGeometry,
const QRectF &oldGeometry)
445 if (newGeometry != oldGeometry) {
446 Q_EMIT availableWidthChanged();
447 Q_EMIT availableHeightChanged();
454void Padding::updatePolish()
456 d->calculateImplicitSize();
457 if (!d->m_contentItem) {
465void Padding::componentComplete()
472#include "moc_padding.cpp"
This item simply adds an external padding to contentItem's size.
qreal rightPadding
This property holds the padding on the right side.
qreal bottomPadding
This property holds the padding on the bottom side.
qreal implicitContentWidth
The implicitWidth of its contentItem, or 0 if not present.
qreal verticalPadding
This property holds the vertical padding.
qreal leftPadding
This property holds the padding on the left side.
qreal availableHeight
The height available to the contentItem after deducting vertical padding from the width of the Paddin...
qreal padding
This property holds the default padding.
qreal topPadding
the padding on the top side.
qreal horizontalPadding
This property holds the horizontal padding.
QML_ELEMENTQQuickItem * contentItem
This property holds the visual content Item.
qreal implicitContentHeight
The implicitHeight of its contentItem, or 0 if not present.
qreal availableWidth
The width available to the contentItem after deducting horizontal padding from the width of the Paddi...
qreal bottom() const const
qreal right() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool disconnect(const QMetaObject::Connection &connection)
virtual void componentComplete() override
virtual void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
void implicitHeightChanged()
void implicitWidthChanged()