Skip to content

Commit

Permalink
Merge pull request #64 from xiaoyifang/staged
Browse files Browse the repository at this point in the history
daily merge
  • Loading branch information
xiaoyifang authored May 5, 2022
2 parents 0656ea4 + 289b0be commit 327d1b4
Show file tree
Hide file tree
Showing 52 changed files with 80 additions and 216 deletions.
21 changes: 11 additions & 10 deletions articleview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -320,27 +320,29 @@ ArticleView::ArticleView( QWidget * parent, ArticleNetworkAccessManager & nm, Au
#if( QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) )
settings->defaultSettings()->setAttribute( QWebEngineSettings::WebAttribute::LocalContentCanAccessRemoteUrls, true );
settings->defaultSettings()->setAttribute( QWebEngineSettings::WebAttribute::LocalContentCanAccessFileUrls, true );
settings->defaultSettings()->setAttribute( QWebEngineSettings::WebAttribute::ErrorPageEnabled, false);
settings->defaultSettings()->setAttribute(QWebEngineSettings::PluginsEnabled, cfg.preferences.enableWebPlugins);
settings->defaultSettings()->setAttribute(QWebEngineSettings::PlaybackRequiresUserGesture, false);
settings->defaultSettings()->setAttribute( QWebEngineSettings::WebAttribute::ErrorPageEnabled, false );
settings->defaultSettings()->setAttribute( QWebEngineSettings::PluginsEnabled, cfg.preferences.enableWebPlugins );
settings->defaultSettings()->setAttribute( QWebEngineSettings::PlaybackRequiresUserGesture, false );
settings->defaultSettings()->setAttribute( QWebEngineSettings::JavascriptCanAccessClipboard, true );
#else
settings->setAttribute( QWebEngineSettings::WebAttribute::LocalContentCanAccessRemoteUrls, true );
settings->setAttribute( QWebEngineSettings::WebAttribute::LocalContentCanAccessFileUrls, true );
settings->setAttribute( QWebEngineSettings::WebAttribute::ErrorPageEnabled, false );
settings->setAttribute( QWebEngineSettings::PluginsEnabled, cfg.preferences.enableWebPlugins );
settings->setAttribute( QWebEngineSettings::PlaybackRequiresUserGesture, false );
settings->setAttribute( QWebEngineSettings::JavascriptCanAccessClipboard, true );
#endif
// Load the default blank page instantly, so there would be no flicker.

QString contentType;
QUrl blankPage( "gdlookup://localhost?blank=1" );
// QUrl blankPage( "gdlookup://localhost?blank=1" );

sptr< Dictionary::DataRequest > r = articleNetMgr.getResource( blankPage,
contentType );
// sptr< Dictionary::DataRequest > r = articleNetMgr.getResource( blankPage,
// contentType );

ui.definition->setHtml( QString::fromUtf8( &( r->getFullData().front() ),
r->getFullData().size() ),
blankPage );
// ui.definition->setHtml( QString::fromUtf8( &( r->getFullData().front() ),
// r->getFullData().size() ),
// blankPage );

expandOptionalParts = cfg.preferences.alwaysExpandOptionalParts;

Expand Down Expand Up @@ -1724,7 +1726,6 @@ void ArticleView::print( QPrinter * printer ) const
void ArticleView::contextMenuRequested( QPoint const & pos )
{
// Is that a link? Is there a selection?

QWebEnginePage* r=ui.definition->page();
updateCurrentArticleFromCurrentFrame(ui.definition->page(), const_cast<QPoint *>(& pos));

Expand Down
13 changes: 11 additions & 2 deletions articlewebview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,17 @@ bool ArticleWebView::eventFilter(QObject *obj, QEvent *ev) {

void ArticleWebView::mousePressEvent(QMouseEvent *event)
{
if (event->buttons() & Qt::MiddleButton)
midButtonPressed = true;
if( event->buttons() & Qt::MiddleButton )
midButtonPressed = true;

if( event->buttons() & Qt::XButton1 )
{
back();
}
if( event->buttons() & Qt::XButton2 )
{
forward();
}
}

void ArticleWebView::singleClickAction(QMouseEvent *event )
Expand Down
44 changes: 22 additions & 22 deletions dictheadwords.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,9 @@ DictHeadwords::DictHeadwords( QWidget *parent, Config::Class & cfg_,

ui.matchCase->setChecked( cfg.headwordsDialog.matchCase );

model = new HeadwordListModel( this );
model = new QStringListModel( this );
model->setStringList( headers );

connect(model,&HeadwordListModel::finished,this,[this](){
ui.exportButton->setEnabled(true);
ui.progressBar->hide();
});
proxy = new QSortFilterProxyModel( this );

proxy->setSourceModel( model );
Expand Down Expand Up @@ -137,12 +134,16 @@ void DictHeadwords::setup( Dictionary::Class *dict_ )

setWindowTitle( QString::fromUtf8( dict->getName().c_str() ) );

auto size = dict->getWordCount();
model->setDict(dict);
headers.clear();
model->setStringList( headers );

dict->getHeadwords( headers );
model->setStringList( headers );

proxy->sort( 0 );
filterChanged();

if( size > AUTO_APPLY_LIMIT )
if( headers.size() > AUTO_APPLY_LIMIT )
{
cfg.headwordsDialog.autoApply = ui.autoApply->isChecked();
ui.autoApply->setChecked( false );
Expand All @@ -154,7 +155,6 @@ void DictHeadwords::setup( Dictionary::Class *dict_ )
ui.autoApply->setChecked( cfg.headwordsDialog.autoApply );
}

ui.exportButton->setEnabled(false);
ui.applyButton->setEnabled( !ui.autoApply->isChecked() );

setWindowIcon( dict->getIcon() );
Expand All @@ -169,7 +169,7 @@ void DictHeadwords::savePos()
cfg.headwordsDialog.searchMode = ui.searchModeCombo->currentIndex();
cfg.headwordsDialog.matchCase = ui.matchCase->isChecked();

if( model->totalCount() <= AUTO_APPLY_LIMIT )
if( headers.size() <= AUTO_APPLY_LIMIT )
cfg.headwordsDialog.autoApply = ui.autoApply->isChecked();

cfg.headwordsDialog.headwordsDialogGeometry = saveGeometry();
Expand Down Expand Up @@ -226,15 +226,12 @@ void DictHeadwords::filterChanged()
QString pattern;
switch( syntax )
{
case QRegExp::FixedString:
pattern = QRegularExpression::escape( ui.filterLine->text() );
break;
case QRegExp::WildcardUnix:
pattern = wildcardsToRegexp( ui.filterLine->text() );
break;
default:
pattern = ui.filterLine->text();
break;
case QRegExp::FixedString: pattern = QRegularExpression::escape( ui.filterLine->text() );
break;
case QRegExp::WildcardUnix: pattern = wildcardsToRegexp( ui.filterLine->text() );
break;
default: pattern = ui.filterLine->text();
break;
}

QRegularExpression regExp( pattern, options );
Expand All @@ -248,6 +245,8 @@ void DictHeadwords::filterChanged()
QApplication::setOverrideCursor( Qt::WaitCursor );

proxy->setFilterRegularExpression( regExp );


proxy->sort( 0 );

QApplication::restoreOverrideCursor();
Expand All @@ -273,7 +272,8 @@ void DictHeadwords::autoApplyStateChanged( int state )
void DictHeadwords::showHeadwordsNumber()
{
ui.headersNumber->setText( tr( "Unique headwords total: %1, filtered: %2" )
.arg( QString::number( model->totalCount() ), QString::number( proxy->rowCount() ) ) );
.arg( QString::number( headers.size() ) )
.arg( QString::number( proxy->rowCount() ) ) );
}

void DictHeadwords::saveHeadersToFile()
Expand Down Expand Up @@ -303,7 +303,7 @@ void DictHeadwords::saveHeadersToFile()
if ( !file.open( QFile::WriteOnly | QIODevice::Text ) )
break;

int headwordsNumber = model->totalCount();
int headwordsNumber = proxy->rowCount();

// Setup progress dialog
int n = headwordsNumber;
Expand Down Expand Up @@ -335,7 +335,7 @@ void DictHeadwords::saveHeadersToFile()
if( progress.wasCanceled() )
break;

QVariant value = model->getRow(i);
QVariant value = proxy->data( proxy->index( i, 0 ) );
if( !value.canConvert< QString >() )
continue;

Expand Down
5 changes: 2 additions & 3 deletions dictheadwords.hh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "dictionary.hh"
#include "delegate.hh"
#include "helpwindow.hh"
#include "headwordslistmodel.h"

class DictHeadwords : public QDialog
{
Expand All @@ -30,8 +29,8 @@ public:
protected:
Config::Class & cfg;
Dictionary::Class * dict;

HeadwordListModel * model;
QStringList headers;
QStringListModel * model;
QSortFilterProxyModel * proxy;
WordListItemDelegate * delegate;
QString dictId;
Expand Down
81 changes: 34 additions & 47 deletions dictheadwords.ui
Original file line number Diff line number Diff line change
Expand Up @@ -19,46 +19,6 @@
<item row="3" column="0">
<widget class="QListView" name="headersListView"/>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="autoApply">
<property name="toolTip">
<string>If checked any filter changes will we immediately applied to headwords list</string>
</property>
<property name="text">
<string>Auto apply</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLineEdit" name="filterLine">
<property name="toolTip">
<string>Filter string (fixed string, wildcards or regular expression)</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Filter:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="applyButton">
<property name="toolTip">
<string>Press this button to apply filter to headwords list</string>
</property>
<property name="text">
<string>Apply</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="1">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
Expand Down Expand Up @@ -135,17 +95,44 @@
</item>
</layout>
</item>
<item row="4" column="0">
<widget class="QProgressBar" name="progressBar">
<property name="maximum">
<number>0</number>
<item row="2" column="1">
<widget class="QPushButton" name="applyButton">
<property name="toolTip">
<string>Press this button to apply filter to headwords list</string>
</property>
<property name="value">
<number>-1</number>
<property name="text">
<string>Apply</string>
</property>
<property name="invertedAppearance">
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="autoApply">
<property name="toolTip">
<string>If checked any filter changes will we immediately applied to headwords list</string>
</property>
<property name="text">
<string>Auto apply</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Filter:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLineEdit" name="filterLine">
<property name="toolTip">
<string>Filter string (fixed string, wildcards or regular expression)</string>
</property>
</widget>
</item>
</layout>
Expand Down
2 changes: 0 additions & 2 deletions goldendict.pro
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ DEFINES += PROGRAM_VERSION=\\\"$$VERSION\\\"
HEADERS += folding.hh \
article_inspect.h \
globalbroadcaster.h \
headwordslistmodel.h \
inc_case_folding.hh \
inc_diacritic_folding.hh \
mainwindow.hh \
Expand Down Expand Up @@ -367,7 +366,6 @@ FORMS += groups.ui \
SOURCES += folding.cc \
article_inspect.cpp \
globalbroadcaster.cpp \
headwordslistmodel.cpp \
main.cc \
dictionary.cc \
config.cc \
Expand Down
Loading

0 comments on commit 327d1b4

Please sign in to comment.