File indexing completed on 2024-04-21 03:56:01
0001 /* 0002 * SPDX-FileCopyrightText: 2023 Marco Martin <mart@kde.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 #ifndef PADDING_H 0007 #define PADDING_H 0008 0009 #include <QQuickItem> 0010 #include <qtmetamacros.h> 0011 0012 class PaddingPrivate; 0013 0014 /** 0015 * This item simply adds an external padding to contentItem's size. 0016 * 0017 * Padding item behaves similarly to QtQuick.Controls/Control::padding, 0018 * but is more lightweight and thus efficient. Its implicit size is set 0019 * to that of its contentItem's implicit size plus padding. 0020 * 0021 * @code 0022 * import QtQuick.Controls as QQC2 0023 * import org.kde.kirigami as Kirigami 0024 * 0025 * Kirigami.Padding { 0026 * padding: Kirigami.Units.largeSpacing 0027 * contentItem: QQC2.Button {} 0028 * } 0029 * @endcode 0030 * 0031 * With this component it is possible to add external paddings as a 0032 * placeholder for an item, whereas with QtQuick.Layouts you would need to 0033 * manually assign or bind attached properties whenever content item changes. 0034 * 0035 * @code 0036 * import QtQuick 0037 * import QtQuick.Layouts 0038 * import QtQuick.Controls as QQC2 0039 * import org.kde.kirigami as Kirigami 0040 * 0041 * ColumnLayout { 0042 * property alias contentItem: container.contentItem 0043 * 0044 * Kirigami.Heading { 0045 * Layout.fillWidth: true 0046 * Layout.margins: Kirigami.Units.largeSpacing 0047 * } 0048 * 0049 * Kirigami.Padding { 0050 * id: container 0051 * Layout.fillWidth: true 0052 * padding: Kirigami.Units.largeSpacing 0053 * } 0054 * } 0055 * @endcode 0056 * 0057 * @since KDE Frameworks 6.0 0058 */ 0059 class Padding : public QQuickItem 0060 { 0061 Q_OBJECT 0062 QML_ELEMENT 0063 0064 /** 0065 * @brief This property holds the visual content Item. 0066 * 0067 * It will automatically resized taking into account all the paddings 0068 */ 0069 Q_PROPERTY(QQuickItem *contentItem READ contentItem WRITE setContentItem NOTIFY contentItemChanged FINAL) 0070 0071 /** 0072 * @brief This property holds the default padding. 0073 * 0074 * Padding adds a space between each edge of this ITem and its contentItem, effectively controlling its size. 0075 * To specify a padding value for a specific edge of the control, set its relevant property: 0076 * * leftPadding 0077 * * rightPadding 0078 * * topPadding 0079 * * bottomPadding 0080 */ 0081 Q_PROPERTY(qreal padding READ padding WRITE setPadding NOTIFY paddingChanged RESET resetPadding FINAL) 0082 0083 /** 0084 * @brief This property holds the horizontal padding. 0085 * 0086 * Unless explicitly set, the value is equal to padding. 0087 */ 0088 Q_PROPERTY(qreal horizontalPadding READ horizontalPadding WRITE setHorizontalPadding NOTIFY horizontalPaddingChanged RESET resetHorizontalPadding FINAL) 0089 0090 /** 0091 * @brief This property holds the vertical padding. 0092 * 0093 * Unless explicitly set, the value is equal to padding. 0094 */ 0095 Q_PROPERTY(qreal verticalPadding READ verticalPadding WRITE setVerticalPadding NOTIFY verticalPaddingChanged RESET resetVerticalPadding FINAL) 0096 0097 /** 0098 * @brief This property holds the padding on the left side. 0099 * 0100 * Unless explicitly set, it falls back to horizontalPadding and then to padding. 0101 * This always refers to the actual left, it won't be flipped on RTL layouts. 0102 */ 0103 Q_PROPERTY(qreal leftPadding READ leftPadding WRITE setLeftPadding NOTIFY leftPaddingChanged RESET resetLeftPadding FINAL) 0104 0105 /** 0106 * @brief the padding on the top side. 0107 * 0108 * Unless explicitly set, it falls back to verticalPadding and then to padding. 0109 */ 0110 Q_PROPERTY(qreal topPadding READ topPadding WRITE setTopPadding NOTIFY topPaddingChanged RESET resetTopPadding FINAL) 0111 0112 /** 0113 * @brief This property holds the padding on the right side. 0114 * 0115 * Unless explicitly set, it falls back to horizontalPadding and then to padding. 0116 * This always refers to the actual right, it won't be flipped on RTL layouts. 0117 */ 0118 Q_PROPERTY(qreal rightPadding READ rightPadding WRITE setRightPadding NOTIFY rightPaddingChanged RESET resetRightPadding FINAL) 0119 0120 /** 0121 * @brief This property holds the padding on the bottom side. 0122 * 0123 * Unless explicitly set, it falls back to verticalPadding and then to padding. 0124 */ 0125 Q_PROPERTY(qreal bottomPadding READ bottomPadding WRITE setBottomPadding NOTIFY bottomPaddingChanged RESET resetBottomPadding FINAL) 0126 0127 /** 0128 * @brief The width available to the contentItem after deducting horizontal padding from the width of the Padding. 0129 */ 0130 Q_PROPERTY(qreal availableWidth READ availableWidth NOTIFY availableWidthChanged FINAL) 0131 0132 /** 0133 * @brief The height available to the contentItem after deducting vertical padding from the width of the Padding. 0134 */ 0135 Q_PROPERTY(qreal availableHeight READ availableHeight NOTIFY availableHeightChanged FINAL) 0136 0137 /** 0138 * @brief The implicitWidth of its contentItem, or 0 if not present. 0139 */ 0140 Q_PROPERTY(qreal implicitContentWidth READ implicitContentWidth NOTIFY implicitContentWidthChanged FINAL) 0141 0142 /** 0143 * @brief The implicitHeight of its contentItem, or 0 if not present. 0144 */ 0145 Q_PROPERTY(qreal implicitContentHeight READ implicitContentHeight NOTIFY implicitContentHeightChanged FINAL) 0146 0147 public: 0148 Padding(QQuickItem *parent = nullptr); 0149 ~Padding() override; 0150 0151 void setContentItem(QQuickItem *item); 0152 QQuickItem *contentItem(); 0153 0154 void setPadding(qreal padding); 0155 void resetPadding(); 0156 qreal padding() const; 0157 0158 void setHorizontalPadding(qreal padding); 0159 void resetHorizontalPadding(); 0160 qreal horizontalPadding() const; 0161 0162 void setVerticalPadding(qreal padding); 0163 void resetVerticalPadding(); 0164 qreal verticalPadding() const; 0165 0166 void setLeftPadding(qreal padding); 0167 void resetLeftPadding(); 0168 qreal leftPadding() const; 0169 0170 void setTopPadding(qreal padding); 0171 void resetTopPadding(); 0172 qreal topPadding() const; 0173 0174 void setRightPadding(qreal padding); 0175 void resetRightPadding(); 0176 qreal rightPadding() const; 0177 0178 void setBottomPadding(qreal padding); 0179 void resetBottomPadding(); 0180 qreal bottomPadding() const; 0181 0182 qreal availableWidth() const; 0183 qreal availableHeight() const; 0184 0185 qreal implicitContentWidth() const; 0186 qreal implicitContentHeight() const; 0187 0188 Q_SIGNALS: 0189 void contentItemChanged(); 0190 void paddingChanged(); 0191 void horizontalPaddingChanged(); 0192 void verticalPaddingChanged(); 0193 void leftPaddingChanged(); 0194 void topPaddingChanged(); 0195 void rightPaddingChanged(); 0196 void bottomPaddingChanged(); 0197 void availableHeightChanged(); 0198 void availableWidthChanged(); 0199 void implicitContentWidthChanged(); 0200 void implicitContentHeightChanged(); 0201 0202 protected: 0203 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override; 0204 void updatePolish() override; 0205 0206 private: 0207 friend class PaddingPrivate; 0208 const std::unique_ptr<PaddingPrivate> d; 0209 }; 0210 0211 #endif