Skip to content

Commit 7884881

Browse files
authored
fix(ui): set maximum size policy for translate box (#2694)
* fix(ui): set maximum size policy for translate box
1 parent f1d4ec4 commit 7884881

File tree

5 files changed

+28
-11
lines changed

5 files changed

+28
-11
lines changed

src/article_maker.cc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ void ArticleRequest::compoundSearchNextStep( bool lastSearchSucceeded )
857857
// Append the beginning
858858
footer += R"(<div class="gdstemmedsuggestion"><span class="gdstemmedsuggestion_head">)"
859859
+ Html::escape( tr( "Compound expressions: " ).toUtf8().data() )
860-
+ "</span><span class=\"gdstemmedsuggestion_body\">";
860+
+ "</span><div class=\"gdstemmedsuggestion_body\">";
861861

862862
firstCompoundWasFound = true;
863863
}
@@ -877,14 +877,13 @@ void ArticleRequest::compoundSearchNextStep( bool lastSearchSucceeded )
877877
// The last word was the last possible to start from
878878

879879
if ( firstCompoundWasFound ) {
880-
footer += "</span>";
880+
footer += "</div>";
881881
}
882882

883883
// Now add links to all the individual words. They conclude the result.
884884

885885
footer += R"(<div class="gdstemmedsuggestion"><span class="gdstemmedsuggestion_head">)"
886-
+ Html::escape( tr( "Individual words: " ).toUtf8().data() )
887-
+ "</span><span class=\"gdstemmedsuggestion_body\"";
886+
+ Html::escape( tr( "Individual words: " ).toUtf8().data() ) + "</span><div class=\"gdstemmedsuggestion_body\"";
888887
if ( splittedWords.first[ 0 ].isRightToLeft() ) {
889888
footer += " dir=\"rtl\"";
890889
}
@@ -897,7 +896,7 @@ void ArticleRequest::compoundSearchNextStep( bool lastSearchSucceeded )
897896
footer += escapeSpacing( splittedWords.second[ x + 1 ] );
898897
}
899898

900-
footer += "</span>";
899+
footer += "</div>";
901900

902901
footer += "</body></html>";
903902

src/stylesheets/article-style.css

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,11 +586,18 @@ div.xdxf {
586586
}
587587

588588
.gdstemmedsuggestion_head {
589-
margin-left: 11px;
589+
margin-left: 12px;
590590
font-style: italic;
591591
}
592592

593593
.gdstemmedsuggestion_body {
594+
display: block;
595+
width: 100%;
596+
margin: 12px;
597+
598+
box-sizing: border-box;
599+
word-break: break-word;
600+
line-height: 1.5;
594601
}
595602

596603
/************* Dictd articles *****************/

src/ui/scanpopup.cc

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ ScanPopup::ScanPopup( QWidget * parent,
8484
foundBar->setAllowedAreas( Qt::LeftToolBarArea | Qt::RightToolBarArea );
8585

8686
// UI style
87-
searchBar->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Maximum );
87+
searchBar->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
8888
searchBar->setMovable( false );
8989
toolBar->setFloatable( false );
9090
dictionaryBar.setFloatable( false );
@@ -111,6 +111,7 @@ ScanPopup::ScanPopup( QWidget * parent,
111111
tabWidget = new MainTabWidget( this );
112112
tabWidget->setTabsClosable( true );
113113
tabWidget->setHideSingleTab( true );
114+
tabWidget->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Expanding );
114115
connect( tabWidget, &QTabWidget::tabCloseRequested, this, [ this ]( int index ) {
115116
if ( index > 0 ) {
116117
auto widget = tabWidget->widget( index );
@@ -133,6 +134,16 @@ ScanPopup::ScanPopup( QWidget * parent,
133134

134135
resize( 247, 400 );
135136

137+
// Set maximum width based on screen size
138+
QScreen * screen = QGuiApplication::primaryScreen();
139+
if ( screen ) {
140+
int maxWidth = screen->availableGeometry().width() * 0.8; // 80% of screen width
141+
setMaximumWidth( maxWidth );
142+
}
143+
144+
translateBox->setMaximumWidth( 200 );
145+
groupList->setMaximumWidth( 200 );
146+
136147
connect( definition, &ArticleView::inspectSignal, this, &ScanPopup::inspectElementWhenPinned );
137148
connect( definition, &ArticleView::forceAddWordToHistory, this, &ScanPopup::forceAddWordToHistory );
138149
connect( this, &ScanPopup::closeMenu, definition, &ArticleView::closePopupMenu );
@@ -647,7 +658,7 @@ void ScanPopup::engagePopup( bool forcePopup, bool giveFocus )
647658
showTranslationFor( pendingWord );
648659
}
649660

650-
QString ScanPopup::elideInputWord()
661+
QString ScanPopup::elideInputWord() const
651662
{
652663
return pendingWord.size() > 32 ? pendingWord.mid( 0, 32 ) + "..." : pendingWord;
653664
}
@@ -729,7 +740,7 @@ void ScanPopup::showTranslationFor( const QString & word ) const
729740
definition->showDefinition( word, groupId );
730741
definition->focus();
731742
// definition is the first tab
732-
tabWidget->setTabText( 0, word );
743+
tabWidget->setTabText( 0, elideInputWord() );
733744
}
734745

735746
const vector< sptr< Dictionary::Class > > & ScanPopup::getActiveDicts()

src/ui/scanpopup.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ private:
185185
virtual void moveEvent( QMoveEvent * );
186186

187187
/// Returns inputWord, chopped with appended ... if it's too long/
188-
QString elideInputWord();
188+
QString elideInputWord() const;
189189

190190
void updateBackForwardButtons() const;
191191

src/ui/translatebox.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ TranslateBox::TranslateBox( QWidget * parent ):
1919
{
2020
completer = new QCompleter( words, this );
2121
resize( 200, 90 );
22-
QSizePolicy sizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
22+
QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Preferred );
2323
setSizePolicy( sizePolicy );
2424

2525
setFocusProxy( translate_line );

0 commit comments

Comments
 (0)