From 9d82ae46223aabefd266ce47ab927a22f0e31a7f Mon Sep 17 00:00:00 2001 From: Abs62 Date: Mon, 23 Mar 2015 18:58:49 +0300 Subject: [PATCH] Show headwords from dictionaries setup dialog in modal mode --- dictheadwords.cc | 38 +++++++++++++++++++++++++------------- dictheadwords.hh | 2 +- mainwindow.cc | 31 +++++++++++++++++++++++++++---- mainwindow.hh | 2 +- 4 files changed, 54 insertions(+), 19 deletions(-) diff --git a/dictheadwords.cc b/dictheadwords.cc index f8b96f90..143f78da 100644 --- a/dictheadwords.cc +++ b/dictheadwords.cc @@ -14,7 +14,7 @@ #define AUTO_APPLY_LIMIT 150000 DictHeadwords::DictHeadwords( QWidget *parent, Config::Class & cfg_, - Dictionary::Class * dict_ ) : + Dictionary::Class * dict_ ) : QDialog(parent) , cfg( cfg_ ) , dict( dict_ ) @@ -25,7 +25,11 @@ DictHeadwords::DictHeadwords( QWidget *parent, Config::Class & cfg_, if( cfg.headwordsDialog.headwordsDialogGeometry.size() > 0 ) restoreGeometry( cfg.headwordsDialog.headwordsDialogGeometry ); - setAttribute( Qt::WA_DeleteOnClose, false ); + bool fromMainWindow = parent->objectName() == "MainWindow"; + + if( fromMainWindow ) + setAttribute( Qt::WA_DeleteOnClose, false ); + setWindowFlags( windowFlags() & ~Qt::WindowContextHelpButtonHint ); ui.searchModeCombo->addItem( tr( "Text" ), QRegExp::FixedString ); @@ -65,6 +69,25 @@ DictHeadwords::DictHeadwords( QWidget *parent, Config::Class & cfg_, connect( this, SIGNAL( finished( int ) ), this, SLOT( savePos() ) ); + if( !fromMainWindow ) + { + ui.helpButton->hide(); + connect( this, SIGNAL( closeDialog() ), this, SLOT( accept() ) ); + } + else + { + connect( ui.helpButton, SIGNAL( clicked() ), + this, SLOT( helpRequested() ) ); + + helpAction.setShortcut( QKeySequence( "F1" ) ); + helpAction.setShortcutContext( Qt::WidgetWithChildrenShortcut ); + + connect( &helpAction, SIGNAL( triggered() ), + this, SLOT( helpRequested() ) ); + + addAction( &helpAction ); + } + connect( ui.OKButton, SIGNAL( clicked( bool ) ), this, SLOT( okButtonClicked() ) ); connect( ui.exportButton, SIGNAL( clicked( bool ) ), this, SLOT( exportButtonClicked() ) ); connect( ui.applyButton, SIGNAL( clicked( bool ) ), this, SLOT( filterChanged() ) ); @@ -85,17 +108,6 @@ DictHeadwords::DictHeadwords( QWidget *parent, Config::Class & cfg_, connect( proxy, SIGNAL( dataChanged( QModelIndex, QModelIndex ) ), this, SLOT( showHeadwordsNumber() ) ); - connect( ui.helpButton, SIGNAL( clicked() ), - this, SLOT( helpRequested() ) ); - - helpAction.setShortcut( QKeySequence( "F1" ) ); - helpAction.setShortcutContext( Qt::WidgetWithChildrenShortcut ); - - connect( &helpAction, SIGNAL( triggered() ), - this, SLOT( helpRequested() ) ); - - addAction( &helpAction ); - ui.headersListView->installEventFilter( this ); setup( dict_ ); diff --git a/dictheadwords.hh b/dictheadwords.hh index ae06fdd2..e2053cce 100644 --- a/dictheadwords.hh +++ b/dictheadwords.hh @@ -21,7 +21,7 @@ class DictHeadwords : public QDialog public: explicit DictHeadwords( QWidget * parent, Config::Class & cfg_, - Dictionary::Class * dict_ ); + Dictionary::Class * dict_ ); virtual ~DictHeadwords(); void setup( Dictionary::Class * dict_ ); diff --git a/mainwindow.cc b/mainwindow.cc index 0c23c27e..9d34f106 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -3738,6 +3738,14 @@ void MainWindow::foundDictsPaneClicked( QListWidgetItem * item ) void MainWindow::showDictionaryInfo( const QString & id ) { + QWidget * owner = 0; + + if( sender()->objectName().compare( "EditDictionaries" ) == 0 ) + owner = qobject_cast< QWidget * >( sender() ); + + if( owner == 0 ) + owner = this; + for( unsigned x = 0; x < dictionaries.size(); x++ ) { if( dictionaries[ x ]->getId() == id.toUtf8().data() ) @@ -3756,7 +3764,7 @@ void MainWindow::showDictionaryInfo( const QString & id ) } else if( result == DictInfo::SHOW_HEADWORDS ) { - showDictionaryHeadwords( dictionaries[x].get() ); + showDictionaryHeadwords( owner, dictionaries[x].get() ); } break; @@ -3766,18 +3774,33 @@ void MainWindow::showDictionaryInfo( const QString & id ) void MainWindow::showDictionaryHeadwords( const QString & id ) { + QWidget * owner = 0; + + if( sender()->objectName().compare( "EditDictionaries" ) == 0 ) + owner = qobject_cast< QWidget * >( sender() ); + + if( owner == 0 ) + owner = this; + for( unsigned x = 0; x < dictionaries.size(); x++ ) { if( dictionaries[ x ]->getId() == id.toUtf8().data() ) { - showDictionaryHeadwords( dictionaries[ x ].get() ); + showDictionaryHeadwords( owner, dictionaries[ x ].get() ); break; } } } -void MainWindow::showDictionaryHeadwords( Dictionary::Class * dict ) +void MainWindow::showDictionaryHeadwords( QWidget * owner, Dictionary::Class * dict ) { + if( owner && owner != this ) + { + DictHeadwords headwords( owner, cfg, dict ); + headwords.exec(); + return; + } + if( headwordsDlg == 0 ) { headwordsDlg = new DictHeadwords( this, cfg, dict ); @@ -3951,7 +3974,7 @@ void MainWindow::foundDictsContextMenuRequested( const QPoint &pos ) { if ( scanPopup ) scanPopup.get()->blockSignals( true ); - showDictionaryHeadwords( pDict ); + showDictionaryHeadwords( this, pDict ); if ( scanPopup ) scanPopup.get()->blockSignals( false ); } diff --git a/mainwindow.hh b/mainwindow.hh index e2c32b98..6012c1ac 100644 --- a/mainwindow.hh +++ b/mainwindow.hh @@ -237,7 +237,7 @@ private: void fillWordListFromHistory(); - void showDictionaryHeadwords( Dictionary::Class * dict ); + void showDictionaryHeadwords( QWidget * owner, Dictionary::Class * dict ); private slots: