From d08d5fe576cf6d236488323073e29b777a99a1ba Mon Sep 17 00:00:00 2001 From: xiaoyifang <105986+xiaoyifang@users.noreply.github.com> Date: Fri, 19 May 2023 19:41:27 +0800 Subject: [PATCH] opt: let qt handle the language direction (#709) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * opt: let qt handle the language direction * 🎨 apply clang-format changes * action: modify auto clang format action --------- Co-authored-by: xiaoyifang --- .github/workflows/auto clang format.yml | 5 +---- src/article_maker.cc | 16 ++++++---------- src/ui/articleview.cc | 6 ------ src/ui/mainwindow.cc | 18 +----------------- 4 files changed, 8 insertions(+), 37 deletions(-) diff --git a/.github/workflows/auto clang format.yml b/.github/workflows/auto clang format.yml index 1629f1a9..ad6075c0 100644 --- a/.github/workflows/auto clang format.yml +++ b/.github/workflows/auto clang format.yml @@ -28,10 +28,7 @@ jobs: - name: ubuntu install clang-format run: | sudo apt-get install git lsb-release wget software-properties-common - wget https://apt.llvm.org/llvm.sh - chmod +x llvm.sh - sudo ./llvm.sh - rm -f llvm.sh + wget -qO - https://apt.llvm.org/llvm.sh| sudo bash sudo apt-get update sudo apt-get install -y clang-format git-clang-format --style=file HEAD^ diff --git a/src/article_maker.cc b/src/article_maker.cc index 5c1d6920..b64814c8 100644 --- a/src/article_maker.cc +++ b/src/article_maker.cc @@ -221,17 +221,13 @@ std::string ArticleMaker::makeNotFoundBody( QString const & word, { string result( "

" ); - QString str( word ); - if( str.isRightToLeft() ) - { - str.insert( 0, (ushort)0x202E ); // RLE, Right-to-Left Embedding - str.append( (ushort)0x202C ); // PDF, POP DIRECTIONAL FORMATTING - } - if ( word.size() ) - result += tr( "No translation for %1 was found in group %2." ). - arg( QString::fromUtf8( Html::escape( str.toUtf8().data() ).c_str() ), QString::fromUtf8( Html::escape( group.toUtf8().data() ).c_str() ) ). - toUtf8().data(); + result += tr( "No translation for %1 was found in group %2." ) + .arg( QString::fromUtf8( Html::escape( word.toUtf8().data() ).c_str() ), + QString::fromUtf8( Html::escape( group.toUtf8().data() ).c_str() ), + word.isRightToLeft() ? "rtl" : "ltr" ) + .toUtf8() + .data(); else result += tr( "No translation was found in group %1." ). arg( QString::fromUtf8( Html::escape( group.toUtf8().data() ).c_str() ) ). diff --git a/src/ui/articleview.cc b/src/ui/articleview.cc index 7826de5f..d4db2ce1 100644 --- a/src/ui/articleview.cc +++ b/src/ui/articleview.cc @@ -1789,12 +1789,6 @@ void ArticleView::contextMenuRequested( QPoint const & pos ) // We don't prompt for selections larger or equal to 60 chars, since // it ruins the menu and it's hardly a single word anyway. - if( text.isRightToLeft() ) - { - text.insert( 0, (ushort)0x202E ); // RLE, Right-to-Left Embedding - text.append( (ushort)0x202C ); // PDF, POP DIRECTIONAL FORMATTING - } - lookupSelection = new QAction( tr( "&Look up \"%1\"" ). arg( text ), &menu ); diff --git a/src/ui/mainwindow.cc b/src/ui/mainwindow.cc index 65fe318e..23245455 100644 --- a/src/ui/mainwindow.cc +++ b/src/ui/mainwindow.cc @@ -1844,12 +1844,6 @@ void MainWindow::titleChanged( ArticleView * view, QString const & title ) } escaped.replace( "&", "&&" ); - if( escaped.isRightToLeft() ) - { - escaped.insert( 0, (ushort)0x202E ); // RLE, Right-to-Left Embedding - escaped.append( (ushort)0x202C ); // PDF, POP DIRECTIONAL FORMATTING - } - int index = ui.tabWidget->indexOf( view ); if( !escaped.isEmpty() ) ui.tabWidget->setTabText( index, escaped ); @@ -1883,13 +1877,7 @@ void MainWindow::updateWindowTitle() if ( view ) { QString str = view->getTitle(); - if( !str.isEmpty() ) - { - if( str.isRightToLeft() ) - { - str.insert( 0, (ushort)0x202E ); // RLE, Right-to-Left Embedding - str.append( (ushort)0x202C ); // PDF, POP DIRECTIONAL FORMATTING - } + if ( !str.isEmpty() ) { if( !blockUpdateWindowTitle ) setWindowTitle( tr( "%1 - %2" ).arg( str, "GoldenDict-ng" ) ); blockUpdateWindowTitle = false; @@ -4423,10 +4411,6 @@ QString MainWindow::unescapeTabHeader(QString const & header ) QString escaped = header; escaped.replace( "&&", "&" ); - if( escaped.startsWith( QChar( 0x202E ) ) ) - escaped = escaped.mid( 1 ); - if( escaped.endsWith( QChar( 0x202C ) ) ) - escaped.chop( 1 ); return escaped; }