From 6f192dca6e778a8043268e09ddadb16c77a5b1a0 Mon Sep 17 00:00:00 2001 From: Tvangeste Date: Tue, 7 Jun 2011 13:27:19 +0200 Subject: [PATCH] Enable/disable Back and Forward buttons depending on the history. This is a standard behavior for any history-enabled app (like web browser). When there is no previous or next item in the history, the appropriate button on the toolbar is disabled. --- articleview.cc | 14 +++++++++++++- articleview.hh | 3 +++ mainwindow.cc | 15 +++++++++++++++ mainwindow.hh | 2 ++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/articleview.cc b/articleview.cc index ce2b9430..8acc1ae8 100644 --- a/articleview.cc +++ b/articleview.cc @@ -790,11 +790,23 @@ void ArticleView::updateMutedContents() } } +bool ArticleView::canGoBack() +{ + // First entry in a history is always an empty page, + // so we skip it. + return ui.definition->history()->currentItemIndex() > 1; +} + +bool ArticleView::canGoForward() +{ + return ui.definition->history()->canGoForward(); +} + void ArticleView::back() { // Don't allow navigating back to page 0, which is usually the initial // empty page - if ( ui.definition->history()->currentItemIndex() > 1 ) + if ( canGoBack() ) { saveHistoryUserData(); ui.definition->back(); diff --git a/articleview.hh b/articleview.hh index 23e9c5dd..76f36dd2 100644 --- a/articleview.hh +++ b/articleview.hh @@ -101,6 +101,9 @@ public: /// The function reloads content if the change affects it. void updateMutedContents(); + bool canGoBack(); + bool canGoForward(); + public slots: /// Goes back in history diff --git a/mainwindow.cc b/mainwindow.cc index cd3ab2ce..b3317eee 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -975,6 +975,8 @@ void MainWindow::iconChanged( ArticleView * view, QIcon const & icon ) void MainWindow::pageLoaded( ArticleView * view ) { + updateBackForwardButtons(); + updatePronounceAvailability(); if ( cfg.preferences.pronounceOnLoadMain ) @@ -985,6 +987,7 @@ void MainWindow::pageLoaded( ArticleView * view ) void MainWindow::tabSwitched( int ) { + updateBackForwardButtons(); updatePronounceAvailability(); updateFoundInDictsList(); } @@ -1065,6 +1068,16 @@ void MainWindow::updateFoundInDictsList() } } +void MainWindow::updateBackForwardButtons() +{ + if ( QWidget * cw = ui.tabWidget->currentWidget() ) + { + ArticleView & view = dynamic_cast< ArticleView & >( *( cw ) ); + navBack->setEnabled(view.canGoBack()); + navForward->setEnabled(view.canGoForward()); + } +} + void MainWindow::updatePronounceAvailability() { bool pronounceEnabled = ui.tabWidget->count() > 0 && @@ -1555,6 +1568,8 @@ void MainWindow::showTranslationFor( QString const & inWord, history.addItem( History::Item( group, inWord.trimmed() ) ); history.save(); + updateBackForwardButtons(); + #if 0 QUrl req; diff --git a/mainwindow.hh b/mainwindow.hh index bfcee33f..b97cdbcf 100644 --- a/mainwindow.hh +++ b/mainwindow.hh @@ -126,6 +126,8 @@ private: void updateFoundInDictsList(); + void updateBackForwardButtons(); + /// Updates word search request and active article view in response to /// muting or unmuting dictionaries, or showing/hiding dictionary bar. void applyMutedDictionariesState();