mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
opt: add Ctrl+Shift+S to stop the current playing sound
[autofix.ci] apply automated fixes
This commit is contained in:
parent
dc1d720ac1
commit
0683afa2b0
|
@ -54,7 +54,9 @@ void AudioService::playMemory( const char * ptr, int size )
|
||||||
emit cancelPlaying( false );
|
emit cancelPlaying( false );
|
||||||
QByteArray audioData( ptr, size );
|
QByteArray audioData( ptr, size );
|
||||||
thread = std::make_shared< DecoderThread >( audioData, this );
|
thread = std::make_shared< DecoderThread >( audioData, this );
|
||||||
|
connect( this, &AudioService::cancelPlaying, thread.get(), [ this ]( bool waitFinished ) {
|
||||||
|
thread->cancel( waitFinished );
|
||||||
|
} );
|
||||||
thread->start();
|
thread->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1433,6 +1433,11 @@ void ArticleView::playSound()
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ArticleView::stopSound()
|
||||||
|
{
|
||||||
|
audioPlayer->stop();
|
||||||
|
}
|
||||||
|
|
||||||
void ArticleView::toHtml( const std::function< void( QString & ) > & callback )
|
void ArticleView::toHtml( const std::function< void( QString & ) > & callback )
|
||||||
{
|
{
|
||||||
webview->page()->toHtml( [ = ]( const QString & content ) {
|
webview->page()->toHtml( [ = ]( const QString & content ) {
|
||||||
|
|
|
@ -200,6 +200,8 @@ public:
|
||||||
/// Reloads the view
|
/// Reloads the view
|
||||||
void reload();
|
void reload();
|
||||||
|
|
||||||
|
void stopSound();
|
||||||
|
|
||||||
/// Returns true if there's an audio reference on the page, false otherwise.
|
/// Returns true if there's an audio reference on the page, false otherwise.
|
||||||
void hasSound( const std::function< void( bool has ) > & callback );
|
void hasSound( const std::function< void( bool has ) > & callback );
|
||||||
|
|
||||||
|
|
|
@ -149,6 +149,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
||||||
focusHeadwordsDlgAction( this ),
|
focusHeadwordsDlgAction( this ),
|
||||||
focusArticleViewAction( this ),
|
focusArticleViewAction( this ),
|
||||||
addAllTabToFavoritesAction( this ),
|
addAllTabToFavoritesAction( this ),
|
||||||
|
stopAudioAction( this ),
|
||||||
trayIconMenu( this ),
|
trayIconMenu( this ),
|
||||||
addTab( this ),
|
addTab( this ),
|
||||||
cfg( cfg_ ),
|
cfg( cfg_ ),
|
||||||
|
@ -428,6 +429,11 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
||||||
showFullTextSearchDialog();
|
showFullTextSearchDialog();
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
addGlobalAction( &stopAudioAction, [ this ]() {
|
||||||
|
stopAudio();
|
||||||
|
} );
|
||||||
|
stopAudioAction.setShortcut( QKeySequence( "Ctrl+Shift+S" ) );
|
||||||
|
|
||||||
addTabAction.setShortcutContext( Qt::WidgetWithChildrenShortcut );
|
addTabAction.setShortcutContext( Qt::WidgetWithChildrenShortcut );
|
||||||
addTabAction.setShortcut( QKeySequence( "Ctrl+T" ) );
|
addTabAction.setShortcut( QKeySequence( "Ctrl+T" ) );
|
||||||
|
|
||||||
|
@ -4023,14 +4029,20 @@ void MainWindow::focusHeadwordsDialog()
|
||||||
|
|
||||||
void MainWindow::focusArticleView()
|
void MainWindow::focusArticleView()
|
||||||
{
|
{
|
||||||
ArticleView * view = getCurrentArticleView();
|
if ( ArticleView * view = getCurrentArticleView() ) {
|
||||||
if ( view ) {
|
|
||||||
if ( !isActiveWindow() )
|
if ( !isActiveWindow() )
|
||||||
activateWindow();
|
activateWindow();
|
||||||
view->focus();
|
view->focus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::stopAudio()
|
||||||
|
{
|
||||||
|
if ( ArticleView * view = getCurrentArticleView() ) {
|
||||||
|
view->stopSound();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::editDictionary( Dictionary::Class * dict )
|
void MainWindow::editDictionary( Dictionary::Class * dict )
|
||||||
{
|
{
|
||||||
QString dictFilename = dict->getMainFilename();
|
QString dictFilename = dict->getMainFilename();
|
||||||
|
|
|
@ -109,6 +109,8 @@ private:
|
||||||
closeRestTabAction, switchToNextTabAction, switchToPrevTabAction, showDictBarNamesAction,
|
closeRestTabAction, switchToNextTabAction, switchToPrevTabAction, showDictBarNamesAction,
|
||||||
useSmallIconsInToolbarsAction, toggleMenuBarAction, focusHeadwordsDlgAction, focusArticleViewAction,
|
useSmallIconsInToolbarsAction, toggleMenuBarAction, focusHeadwordsDlgAction, focusArticleViewAction,
|
||||||
addAllTabToFavoritesAction;
|
addAllTabToFavoritesAction;
|
||||||
|
|
||||||
|
QAction stopAudioAction;
|
||||||
QToolBar * navToolbar;
|
QToolBar * navToolbar;
|
||||||
MainStatusBar * mainStatusBar;
|
MainStatusBar * mainStatusBar;
|
||||||
QAction *navBack, *navForward, *navPronounce, *enableScanningAction;
|
QAction *navBack, *navForward, *navPronounce, *enableScanningAction;
|
||||||
|
@ -454,6 +456,7 @@ private slots:
|
||||||
void focusHeadwordsDialog();
|
void focusHeadwordsDialog();
|
||||||
|
|
||||||
void focusArticleView();
|
void focusArticleView();
|
||||||
|
void stopAudio();
|
||||||
|
|
||||||
void proxyAuthentication( const QNetworkProxy & proxy, QAuthenticator * authenticator );
|
void proxyAuthentication( const QNetworkProxy & proxy, QAuthenticator * authenticator );
|
||||||
|
|
||||||
|
|
|
@ -77,6 +77,7 @@ ScanPopup::ScanPopup( QWidget * parent,
|
||||||
escapeAction( this ),
|
escapeAction( this ),
|
||||||
switchExpandModeAction( this ),
|
switchExpandModeAction( this ),
|
||||||
focusTranslateLineAction( this ),
|
focusTranslateLineAction( this ),
|
||||||
|
stopAudioAction( this ),
|
||||||
openSearchAction( this ),
|
openSearchAction( this ),
|
||||||
wordFinder( this ),
|
wordFinder( this ),
|
||||||
dictionaryBar( this, configEvents, cfg.editDictionaryCommandLine, cfg.preferences.maxDictionaryRefsInContextMenu ),
|
dictionaryBar( this, configEvents, cfg.editDictionaryCommandLine, cfg.preferences.maxDictionaryRefsInContextMenu ),
|
||||||
|
@ -212,6 +213,12 @@ ScanPopup::ScanPopup( QWidget * parent,
|
||||||
|
|
||||||
connect( &focusTranslateLineAction, &QAction::triggered, this, &ScanPopup::focusTranslateLine );
|
connect( &focusTranslateLineAction, &QAction::triggered, this, &ScanPopup::focusTranslateLine );
|
||||||
|
|
||||||
|
stopAudioAction.setShortcutContext( Qt::WidgetWithChildrenShortcut );
|
||||||
|
addAction( &stopAudioAction );
|
||||||
|
stopAudioAction.setShortcut( QKeySequence( "Ctrl+Shift+S" ) );
|
||||||
|
|
||||||
|
connect( &stopAudioAction, &QAction::triggered, this, &ScanPopup::stopAudio );
|
||||||
|
|
||||||
QAction * const focusArticleViewAction = new QAction( this );
|
QAction * const focusArticleViewAction = new QAction( this );
|
||||||
focusArticleViewAction->setShortcutContext( Qt::WidgetWithChildrenShortcut );
|
focusArticleViewAction->setShortcutContext( Qt::WidgetWithChildrenShortcut );
|
||||||
focusArticleViewAction->setShortcut( QKeySequence( "Ctrl+N" ) );
|
focusArticleViewAction->setShortcut( QKeySequence( "Ctrl+N" ) );
|
||||||
|
@ -313,7 +320,7 @@ ScanPopup::~ScanPopup()
|
||||||
ungrabGesture( Gestures::GDSwipeGestureType );
|
ungrabGesture( Gestures::GDSwipeGestureType );
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScanPopup::saveConfigData()
|
void ScanPopup::saveConfigData() const
|
||||||
{
|
{
|
||||||
// Save state, geometry and pin status
|
// Save state, geometry and pin status
|
||||||
cfg.popupWindowState = saveState();
|
cfg.popupWindowState = saveState();
|
||||||
|
@ -328,7 +335,7 @@ void ScanPopup::inspectElementWhenPinned( QWebEnginePage * page )
|
||||||
emit inspectSignal( page );
|
emit inspectSignal( page );
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScanPopup::applyZoomFactor()
|
void ScanPopup::applyZoomFactor() const
|
||||||
{
|
{
|
||||||
definition->setZoomFactor( cfg.preferences.zoomFactor );
|
definition->setZoomFactor( cfg.preferences.zoomFactor );
|
||||||
}
|
}
|
||||||
|
@ -649,7 +656,7 @@ void ScanPopup::translateInputFinished()
|
||||||
showTranslationFor( pendingWord );
|
showTranslationFor( pendingWord );
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScanPopup::showTranslationFor( QString const & word )
|
void ScanPopup::showTranslationFor( QString const & word ) const
|
||||||
{
|
{
|
||||||
ui.pronounceButton->setDisabled( true );
|
ui.pronounceButton->setDisabled( true );
|
||||||
|
|
||||||
|
@ -914,7 +921,7 @@ void ScanPopup::prefixMatchFinished()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScanPopup::on_pronounceButton_clicked()
|
void ScanPopup::on_pronounceButton_clicked() const
|
||||||
{
|
{
|
||||||
definition->playSound();
|
definition->playSound();
|
||||||
}
|
}
|
||||||
|
@ -966,6 +973,11 @@ void ScanPopup::focusTranslateLine()
|
||||||
ui.translateBox->translateLine()->selectAll();
|
ui.translateBox->translateLine()->selectAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScanPopup::stopAudio() const
|
||||||
|
{
|
||||||
|
definition->stopSound();
|
||||||
|
}
|
||||||
|
|
||||||
void ScanPopup::on_showDictionaryBar_clicked( bool checked )
|
void ScanPopup::on_showDictionaryBar_clicked( bool checked )
|
||||||
{
|
{
|
||||||
dictionaryBar.setVisible( checked );
|
dictionaryBar.setVisible( checked );
|
||||||
|
@ -979,7 +991,7 @@ void ScanPopup::hideTimerExpired()
|
||||||
hideWindow();
|
hideWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScanPopup::pageLoaded( ArticleView * )
|
void ScanPopup::pageLoaded( ArticleView * ) const
|
||||||
{
|
{
|
||||||
if ( !isVisible() )
|
if ( !isVisible() )
|
||||||
return;
|
return;
|
||||||
|
@ -992,7 +1004,7 @@ void ScanPopup::pageLoaded( ArticleView * )
|
||||||
updateBackForwardButtons();
|
updateBackForwardButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScanPopup::showStatusBarMessage( QString const & message, int timeout, QPixmap const & icon )
|
void ScanPopup::showStatusBarMessage( QString const & message, int timeout, QPixmap const & icon ) const
|
||||||
{
|
{
|
||||||
mainStatusBar->showMessage( message, timeout, icon );
|
mainStatusBar->showMessage( message, timeout, icon );
|
||||||
}
|
}
|
||||||
|
@ -1104,18 +1116,18 @@ void ScanPopup::switchExpandOptionalPartsMode()
|
||||||
emit switchExpandMode();
|
emit switchExpandMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScanPopup::updateBackForwardButtons()
|
void ScanPopup::updateBackForwardButtons() const
|
||||||
{
|
{
|
||||||
ui.goBackButton->setEnabled( definition->canGoBack() );
|
ui.goBackButton->setEnabled( definition->canGoBack() );
|
||||||
ui.goForwardButton->setEnabled( definition->canGoForward() );
|
ui.goForwardButton->setEnabled( definition->canGoForward() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScanPopup::on_goBackButton_clicked()
|
void ScanPopup::on_goBackButton_clicked() const
|
||||||
{
|
{
|
||||||
definition->back();
|
definition->back();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScanPopup::on_goForwardButton_clicked()
|
void ScanPopup::on_goForwardButton_clicked() const
|
||||||
{
|
{
|
||||||
definition->forward();
|
definition->forward();
|
||||||
}
|
}
|
||||||
|
@ -1127,7 +1139,7 @@ void ScanPopup::setDictionaryIconSize()
|
||||||
dictionaryBar.setDictionaryIconSize( extent );
|
dictionaryBar.setDictionaryIconSize( extent );
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScanPopup::setGroupByName( QString const & name )
|
void ScanPopup::setGroupByName( QString const & name ) const
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for ( i = 0; i < ui.groupList->count(); i++ ) {
|
for ( i = 0; i < ui.groupList->count(); i++ ) {
|
||||||
|
@ -1154,7 +1166,7 @@ void ScanPopup::alwaysOnTopClicked( bool checked )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScanPopup::titleChanged( ArticleView *, QString const & title )
|
void ScanPopup::titleChanged( ArticleView *, QString const & title ) const
|
||||||
{
|
{
|
||||||
unsigned groupId = ui.groupList->getCurrentGroup();
|
unsigned groupId = ui.groupList->getCurrentGroup();
|
||||||
|
|
||||||
|
|
|
@ -42,14 +42,14 @@ public:
|
||||||
|
|
||||||
/// Applies current zoom factor to the popup's view. Should be called when
|
/// Applies current zoom factor to the popup's view. Should be called when
|
||||||
/// it's changed.
|
/// it's changed.
|
||||||
void applyZoomFactor();
|
void applyZoomFactor() const;
|
||||||
void applyWordsZoomLevel();
|
void applyWordsZoomLevel();
|
||||||
/// Translate the word
|
/// Translate the word
|
||||||
void translateWord( QString const & word );
|
void translateWord( QString const & word );
|
||||||
|
|
||||||
void setDictionaryIconSize();
|
void setDictionaryIconSize();
|
||||||
|
|
||||||
void saveConfigData();
|
void saveConfigData() const;
|
||||||
|
|
||||||
#ifdef HAVE_X11
|
#ifdef HAVE_X11
|
||||||
/// Interaction with scan flag window
|
/// Interaction with scan flag window
|
||||||
|
@ -98,7 +98,7 @@ public slots:
|
||||||
/// From the dictionary bar.
|
/// From the dictionary bar.
|
||||||
void editGroupRequested();
|
void editGroupRequested();
|
||||||
|
|
||||||
void setGroupByName( QString const & name );
|
void setGroupByName( QString const & name ) const;
|
||||||
|
|
||||||
#ifdef HAVE_X11
|
#ifdef HAVE_X11
|
||||||
void showEngagePopup();
|
void showEngagePopup();
|
||||||
|
@ -131,6 +131,7 @@ private:
|
||||||
Ui::ScanPopup ui;
|
Ui::ScanPopup ui;
|
||||||
ArticleView * definition;
|
ArticleView * definition;
|
||||||
QAction escapeAction, switchExpandModeAction, focusTranslateLineAction;
|
QAction escapeAction, switchExpandModeAction, focusTranslateLineAction;
|
||||||
|
QAction stopAudioAction;
|
||||||
QAction openSearchAction;
|
QAction openSearchAction;
|
||||||
QString pendingWord; // Word that is going to be translated
|
QString pendingWord; // Word that is going to be translated
|
||||||
WordFinder wordFinder;
|
WordFinder wordFinder;
|
||||||
|
@ -186,23 +187,23 @@ private:
|
||||||
/// Returns inputWord, chopped with appended ... if it's too long/
|
/// Returns inputWord, chopped with appended ... if it's too long/
|
||||||
QString elideInputWord();
|
QString elideInputWord();
|
||||||
|
|
||||||
void updateBackForwardButtons();
|
void updateBackForwardButtons() const;
|
||||||
|
|
||||||
void showTranslationFor( QString const & inputPhrase );
|
void showTranslationFor( QString const & inputPhrase ) const;
|
||||||
|
|
||||||
void updateSuggestionList();
|
void updateSuggestionList();
|
||||||
void updateSuggestionList( QString const & text );
|
void updateSuggestionList( QString const & text );
|
||||||
private slots:
|
private slots:
|
||||||
void currentGroupChanged( int );
|
void currentGroupChanged( int );
|
||||||
void prefixMatchFinished();
|
void prefixMatchFinished();
|
||||||
void on_pronounceButton_clicked();
|
void on_pronounceButton_clicked() const;
|
||||||
void pinButtonClicked( bool checked );
|
void pinButtonClicked( bool checked );
|
||||||
void on_showDictionaryBar_clicked( bool checked );
|
void on_showDictionaryBar_clicked( bool checked );
|
||||||
void showStatusBarMessage( QString const &, int, QPixmap const & );
|
void showStatusBarMessage( QString const &, int, QPixmap const & ) const;
|
||||||
void on_sendWordButton_clicked();
|
void on_sendWordButton_clicked();
|
||||||
void on_sendWordToFavoritesButton_clicked();
|
void on_sendWordToFavoritesButton_clicked();
|
||||||
void on_goBackButton_clicked();
|
void on_goBackButton_clicked() const;
|
||||||
void on_goForwardButton_clicked();
|
void on_goForwardButton_clicked() const;
|
||||||
|
|
||||||
void hideTimerExpired();
|
void hideTimerExpired();
|
||||||
|
|
||||||
|
@ -212,7 +213,7 @@ private slots:
|
||||||
/// polling stops.
|
/// polling stops.
|
||||||
void mouseGrabPoll();
|
void mouseGrabPoll();
|
||||||
|
|
||||||
void pageLoaded( ArticleView * );
|
void pageLoaded( ArticleView * ) const;
|
||||||
|
|
||||||
void escapePressed();
|
void escapePressed();
|
||||||
|
|
||||||
|
@ -224,12 +225,13 @@ private slots:
|
||||||
void translateInputFinished();
|
void translateInputFinished();
|
||||||
|
|
||||||
void focusTranslateLine();
|
void focusTranslateLine();
|
||||||
|
void stopAudio() const;
|
||||||
|
|
||||||
void typingEvent( QString const & );
|
void typingEvent( QString const & );
|
||||||
|
|
||||||
void alwaysOnTopClicked( bool checked );
|
void alwaysOnTopClicked( bool checked );
|
||||||
|
|
||||||
void titleChanged( ArticleView *, QString const & title );
|
void titleChanged( ArticleView *, QString const & title ) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue