mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
* 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.
This commit is contained in:
parent
aeaad6ad80
commit
3cafe23d3a
Binary file not shown.
Before Width: | Height: | Size: 325 B |
|
@ -1,6 +1,5 @@
|
|||
<RCC>
|
||||
<qresource>
|
||||
<file>icons/accents.png</file>
|
||||
<file>icons/prefix.png</file>
|
||||
<file>icons/pushpin.png</file>
|
||||
<file>icons/playsound.png</file>
|
||||
|
|
|
@ -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 )
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -51,43 +51,14 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="word">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<widget class="QLabel" name="word">
|
||||
<property name="text">
|
||||
<string>word</string>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="diacriticButton">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="resources.qrc">
|
||||
<normaloff>:/icons/accents.png</normaloff>:/icons/accents.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>22</width>
|
||||
<height>16</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="arrowType">
|
||||
<enum>Qt::NoArrow</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="prefixButton">
|
||||
<widget class="QToolButton" name="wordListButton">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
|
|
Loading…
Reference in a new issue