Skip to content

Commit

Permalink
Align Search Suggestion with Line Edit
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaopengLin committed Sep 4, 2024
1 parent 3e203be commit c6a4611
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 3 additions & 0 deletions resources/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ QToolButton {
border: none;
}

/* updateCompletion of src/searchbar.cpp references the margin and border */
SearchBar {
background-color: white;
margin: 2px 5px;
Expand All @@ -39,6 +40,7 @@ SearchBar {
max-height: 40px;
}

/* updateCompletion of src/searchbar.cpp references the width and height */
SearchBar > QLabel#searchIcon {
padding: 0;
border: none;
Expand All @@ -60,6 +62,7 @@ SearchBar > SearchBarLineEdit {
max-height: 38px;
}

/* updateCompletion of src/searchbar.cpp references the width and height */
SearchBar > QToolButton {
padding: 0;
border: 0 solid #fff;
Expand Down
21 changes: 20 additions & 1 deletion src/searchbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,26 @@ void SearchBarLineEdit::updateCompletion()
return;
}
m_suggestionModel.resetSuggestions(suggestions);
m_completer.complete();

auto searchGeo = KiwixApp::instance()->getSearchBar().geometry();

/* See SearchBar border and margin and SearchBar::QToolButton size
in resources/css/style.css */
int top = searchGeo.height() - 6; /* top bottom margin + border */
int width = searchGeo.width() - 12; /* top bottom margin + border */

/* LTR: shifting left to the border on left end: size + border
RTL: shifting left considering x flipped while display didn't:
The lineedit in LTR was size pixels away from border. Here
x is flipped so it became -x in the sense of LTR, hence the
adjustment of moving width + 2 * size.
*/
int left = KiwixApp::isRightToLeft() ? -searchGeo.width() - (38 * 2)
: -39;


/* Can't set height to 0. Will cause rectangle to be ignored. */
m_completer.complete(QRect(QPoint(left, top), QSize(width, 1)));
m_completer.popup()->selectionModel()->setCurrentIndex(
m_suggestionModel.index(0), QItemSelectionModel::Current);
});
Expand Down

0 comments on commit c6a4611

Please sign in to comment.