diff options
Diffstat (limited to 'examples/webenginewidgets')
7 files changed, 79 insertions, 37 deletions
diff --git a/examples/webenginewidgets/demobrowser/downloaditem.ui b/examples/webenginewidgets/demobrowser/downloaditem.ui index b7f7deb72..e506f28b6 100644 --- a/examples/webenginewidgets/demobrowser/downloaditem.ui +++ b/examples/webenginewidgets/demobrowser/downloaditem.ui @@ -13,7 +13,16 @@ <string>Form</string> </property> <layout class="QHBoxLayout" name="horizontalLayout" > - <property name="margin" > + <property name="leftMargin"> + <number>5</number> + </property> + <property name="topMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>5</number> + </property> + <property name="bottomMargin"> <number>0</number> </property> <item> diff --git a/examples/webenginewidgets/demobrowser/fullscreennotification.h b/examples/webenginewidgets/demobrowser/fullscreennotification.h index 051075ab3..f515bfecb 100644 --- a/examples/webenginewidgets/demobrowser/fullscreennotification.h +++ b/examples/webenginewidgets/demobrowser/fullscreennotification.h @@ -44,9 +44,11 @@ #include <QWidget> +QT_BEGIN_NAMESPACE class QLabel; class QGridLayout; class QPropertyAnimation; +QT_END_NAMESPACE class FullScreenNotification : public QWidget { @@ -72,5 +74,4 @@ private: int y; }; - #endif // FULLSCREENNOTIFICATION_H diff --git a/examples/webenginewidgets/demobrowser/searchlineedit.cpp b/examples/webenginewidgets/demobrowser/searchlineedit.cpp index 5152ac1c0..1573b1046 100644 --- a/examples/webenginewidgets/demobrowser/searchlineedit.cpp +++ b/examples/webenginewidgets/demobrowser/searchlineedit.cpp @@ -45,7 +45,7 @@ #include <QtGui/QMouseEvent> #include <QtWidgets/QMenu> #include <QtWidgets/QStyle> -#include <QtWidgets/QStyleOptionFrameV2> +#include <QtWidgets/QStyleOptionFrame> ClearButton::ClearButton(QWidget *parent) : QAbstractButton(parent) @@ -181,7 +181,7 @@ void SearchLineEdit::paintEvent(QPaintEvent *event) { if (lineEdit()->text().isEmpty() && !hasFocus() && !m_inactiveText.isEmpty()) { ExLineEdit::paintEvent(event); - QStyleOptionFrameV2 panel; + QStyleOptionFrame panel; initStyleOption(&panel); QRect r = style()->subElementRect(QStyle::SE_LineEditContents, &panel, this); QFontMetrics fm = fontMetrics(); diff --git a/examples/webenginewidgets/demobrowser/tabwidget.cpp b/examples/webenginewidgets/demobrowser/tabwidget.cpp index 23903e88a..b744fad90 100644 --- a/examples/webenginewidgets/demobrowser/tabwidget.cpp +++ b/examples/webenginewidgets/demobrowser/tabwidget.cpp @@ -171,7 +171,17 @@ void TabBar::mousePressEvent(QMouseEvent *event) { if (event->button() == Qt::LeftButton) m_dragStartPos = event->pos(); + QTabBar::mousePressEvent(event); + + // Middle click on tab should close it. + if (event->button() == Qt::MiddleButton) { + const QPoint pos = event->pos(); + int index = tabAt(pos); + if (index != -1) { + emit closeTab(index); + } + } } void TabBar::mouseMoveEvent(QMouseEvent *event) @@ -259,6 +269,7 @@ TabWidget::TabWidget(QWidget *parent) connect(m_tabBar, SIGNAL(reloadTab(int)), this, SLOT(reloadTab(int))); connect(m_tabBar, SIGNAL(reloadAllTabs()), this, SLOT(reloadAllTabs())); connect(m_tabBar, SIGNAL(tabMoved(int,int)), this, SLOT(moveTab(int,int))); + connect(m_tabBar, SIGNAL(tabBarDoubleClicked(int)), this, SLOT(handleTabBarDoubleClicked(int))); connect(m_tabBar, SIGNAL(muteTab(int,bool)), this, SLOT(setAudioMutedForTab(int,bool))); setTabBar(m_tabBar); setDocumentMode(true); @@ -427,6 +438,12 @@ void TabWidget::fullScreenRequested(QWebEngineFullScreenRequest request) } } +void TabWidget::handleTabBarDoubleClicked(int index) +{ + if (index != -1) return; + newTab(); +} + QAction *TabWidget::newTabAction() const { return m_newTabAction; @@ -500,6 +517,36 @@ int TabWidget::webViewIndex(WebView *webView) const return index; } +void TabWidget::setupPage(QWebEnginePage* page) +{ + connect(page, SIGNAL(windowCloseRequested()), + this, SLOT(windowCloseRequested())); + connect(page, SIGNAL(geometryChangeRequested(QRect)), + this, SIGNAL(geometryChangeRequested(QRect))); +#if defined(QWEBENGINEPAGE_PRINTREQUESTED) + connect(page, SIGNAL(printRequested(QWebEngineFrame*)), + this, SIGNAL(printRequested(QWebEngineFrame*))); +#endif +#if defined(QWEBENGINEPAGE_MENUBARVISIBILITYCHANGEREQUESTED) + connect(page, SIGNAL(menuBarVisibilityChangeRequested(bool)), + this, SIGNAL(menuBarVisibilityChangeRequested(bool))); +#endif +#if defined(QWEBENGINEPAGE_STATUSBARVISIBILITYCHANGEREQUESTED) + connect(page, SIGNAL(statusBarVisibilityChangeRequested(bool)), + this, SIGNAL(statusBarVisibilityChangeRequested(bool))); +#endif +#if defined(QWEBENGINEPAGE_TOOLBARVISIBILITYCHANGEREQUESTED) + connect(page, SIGNAL(toolBarVisibilityChangeRequested(bool)), + this, SIGNAL(toolBarVisibilityChangeRequested(bool))); +#endif + + // webview actions + for (int i = 0; i < m_actions.count(); ++i) { + WebActionMapper *mapper = m_actions[i]; + mapper->addChild(page->action(mapper->webAction())); + } +} + WebView *TabWidget::newTab(bool makeCurrent) { // line edit @@ -551,35 +598,13 @@ WebView *TabWidget::newTab(bool makeCurrent) this, SLOT(webPageMutedOrAudibleChanged())); connect(webView, SIGNAL(urlChanged(QUrl)), this, SLOT(webViewUrlChanged(QUrl))); - connect(webView->page(), SIGNAL(windowCloseRequested()), - this, SLOT(windowCloseRequested())); - connect(webView->page(), SIGNAL(geometryChangeRequested(QRect)), - this, SIGNAL(geometryChangeRequested(QRect))); -#if defined(QWEBENGINEPAGE_PRINTREQUESTED) - connect(webView->page(), SIGNAL(printRequested(QWebEngineFrame*)), - this, SIGNAL(printRequested(QWebEngineFrame*))); -#endif -#if defined(QWEBENGINEPAGE_MENUBARVISIBILITYCHANGEREQUESTED) - connect(webView->page(), SIGNAL(menuBarVisibilityChangeRequested(bool)), - this, SIGNAL(menuBarVisibilityChangeRequested(bool))); -#endif -#if defined(QWEBENGINEPAGE_STATUSBARVISIBILITYCHANGEREQUESTED) - connect(webView->page(), SIGNAL(statusBarVisibilityChangeRequested(bool)), - this, SIGNAL(statusBarVisibilityChangeRequested(bool))); -#endif -#if defined(QWEBENGINEPAGE_TOOLBARVISIBILITYCHANGEREQUESTED) - connect(webView->page(), SIGNAL(toolBarVisibilityChangeRequested(bool)), - this, SIGNAL(toolBarVisibilityChangeRequested(bool))); -#endif + + addTab(webView, tr("(Untitled)")); if (makeCurrent) setCurrentWidget(webView); - // webview actions - for (int i = 0; i < m_actions.count(); ++i) { - WebActionMapper *mapper = m_actions[i]; - mapper->addChild(webView->page()->action(mapper->webAction())); - } + setupPage(webView->page()); if (count() == 1) currentChanged(currentIndex()); @@ -685,6 +710,7 @@ void TabWidget::setProfile(QWebEngineProfile *profile) QWidget *tabWidget = widget(i); if (WebView *tab = qobject_cast<WebView*>(tabWidget)) { WebPage* webPage = new WebPage(m_profile, tab); + setupPage(webPage); webPage->load(tab->page()->url()); tab->setPage(webPage); } diff --git a/examples/webenginewidgets/demobrowser/tabwidget.h b/examples/webenginewidgets/demobrowser/tabwidget.h index f4ad9c02d..c6eef58f9 100644 --- a/examples/webenginewidgets/demobrowser/tabwidget.h +++ b/examples/webenginewidgets/demobrowser/tabwidget.h @@ -131,13 +131,16 @@ private: #include <QtCore/QUrl> #include <QtWidgets/QTabWidget> -QT_BEGIN_NAMESPACE + class FullScreenNotification; + +QT_BEGIN_NAMESPACE class QCompleter; class QLineEdit; class QMenu; class QStackedWidget; QT_END_NAMESPACE + /*! TabWidget that contains WebViews and a stack widget of associated line edits. @@ -222,9 +225,12 @@ private slots: void windowCloseRequested(); void moveTab(int fromIndex, int toIndex); void fullScreenRequested(QWebEngineFullScreenRequest request); + void handleTabBarDoubleClicked(int index); void webPageMutedOrAudibleChanged(); private: + void setupPage(QWebEnginePage* page); + QAction *m_recentlyClosedTabsAction; QAction *m_newTabAction; QAction *m_closeTabAction; diff --git a/examples/webenginewidgets/demobrowser/urllineedit.cpp b/examples/webenginewidgets/demobrowser/urllineedit.cpp index 685277d9c..0f4e59c4b 100644 --- a/examples/webenginewidgets/demobrowser/urllineedit.cpp +++ b/examples/webenginewidgets/demobrowser/urllineedit.cpp @@ -57,7 +57,7 @@ #include <QtGui/QDrag> #include <QtGui/QPainter> #include <QtWidgets/QStyle> -#include <QtWidgets/QStyleOptionFrameV2> +#include <QtWidgets/QStyleOptionFrame> #include <QtCore/QDebug> @@ -112,7 +112,7 @@ void ExLineEdit::resizeEvent(QResizeEvent *event) void ExLineEdit::updateGeometries() { - QStyleOptionFrameV2 panel; + QStyleOptionFrame panel; initStyleOption(&panel); QRect rect = style()->subElementRect(QStyle::SE_LineEditContents, &panel, this); @@ -131,7 +131,7 @@ void ExLineEdit::updateGeometries() clearButtonWidth, this->height()); } -void ExLineEdit::initStyleOption(QStyleOptionFrameV2 *option) const +void ExLineEdit::initStyleOption(QStyleOptionFrame *option) const { option->initFrom(this); option->rect = contentsRect(); @@ -144,7 +144,7 @@ void ExLineEdit::initStyleOption(QStyleOptionFrameV2 *option) const if (hasEditFocus()) option->state |= QStyle::State_HasEditFocus; #endif - option->features = QStyleOptionFrameV2::None; + option->features = QStyleOptionFrame::None; } QSize ExLineEdit::sizeHint() const @@ -189,7 +189,7 @@ bool ExLineEdit::event(QEvent *event) void ExLineEdit::paintEvent(QPaintEvent *) { QPainter p(this); - QStyleOptionFrameV2 panel; + QStyleOptionFrame panel; initStyleOption(&panel); style()->drawPrimitive(QStyle::PE_PanelLineEdit, &panel, &p, this); } @@ -322,7 +322,7 @@ void UrlLineEdit::paintEvent(QPaintEvent *event) ExLineEdit::paintEvent(event); QPainter painter(this); - QStyleOptionFrameV2 panel; + QStyleOptionFrame panel; initStyleOption(&panel); QRect backgroundRect = style()->subElementRect(QStyle::SE_LineEditContents, &panel, this); if (m_webView && !hasFocus()) { diff --git a/examples/webenginewidgets/demobrowser/urllineedit.h b/examples/webenginewidgets/demobrowser/urllineedit.h index 775aa7d18..b9f2cff7c 100644 --- a/examples/webenginewidgets/demobrowser/urllineedit.h +++ b/examples/webenginewidgets/demobrowser/urllineedit.h @@ -77,7 +77,7 @@ protected: protected: void updateGeometries(); - void initStyleOption(QStyleOptionFrameV2 *option) const; + void initStyleOption(QStyleOptionFrame *option) const; QWidget *m_leftWidget; QLineEdit *m_lineEdit; |