Skip to content
Snippets Groups Projects
Commit af358cb6 authored by Kirill Anisimov's avatar Kirill Anisimov Committed by andrey.daragan
Browse files

Features 3030

parent 5b93902e
No related branches found
No related tags found
No related merge requests found
......@@ -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