Commit c791195a authored by J-P Nurmi's avatar J-P Nurmi Committed by The Qt Project
Browse files

ScrollView & TextArea: fix vertical scrollbar visibility


Avoid binding loops by using recursion guards...

Change-Id: I1fb9f4ac54d6fa3cf930a848e22ec6b23edfa200
Reviewed-by: default avatarJens Bache-Wiig <jens.bache-wiig@digia.com>
parent c2e4db37
Branches
Tags
No related merge requests found
Showing with 62 additions and 7 deletions
...@@ -146,6 +146,12 @@ Item { ...@@ -146,6 +146,12 @@ Item {
id: tickmarkCheck id: tickmarkCheck
text: "Tickmarks" text: "Tickmarks"
checked: false checked: false
KeyNavigation.tab: wrapCheck
}
CheckBox {
id: wrapCheck
text: "Word wrap"
checked: true
KeyNavigation.tab: r1 KeyNavigation.tab: r1
} }
} }
...@@ -179,6 +185,7 @@ Item { ...@@ -179,6 +185,7 @@ Item {
frameVisible: frameCheckbox.checked frameVisible: frameCheckbox.checked
text: loremIpsum + loremIpsum text: loremIpsum + loremIpsum
KeyNavigation.tab: button1 KeyNavigation.tab: button1
wrapMode: wrapCheck.checked ? TextEdit.WordWrap : TextEdit.NoWrap
width: contentRow.width - firstColumn.width - contentRow.spacing width: contentRow.width - firstColumn.width - contentRow.spacing
height: parent.height - group1.height - group2.height - 2 * parent.spacing height: parent.height - group1.height - group2.height - 2 * parent.spacing
anchors { right: parent.right } anchors { right: parent.right }
......
...@@ -616,6 +616,31 @@ ScrollView { ...@@ -616,6 +616,31 @@ ScrollView {
z: -1 z: -1
} }
property bool recursionGuard: false
function doLayout() {
if (!recursionGuard) {
recursionGuard = true
if (wrapMode == TextEdit.NoWrap) {
horizontalScrollBar.visible = edit.paintedWidth + (2 * documentMargins) > area.viewport.width
edit.width = edit.paintedWidth + (2 * documentMargins)
} else {
horizontalScrollBar.visible = false
edit.width = area.viewport.width - (2 * documentMargins)
}
edit.height = Math.max(area.viewport.height - (2 * documentMargins), paintedHeight + (2 * documentMargins))
recursionGuard = false
}
}
Connections {
target: area.viewport
onWidthChanged: edit.doLayout()
onHeightChanged: edit.doLayout()
}
onPaintedWidthChanged: edit.doLayout()
onPaintedHeightChanged: edit.doLayout()
onWrapModeChanged: edit.doLayout()
renderType: Text.NativeRendering renderType: Text.NativeRendering
...@@ -623,8 +648,6 @@ ScrollView { ...@@ -623,8 +648,6 @@ ScrollView {
selectionColor: palette.highlight selectionColor: palette.highlight
selectedTextColor: palette.highlightedText selectedTextColor: palette.highlightedText
wrapMode: TextEdit.WordWrap wrapMode: TextEdit.WordWrap
width: area.viewport.width - (2 * documentMargins)
height: Math.max(area.viewport.height - (2 * documentMargins), paintedHeight + (2 * documentMargins))
x: documentMargins x: documentMargins
y: documentMargins y: documentMargins
......
...@@ -53,15 +53,40 @@ Item { ...@@ -53,15 +53,40 @@ Item {
property alias horizontalScrollBar: hscrollbar property alias horizontalScrollBar: hscrollbar
property alias verticalScrollBar: vscrollbar property alias verticalScrollBar: vscrollbar
property bool blockUpdates: false property bool blockUpdates: false
property int availableHeight : viewport ? viewport.height : 0 property int availableHeight
property int availableWidth: viewport ? viewport.width : 0 property int availableWidth
property int contentHeight: flickableItem ? flickableItem.contentHeight : 0 property int contentHeight
property int contentWidth: flickableItem ? flickableItem.contentWidth: 0 property int contentWidth
anchors.fill: parent anchors.fill: parent
property int frameMargin: outerFrame ? frameWidth : 0 property int frameMargin: outerFrame ? frameWidth : 0
property bool recursionGuard: false
function doLayout() {
if (!recursionGuard) {
recursionGuard = true
wheelarea.availableWidth = viewport.width
wheelarea.availableHeight = viewport.height
wheelarea.contentWidth = flickableItem.contentWidth
wheelarea.contentHeight = flickableItem.contentHeight
recursionGuard = false
}
}
Connections {
target: viewport
onWidthChanged: doLayout()
onHeightChanged: doLayout()
}
Connections {
target: flickableItem
onContentWidthChanged: doLayout()
onContentHeightChanged: doLayout()
}
Connections { Connections {
target: flickableItem target: flickableItem
onContentXChanged: { onContentXChanged: {
...@@ -126,7 +151,7 @@ Item { ...@@ -126,7 +151,7 @@ Item {
property bool isTransient: !!styleItem && styleItem.styleHint("transientScrollBars") property bool isTransient: !!styleItem && styleItem.styleHint("transientScrollBars")
property bool active: !!styleItem && (styleItem.sunken || styleItem.activeControl != "none") property bool active: !!styleItem && (styleItem.sunken || styleItem.activeControl != "none")
orientation: Qt.Vertical orientation: Qt.Vertical
// visible: contentHeight > availableHeight visible: contentHeight > availableHeight
width: visible ? implicitWidth : 0 width: visible ? implicitWidth : 0
z: 1 z: 1
anchors.bottom: cornerFill.top anchors.bottom: cornerFill.top
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment