From 54bba79c60aacdac451f55ec384f1fede15d7f0b Mon Sep 17 00:00:00 2001 From: Abs62 Date: Mon, 10 Sep 2012 20:23:58 +0400 Subject: [PATCH] Allow history import during history review --- mainwindow.cc | 44 ++++++++++++++++++++++++++------------------ mainwindow.hh | 2 ++ 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/mainwindow.cc b/mainwindow.cc index a26eb24b..4ba229ba 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -2653,11 +2653,9 @@ static bool needHideSearchPane; ui.wordList->clear(); history.enableAdd( true ); - ui.importHistory->setDisabled( false ); } else { - ui.importHistory->setDisabled( true ); history.enableAdd( false ); disconnect( ui.translateLine, SIGNAL( textChanged( QString const & ) ), @@ -2679,22 +2677,7 @@ static bool needHideSearchPane; ui.translateLine->setProperty( "noResults", true ); setStyleSheet( styleSheet() ); - ui.wordList->setUpdatesEnabled( false ); - ui.wordList->clear(); - - QList< History::Item > const & items = history.getItems(); - for( int x = 0; x < items.size(); ++x ) - { - History::Item const * i = &items[ x ]; - QListWidgetItem * s = new QListWidgetItem( i->word, ui.wordList ); - if (s->text().at(0).direction() == QChar::DirR) - s->setTextAlignment(Qt::AlignRight); - if (s->text().at(0).direction() == QChar::DirL) - s->setTextAlignment(Qt::AlignLeft); - ui.wordList->addItem( s ); - } - - ui.wordList->setUpdatesEnabled( true ); + fillWordListFromHistory(); } } @@ -2785,8 +2768,14 @@ void MainWindow::on_importHistory_activated() } while( !fileStream.atEnd() && itemList.size() < (int)history.getMaxSize() ); + history.enableAdd( true ); for( QList< QString >::const_iterator i = itemList.constBegin(); i != itemList.constEnd(); ++i ) history.addItem( History::Item( 1, *i ) ); + if( showHistory ) + { + history.enableAdd( false ); + fillWordListFromHistory(); + } if( file.error() != QFile::NoError ) break; @@ -2805,3 +2794,22 @@ void MainWindow::on_importHistory_activated() mainStatusBar->showMessage( errStr, 10000, QPixmap( ":/icons/error.png" ) ); } +void MainWindow::fillWordListFromHistory() +{ + ui.wordList->setUpdatesEnabled( false ); + ui.wordList->clear(); + + QList< History::Item > const & items = history.getItems(); + for( int x = 0; x < items.size(); ++x ) + { + History::Item const * i = &items[ x ]; + QListWidgetItem * s = new QListWidgetItem( i->word, ui.wordList ); + if (s->text().at(0).direction() == QChar::DirR) + s->setTextAlignment(Qt::AlignRight); + if (s->text().at(0).direction() == QChar::DirL) + s->setTextAlignment(Qt::AlignLeft); + ui.wordList->addItem( s ); + } + + ui.wordList->setUpdatesEnabled( true ); +} diff --git a/mainwindow.hh b/mainwindow.hh index 0f64c279..f665e1e0 100644 --- a/mainwindow.hh +++ b/mainwindow.hh @@ -174,6 +174,8 @@ private: ArticleView * getCurrentArticleView(); void ctrlTabPressed(); + void fillWordListFromHistory(); + private slots: void hotKeyActivated( int );