Skip to content
Snippets Groups Projects
Commit 103c3d10 authored by littletux89@gmail.com's avatar littletux89@gmail.com
Browse files

Merge branch 'develop' into features-3005

parents f067fa0c 82ecdc8e
No related branches found
No related tags found
2 merge requests!50Features 3819,!33Master
......@@ -22,6 +22,8 @@
<file>widgets/DapRadioButtonForm.ui.qml</file>
<file>widgets/DapScrollView.qml</file>
<file>widgets/DapScrollViewForm.ui.qml</file>
<file>widgets/DapText.qml</file>
<file>widgets/DapTextForm.ui.qml</file>
<file>widgets/DapScrollViewHandling.qml</file>
</qresource>
</RCC>
import QtQuick 2.4
DapTextForm
{
onTextChanged:
{
elidedText = (width > 2) ? elideByWidth(width) : (maxSymbolCapacity > 2) ? elideByCapacity(maxSymbolCapacity) : text
width = _metrics.boundingRect(elidedText).width
height = _metrics.boundingRect(elidedText).height
}
// "Copy Button" handler
function copy()
{
_fullText.selectAll()
_fullText.copy()
}
// Elides text by number of symbols
function elideByCapacity(maxSymbols)
{
var res = ""
if (text.length > maxSymbols)
{
switch (elide)
{
case Qt.ElideLeft:
res = ".." + text.slice(-maxSymbols, text.length-1)
break
case Qt.ElideMiddle:
res = text.slice(0, Math.floor(maxSymbols/2)) + ".." + text.slice(Math.floor(maxSymbols/2) + 1, text.length-1)
break
case Qt.ElideRight:
res = text.slice(0, maxSymbols) + ".."
break
default:
res = text
break
}
}
else
{
res = text
}
return res
}
// Elides text by width
function elideByWidth(maxWidth)
{
if (_metrics.advanceWidth(text) > maxWidth)
{
var symbolsNum = (maxWidth / _metrics.averageCharacterWidth)
return elideByCapacity(Math.floor(symbolsNum))
}
else
{
return text
}
}
}
import QtQuick 2.4
import QtQuick.Controls 2.2
Item
{
id: dapText
///@details Text.
property alias text: fullText.text
///@details Text color.
property alias color: elidedText.color
///@details Font.
property alias font: elidedText.font
///@details Elide style.
property int elide: Qt.ElideRight
///@details The number of symbols to display.
property int maxSymbolCapacity: 0
///@details Text to display.
property alias elidedText: elidedText.text
property alias _fullText: fullText
property alias _metrics: metrics
// Displays the text
Text
{
id: elidedText
}
// Calculates elide
FontMetrics
{
id: metrics
font: parent.font
}
// Stores full string to copy
TextInput
{
id: fullText
visible: false
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment