2020-05-19 19:49:52 +00:00
|
|
|
import QtQuick 2.7
|
|
|
|
import QtQuick.Controls 2.4
|
|
|
|
import QtQuick.Controls.Material 2.0
|
|
|
|
import QtQuick.Layouts 1.3
|
|
|
|
import CustomQmlTypes 1.0
|
2020-05-19 22:56:09 +00:00
|
|
|
import "." as Widgets
|
2020-05-19 20:25:56 +00:00
|
|
|
import "theme"
|
2020-05-19 19:49:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Needs the parent to have an onWidthChanged that calls .textResize()
|
|
|
|
Item {
|
|
|
|
property string text
|
|
|
|
|
|
|
|
property alias color: label.color
|
2020-05-26 22:11:43 +00:00
|
|
|
property alias size: label.font.pixelSize
|
2020-05-19 19:49:52 +00:00
|
|
|
property alias weight: label.font.weight
|
|
|
|
property alias strikeout: label.font.strikeout
|
|
|
|
property alias font: label.font
|
2020-07-08 22:30:15 +00:00
|
|
|
property alias topPadding: label.topPadding
|
2020-07-25 16:44:47 +00:00
|
|
|
property alias leftPadding: label.leftPadding
|
2020-05-19 19:49:52 +00:00
|
|
|
property int extraPadding: 0
|
|
|
|
|
|
|
|
property Item container: parent
|
|
|
|
|
|
|
|
height: textMetric.height
|
|
|
|
width: textMetric.width + 10
|
|
|
|
anchors.leftMargin: 10
|
|
|
|
|
|
|
|
Label {
|
|
|
|
id: label
|
|
|
|
textFormat: Text.PlainText
|
|
|
|
|
|
|
|
elide: Text.ElideRight
|
|
|
|
text: textMetric.text
|
|
|
|
}
|
|
|
|
|
|
|
|
TextMetrics {
|
|
|
|
id: textMetric
|
|
|
|
text: text
|
|
|
|
font: label.font
|
|
|
|
}
|
|
|
|
|
|
|
|
onTextChanged: {
|
|
|
|
textResize()
|
|
|
|
}
|
|
|
|
|
|
|
|
function textResize() {
|
|
|
|
textMetric.text = text
|
|
|
|
var i = 2
|
|
|
|
var containerWidth = container != null ? container.width : 50
|
|
|
|
// - 30 for padding
|
2020-07-25 16:44:47 +00:00
|
|
|
while (textMetric.width > containerWidth - ((30 + extraPadding) * gcd.themeScale) && textMetric.width > 50) {
|
2020-05-19 19:49:52 +00:00
|
|
|
textMetric.text = text.slice(0, text.length - (i * 3)) + "..."
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|