summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2019-09-24 12:03:59 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2019-09-24 13:03:43 +0200
commit52345f558f55e04ea68a8fa30d9862ca69131a18 (patch)
tree3bd9da3e6842af2d0b9c04b46693c66ab437fd2e /examples
parent16192598a84eaf9ac9a50b7cca6ac5e4c21bb5e8 (diff)
parentd8fe250e542519012247952a034e78b0d492b730 (diff)
Merge remote-tracking branch 'origin/5.13' into 5.14
Conflicts: config.tests/glibc/glibc.cpp src/3rdparty src/core/configure.json src/core/profile_io_data_qt.cpp src/webengine/configure.json src/webenginewidgets/api/qwebenginepage.cpp tests/auto/widgets/qwebenginepage/BLACKLIST Change-Id: I3e1781048c3cb09bfbf7427dfc5dd1fec11a2b97
Diffstat (limited to 'examples')
-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();