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" 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