From 759085eb6ae57bc9c2bc35095798501824482da3 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Thu, 18 Jul 2019 12:43:02 +0200 Subject: 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 Reviewed-by: Kirill Burtsev Reviewed-by: Allan Sandfeld Jensen --- .../notifications/doc/src/notifications.qdoc | 28 +++++++++++----------- examples/webenginewidgets/notifications/main.cpp | 19 ++++++++------- .../notifications/notificationpopup.h | 15 ++++++++---- 3 files changed, 34 insertions(+), 28 deletions(-) (limited to 'examples/webenginewidgets') 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 #include -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 notification) { - popup->present(notification); - }); + profile->setNotificationPresenter([&] (std::unique_ptr 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 -class NotificationPopup : public QWidget { +class NotificationPopup : public QWidget +{ Q_OBJECT QLabel m_icon, m_title, m_message; std::unique_ptr 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 &newNotification) { + void present(std::unique_ptr &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(); -- cgit v1.2.3