Merge branch 'feature/add-ignore-punctuation' into staged

This commit is contained in:
YiFang Xiao 2022-04-23 22:34:05 +08:00
commit f6cf152804
9 changed files with 110 additions and 70 deletions

View file

@ -16,6 +16,7 @@
#include <QRegularExpression>
#include "wildcard.hh"
#include "globalbroadcaster.h"
//#define __BTREE_USE_LZO
// LZO mode is experimental and unsupported. Tests didn't show any substantial
@ -853,7 +854,8 @@ void BtreeIndex::antialias( wstring const & str,
if( ignoreDiacritics )
caseFolded = Folding::applyDiacriticsOnly( caseFolded );
caseFolded = Folding::trimWhitespaceOrPunct( caseFolded );
if(GlobalBroadcaster::instance()->getPreference()->ignorePunctuation)
caseFolded = Folding::trimWhitespaceOrPunct( caseFolded );
for( unsigned x = chain.size(); x--; )
{
@ -863,7 +865,9 @@ void BtreeIndex::antialias( wstring const & str,
if( ignoreDiacritics )
entry = Folding::applyDiacriticsOnly( entry );
entry = Folding::trimWhitespaceOrPunct( entry );
if( GlobalBroadcaster::instance()->getPreference()->ignorePunctuation )
entry = Folding::trimWhitespaceOrPunct( entry );
if ( entry != caseFolded )
chain.erase( chain.begin() + x );
else

View file

@ -234,6 +234,7 @@ Preferences::Preferences():
scanPopupUnpinnedBypassWMHint( false ),
scanToMainWindow( false ),
ignoreDiacritics( false ),
ignorePunctuation( false ),
#ifdef HAVE_X11
showScanFlag( false ),
#endif
@ -891,6 +892,8 @@ Class load()
c.preferences.ignoreOwnClipboardChanges = ( preferences.namedItem( "ignoreOwnClipboardChanges" ).toElement().text() == "1" );
c.preferences.scanToMainWindow = ( preferences.namedItem( "scanToMainWindow" ).toElement().text() == "1" );
c.preferences.ignoreDiacritics = ( preferences.namedItem( "ignoreDiacritics" ).toElement().text() == "1" );
if( !preferences.namedItem( "ignorePunctuation" ).isNull() )
c.preferences.ignorePunctuation = ( preferences.namedItem( "ignorePunctuation" ).toElement().text() == "1" );
#ifdef HAVE_X11
c.preferences.showScanFlag= ( preferences.namedItem( "showScanFlag" ).toElement().text() == "1" );
#endif
@ -1763,6 +1766,10 @@ void save( Class const & c )
opt.appendChild( dd.createTextNode( c.preferences.ignoreDiacritics ? "1":"0" ) );
preferences.appendChild( opt );
opt = dd.createElement( "ignorePunctuation" );
opt.appendChild( dd.createTextNode( c.preferences.ignorePunctuation ? "1":"0" ) );
preferences.appendChild( opt );
#ifdef HAVE_X11
opt = dd.createElement( "showScanFlag" );
opt.appendChild( dd.createTextNode( c.preferences.showScanFlag? "1":"0" ) );

View file

@ -316,6 +316,7 @@ struct Preferences
bool scanPopupUnpinnedBypassWMHint;
bool scanToMainWindow;
bool ignoreDiacritics;
bool ignorePunctuation;
#ifdef HAVE_X11
bool showScanFlag;
#endif

View file

@ -1,14 +1,22 @@
#include "globalbroadcaster.h"
#include <QGlobalStatic>
Q_GLOBAL_STATIC(GlobalBroadcaster, bdcaster)
GlobalBroadcaster::GlobalBroadcaster(QObject *parent) : QObject(parent)
Q_GLOBAL_STATIC( GlobalBroadcaster, bdcaster )
GlobalBroadcaster::GlobalBroadcaster( QObject * parent ) : QObject( parent )
{
}
GlobalBroadcaster* GlobalBroadcaster::instance() { return bdcaster; }
GlobalBroadcaster * GlobalBroadcaster::instance()
{
return bdcaster;
}
void GlobalBroadcaster::setPreference( Config::Preferences * p )
{
preference = p;
}
Config::Preferences * GlobalBroadcaster::getPreference()
{
return preference;
}
// namespace global

View file

@ -2,23 +2,27 @@
#define GLOBAL_GLOBALBROADCASTER_H
#include <QObject>
#include "config.hh"
struct ActiveDictIds {
struct ActiveDictIds
{
QString word;
QStringList dictIds;
}
;
};
class GlobalBroadcaster : public QObject
{
Q_OBJECT
public:
GlobalBroadcaster(QObject *parent = nullptr);
static GlobalBroadcaster *instance();
signals:
void emitDictIds(ActiveDictIds ad);
private:
Config::Preferences * preference;
public:
void setPreference( Config::Preferences * _pre );
Config::Preferences * getPreference();
GlobalBroadcaster( QObject * parent = nullptr );
static GlobalBroadcaster * instance();
signals:
void emitDictIds( ActiveDictIds ad );
};
#endif // GLOBAL_GLOBALBROADCASTER_H

View file

@ -4056,7 +4056,12 @@ from mouse-over, selection, clipboard or command line</source>
<translation></translation>
</message>
<message>
<location filename="../preferences.ui" line="1817"/>
<location filename="../preferences.ui" line="1741"/>
<source>Ignore punctuation while searching</source>
<translation></translation>
</message>
<message>
<location filename="../preferences.ui" line="1751"/>
<source>Turn this option on to enable extra articles search via synonym lists
from Stardict, Babylon and GLS dictionaries</source>
<translation>

View file

@ -144,6 +144,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
QThreadPool::globalInstance()->start( new InitSSLRunnable );
#endif
GlobalBroadcaster::instance()->setPreference(&cfg.preferences);
localSchemeHandler = new LocalSchemeHandler(articleNetMgr);
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler("gdlookup", localSchemeHandler);

View file

@ -215,6 +215,8 @@ Preferences::Preferences( QWidget * parent, Config::Class & cfg_ ):
ui.ignoreDiacritics->setChecked( p.ignoreDiacritics );
ui.ignorePunctuation->setChecked( p.ignorePunctuation );
ui.synonymSearchEnabled->setChecked( p.synonymSearchEnabled );
ui.maxDictsInContextMenu->setValue( p.maxDictionaryRefsInContextMenu );
@ -424,6 +426,7 @@ Config::Preferences Preferences::getPreferences()
p.limitInputPhraseLength = ui.limitInputPhraseLength->isChecked();
p.inputPhraseLengthLimit = ui.inputPhraseLengthLimit->value();
p.ignoreDiacritics = ui.ignoreDiacritics->isChecked();
p.ignorePunctuation = ui.ignorePunctuation->isChecked();
p.synonymSearchEnabled = ui.synonymSearchEnabled->isChecked();

View file

@ -1625,16 +1625,46 @@ download page.</string>
<string>Articles</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QCheckBox" name="collapseBigArticles">
<item row="1" column="0">
<widget class="QCheckBox" name="limitInputPhraseLength">
<property name="toolTip">
<string>Select this option to automatic collapse big articles</string>
<string>Turn this option on to ignore unreasonably long input text
from mouse-over, selection, clipboard or command line</string>
</property>
<property name="text">
<string>Collapse articles more than</string>
<string>Ignore input phrases longer than</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="3">
<spacer name="horizontalSpacer_11">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="3">
<spacer name="horizontalSpacer_14">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="articleSizeLimit">
<property name="toolTip">
@ -1651,6 +1681,16 @@ download page.</string>
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QCheckBox" name="ignoreDiacritics">
<property name="toolTip">
<string>Turn this option on to ignore diacritics while searching articles</string>
</property>
<property name="text">
<string>Ignore diacritics while searching</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_13">
<property name="text">
@ -1658,33 +1698,6 @@ download page.</string>
</property>
</widget>
</item>
<item row="0" column="3">
<spacer name="horizontalSpacer_11">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="limitInputPhraseLength">
<property name="toolTip">
<string>Turn this option on to ignore unreasonably long input text
from mouse-over, selection, clipboard or command line</string>
</property>
<property name="text">
<string>Ignore input phrases longer than</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="inputPhraseLengthLimit">
<property name="toolTip">
@ -1701,20 +1714,13 @@ from mouse-over, selection, clipboard or command line</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label_19">
<property name="text">
<string>symbols</string>
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QCheckBox" name="ignoreDiacritics">
<item row="0" column="0">
<widget class="QCheckBox" name="collapseBigArticles">
<property name="toolTip">
<string>Turn this option on to ignore diacritics while searching articles</string>
<string>Select this option to automatic collapse big articles</string>
</property>
<property name="text">
<string>Ignore diacritics while searching</string>
<string>Collapse articles more than</string>
</property>
</widget>
</item>
@ -1728,18 +1734,19 @@ from mouse-over, selection, clipboard or command line</string>
</property>
</widget>
</item>
<item row="1" column="3">
<spacer name="horizontalSpacer_14">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<item row="1" column="2">
<widget class="QLabel" name="label_19">
<property name="text">
<string>symbols</string>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</widget>
</item>
<item row="2" column="4">
<widget class="QCheckBox" name="ignorePunctuation">
<property name="text">
<string>Ignore punctuation while searching</string>
</property>
</spacer>
</widget>
</item>
</layout>
</widget>