From 05fcff0834fefe23fe8ca592de6da3265a03c550 Mon Sep 17 00:00:00 2001 From: ShaopengLin Date: Fri, 23 Aug 2024 06:09:54 -0400 Subject: [PATCH 1/2] Fix SearchBar Cursor Alignment in RTL The cursor was misaligned to the left in RTL. --- src/searchbar.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/searchbar.cpp b/src/searchbar.cpp index b213141..020dec6 100644 --- a/src/searchbar.cpp +++ b/src/searchbar.cpp @@ -51,6 +51,7 @@ SearchBarLineEdit::SearchBarLineEdit(QWidget *parent) : QLineEdit(parent), m_completer(&m_completionModel, this) { + setAlignment(KiwixApp::isRightToLeft() ? Qt::AlignRight : Qt::AlignLeft); mp_typingTimer = new QTimer(this); mp_typingTimer->setSingleShot(true); setPlaceholderText(gt("search")); @@ -77,6 +78,12 @@ SearchBarLineEdit::SearchBarLineEdit(QWidget *parent) : if (m_returnPressed) { this->setText(m_searchbarInput); } + + /* Empty text is LTR which changes the line edit alignment. + Need to explicitly align right. This is a generalized + solution that aligns text to the direction of the app. */ + bool isSameDirection = text.isRightToLeft() == KiwixApp::isRightToLeft(); + setAlignment(isSameDirection ? Qt::AlignLeft : Qt::AlignRight); }); connect(this, &QLineEdit::returnPressed, this, [=]() { m_returnPressed = true; From 39068888011eea2c10f55a04c747418a92e73aee Mon Sep 17 00:00:00 2001 From: ShaopengLin Date: Thu, 5 Sep 2024 16:16:16 -0400 Subject: [PATCH 2/2] Fix SearchBar Placeholder Alignment in RTL Align placeholder at leading position in line edit --- src/searchbar.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/searchbar.cpp b/src/searchbar.cpp index 020dec6..a004e1e 100644 --- a/src/searchbar.cpp +++ b/src/searchbar.cpp @@ -54,7 +54,14 @@ SearchBarLineEdit::SearchBarLineEdit(QWidget *parent) : setAlignment(KiwixApp::isRightToLeft() ? Qt::AlignRight : Qt::AlignLeft); mp_typingTimer = new QTimer(this); mp_typingTimer->setSingleShot(true); - setPlaceholderText(gt("search")); + + /* Placeholder does not affect line edit alignment and is aligned to line + edit purely by text direction (LTR leading RTL ending). Thus, we need + directional mask to make it LTR at leading position. + https://stackoverflow.com/questions/66430215/english-and-arabic-mixed-string-not-ordered-correctly-qt + */ + const QString ltrConversionChar = QString{"\u200e"}; + setPlaceholderText(ltrConversionChar + gt("search")); setToolTip(gt("search")); m_completer.setCompletionMode(QCompleter::UnfilteredPopupCompletion); m_completer.setCaseSensitivity(Qt::CaseInsensitive);