summaryrefslogtreecommitdiffstats
path: root/examples/webenginewidgets
diff options
context:
space:
mode:
authorSzabolcs David <davidsz@inf.u-szeged.hu>2015-10-26 06:06:25 -0700
committerSzabolcs David <davidsz@inf.u-szeged.hu>2015-10-30 13:48:47 +0000
commit22da1274f0dd9cf7211fdca21e9634a85ae25430 (patch)
tree3e9b10b8d49e5b766976173c476c4740d3b44045 /examples/webenginewidgets
parentb4c9c02e736b70572d30311e080a3d5cdf9ca154 (diff)
Fullscreen notification popup for Widgets demobrowser
Change-Id: I3afc0399e4156cd17917103face68ca1945409f9 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com>
Diffstat (limited to 'examples/webenginewidgets')
-rw-r--r--examples/webenginewidgets/demobrowser/demobrowser.pro2
-rw-r--r--examples/webenginewidgets/demobrowser/fullscreennotification.cpp112
-rw-r--r--examples/webenginewidgets/demobrowser/fullscreennotification.h76
-rw-r--r--examples/webenginewidgets/demobrowser/tabwidget.cpp19
-rw-r--r--examples/webenginewidgets/demobrowser/tabwidget.h2
5 files changed, 208 insertions, 3 deletions
diff --git a/examples/webenginewidgets/demobrowser/demobrowser.pro b/examples/webenginewidgets/demobrowser/demobrowser.pro
index 14347de71..113eeb40e 100644
--- a/examples/webenginewidgets/demobrowser/demobrowser.pro
+++ b/examples/webenginewidgets/demobrowser/demobrowser.pro
@@ -28,6 +28,7 @@ HEADERS += \
edittableview.h \
edittreeview.h \
featurepermissionbar.h\
+ fullscreennotification.h \
history.h \
modelmenu.h \
searchlineedit.h \
@@ -49,6 +50,7 @@ SOURCES += \
edittableview.cpp \
edittreeview.cpp \
featurepermissionbar.cpp\
+ fullscreennotification.cpp \
history.cpp \
modelmenu.cpp \
searchlineedit.cpp \
diff --git a/examples/webenginewidgets/demobrowser/fullscreennotification.cpp b/examples/webenginewidgets/demobrowser/fullscreennotification.cpp
new file mode 100644
index 000000000..8ee968bec
--- /dev/null
+++ b/examples/webenginewidgets/demobrowser/fullscreennotification.cpp
@@ -0,0 +1,112 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "fullscreennotification.h"
+
+#include <QApplication>
+#include <QDesktopWidget>
+#include <QGridLayout>
+#include <QLabel>
+#include <QPropertyAnimation>
+#include <QTimer>
+
+FullScreenNotification::FullScreenNotification(QWidget *parent)
+ : QWidget(parent)
+ , width(400)
+ , height(80)
+ , x((parent->geometry().width() - width) / 2)
+ , y(80)
+{
+ setVisible(false);
+ setWindowFlags(Qt::ToolTip | Qt::WindowDoesNotAcceptFocus);
+
+ QGridLayout *layout = new QGridLayout(this);
+
+ m_label = new QLabel(tr("You are now in fullscreen mode. Press ESC to quit!"), this);
+ layout->addWidget(m_label, 0, 0, 0, 0, Qt::AlignHCenter | Qt::AlignVCenter);
+
+ setGeometry(x, y, width, height);
+
+ setStyleSheet("background-color: white;\
+ color: black;");
+
+ m_animation = new QPropertyAnimation(this, "windowOpacity");
+ connect(m_animation, SIGNAL(finished()), this, SLOT(fadeOutFinished()));
+}
+
+FullScreenNotification::~FullScreenNotification()
+{
+}
+
+void FullScreenNotification::show()
+{
+ setWindowOpacity(1.0);
+ QTimer::singleShot(300, [&] {
+ QWidget *parent = parentWidget();
+ x = (parent->geometry().width() - width) / 2;
+ QPoint topLeft = parent->mapToGlobal(QPoint(x, y));
+ QWidget::move(topLeft.x(), topLeft.y());
+ QWidget::show();
+ QWidget::raise();
+ });
+ QTimer::singleShot(5000, this, SLOT(fadeOut()));
+}
+
+void FullScreenNotification::hide()
+{
+ QWidget::hide();
+ m_animation->stop();
+}
+
+void FullScreenNotification::fadeOut()
+{
+ m_animation->setDuration(800);
+ m_animation->setStartValue(1.0);
+ m_animation->setEndValue(0.0);
+ m_animation->setEasingCurve(QEasingCurve::OutQuad);
+ m_animation->start();
+}
+
+void FullScreenNotification::fadeOutFinished()
+{
+ hide();
+ setWindowOpacity(1.0);
+}
diff --git a/examples/webenginewidgets/demobrowser/fullscreennotification.h b/examples/webenginewidgets/demobrowser/fullscreennotification.h
new file mode 100644
index 000000000..051075ab3
--- /dev/null
+++ b/examples/webenginewidgets/demobrowser/fullscreennotification.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef FULLSCREENNOTIFICATION_H
+#define FULLSCREENNOTIFICATION_H
+
+#include <QWidget>
+
+class QLabel;
+class QGridLayout;
+class QPropertyAnimation;
+
+class FullScreenNotification : public QWidget
+{
+ Q_OBJECT
+public:
+ FullScreenNotification(QWidget *parent = 0);
+ ~FullScreenNotification();
+
+ void show();
+ void hide();
+
+public slots:
+ void fadeOut();
+ void fadeOutFinished();
+
+private:
+ QLabel *m_label;
+ QGridLayout *m_layout;
+ QPropertyAnimation *m_animation;
+ int width;
+ int height;
+ int x;
+ int y;
+};
+
+
+#endif // FULLSCREENNOTIFICATION_H
diff --git a/examples/webenginewidgets/demobrowser/tabwidget.cpp b/examples/webenginewidgets/demobrowser/tabwidget.cpp
index 4e2073b11..3b2069858 100644
--- a/examples/webenginewidgets/demobrowser/tabwidget.cpp
+++ b/examples/webenginewidgets/demobrowser/tabwidget.cpp
@@ -44,6 +44,7 @@
#include "browserapplication.h"
#include "browsermainwindow.h"
#include "downloadmanager.h"
+#include "fullscreennotification.h"
#include "history.h"
#include "urllineedit.h"
#include "webview.h"
@@ -88,6 +89,7 @@ TabBar::TabBar(QWidget *parent)
TabWidget::~TabWidget()
{
+ delete m_fullScreenNotification;
delete m_fullScreenView;
}
@@ -220,6 +222,7 @@ TabWidget::TabWidget(QWidget *parent)
, m_tabBar(new TabBar(this))
, m_profile(QWebEngineProfile::defaultProfile())
, m_fullScreenView(0)
+ , m_fullScreenNotification(0)
{
setElideMode(Qt::ElideRight);
@@ -355,23 +358,33 @@ void TabWidget::currentChanged(int index)
void TabWidget::fullScreenRequested(const QWebEngineFullScreenRequest &request)
{
+ WebPage *webPage = qobject_cast<WebPage*>(sender());
if (request.toggleOn()) {
- if (!m_fullScreenView)
+ if (!m_fullScreenView) {
m_fullScreenView = new QWebEngineView();
- WebPage *webPage = qobject_cast<WebPage*>(sender());
+ m_fullScreenNotification = new FullScreenNotification(m_fullScreenView);
+
+ QAction *exitFullScreenAction = new QAction(m_fullScreenView);
+ exitFullScreenAction->setShortcut(Qt::Key_Escape);
+ connect(exitFullScreenAction, &QAction::triggered, [webPage] {
+ webPage->triggerAction(QWebEnginePage::ExitFullScreen);
+ });
+ m_fullScreenView->addAction(exitFullScreenAction);
+ }
webPage->setView(m_fullScreenView);
request.accept();
m_fullScreenView->showFullScreen();
m_fullScreenView->raise();
+ m_fullScreenNotification->show();
} else {
if (!m_fullScreenView)
return;
- WebPage *webPage = qobject_cast<WebPage*>(sender());
WebView *oldWebView = this->webView(m_lineEdits->currentIndex());
webPage->setView(oldWebView);
request.accept();
raise();
m_fullScreenView->hide();
+ m_fullScreenNotification->hide();
}
}
diff --git a/examples/webenginewidgets/demobrowser/tabwidget.h b/examples/webenginewidgets/demobrowser/tabwidget.h
index 3a1fe7171..f71ac398a 100644
--- a/examples/webenginewidgets/demobrowser/tabwidget.h
+++ b/examples/webenginewidgets/demobrowser/tabwidget.h
@@ -129,6 +129,7 @@ private:
#include <QtCore/QUrl>
#include <QtWidgets/QTabWidget>
QT_BEGIN_NAMESPACE
+class FullScreenNotification;
class QCompleter;
class QLineEdit;
class QMenu;
@@ -235,6 +236,7 @@ private:
TabBar *m_tabBar;
QWebEngineProfile *m_profile;
QWebEngineView *m_fullScreenView;
+ FullScreenNotification *m_fullScreenNotification;
};
#endif // TABWIDGET_H