Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #1451 - unicode in mixer should wrap on character boundaries #1993

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions src/audiomixerboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -642,22 +644,26 @@ 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
{
// in normal mode use bold font
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;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/audiomixerboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <QListWidget>
#include <QMenu>
#include <QMutex>
#include <QTextBoundaryFinder>
#include "global.h"
#include "util.h"
#include "levelmeter.h"
Expand Down
14 changes: 13 additions & 1 deletion src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,18 @@ void CMusProfDlg::showEvent ( QShowEvent* )
static_cast<int> ( 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
Expand All @@ -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 ) );
}
}

Expand Down
1 change: 1 addition & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
# include <QDateTime>
# include <QDesktopServices>
# include <QKeyEvent>
# include <QTextBoundaryFinder>
# include "ui_aboutdlgbase.h"
#endif
#include <QFile>
Expand Down