aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2015-05-23 10:57:02 +0200
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2015-05-23 09:20:00 +0000
commitab71cd2439dba00c751becd91dcf111b8ec38ba9 (patch)
tree2b94d23d57212526ddf6c6531b2ff5b27ac6fb20
parentbd1e79de9c0b5073ca299d65e0696ecad94f6fc5 (diff)
Button: revert automatic label layouting
It got ugly and hackish, and broke for QQuickButton subclasses. Instead, use simple and pretty bindings (thanks to newly introduced contentWidth and contentHeight) to give the label a default size and position. Change-Id: I4cd705e86a12e8c9ffa0b7a768b1878bba797036 Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
-rw-r--r--src/controls/qquickbutton.cpp48
-rw-r--r--src/controls/qquickbutton_p.h5
-rw-r--r--src/controls/qquickbutton_p_p.h4
-rw-r--r--src/imports/controls/Button.qml5
4 files changed, 7 insertions, 55 deletions
diff --git a/src/controls/qquickbutton.cpp b/src/controls/qquickbutton.cpp
index 4bf2c08a..f8aa426c 100644
--- a/src/controls/qquickbutton.cpp
+++ b/src/controls/qquickbutton.cpp
@@ -97,9 +97,7 @@ QT_BEGIN_NAMESPACE
\image qtquickcontrols2-button-label.png
- If the \l {Button::label}{label} delegate has no explicit size specified,
- it automatically follows the control's size without padding. The following
- snippet presents the default label delegate implementation.
+ The following snippet presents the default label delegate implementation.
\snippet Button.qml label
@@ -134,26 +132,10 @@ QT_BEGIN_NAMESPACE
This signal is emitted when the button is clicked.
*/
-QQuickButtonPrivate::QQuickButtonPrivate() :
- pressed(false), label(Q_NULLPTR), labelHasWidth(true), labelHasHeight(true)
+QQuickButtonPrivate::QQuickButtonPrivate() : pressed(false), label(Q_NULLPTR)
{
}
-void QQuickButtonPrivate::updateGeometry()
-{
- Q_Q(QQuickButton);
- if (label) {
- if (!labelHasWidth) {
- label->setX(q->leftPadding());
- label->setWidth(q->width() - q->leftPadding() - q->rightPadding());
- }
- if (!labelHasHeight) {
- label->setY(q->topPadding());
- label->setHeight(q->height() - q->topPadding() - q->bottomPadding());
- }
- }
-}
-
QQuickButton::QQuickButton(QQuickItem *parent) :
QQuickControl(*(new QQuickButtonPrivate), parent)
{
@@ -218,9 +200,6 @@ void QQuickButton::setPressed(bool isPressed)
This property holds the label delegate.
- If the label delegate has no explicit size specified, it
- automatically follows the control's size without padding.
-
The implicit size of the label delegate is used to calculate
the implicit size of the control.
@@ -315,27 +294,4 @@ void QQuickButton::mouseUngrabEvent()
}
}
-void QQuickButton::componentComplete()
-{
- Q_D(QQuickButton);
- QQuickControl::componentComplete();
- d->labelHasWidth = d->label && QQuickItemPrivate::get(d->label)->widthValid;
- d->labelHasHeight = d->label && QQuickItemPrivate::get(d->label)->heightValid;
- d->updateGeometry();
-}
-
-void QQuickButton::paddingChange()
-{
- Q_D(QQuickButton);
- QQuickControl::paddingChange();
- d->updateGeometry();
-}
-
-void QQuickButton::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
-{
- Q_D(QQuickButton);
- QQuickControl::geometryChanged(newGeometry, oldGeometry);
- d->updateGeometry();
-}
-
QT_END_NAMESPACE
diff --git a/src/controls/qquickbutton_p.h b/src/controls/qquickbutton_p.h
index 903af206..43ac6ae4 100644
--- a/src/controls/qquickbutton_p.h
+++ b/src/controls/qquickbutton_p.h
@@ -93,11 +93,6 @@ protected:
void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
void mouseUngrabEvent() Q_DECL_OVERRIDE;
- void componentComplete() Q_DECL_OVERRIDE;
-
- void paddingChange() Q_DECL_OVERRIDE;
- void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE;
-
private:
Q_DISABLE_COPY(QQuickButton)
Q_DECLARE_PRIVATE(QQuickButton)
diff --git a/src/controls/qquickbutton_p_p.h b/src/controls/qquickbutton_p_p.h
index 42827fd2..ca67c224 100644
--- a/src/controls/qquickbutton_p_p.h
+++ b/src/controls/qquickbutton_p_p.h
@@ -59,13 +59,9 @@ class QQuickButtonPrivate : public QQuickControlPrivate
public:
QQuickButtonPrivate();
- void updateGeometry();
-
QString text;
bool pressed;
QQuickItem *label;
- bool labelHasWidth;
- bool labelHasHeight;
};
QT_END_NAMESPACE
diff --git a/src/imports/controls/Button.qml b/src/imports/controls/Button.qml
index 708dc845..c0c4033c 100644
--- a/src/imports/controls/Button.qml
+++ b/src/imports/controls/Button.qml
@@ -53,6 +53,11 @@ AbstractButton {
//! [label]
label: Text {
+ x: control.leftPadding
+ y: control.topPadding
+ width: control.contentWidth
+ height: control.contentHeight
+
text: control.text
color: control.Theme.selectedTextColor
horizontalAlignment: Text.AlignHCenter