mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 23:34:06 +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>
|
<RCC>
|
||||||
<qresource>
|
<qresource>
|
||||||
<file>icons/accents.png</file>
|
|
||||||
<file>icons/prefix.png</file>
|
<file>icons/prefix.png</file>
|
||||||
<file>icons/pushpin.png</file>
|
<file>icons/pushpin.png</file>
|
||||||
<file>icons/playsound.png</file>
|
<file>icons/playsound.png</file>
|
||||||
|
|
|
@ -35,8 +35,7 @@ ScanPopup::ScanPopup( QWidget * parent,
|
||||||
definition = new ArticleView( ui.outerFrame, articleNetMgr, groups, true ),
|
definition = new ArticleView( ui.outerFrame, articleNetMgr, groups, true ),
|
||||||
ui.mainLayout->addWidget( definition );
|
ui.mainLayout->addWidget( definition );
|
||||||
|
|
||||||
ui.diacriticButton->hide();
|
ui.wordListButton->hide();
|
||||||
ui.prefixButton->hide();
|
|
||||||
|
|
||||||
ui.groupList->fill( groups );
|
ui.groupList->fill( groups );
|
||||||
ui.groupList->setCurrentGroup( cfg.lastPopupGroupId );
|
ui.groupList->setCurrentGroup( cfg.lastPopupGroupId );
|
||||||
|
@ -69,13 +68,6 @@ ScanPopup::ScanPopup( QWidget * parent,
|
||||||
connect( &wordFinder, SIGNAL( finished() ),
|
connect( &wordFinder, SIGNAL( finished() ),
|
||||||
this, SLOT( prefixMatchFinished() ) );
|
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 ) ),
|
connect( ui.pinButton, SIGNAL( clicked( bool ) ),
|
||||||
this, SLOT( pinButtonClicked( bool ) ) );
|
this, SLOT( pinButtonClicked( bool ) ) );
|
||||||
|
|
||||||
|
@ -339,79 +331,44 @@ void ScanPopup::prefixMatchFinished()
|
||||||
else
|
else
|
||||||
ui.queryError->hide();
|
ui.queryError->hide();
|
||||||
|
|
||||||
// Find the matches that aren't prefix. If there're more than one,
|
ui.wordListButton->setVisible( wordFinder.getPrefixMatchResults().size() );
|
||||||
// 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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScanPopup::diacriticButtonClicked()
|
void ScanPopup::on_wordListButton_clicked()
|
||||||
{
|
|
||||||
popupWordlist( diacriticMatches, ui.diacriticButton );
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScanPopup::prefixButtonClicked()
|
|
||||||
{
|
|
||||||
popupWordlist( prefixMatches, ui.prefixButton );
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScanPopup::popupWordlist( vector< QString > const & words, QToolButton * button )
|
|
||||||
{
|
{
|
||||||
if ( !isVisible() )
|
if ( !isVisible() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ( words.empty() )
|
WordFinder::SearchResults const & results = wordFinder.getPrefixMatchResults();
|
||||||
|
|
||||||
|
if ( results.empty() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QMenu menu( this );
|
QMenu menu( this );
|
||||||
|
|
||||||
for( unsigned x = 0; x < words.size(); ++x )
|
unsigned total = results.size() < 20 ? results.size() : 20;
|
||||||
menu.addAction( words[ x ] );
|
|
||||||
|
|
||||||
QAction * result = menu.exec( mapToGlobal( button->pos() ) +
|
for( unsigned x = 0; x < total; ++x )
|
||||||
QPoint( 0, button->height() ) );
|
{
|
||||||
|
// 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 )
|
if ( result )
|
||||||
definition->showDefinition( result->text(), ui.groupList->getCurrentGroup() );
|
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 )
|
void ScanPopup::pinButtonClicked( bool checked )
|
||||||
{
|
{
|
||||||
if ( checked )
|
if ( checked )
|
||||||
|
|
|
@ -46,8 +46,6 @@ private:
|
||||||
QString inputWord;
|
QString inputWord;
|
||||||
WordFinder wordFinder;
|
WordFinder wordFinder;
|
||||||
|
|
||||||
vector< QString > diacriticMatches, prefixMatches;
|
|
||||||
|
|
||||||
bool mouseEnteredOnce;
|
bool mouseEnteredOnce;
|
||||||
|
|
||||||
QPoint startPos; // For window moving
|
QPoint startPos; // For window moving
|
||||||
|
@ -69,8 +67,6 @@ private:
|
||||||
virtual void resizeEvent( QResizeEvent * event );
|
virtual void resizeEvent( QResizeEvent * event );
|
||||||
virtual void showEvent( QShowEvent * );
|
virtual void showEvent( QShowEvent * );
|
||||||
|
|
||||||
void popupWordlist( vector< QString > const &, QToolButton * button );
|
|
||||||
|
|
||||||
/// Returns inputWord, chopped with appended ... if it's too long/
|
/// Returns inputWord, chopped with appended ... if it's too long/
|
||||||
QString elideInputWord();
|
QString elideInputWord();
|
||||||
|
|
||||||
|
@ -80,9 +76,7 @@ private slots:
|
||||||
void mouseHovered( QString const & );
|
void mouseHovered( QString const & );
|
||||||
void currentGroupChanged( QString const & );
|
void currentGroupChanged( QString const & );
|
||||||
void prefixMatchFinished();
|
void prefixMatchFinished();
|
||||||
void diacriticButtonClicked();
|
void on_wordListButton_clicked();
|
||||||
void prefixButtonClicked();
|
|
||||||
void initialWordClicked();
|
|
||||||
void pinButtonClicked( bool checked );
|
void pinButtonClicked( bool checked );
|
||||||
|
|
||||||
void hideTimerExpired();
|
void hideTimerExpired();
|
||||||
|
|
|
@ -51,43 +51,14 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QToolButton" name="word">
|
<widget class="QLabel" name="word">
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>word</string>
|
<string>word</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="autoRaise">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QToolButton" name="diacriticButton">
|
<widget class="QToolButton" name="wordListButton">
|
||||||
<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">
|
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>...</string>
|
<string>...</string>
|
||||||
</property>
|
</property>
|
||||||
|
|
Loading…
Reference in a new issue