Skip to content
Snippets Groups Projects

Features 3030

Merged Kirill Anisimov requested to merge features-3030 into develop
2 files
+ 29
40
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 16
24
@@ -2,44 +2,35 @@ import QtQuick 2.4
@@ -2,44 +2,35 @@ import QtQuick 2.4
DapTextForm {
DapTextForm {
property font font:
Qt.font(
{
family: "Roboto",
weight: Font.Normal,
italic: false,
pixelSize: 12 * pt
}
)
elide: Qt.ElideRight
onTextChanged:
onTextChanged:
{
{
elidedText.text = (width > 2) ? elideByWidth(width) : (charsNumber > 2) ? elideByCharNum(charsNumber) : text
elidedText = (width > 2) ? elideByWidth(width) : (maxSymbolCapacity > 2) ? elideByCapacity(maxSymbolCapacity) : text
console.log("---->>> text changed")
width = _metrics.boundingRect(elidedText).width
 
height = _metrics.boundingRect(elidedText).height
}
}
// "Copy Button" handler
// "Copy Button" handler
function copy() {
function copy() {
fullText.selectAll()
_fullText.selectAll()
fullText.copy()
_fullText.copy()
}
}
function elideByCharNumbers(chrNum)
// Elides text by number of symbols
 
function elideByCapacity(maxSymbols)
{
{
var res = ""
var res = ""
if (text.length > chrNum)
if (text.length > maxSymbols)
{
{
switch (elide)
switch (elide)
{
{
case Qt.ElideLeft:
case Qt.ElideLeft:
res = ".." + text.slice(-chrNum, text.length-1)
res = ".." + text.slice(-maxSymbols, text.length-1)
break
break
case Qt.ElideMiddle:
case Qt.ElideMiddle:
res = text.slice(0, chrNum/2) + ".." + text.slice((chrNum/2) + 1, text.length-1)
res = text.slice(0, Math.floor(maxSymbols/2)) + ".." + text.slice(Math.floor(maxSymbols/2) + 1, text.length-1)
break
break
case Qt.ElideRight:
case Qt.ElideRight:
res = text.slice(0, chrNum) + ".."
res = text.slice(0, maxSymbols) + ".."
break
break
default:
default:
res = text
res = text
@@ -53,12 +44,13 @@ DapTextForm {
@@ -53,12 +44,13 @@ DapTextForm {
return res
return res
}
}
function elideByWidth(strWidth)
// Elides text by width
 
function elideByWidth(maxWidth)
{
{
if (metrics.advanceWidth(text) > width)
if (_metrics.advanceWidth(text) > maxWidth)
{
{
var chrNum = (width / metrics.averageCharacterWidth)
var symbolsNum = (maxWidth / _metrics.averageCharacterWidth)
return elideByCharNumbers(Math.floor(chrNum))
return elideByCapacity(Math.floor(symbolsNum))
}
}
else
else
{
{
Loading