mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-02-01 11:39:26 +00:00
New algorithm to compute needed width on dynamic texts. Fix binding loops on scrolls. Fix texts display in reply preview.
80 lines
2.2 KiB
QML
80 lines
2.2 KiB
QML
import QtQuick 2.7
|
|
import QtQuick.Controls 2.2
|
|
|
|
import Common 1.0
|
|
import Common.Styles 1.0
|
|
|
|
// =============================================================================
|
|
|
|
Rectangle {
|
|
id: mainItem
|
|
property alias text: textArea.text
|
|
property alias placeholderText: textArea.placeholderText
|
|
readonly property alias length: textArea.length
|
|
property alias boundsBehavior: flickable.boundsBehavior
|
|
property alias font: textArea.font
|
|
property alias textColor: textArea.color
|
|
property alias readOnly: textArea.readOnly
|
|
property int padding: TextAreaFieldStyle.text.padding
|
|
property alias implicitHeight: flickable.contentHeight
|
|
property int fitWidth: 0
|
|
|
|
height: TextAreaFieldStyle.background.height
|
|
width: TextAreaFieldStyle.background.width
|
|
border {
|
|
color: TextAreaFieldStyle.background.border.color
|
|
width: TextAreaFieldStyle.background.border.width
|
|
}
|
|
|
|
color: textArea.readOnly
|
|
? TextAreaFieldStyle.background.color.readOnly
|
|
: TextAreaFieldStyle.background.color.normal
|
|
|
|
radius: TextAreaFieldStyle.background.radius
|
|
// Fit Width computation
|
|
onTextChanged:{
|
|
var lines = text.split('\n')
|
|
var totalWidth = 0
|
|
for(var index in lines){
|
|
metrics.text = lines[index]
|
|
if( totalWidth < metrics.width)
|
|
totalWidth = metrics.width
|
|
}
|
|
fitWidth = totalWidth
|
|
}
|
|
TextMetrics{
|
|
id: metrics
|
|
font: mainItem.font
|
|
}
|
|
//-----------------------------------
|
|
Flickable {
|
|
id: flickable
|
|
anchors.fill: parent
|
|
|
|
boundsBehavior: Flickable.StopAtBounds
|
|
|
|
ScrollBar.vertical: ForceScrollBar {
|
|
id: scrollBar
|
|
//policy: flickable.contentHeight > height ? ScrollBar.AlwaysOn : ScrollBar.AlwaysOff // Do not use because of binding loop issues
|
|
contentSizeTarget: flickable.contentHeight
|
|
sizeTarget: flickable.height
|
|
Component.onCompleted: updatePolicy()
|
|
}
|
|
TextArea.flickable: TextArea {
|
|
id: textArea
|
|
|
|
background: Item{}
|
|
|
|
color: TextAreaFieldStyle.text.color
|
|
font.pointSize: TextAreaFieldStyle.text.pointSize
|
|
selectByMouse: true
|
|
wrapMode: TextArea.Wrap
|
|
height: flickable.height
|
|
|
|
bottomPadding: mainItem.padding
|
|
leftPadding: mainItem.padding
|
|
rightPadding: mainItem.padding + Number(scrollBar.visible) * scrollBar.width
|
|
topPadding: mainItem.padding
|
|
}
|
|
}
|
|
}
|