From e5865e643ba5c49df847473ace3d22ed2bb1626f Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig <jensb.bache-wiig@nokia.com> Date: Tue, 20 Sep 2011 11:04:36 +0200 Subject: [PATCH] Fix focus issues with GroupBox and other things --- components/Button.qml | 2 +- components/CheckBox.qml | 22 +++++++-------- components/ChoiceList.qml | 2 +- components/ComboBox.qml | 2 +- components/GroupBox.qml | 4 +-- components/RadioButton.qml | 24 ++++++++--------- components/Slider.qml | 2 +- components/SpinBox.qml | 2 +- components/TabBar.qml | 3 +-- components/TextArea.qml | 1 - components/TextField.qml | 2 +- components/custom/CheckBox.qml | 8 +++--- components/custom/GroupBox.qml | 47 +++++++++++++++------------------ components/custom/TextField.qml | 1 - examples/Gallery.qml | 9 +++---- src/styleitem/qstyleitem.cpp | 2 +- src/styleitem/qstyleitem.h | 8 +++--- 17 files changed, 67 insertions(+), 74 deletions(-) diff --git a/components/Button.qml b/components/Button.qml index 68217b27f..1a978be45 100644 --- a/components/Button.qml +++ b/components/Button.qml @@ -20,7 +20,7 @@ Components.Button { raised: !(pressed || checked) hover: containsMouse text: iconSource === "" ? "" : button.text - focus: button.focus + hasFocus: button.focus hint: button.hint // If no icon, let the style do the drawing diff --git a/components/CheckBox.qml b/components/CheckBox.qml index cd4ad29c3..991924a1e 100644 --- a/components/CheckBox.qml +++ b/components/CheckBox.qml @@ -3,24 +3,24 @@ import "custom" as Components // jb : Size should not depend on background, we should make it consistent -Components.CheckBox{ +Components.CheckBox { id:checkbox property string text property string hint + property bool activeFocusOnPress: true width: Math.max(110, backgroundItem.textWidth(text) + 40) height: 20 background: StyleItem { - id:styleitem - elementType:"checkbox" - sunken:pressed - on:checked || pressed - hover:containsMouse - text:checkbox.text - enabled:checkbox.enabled - focus:checkbox.focus - hint:checkbox.hint + id: styleitem + elementType: "checkbox" + sunken: pressed + on: checked || pressed + hover: containsMouse + text: checkbox.text + enabled: checkbox.enabled + hasFocus: checkbox.activeFocus + hint: checkbox.hint } - Keys.onSpacePressed:checked = !checked } diff --git a/components/ChoiceList.qml b/components/ChoiceList.qml index 381db9ee0..e45dc0f26 100644 --- a/components/ChoiceList.qml +++ b/components/ChoiceList.qml @@ -23,7 +23,7 @@ Components.ChoiceList { hover: containsMouse enabled: choicelist.enabled text: currentItemText - focus: choicelist.focus + hasFocus: choicelist.focus hint: choicelist.hint } diff --git a/components/ComboBox.qml b/components/ComboBox.qml index 6ac465f7f..8dcd06942 100644 --- a/components/ComboBox.qml +++ b/components/ComboBox.qml @@ -72,7 +72,7 @@ Custom.BasicButton { hover: comboBox.containsMouse enabled: comboBox.enabled text: comboBox.selectedText - focus: comboBox.focus + hasFocus: comboBox.focus } // ToDo: adjust margins so that selected popup label diff --git a/components/GroupBox.qml b/components/GroupBox.qml index f8aac8997..5cc6d77d2 100644 --- a/components/GroupBox.qml +++ b/components/GroupBox.qml @@ -7,7 +7,7 @@ Components.GroupBox { height: contentHeight + sizeHint.height + 4 property variant sizeHint: backgroundItem.sizeFromContents(0, (title.length > 0 || checkable) ? 24 : 4) - property bool flat: false + property bool flat: focus background : StyleItem { id: styleitem elementType: "groupbox" @@ -15,7 +15,7 @@ Components.GroupBox { text: groupbox.title hover: checkbox.containsMouse on: checkbox.checked - focus: checkbox.activeFocus + hasFocus: checkbox.activeFocus activeControl: checkable ? "checkbox" : "" sunken: !flat } diff --git a/components/RadioButton.qml b/components/RadioButton.qml index 8d490c002..3fee200e8 100644 --- a/components/RadioButton.qml +++ b/components/RadioButton.qml @@ -4,22 +4,22 @@ import "custom" as Components // jb : Size should not depend on background, we should make it consistent Components.CheckBox { - id:radiobutton + id: radiobutton property string text property string hint - width:110 - height:20 + width: 110 + height: 20 background: StyleItem { - elementType:"radiobutton" - sunken:pressed - on:checked || pressed - hover:containsMouse - text:radiobutton.text - enabled:radiobutton.enabled - focus:radiobutton.focus - hint:radiobutton.hint + elementType: "radiobutton" + sunken: pressed + on: checked || pressed + hover: containsMouse + text: radiobutton.text + enabled: radiobutton.enabled + hasFocus: radiobutton.activeFocus + hint: radiobutton.hint } - Keys.onSpacePressed:clicked() + Keys.onSpacePressed: {clicked(); checked = !checked; } } diff --git a/components/Slider.qml b/components/Slider.qml index 6c8aa0034..9b037f1c1 100644 --- a/components/Slider.qml +++ b/components/Slider.qml @@ -28,7 +28,7 @@ Components.Slider{ value: slider.value*100 horizontal: slider.orientation == Qt.Horizontal enabled: slider.enabled - focus: slider.focus + hasFocus: slider.focus hint: slider.hint activeControl: tickmarksEnabled ? tickPosition.toLowerCase() : "" } diff --git a/components/SpinBox.qml b/components/SpinBox.qml index 383a06d15..8c2a10627 100644 --- a/components/SpinBox.qml +++ b/components/SpinBox.qml @@ -69,7 +69,7 @@ Components.SpinBox { elementType: "spinbox" sunken: (downEnabled && downPressed) | (upEnabled && upPressed) hover: containsMouse - focus: spinbox.focus + hasFocus: spinbox.focus enabled: spinbox.enabled value: (upPressed ? 1 : 0) | (downPressed == 1 ? 1<<1 : 0) | diff --git a/components/TabBar.qml b/components/TabBar.qml index 4a1504575..b2fa1bc3f 100644 --- a/components/TabBar.qml +++ b/components/TabBar.qml @@ -47,7 +47,6 @@ Item { Row { id: tabrow - focus: true property int paintMargins: 1 states: State { @@ -82,7 +81,7 @@ Item { info: tabbar.position text: tabFrame.tabs[index].title hover: mousearea.containsMouse - focus: tabbar.focus && selected + hasFocus: tabbar.focus && selected property bool first: index === 0 paintMargins: tabrow.paintMargins activeControl: tabFrame.count == 1 ? "only" : index === 0 ? "beginning" : diff --git a/components/TextArea.qml b/components/TextArea.qml index b9c84e35a..c5c8f77ba 100644 --- a/components/TextArea.qml +++ b/components/TextArea.qml @@ -31,7 +31,6 @@ ScrollArea { height: area.height selectByMouse: true readOnly: false - focus: true color: syspal.text SystemPalette { id: syspal diff --git a/components/TextField.qml b/components/TextField.qml index 9ff7debf4..f7925f013 100644 --- a/components/TextField.qml +++ b/components/TextField.qml @@ -19,7 +19,7 @@ Components.TextField { anchors.fill: parent elementType: "edit" sunken: true - focus: textfield.activeFocus + hasFocus: textfield.activeFocus hover: containsMouse } diff --git a/components/custom/CheckBox.qml b/components/custom/CheckBox.qml index b6cc518e1..4008d1d36 100644 --- a/components/custom/CheckBox.qml +++ b/components/custom/CheckBox.qml @@ -1,7 +1,7 @@ import QtQuick 1.0 import "./behaviors" -Item { +FocusScope { id: checkBox signal clicked @@ -23,10 +23,10 @@ Item { ButtonBehavior { id: behavior + focus: true anchors.fill: parent checkable: true - onClicked: {if (activeFocusOnPress)checkBox.focus = true; checkBox.clicked()} + onClicked: {if (activeFocusOnPress)checkBox.forceActiveFocus(); checkBox.clicked(); checked = !checked; } } - - SystemPalette { id: syspal } + Keys.onSpacePressed: behavior.clicked() } diff --git a/components/custom/GroupBox.qml b/components/custom/GroupBox.qml index 299615fce..95ddcb95f 100644 --- a/components/custom/GroupBox.qml +++ b/components/custom/GroupBox.qml @@ -1,6 +1,6 @@ import QtQuick 1.0 -FocusScope { +Item { id: groupbox width: adjustToContentSize ? Math.max(200, contentWidth + loader.leftMargin + loader.rightMargin) : 100 @@ -17,11 +17,10 @@ FocusScope { property Component background: null property Item backgroundItem: loader.item - property CheckBox checkbox: check + property Item checkbox: check property alias checked: check.checked property bool adjustToContentSize: false // Resizes groupbox to fit contents. // Note when using this, you cannot anchor children - Loader { id: loader anchors.fill: parent @@ -29,29 +28,27 @@ FocusScope { property int bottomMargin: 4 property int leftMargin: 4 property int rightMargin: 4 - property alias styledItem: groupbox sourceComponent: background - - Item { - id:content - z: 1 - opacity: contentOpacity - anchors.topMargin: loader.topMargin - anchors.leftMargin: 8 - anchors.rightMargin: 8 - anchors.bottomMargin: 8 - anchors.fill: parent - enabled: (!checkable || checkbox.checked) - } - - CheckBox { - id: check - checked: true - anchors.top: parent.top - anchors.left: parent.left - anchors.right: parent.right - height: loader.topMargin - } + } + CheckBox { + id: check + checked: true + anchors.top: parent.top + anchors.left: parent.left + anchors.right: parent.right + height: loader.topMargin + } + Item { + id:content + z: 1 + focus: true + opacity: contentOpacity + anchors.topMargin: loader.topMargin + anchors.leftMargin: 8 + anchors.rightMargin: 8 + anchors.bottomMargin: 8 + anchors.fill: parent + enabled: (!checkable || checkbox.checked) } } diff --git a/components/custom/TextField.qml b/components/custom/TextField.qml index 1a826bc34..55d5619be 100644 --- a/components/custom/TextField.qml +++ b/components/custom/TextField.qml @@ -106,7 +106,6 @@ FocusScope { TextInput { // see QTBUG-14936 id: textInput selectByMouse:true - focus: true anchors.leftMargin: leftMargin anchors.topMargin: topMargin diff --git a/examples/Gallery.qml b/examples/Gallery.qml index 1d57d8495..4eee50e46 100644 --- a/examples/Gallery.qml +++ b/examples/Gallery.qml @@ -206,12 +206,12 @@ Rectangle { ListElement { text: "Coconut" } } - TabFrame { id:frame - position: tabPositionGroup.checkedButton == r2 ? "South" : "North" tabbar: TabBar{parent: frame; KeyNavigation.tab:button1} - + position: tabPositionGroup.checkedButton == r2 ? "South" : "North" + KeyNavigation.tab:button1 + KeyNavigation.backtab: button2 property int margins : styleitem.style == "mac" ? 16 : 0 anchors.top: toolbar.bottom anchors.bottom: parent.bottom @@ -297,12 +297,11 @@ Rectangle { KeyNavigation.tab: frameCheckbox KeyNavigation.backtab: t3 } - smooth:true } Column { id: rightcol spacing: 12 - GroupBox{ + GroupBox { id: group1 title: "CheckBox" width: area.width diff --git a/src/styleitem/qstyleitem.cpp b/src/styleitem/qstyleitem.cpp index f7beddbcc..1669a2a7a 100644 --- a/src/styleitem/qstyleitem.cpp +++ b/src/styleitem/qstyleitem.cpp @@ -86,7 +86,7 @@ QStyleItem::QStyleItem(QDeclarativeItem *parent) connect(this, SIGNAL(valueChanged()), this, SLOT(updateItem())); connect(this, SIGNAL(horizontalChanged()), this, SLOT(updateItem())); connect(this, SIGNAL(activeControlChanged()), this, SLOT(updateItem())); - connect(this, SIGNAL(focusChanged()), this, SLOT(updateItem())); + connect(this, SIGNAL(hasFocusChanged()), this, SLOT(updateItem())); connect(this, SIGNAL(activeControlChanged()), this, SLOT(updateItem())); connect(this, SIGNAL(elementTypeChanged()), this, SLOT(updateItem())); } diff --git a/src/styleitem/qstyleitem.h b/src/styleitem/qstyleitem.h index 166b39fa0..43ff011fc 100644 --- a/src/styleitem/qstyleitem.h +++ b/src/styleitem/qstyleitem.h @@ -53,7 +53,7 @@ class QStyleItem: public QDeclarativeItem Q_PROPERTY( bool raised READ raised WRITE setRaised NOTIFY raisedChanged) Q_PROPERTY( bool active READ active WRITE setActive NOTIFY activeChanged) Q_PROPERTY( bool selected READ selected WRITE setSelected NOTIFY selectedChanged) - Q_PROPERTY( bool focus READ focus WRITE setFocus NOTIFY focusChanged) + Q_PROPERTY( bool hasFocus READ hasFocus WRITE sethasFocus NOTIFY hasFocusChanged) Q_PROPERTY( bool on READ on WRITE setOn NOTIFY onChanged) Q_PROPERTY( bool hover READ hover WRITE setHover NOTIFY hoverChanged) Q_PROPERTY( bool horizontal READ horizontal WRITE setHorizontal NOTIFY horizontalChanged) @@ -116,7 +116,7 @@ public: bool raised() const { return m_raised; } bool active() const { return m_active; } bool selected() const { return m_selected; } - bool focus() const { return m_focus; } + bool hasFocus() const { return m_focus; } bool on() const { return m_on; } bool hover() const { return m_hover; } bool horizontal() const { return m_horizontal; } @@ -139,7 +139,7 @@ public: void setRaised(bool raised) { if (m_raised!= raised) {m_raised = raised; emit raisedChanged();}} void setActive(bool active) { if (m_active!= active) {m_active = active; emit activeChanged();}} void setSelected(bool selected) { if (m_selected!= selected) {m_selected = selected; emit selectedChanged();}} - void setFocus(bool focus) { if (m_focus != focus) {m_focus = focus; emit focusChanged();}} + void sethasFocus(bool focus) { if (m_focus != focus) {m_focus = focus; emit hasFocusChanged();}} void setOn(bool on) { if (m_on != on) {m_on = on ; emit onChanged();}} void setHover(bool hover) { if (m_hover != hover) {m_hover = hover ; emit hoverChanged();}} void setHorizontal(bool horizontal) { if (m_horizontal != horizontal) {m_horizontal = horizontal; emit horizontalChanged();}} @@ -186,7 +186,7 @@ Q_SIGNALS: void raisedChanged(); void activeChanged(); void selectedChanged(); - void focusChanged(); + void hasFocusChanged(); void onChanged(); void hoverChanged(); void horizontalChanged(); -- GitLab