diff options
author | Jens Bache-Wiig <jens.bache-wiig@digia.com> | 2013-11-20 18:39:58 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-11-26 19:11:53 +0100 |
commit | f28449dd060ac6b2f6969a6adba6dbd5d095b18e (patch) | |
tree | d54132ad401ed9366534a6267f0e625cf8325eab | |
parent | 6ab374f0fd530c841470f93c8befb92f1f646470 (diff) |
Make TextFieldStyle and SpinBoxStyle respect font size
This makes both the controls respect a custom font size.
Before this patch these controls would only support the
global application font.
Task-number: QTBUG-34750
Change-Id: I200a14adba5b75088ab54ba691430330d9226ada
Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
-rw-r--r-- | src/controls/Styles/Base/SpinBoxStyle.qml | 9 | ||||
-rw-r--r-- | src/controls/Styles/Base/TextFieldStyle.qml | 8 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_spinbox.qml | 10 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_textfield.qml | 10 |
4 files changed, 28 insertions, 9 deletions
diff --git a/src/controls/Styles/Base/SpinBoxStyle.qml b/src/controls/Styles/Base/SpinBoxStyle.qml index 9f1b565d3..9cedf2b98 100644 --- a/src/controls/Styles/Base/SpinBoxStyle.qml +++ b/src/controls/Styles/Base/SpinBoxStyle.qml @@ -76,8 +76,7 @@ Style { } /*! The content margins of the text field. */ - padding { top: 1 ; left: Math.round(TextSingleton.implicitHeight/2) ; right: Math.round(TextSingleton.implicitHeight) ; bottom: 0 } - + padding { top: 1 ; left: Math.round(styleData.contentHeight/2) ; right: Math.max(22, Math.round(styleData.contentHeight)) ; bottom: 0 } /*! \qmlproperty enumeration horizontalAlignment This property defines the default text aligment. @@ -141,8 +140,8 @@ Style { /*! The background of the SpinBox. */ property Component background: Item { - implicitHeight: Math.max(25, Math.round(TextSingleton.implicitHeight * 1.2)) - implicitWidth: styleData.contentWidth + 26 + implicitHeight: Math.max(25, Math.round(styleData.contentHeight * 1.2)) + implicitWidth: styleData.contentWidth + padding.left + padding.right Rectangle { anchors.fill: parent anchors.bottomMargin: -1 @@ -156,7 +155,7 @@ Style { GradientStop {color: "#fff" ; position: 0.1} GradientStop {color: "#fff" ; position: 1} } - radius: TextSingleton.implicitHeight * 0.16 + radius: control.font.pixelSize * 0.16 anchors.fill: parent border.color: control.activeFocus ? "#47b" : "#999" } diff --git a/src/controls/Styles/Base/TextFieldStyle.qml b/src/controls/Styles/Base/TextFieldStyle.qml index 8b4494d18..b4ee49cac 100644 --- a/src/controls/Styles/Base/TextFieldStyle.qml +++ b/src/controls/Styles/Base/TextFieldStyle.qml @@ -77,7 +77,7 @@ Style { readonly property TextField control: __control /*! The content margins of the text field. */ - padding { top: 4 ; left: TextSingleton.implicitHeight/3 ; right: TextSingleton.implicitHeight/3 ; bottom:4 } + padding { top: 4 ; left: Math.round(control.__contentHeight/3) ; right: control.__contentHeight/3 ; bottom: 4 } /*! The current font. */ property font font @@ -113,8 +113,8 @@ Style { /*! The background of the text field. */ property Component background: Item { - implicitWidth: Math.round(TextSingleton.implicitHeight * 8) - implicitHeight: Math.max(25, Math.round(TextSingleton.implicitHeight * 1.2)) + implicitWidth: Math.round(control.__contentHeight * 8) + implicitHeight: Math.max(25, Math.round(control.__contentHeight * 1.2)) Rectangle { anchors.fill: parent anchors.bottomMargin: -1 @@ -128,7 +128,7 @@ Style { GradientStop {color: "#fff" ; position: 0.1} GradientStop {color: "#fff" ; position: 1} } - radius: TextSingleton.implicitHeight * 0.16 + radius: control.__contentHeight * 0.16 anchors.fill: parent border.color: control.activeFocus ? "#47b" : "#999" } diff --git a/tests/auto/controls/data/tst_spinbox.qml b/tests/auto/controls/data/tst_spinbox.qml index 124ab8814..176a70b5e 100644 --- a/tests/auto/controls/data/tst_spinbox.qml +++ b/tests/auto/controls/data/tst_spinbox.qml @@ -343,6 +343,16 @@ Item { spinbox2.destroy() } + function test_setFontsize(){ + var control = Qt.createQmlObject('import QtQuick.Controls 1.1; import QtQuick.Controls.Styles 1.1; SpinBox {style: SpinBoxStyle{}}', container, '') + var width = control.width; + var height = control.height; + control.font.pixelSize = 40 + verify(control.width > width) // ensure that the text field resizes + verify(control.height > height) + control.destroy() + } + function test_get_active_focus_when_up_or_down_was_pressed(){ var test_control = 'import QtQuick 2.1; \ import QtQuick.Controls 1.1; \ diff --git a/tests/auto/controls/data/tst_textfield.qml b/tests/auto/controls/data/tst_textfield.qml index a5dc2d874..a526d1f0e 100644 --- a/tests/auto/controls/data/tst_textfield.qml +++ b/tests/auto/controls/data/tst_textfield.qml @@ -280,6 +280,16 @@ TestCase { control.destroy() } + function test_setFontsize(){ + var control = Qt.createQmlObject('import QtQuick.Controls 1.1; import QtQuick.Controls.Styles 1.1; TextField {style:TextFieldStyle{}}', container, '') + var width = control.width; + var height = control.height; + control.font.pixelSize = 40 + verify(control.width > width) // ensure that the text field resizes + verify(control.height > height) + control.destroy() + } + function test_activeFocusOnTab() { // Set TextField readonly so the tab/backtab can be tested toward the navigation var test_control = 'import QtQuick 2.1; \ |