diff options
author | Zeno Albisser <zeno.albisser@digia.com> | 2013-06-18 17:15:00 +0200 |
---|---|---|
committer | Zeno Albisser <zeno.albisser@digia.com> | 2013-06-18 17:48:21 +0200 |
commit | f1f5170c062c4a96dd986116631a6d8e1fb1d87f (patch) | |
tree | 5d4206785cf0300b894e84274fcd2f04f5777a91 | |
parent | cdb864f35e765cfef374cce18583fffff57359a3 (diff) |
Disable the back/forward buttons when appropriate.
-rw-r--r-- | examples/qtquick/quickwindow.qml | 2 | ||||
-rw-r--r-- | examples/widgets/widgetwindow.cpp | 6 | ||||
-rw-r--r-- | examples/widgets/widgetwindow.h | 2 | ||||
-rw-r--r-- | lib/qwebcontentsview.cpp | 10 | ||||
-rw-r--r-- | lib/qwebcontentsview.h | 2 |
5 files changed, 20 insertions, 2 deletions
diff --git a/examples/qtquick/quickwindow.qml b/examples/qtquick/quickwindow.qml index 7962be141..afaff7c8d 100644 --- a/examples/qtquick/quickwindow.qml +++ b/examples/qtquick/quickwindow.qml @@ -20,12 +20,14 @@ ApplicationWindow { iconName: "go-previous" iconSource: ":/icons/go-previous.png" onClicked: webContentsView.goBack() + enabled: webContentsView.canGoBack } ToolButton { id: forwardButton iconName: "go-next" iconSource: ":/icons/go-next.png" onClicked: webContentsView.goForward() + enabled: webContentsView.canGoForward } ToolButton { id: reloadButton diff --git a/examples/widgets/widgetwindow.cpp b/examples/widgets/widgetwindow.cpp index 589ef13c3..a28a6f130 100644 --- a/examples/widgets/widgetwindow.cpp +++ b/examples/widgets/widgetwindow.cpp @@ -63,11 +63,11 @@ WidgetWindow::WidgetWindow() QHBoxLayout* addressBar = new QHBoxLayout; addressBar->setSpacing(margin); // Bigger buttons, less space between them - QToolButton* backButton = new QToolButton; + backButton = new QToolButton; backButton->setIcon(QIcon::fromTheme("go-previous")); addressBar->addWidget(backButton); - QToolButton* forwardButton = new QToolButton; + forwardButton = new QToolButton; forwardButton->setIcon(QIcon::fromTheme("go-next")); addressBar->addWidget(forwardButton); @@ -117,5 +117,7 @@ void WidgetWindow::loadStarted() void WidgetWindow::loadFinished(bool success) { Q_UNUSED(success); + forwardButton->setEnabled(m_webView->canGoForward()); + backButton->setEnabled(m_webView->canGoBack()); reloadButton->setIcon(QIcon::fromTheme("view-refresh")); } diff --git a/examples/widgets/widgetwindow.h b/examples/widgets/widgetwindow.h index 5273d4255..863e8a73f 100644 --- a/examples/widgets/widgetwindow.h +++ b/examples/widgets/widgetwindow.h @@ -62,6 +62,8 @@ private Q_SLOTS: private: QScopedPointer<QWebContentsView> m_webView; QLineEdit* addressLineEdit; + QToolButton* forwardButton; + QToolButton* backButton; QToolButton* reloadButton; }; diff --git a/lib/qwebcontentsview.cpp b/lib/qwebcontentsview.cpp index 323bb3b60..07aa034d5 100644 --- a/lib/qwebcontentsview.cpp +++ b/lib/qwebcontentsview.cpp @@ -95,6 +95,16 @@ void QWebContentsView::load(const QUrl& url) d->webContentsDelegate->web_contents()->GetView()->Focus(); } +bool QWebContentsView::canGoBack() const +{ + return d->webContentsDelegate->web_contents()->GetController().CanGoBack(); +} + +bool QWebContentsView::canGoForward() const +{ + return d->webContentsDelegate->web_contents()->GetController().CanGoForward(); +} + void QWebContentsView::back() { d->webContentsDelegate->web_contents()->GetController().GoToOffset(-1); diff --git a/lib/qwebcontentsview.h b/lib/qwebcontentsview.h index 6eef056c7..83eefd59e 100644 --- a/lib/qwebcontentsview.h +++ b/lib/qwebcontentsview.h @@ -54,6 +54,8 @@ public: ~QWebContentsView(); void load(const QUrl& url); + bool canGoBack() const; + bool canGoForward() const; public Q_SLOTS: void back(); |