clean: convert MainWindow::addGlobalAction SLOT to new syntax

Historical context: `MainWindow::addGlobalAction` was invented by

https://github.com/goldendict/goldendict/pull/482/files
This commit is contained in:
shenleban tongying 2023-06-11 03:44:07 -04:00
parent ca4664f209
commit f14d28d193
No known key found for this signature in database
2 changed files with 19 additions and 8 deletions

View file

@ -382,21 +382,31 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
trayIconMenu.addSeparator(); trayIconMenu.addSeparator();
connect( trayIconMenu.addAction( tr( "&Quit" ) ), &QAction::triggered, this, &MainWindow::quitApp ); connect( trayIconMenu.addAction( tr( "&Quit" ) ), &QAction::triggered, this, &MainWindow::quitApp );
addGlobalAction( &escAction, SLOT( handleEsc() ) ); addGlobalAction( &escAction, [ this ]() {
handleEsc();
} );
escAction.setShortcut( QKeySequence( "Esc" ) ); escAction.setShortcut( QKeySequence( "Esc" ) );
addGlobalAction( &focusTranslateLineAction, SLOT( focusTranslateLine() ) ); addGlobalAction( &focusTranslateLineAction, [ this ]() {
focusTranslateLine();
} );
focusTranslateLineAction.setShortcuts( QList< QKeySequence >() << focusTranslateLineAction.setShortcuts( QList< QKeySequence >() <<
QKeySequence( "Alt+D" ) << QKeySequence( "Alt+D" ) <<
QKeySequence( "Ctrl+L" ) ); QKeySequence( "Ctrl+L" ) );
addGlobalAction( &focusHeadwordsDlgAction, SLOT( focusHeadwordsDialog() ) ); addGlobalAction( &focusHeadwordsDlgAction, [ this ]() {
focusHeadwordsDialog();
} );
focusHeadwordsDlgAction.setShortcut( QKeySequence( "Ctrl+D" ) ); focusHeadwordsDlgAction.setShortcut( QKeySequence( "Ctrl+D" ) );
addGlobalAction( &focusArticleViewAction, SLOT( focusArticleView() ) ); addGlobalAction( &focusArticleViewAction, [ this ]() {
focusArticleView();
} );
focusArticleViewAction.setShortcut( QKeySequence( "Ctrl+N" ) ); focusArticleViewAction.setShortcut( QKeySequence( "Ctrl+N" ) );
addGlobalAction( ui.fullTextSearchAction, SLOT( showFullTextSearchDialog() ) ); addGlobalAction( ui.fullTextSearchAction, [ this ]() {
showFullTextSearchDialog();
} );
addTabAction.setShortcutContext( Qt::WidgetWithChildrenShortcut ); addTabAction.setShortcutContext( Qt::WidgetWithChildrenShortcut );
addTabAction.setShortcut( QKeySequence( "Ctrl+T" ) ); addTabAction.setShortcut( QKeySequence( "Ctrl+T" ) );
@ -1122,10 +1132,10 @@ MainWindow::~MainWindow()
#endif #endif
} }
void MainWindow::addGlobalAction( QAction * action, const char * slot ) void MainWindow::addGlobalAction( QAction * action, const std::function< void() > & slotFunc )
{ {
action->setShortcutContext( Qt::WidgetWithChildrenShortcut ); action->setShortcutContext( Qt::WidgetWithChildrenShortcut );
connect( action, SIGNAL( triggered() ), this, slot ); connect( action, &QAction::triggered, this, slotFunc );
ui.centralWidget->addAction( action ); ui.centralWidget->addAction( action );
ui.dictsPane->addAction( action ); ui.dictsPane->addAction( action );

View file

@ -10,6 +10,7 @@
#include <QSystemTrayIcon> #include <QSystemTrayIcon>
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QProgressDialog> #include <QProgressDialog>
#include <functional>
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
#include "config.hh" #include "config.hh"
#include "dict/dictionary.hh" #include "dict/dictionary.hh"
@ -68,7 +69,7 @@ public slots:
void quitApp(); void quitApp();
private: private:
void addGlobalAction( QAction * action, const char * slot ); void addGlobalAction( QAction * action, const std::function< void() > & slotFunc );
void addGlobalActionsToDialog( QDialog * dialog ); void addGlobalActionsToDialog( QDialog * dialog );
void addGroupComboBoxActionsToDialog( QDialog * dialog, GroupComboBox * pGroupComboBox ); void addGroupComboBoxActionsToDialog( QDialog * dialog, GroupComboBox * pGroupComboBox );
void removeGroupComboBoxActionsFromDialog( QDialog * dialog, GroupComboBox * pGroupComboBox ); void removeGroupComboBoxActionsFromDialog( QDialog * dialog, GroupComboBox * pGroupComboBox );