summaryrefslogtreecommitdiffstats
path: root/examples/webenginewidgets
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2019-07-18 12:43:02 +0200
committerKirill Burtsev <kirill.burtsev@qt.io>2019-08-29 18:29:23 +0200
commit759085eb6ae57bc9c2bc35095798501824482da3 (patch)
tree5d9fbada06794f45b58ce74319e10820ff3a4ce2 /examples/webenginewidgets
parent299993a4f60325fc5e70deff7b7734cf6bb0ede5 (diff)
Fix snippet in notification example
QDoc couldn't find the lines asked for. Also switch example to Qt coding style for good measure. Change-Id: I8798d4e85011cb1f46ea9a051f205dc2f650eccb Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io> Reviewed-by: Kirill Burtsev <kirill.burtsev@qt.io> Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'examples/webenginewidgets')
-rw-r--r--examples/webenginewidgets/notifications/doc/src/notifications.qdoc28
-rw-r--r--examples/webenginewidgets/notifications/main.cpp19
-rw-r--r--examples/webenginewidgets/notifications/notificationpopup.h15
3 files changed, 34 insertions, 28 deletions
diff --git a/examples/webenginewidgets/notifications/doc/src/notifications.qdoc b/examples/webenginewidgets/notifications/doc/src/notifications.qdoc
index 2c999e7e1..ec932f90c 100644
--- a/examples/webenginewidgets/notifications/doc/src/notifications.qdoc
+++ b/examples/webenginewidgets/notifications/doc/src/notifications.qdoc
@@ -44,22 +44,22 @@
In this example, we create an internal HTML page that is added through
a resource collection file (.qrc). The page displays buttons for requesting
- permissions and creating a notification. In addition, it contains JavaScript
- logic for triggering these actions.
+ permissions and contains necessary JavaScript code to trigger this request:
\quotefromfile webenginewidgets/notifications/data/index.html
\skipto Notification.requestPermission
\printline requestPermission
- \dots
- \skipto if
- \printuntil createNotification()
- \printline /^})$/
+ \skipuntil resetPermission
+ \printuntil /\}\)$/
+
+ Also page contains a button for creating a notification. The following
+ JavaScript constructions are executed on the press event:
\quotefromfile webenginewidgets/notifications/data/index.html
\skipto createNotification()
- \printuntil Notification
- \dots
- \printline /^})$/
+ \printuntil new Notification
+ \skipuntil Notification was created
+ \printline }
\section1 Main Function
@@ -127,7 +127,8 @@
\skipto QWebEngineNotification::closed
\printuntil QTimer
- \printline /^\}/
+ \skipto /\}/
+ \printline /\}/
\section2 Closing Active Notification
@@ -138,9 +139,7 @@
destroy the notification object through the \c std::unique_ptr::reset() method.
\skipto onClosed
- \dots
- \skipto hide()
- \printuntil reset
+ \printuntil }
\section2 Implementing User Interaction
@@ -152,5 +151,6 @@
\skipto mouseReleaseEvent
\printuntil onClosed
- \printuntil /^\}/
+ \printline /\}$/
+ \printline /\}$/
*/
diff --git a/examples/webenginewidgets/notifications/main.cpp b/examples/webenginewidgets/notifications/main.cpp
index 661b82ff5..c3039b9e0 100644
--- a/examples/webenginewidgets/notifications/main.cpp
+++ b/examples/webenginewidgets/notifications/main.cpp
@@ -56,11 +56,13 @@
#include <QWebEngineProfile>
#include <QWebEngineView>
-class WebEnginePage : public QWebEnginePage {
+class WebEnginePage : public QWebEnginePage
+{
public:
WebEnginePage(QWidget *parent) : QWebEnginePage(parent) { }
- bool acceptNavigationRequest(const QUrl &url, NavigationType, bool) override {
+ bool acceptNavigationRequest(const QUrl &url, NavigationType, bool) override
+ {
if (url.scheme() != "https")
return true;
QDesktopServices::openUrl(url);
@@ -81,16 +83,15 @@ int main(int argc, char *argv[])
QObject::connect(view.page(), &QWebEnginePage::featurePermissionRequested,
[&] (const QUrl &origin, QWebEnginePage::Feature feature) {
- if (feature != QWebEnginePage::Notifications)
- return;
- view.page()->setFeaturePermission(origin, feature, QWebEnginePage::PermissionGrantedByUser);
- });
+ if (feature != QWebEnginePage::Notifications)
+ return;
+ view.page()->setFeaturePermission(origin, feature, QWebEnginePage::PermissionGrantedByUser);
+ });
auto profile = view.page()->profile();
auto popup = new NotificationPopup(&view);
- profile->setNotificationPresenter([&] (std::unique_ptr<QWebEngineNotification> notification) {
- popup->present(notification);
- });
+ profile->setNotificationPresenter([&] (std::unique_ptr<QWebEngineNotification> notification)
+ { popup->present(notification); });
view.resize(640, 480);
view.show();
diff --git a/examples/webenginewidgets/notifications/notificationpopup.h b/examples/webenginewidgets/notifications/notificationpopup.h
index fcbb003b9..d211c7996 100644
--- a/examples/webenginewidgets/notifications/notificationpopup.h
+++ b/examples/webenginewidgets/notifications/notificationpopup.h
@@ -61,14 +61,16 @@
#include <memory>
-class NotificationPopup : public QWidget {
+class NotificationPopup : public QWidget
+{
Q_OBJECT
QLabel m_icon, m_title, m_message;
std::unique_ptr<QWebEngineNotification> notification;
public:
- NotificationPopup(QWidget *parent) : QWidget(parent) {
+ NotificationPopup(QWidget *parent) : QWidget(parent)
+ {
setWindowFlags(Qt::ToolTip);
auto rootLayout = new QHBoxLayout(this);
@@ -91,7 +93,8 @@ public:
adjustSize();
}
- void present(std::unique_ptr<QWebEngineNotification> &newNotification) {
+ void present(std::unique_ptr<QWebEngineNotification> &newNotification)
+ {
if (notification) {
notification->close();
notification.reset();
@@ -114,14 +117,16 @@ public:
}
protected slots:
- void onClosed() {
+ void onClosed()
+ {
hide();
notification->close();
notification.reset();
}
protected:
- void mouseReleaseEvent(QMouseEvent *event) override {
+ void mouseReleaseEvent(QMouseEvent *event) override
+ {
QWidget::mouseReleaseEvent(event);
if (notification && event->button() == Qt::LeftButton) {
notification->click();