From 3cafe23d3a2f60ac1fc4ab730f2e87382f532f94 Mon Sep 17 00:00:00 2001 From: Konstantin Isakov Date: Fri, 10 Apr 2009 15:52:08 +0000 Subject: [PATCH] * Clean up scanpopup a bit by removing diacritic and prefix matches lists, replacing them by a simple list of matches, limited to 20 first items. --- src/icons/accents.png | Bin 325 -> 0 bytes src/resources.qrc | 1 - src/scanpopup.cc | 87 +++++++++++------------------------------- src/scanpopup.hh | 8 +--- src/scanpopup.ui | 33 +--------------- 5 files changed, 25 insertions(+), 104 deletions(-) delete mode 100644 src/icons/accents.png diff --git a/src/icons/accents.png b/src/icons/accents.png deleted file mode 100644 index e7924360999765c46c42f692ef828af78c475a7e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 325 zcmeAS@N?(olHy`uVBq!ia0vp^Vn8gw!3HFS-u9~jDaPU;cPEB*=VV?2Ic!PZ?k)^> zKycrN>K>p7XMsm#F#`j)00=X#Ro+_)6l5>)^mS#w$tW)@W10Qd(FrJY)YHW=#NzbU zDF=BEEAY757dSjR$1qi5A#(~3|6zxoiH>`^t1}iXY-OAE%zNUZn%jow{TiYUooTX^ zefFeb=A*-w`$cSvZxstMB=y|fAGzh)q`hI&uicvWoku|_F->ui)(Ok-cby)4zPDzd zI~ljSV*2%c9}XNiWo&ym>-DSIAsmjiA96RAoZDM15xMb_p)qsAt#w{El^5MPvT#|z zk|`m@bFYQ|om$u?=i)<5NbU(3<^`6+Mma`{VtO+RE+ulr&8fH9Z%qICF- Sj)y=GF?hQAxvX - icons/accents.png icons/prefix.png icons/pushpin.png icons/playsound.png diff --git a/src/scanpopup.cc b/src/scanpopup.cc index 556e10b1..379eda18 100644 --- a/src/scanpopup.cc +++ b/src/scanpopup.cc @@ -35,8 +35,7 @@ ScanPopup::ScanPopup( QWidget * parent, definition = new ArticleView( ui.outerFrame, articleNetMgr, groups, true ), ui.mainLayout->addWidget( definition ); - ui.diacriticButton->hide(); - ui.prefixButton->hide(); + ui.wordListButton->hide(); ui.groupList->fill( groups ); ui.groupList->setCurrentGroup( cfg.lastPopupGroupId ); @@ -69,13 +68,6 @@ ScanPopup::ScanPopup( QWidget * parent, connect( &wordFinder, SIGNAL( finished() ), this, SLOT( prefixMatchFinished() ) ); - connect( ui.word, SIGNAL( clicked() ), - this, SLOT( initialWordClicked() ) ); - connect( ui.diacriticButton, SIGNAL( clicked() ), - this, SLOT( diacriticButtonClicked() ) ); - connect( ui.prefixButton, SIGNAL( clicked() ), - this, SLOT( prefixButtonClicked() ) ); - connect( ui.pinButton, SIGNAL( clicked( bool ) ), this, SLOT( pinButtonClicked( bool ) ) ); @@ -339,79 +331,44 @@ void ScanPopup::prefixMatchFinished() else ui.queryError->hide(); - // Find the matches that aren't prefix. If there're more than one, - // show the diacritic toolbutton. If there are prefix matches, show - // the prefix toolbutton. - - diacriticMatches.clear(); - prefixMatches.clear(); - - wstring foldedInputWord = Folding::apply( inputWord.toStdWString() ); - - WordFinder::SearchResults const & results = wordFinder.getPrefixMatchResults(); - - for( unsigned x = 0; x < results.size(); ++x ) - { - if ( Folding::apply( results[ x ].first.toStdWString() ) == foldedInputWord ) - diacriticMatches.push_back( results[ x ].first ); - else - prefixMatches.push_back( results[ x ].first ); - } - - if ( diacriticMatches.size() > 1 ) - { - ui.diacriticButton->setToolTip( tr( "%1 results differing in diacritic marks" ).arg( diacriticMatches.size() ) ); - ui.diacriticButton->show(); - } - else - ui.diacriticButton->hide(); - - if ( prefixMatches.size() ) - { - ui.prefixButton->setToolTip( tr( "%1 result(s) beginning with the search word" ).arg( prefixMatches.size() ) ); - ui.prefixButton->show(); - } - else - ui.prefixButton->hide(); + ui.wordListButton->setVisible( wordFinder.getPrefixMatchResults().size() ); } } -void ScanPopup::diacriticButtonClicked() -{ - popupWordlist( diacriticMatches, ui.diacriticButton ); -} - -void ScanPopup::prefixButtonClicked() -{ - popupWordlist( prefixMatches, ui.prefixButton ); -} - -void ScanPopup::popupWordlist( vector< QString > const & words, QToolButton * button ) +void ScanPopup::on_wordListButton_clicked() { if ( !isVisible() ) return; - if ( words.empty() ) + WordFinder::SearchResults const & results = wordFinder.getPrefixMatchResults(); + + if ( results.empty() ) return; QMenu menu( this ); - for( unsigned x = 0; x < words.size(); ++x ) - menu.addAction( words[ x ] ); + unsigned total = results.size() < 20 ? results.size() : 20; - QAction * result = menu.exec( mapToGlobal( button->pos() ) + - QPoint( 0, button->height() ) ); + for( unsigned x = 0; x < total; ++x ) + { + // Some items are just too large! For now skip them. + + if ( results[ x ].first.size() > 64 ) + { + if ( total < results.size() ) + ++total; + } + else + menu.addAction( results[ x ].first ); + } + + QAction * result = menu.exec( mapToGlobal( ui.wordListButton->pos() ) + + QPoint( 0, ui.wordListButton->height() ) ); if ( result ) definition->showDefinition( result->text(), ui.groupList->getCurrentGroup() ); } -void ScanPopup::initialWordClicked() -{ - if ( isVisible() && diacriticMatches.size() ) - definition->showDefinition( diacriticMatches[ 0 ], ui.groupList->getCurrentGroup() ); -} - void ScanPopup::pinButtonClicked( bool checked ) { if ( checked ) diff --git a/src/scanpopup.hh b/src/scanpopup.hh index 05d4e24d..32df1579 100644 --- a/src/scanpopup.hh +++ b/src/scanpopup.hh @@ -46,8 +46,6 @@ private: QString inputWord; WordFinder wordFinder; - vector< QString > diacriticMatches, prefixMatches; - bool mouseEnteredOnce; QPoint startPos; // For window moving @@ -69,8 +67,6 @@ private: virtual void resizeEvent( QResizeEvent * event ); virtual void showEvent( QShowEvent * ); - void popupWordlist( vector< QString > const &, QToolButton * button ); - /// Returns inputWord, chopped with appended ... if it's too long/ QString elideInputWord(); @@ -80,9 +76,7 @@ private slots: void mouseHovered( QString const & ); void currentGroupChanged( QString const & ); void prefixMatchFinished(); - void diacriticButtonClicked(); - void prefixButtonClicked(); - void initialWordClicked(); + void on_wordListButton_clicked(); void pinButtonClicked( bool checked ); void hideTimerExpired(); diff --git a/src/scanpopup.ui b/src/scanpopup.ui index 53ace267..bc8d0a0e 100644 --- a/src/scanpopup.ui +++ b/src/scanpopup.ui @@ -51,43 +51,14 @@ - - - - 0 - 0 - - + word - - true - - - - ... - - - - :/icons/accents.png:/icons/accents.png - - - - 22 - 16 - - - - Qt::NoArrow - - - - - + ...