opt: add Ctrl+Shift+S to stop the current playing sound

[autofix.ci] apply automated fixes
This commit is contained in:
YiFang Xiao 2023-08-24 22:10:38 +08:00
parent dc1d720ac1
commit 0683afa2b0
7 changed files with 63 additions and 25 deletions

View file

@ -54,7 +54,9 @@ void AudioService::playMemory( const char * ptr, int size )
emit cancelPlaying( false );
QByteArray audioData( ptr, size );
thread = std::make_shared< DecoderThread >( audioData, this );
connect( this, &AudioService::cancelPlaying, thread.get(), [ this ]( bool waitFinished ) {
thread->cancel( waitFinished );
} );
thread->start();
}

View file

@ -1433,6 +1433,11 @@ void ArticleView::playSound()
} );
}
void ArticleView::stopSound()
{
audioPlayer->stop();
}
void ArticleView::toHtml( const std::function< void( QString & ) > & callback )
{
webview->page()->toHtml( [ = ]( const QString & content ) {

View file

@ -200,6 +200,8 @@ public:
/// Reloads the view
void reload();
void stopSound();
/// Returns true if there's an audio reference on the page, false otherwise.
void hasSound( const std::function< void( bool has ) > & callback );

View file

@ -149,6 +149,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
focusHeadwordsDlgAction( this ),
focusArticleViewAction( this ),
addAllTabToFavoritesAction( this ),
stopAudioAction( this ),
trayIconMenu( this ),
addTab( this ),
cfg( cfg_ ),
@ -428,6 +429,11 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
showFullTextSearchDialog();
} );
addGlobalAction( &stopAudioAction, [ this ]() {
stopAudio();
} );
stopAudioAction.setShortcut( QKeySequence( "Ctrl+Shift+S" ) );
addTabAction.setShortcutContext( Qt::WidgetWithChildrenShortcut );
addTabAction.setShortcut( QKeySequence( "Ctrl+T" ) );
@ -4023,14 +4029,20 @@ void MainWindow::focusHeadwordsDialog()
void MainWindow::focusArticleView()
{
ArticleView * view = getCurrentArticleView();
if ( view ) {
if ( ArticleView * view = getCurrentArticleView() ) {
if ( !isActiveWindow() )
activateWindow();
view->focus();
}
}
void MainWindow::stopAudio()
{
if ( ArticleView * view = getCurrentArticleView() ) {
view->stopSound();
}
}
void MainWindow::editDictionary( Dictionary::Class * dict )
{
QString dictFilename = dict->getMainFilename();

View file

@ -109,6 +109,8 @@ private:
closeRestTabAction, switchToNextTabAction, switchToPrevTabAction, showDictBarNamesAction,
useSmallIconsInToolbarsAction, toggleMenuBarAction, focusHeadwordsDlgAction, focusArticleViewAction,
addAllTabToFavoritesAction;
QAction stopAudioAction;
QToolBar * navToolbar;
MainStatusBar * mainStatusBar;
QAction *navBack, *navForward, *navPronounce, *enableScanningAction;
@ -454,6 +456,7 @@ private slots:
void focusHeadwordsDialog();
void focusArticleView();
void stopAudio();
void proxyAuthentication( const QNetworkProxy & proxy, QAuthenticator * authenticator );

View file

@ -77,6 +77,7 @@ ScanPopup::ScanPopup( QWidget * parent,
escapeAction( this ),
switchExpandModeAction( this ),
focusTranslateLineAction( this ),
stopAudioAction( this ),
openSearchAction( this ),
wordFinder( this ),
dictionaryBar( this, configEvents, cfg.editDictionaryCommandLine, cfg.preferences.maxDictionaryRefsInContextMenu ),
@ -212,6 +213,12 @@ ScanPopup::ScanPopup( QWidget * parent,
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 );
focusArticleViewAction->setShortcutContext( Qt::WidgetWithChildrenShortcut );
focusArticleViewAction->setShortcut( QKeySequence( "Ctrl+N" ) );
@ -313,7 +320,7 @@ ScanPopup::~ScanPopup()
ungrabGesture( Gestures::GDSwipeGestureType );
}
void ScanPopup::saveConfigData()
void ScanPopup::saveConfigData() const
{
// Save state, geometry and pin status
cfg.popupWindowState = saveState();
@ -328,7 +335,7 @@ void ScanPopup::inspectElementWhenPinned( QWebEnginePage * page )
emit inspectSignal( page );
}
void ScanPopup::applyZoomFactor()
void ScanPopup::applyZoomFactor() const
{
definition->setZoomFactor( cfg.preferences.zoomFactor );
}
@ -649,7 +656,7 @@ void ScanPopup::translateInputFinished()
showTranslationFor( pendingWord );
}
void ScanPopup::showTranslationFor( QString const & word )
void ScanPopup::showTranslationFor( QString const & word ) const
{
ui.pronounceButton->setDisabled( true );
@ -914,7 +921,7 @@ void ScanPopup::prefixMatchFinished()
}
}
void ScanPopup::on_pronounceButton_clicked()
void ScanPopup::on_pronounceButton_clicked() const
{
definition->playSound();
}
@ -966,6 +973,11 @@ void ScanPopup::focusTranslateLine()
ui.translateBox->translateLine()->selectAll();
}
void ScanPopup::stopAudio() const
{
definition->stopSound();
}
void ScanPopup::on_showDictionaryBar_clicked( bool checked )
{
dictionaryBar.setVisible( checked );
@ -979,7 +991,7 @@ void ScanPopup::hideTimerExpired()
hideWindow();
}
void ScanPopup::pageLoaded( ArticleView * )
void ScanPopup::pageLoaded( ArticleView * ) const
{
if ( !isVisible() )
return;
@ -992,7 +1004,7 @@ void ScanPopup::pageLoaded( ArticleView * )
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 );
}
@ -1104,18 +1116,18 @@ void ScanPopup::switchExpandOptionalPartsMode()
emit switchExpandMode();
}
void ScanPopup::updateBackForwardButtons()
void ScanPopup::updateBackForwardButtons() const
{
ui.goBackButton->setEnabled( definition->canGoBack() );
ui.goForwardButton->setEnabled( definition->canGoForward() );
}
void ScanPopup::on_goBackButton_clicked()
void ScanPopup::on_goBackButton_clicked() const
{
definition->back();
}
void ScanPopup::on_goForwardButton_clicked()
void ScanPopup::on_goForwardButton_clicked() const
{
definition->forward();
}
@ -1127,7 +1139,7 @@ void ScanPopup::setDictionaryIconSize()
dictionaryBar.setDictionaryIconSize( extent );
}
void ScanPopup::setGroupByName( QString const & name )
void ScanPopup::setGroupByName( QString const & name ) const
{
int 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();

View file

@ -42,14 +42,14 @@ public:
/// Applies current zoom factor to the popup's view. Should be called when
/// it's changed.
void applyZoomFactor();
void applyZoomFactor() const;
void applyWordsZoomLevel();
/// Translate the word
void translateWord( QString const & word );
void setDictionaryIconSize();
void saveConfigData();
void saveConfigData() const;
#ifdef HAVE_X11
/// Interaction with scan flag window
@ -98,7 +98,7 @@ public slots:
/// From the dictionary bar.
void editGroupRequested();
void setGroupByName( QString const & name );
void setGroupByName( QString const & name ) const;
#ifdef HAVE_X11
void showEngagePopup();
@ -131,6 +131,7 @@ private:
Ui::ScanPopup ui;
ArticleView * definition;
QAction escapeAction, switchExpandModeAction, focusTranslateLineAction;
QAction stopAudioAction;
QAction openSearchAction;
QString pendingWord; // Word that is going to be translated
WordFinder wordFinder;
@ -186,23 +187,23 @@ private:
/// Returns inputWord, chopped with appended ... if it's too long/
QString elideInputWord();
void updateBackForwardButtons();
void updateBackForwardButtons() const;
void showTranslationFor( QString const & inputPhrase );
void showTranslationFor( QString const & inputPhrase ) const;
void updateSuggestionList();
void updateSuggestionList( QString const & text );
private slots:
void currentGroupChanged( int );
void prefixMatchFinished();
void on_pronounceButton_clicked();
void on_pronounceButton_clicked() const;
void pinButtonClicked( 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_sendWordToFavoritesButton_clicked();
void on_goBackButton_clicked();
void on_goForwardButton_clicked();
void on_goBackButton_clicked() const;
void on_goForwardButton_clicked() const;
void hideTimerExpired();
@ -212,7 +213,7 @@ private slots:
/// polling stops.
void mouseGrabPoll();
void pageLoaded( ArticleView * );
void pageLoaded( ArticleView * ) const;
void escapePressed();
@ -224,12 +225,13 @@ private slots:
void translateInputFinished();
void focusTranslateLine();
void stopAudio() const;
void typingEvent( QString const & );
void alwaysOnTopClicked( bool checked );
void titleChanged( ArticleView *, QString const & title );
void titleChanged( ArticleView *, QString const & title ) const;
};
#endif