Merge pull request #849 from shenlebantongying/no_SIGNAL

clean: convert `MainWindow::addGlobalAction` SLOT to new syntax
This commit is contained in:
xiaoyifang 2023-06-11 18:33:02 +08:00 committed by GitHub
commit 4722193048
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 8 deletions

View file

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

View file

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