/**************************************************************************** ** ** Copyright (C) 2015 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the Qt Quick Controls module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL3$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see http://www.qt.io/terms-conditions. For further ** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 3 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPLv3 included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 3 requirements ** will be met: https://www.gnu.org/licenses/lgpl.html. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 2.0 or later as published by the Free ** Software Foundation and appearing in the file LICENSE.GPL included in ** the packaging of this file. Please review the following information to ** ensure the GNU General Public License version 2.0 requirements will be ** met: http://www.gnu.org/licenses/gpl-2.0.html. ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #include "qquickcontrol_p.h" #include "qquickcontrol_p_p.h" QT_BEGIN_NAMESPACE /*! \qmltype Control \inherits Item \instantiates QQuickControl \inqmlmodule QtQuick.Controls \brief A basic control type. TODO */ QQuickControlPrivate::QQuickControlPrivate() : hasTopPadding(false), hasLeftPadding(false), hasRightPadding(false), hasBottomPadding(false), padding(0), topPadding(0), leftPadding(0), rightPadding(0), bottomPadding(0), layoutDirection(Qt::LeftToRight), background(Q_NULLPTR) { } void QQuickControlPrivate::mirrorChange() { Q_Q(QQuickControl); q->mirrorChange(); emit q->effectiveLayoutDirectionChanged(); } void QQuickControlPrivate::setTopPadding(qreal value, bool reset) { Q_Q(QQuickControl); qreal oldPadding = q->topPadding(); topPadding = value; hasTopPadding = !reset; if ((!reset && !qFuzzyCompare(oldPadding, value)) || (reset && !qFuzzyCompare(oldPadding, padding))) { emit q->topPaddingChanged(); q->paddingChange(); } } void QQuickControlPrivate::setLeftPadding(qreal value, bool reset) { Q_Q(QQuickControl); qreal oldPadding = q->leftPadding(); leftPadding = value; hasLeftPadding = !reset; if ((!reset && !qFuzzyCompare(oldPadding, value)) || (reset && !qFuzzyCompare(oldPadding, padding))) { emit q->leftPaddingChanged(); q->paddingChange(); } } void QQuickControlPrivate::setRightPadding(qreal value, bool reset) { Q_Q(QQuickControl); qreal oldPadding = q->rightPadding(); rightPadding = value; hasRightPadding = !reset; if ((!reset && !qFuzzyCompare(oldPadding, value)) || (reset && !qFuzzyCompare(oldPadding, padding))) { emit q->rightPaddingChanged(); q->paddingChange(); } } void QQuickControlPrivate::setBottomPadding(qreal value, bool reset) { Q_Q(QQuickControl); qreal oldPadding = q->bottomPadding(); bottomPadding = value; hasBottomPadding = !reset; if ((!reset && !qFuzzyCompare(oldPadding, value)) || (reset && !qFuzzyCompare(oldPadding, padding))) { emit q->bottomPaddingChanged(); q->paddingChange(); } } QQuickControl::QQuickControl(QQuickItem *parent) : QQuickItem(*(new QQuickControlPrivate), parent) { } QQuickControl::QQuickControl(QQuickControlPrivate &dd, QQuickItem *parent) : QQuickItem(dd, parent) { } /*! \qmlproperty real QtQuickControls2::Control::padding \qmlproperty real QtQuickControls2::Control::topPadding \qmlproperty real QtQuickControls2::Control::leftPadding \qmlproperty real QtQuickControls2::Control::rightPadding \qmlproperty real QtQuickControls2::Control::bottomPadding These properties hold the padding. */ qreal QQuickControl::padding() const { Q_D(const QQuickControl); return d->padding; } void QQuickControl::setPadding(qreal padding) { Q_D(QQuickControl); if (qFuzzyCompare(d->padding, padding)) return; d->padding = padding; emit paddingChanged(); if (!d->hasTopPadding) emit topPaddingChanged(); if (!d->hasLeftPadding) emit leftPaddingChanged(); if (!d->hasRightPadding) emit rightPaddingChanged(); if (!d->hasBottomPadding) emit bottomPaddingChanged(); paddingChange(); } void QQuickControl::resetPadding() { setPadding(0); } qreal QQuickControl::topPadding() const { Q_D(const QQuickControl); if (d->hasTopPadding) return d->topPadding; return d->padding; } void QQuickControl::setTopPadding(qreal padding) { Q_D(QQuickControl); d->setTopPadding(padding); } void QQuickControl::resetTopPadding() { Q_D(QQuickControl); d->setTopPadding(0, true); } qreal QQuickControl::leftPadding() const { Q_D(const QQuickControl); if (d->hasLeftPadding) return d->leftPadding; return d->padding; } void QQuickControl::setLeftPadding(qreal padding) { Q_D(QQuickControl); d->setLeftPadding(padding); } void QQuickControl::resetLeftPadding() { Q_D(QQuickControl); d->setLeftPadding(0, true); } qreal QQuickControl::rightPadding() const { Q_D(const QQuickControl); if (d->hasRightPadding) return d->rightPadding; return d->padding; } void QQuickControl::setRightPadding(qreal padding) { Q_D(QQuickControl); d->setRightPadding(padding); } void QQuickControl::resetRightPadding() { Q_D(QQuickControl); d->setRightPadding(0, true); } qreal QQuickControl::bottomPadding() const { Q_D(const QQuickControl); if (d->hasBottomPadding) return d->bottomPadding; return d->padding; } void QQuickControl::setBottomPadding(qreal padding) { Q_D(QQuickControl); d->setBottomPadding(padding); } void QQuickControl::resetBottomPadding() { Q_D(QQuickControl); d->setBottomPadding(0, true); } /*! \qmlproperty enumeration QtQuickControls2::Control::layoutDirection TODO */ Qt::LayoutDirection QQuickControl::layoutDirection() const { Q_D(const QQuickControl); return d->layoutDirection; } /*! \qmlproperty enumeration QtQuickControls2::Control::effectiveLayoutDirection TODO */ Qt::LayoutDirection QQuickControl::effectiveLayoutDirection() const { Q_D(const QQuickControl); if (d->isMirrored()) return d->layoutDirection == Qt::RightToLeft ? Qt::LeftToRight : Qt::RightToLeft; return d->layoutDirection; } void QQuickControl::setLayoutDirection(Qt::LayoutDirection direction) { Q_D(QQuickControl); if (d->layoutDirection != direction) { d->layoutDirection = direction; emit layoutDirectionChanged(); emit effectiveLayoutDirectionChanged(); } } /*! \qmlproperty Item QtQuickControls2::Control::background This property holds the background item. */ QQuickItem *QQuickControl::background() const { Q_D(const QQuickControl); return d->background; } void QQuickControl::setBackground(QQuickItem *background) { Q_D(QQuickControl); if (d->background != background) { delete d->background; d->background = background; if (background) { background->setParentItem(this); if (qFuzzyIsNull(background->z())) background->setZ(-1); } emit backgroundChanged(); } } void QQuickControl::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { Q_D(QQuickControl); QQuickItem::geometryChanged(newGeometry, oldGeometry); if (d->background) { QQuickItemPrivate *p = QQuickItemPrivate::get(d->background); if (!p->widthValid) { d->background->setWidth(newGeometry.width()); p->widthValid = false; } if (!p->heightValid) { d->background->setHeight(newGeometry.height()); p->heightValid = false; } } } bool QQuickControl::isMirrored() const { Q_D(const QQuickControl); return d->isMirrored(); } void QQuickControl::mirrorChange() { } void QQuickControl::paddingChange() { } QT_END_NAMESPACE