From 3efd59c8354c0ba0cdddf76d46ade046ce0b42d3 Mon Sep 17 00:00:00 2001 From: Martin Kaistra Date: Tue, 6 Apr 2021 18:13:59 +0200 Subject: [PATCH 1/2] Fix inserting line breaks into musician names with unicode characters Signed-off-by: Martin Kaistra --- src/audiomixerboard.cpp | 24 +++++++++++++++--------- src/audiomixerboard.h | 1 + 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/audiomixerboard.cpp b/src/audiomixerboard.cpp index fb673fd0c4..7faff11014 100755 --- a/src/audiomixerboard.cpp +++ b/src/audiomixerboard.cpp @@ -634,6 +634,8 @@ void CChannelFader::SetChannelInfos ( const CChannelInfo& cChanInfo ) // Label text -------------------------------------------------------------- QString strModText = cChanInfo.strName; + QTextBoundaryFinder tbfName ( QTextBoundaryFinder::Grapheme, cChanInfo.strName ); + int iBreakPos; // apply break position and font size depending on the selected design if ( eDesign == GD_SLIMFADER ) @@ -642,10 +644,7 @@ void CChannelFader::SetChannelInfos ( const CChannelInfo& cChanInfo ) plblLabel->setStyleSheet ( "QLabel { color: black; }" ); // break at every 4th character - for ( int iInsPos = 4; iInsPos <= strModText.size() - 1; iInsPos += 4 + 1 ) - { - strModText.insert ( iInsPos, "\n" ); - } + iBreakPos = 4; } else { @@ -653,11 +652,18 @@ void CChannelFader::SetChannelInfos ( const CChannelInfo& cChanInfo ) plblLabel->setStyleSheet ( "QLabel { color: black; font: bold; }" ); // break text at predefined position - const int iBreakPos = MAX_LEN_FADER_TAG / 2; - - if ( strModText.length() > iBreakPos ) - { - strModText.insert ( iBreakPos, QString ( "\n" ) ); + iBreakPos = MAX_LEN_FADER_TAG / 2; + } + + int iInsPos = iBreakPos; + int iCount = 0; + int iLineNumber = 0; + while ( tbfName.toNextBoundary() != -1 ) { + ++iCount; + if ( iCount == iInsPos ) { + strModText.insert ( tbfName.position() + iLineNumber, QString ( "\n" ) ); + iLineNumber ++; + iInsPos += iBreakPos; } } diff --git a/src/audiomixerboard.h b/src/audiomixerboard.h index 3fd9168170..132e883942 100755 --- a/src/audiomixerboard.h +++ b/src/audiomixerboard.h @@ -38,6 +38,7 @@ #include #include #include +#include #include "global.h" #include "util.h" #include "levelmeter.h" From ce370e95d43b2051ba20160e5ec50f13b2de5748 Mon Sep 17 00:00:00 2001 From: Martin Kaistra Date: Wed, 7 Apr 2021 20:18:05 +0200 Subject: [PATCH 2/2] Fix truncation of name in profile dialog with unicode characters Signed-off-by: Martin Kaistra --- src/util.cpp | 14 +++++++++++++- src/util.h | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/util.cpp b/src/util.cpp index c0fda1b486..ddec277a41 100755 --- a/src/util.cpp +++ b/src/util.cpp @@ -795,6 +795,18 @@ void CMusProfDlg::showEvent ( QShowEvent* ) static_cast ( pClient->ChannelInfo.eSkillLevel ) ) ); } +static inline QString TruncateString ( QString str, int position ) +{ + QTextBoundaryFinder tbfString ( QTextBoundaryFinder::Grapheme, str ); + + tbfString.setPosition ( position ); + if ( !tbfString.isAtBoundary() ) { + tbfString.toPreviousBoundary(); + position = tbfString.position(); + } + return str.left ( position ); +} + void CMusProfDlg::OnAliasTextChanged ( const QString& strNewName ) { // check length @@ -809,7 +821,7 @@ void CMusProfDlg::OnAliasTextChanged ( const QString& strNewName ) else { // text is too long, update control with shortened text - pedtAlias->setText ( strNewName.left ( MAX_LEN_FADER_TAG ) ); + pedtAlias->setText ( TruncateString ( strNewName, MAX_LEN_FADER_TAG ) ); } } diff --git a/src/util.h b/src/util.h index 1570aa2cdf..4b73f5d4ba 100755 --- a/src/util.h +++ b/src/util.h @@ -39,6 +39,7 @@ # include # include # include +# include # include "ui_aboutdlgbase.h" #endif #include