From a71efecbcc6f714d619a922a0eaa665a3c68a3b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCri=20Valdmann?= Date: Mon, 12 Jun 2017 15:57:31 +0200 Subject: Update Simple Browser example - Accept downloads and add a downloads list. - Fix toolbar icons being pixelated on hidpi screens by - enabling attribute AA_UseHighDpiPixmaps, and - replacing the 22x22 icons with 32x32 versions. - Move favicon selection to WebView to reduce duplication. - Replace UrlLineEdit with a standard QLineEdit using a QAction for the favicon and setClearButtonEnabled(true) for the clear button. - Fix bug where the "File -> New Tab" action would create background tabs because the QAction::triggered(bool) signal was connected to the TabWidget::createTab(bool) slot with the bool argument having a completely different meaning between the two. - Make the toolbar unmovable. Nobody wants to move the toolbar. - Add tooltips to toolbar buttons. - Add tooltips to the tab bar (page titles). - Stop adding icons to menu items only to disable them right after. Task-number: QTBUG-60655 Change-Id: I10cc0fa82dbf39281bbdbbf9ef901e1b26402f80 Reviewed-by: Leena Miettinen Reviewed-by: Michal Klocek --- .../webenginewidgets/simplebrowser/tabwidget.cpp | 52 +++++++++------------- 1 file changed, 21 insertions(+), 31 deletions(-) (limited to 'examples/webenginewidgets/simplebrowser/tabwidget.cpp') diff --git a/examples/webenginewidgets/simplebrowser/tabwidget.cpp b/examples/webenginewidgets/simplebrowser/tabwidget.cpp index a7f855c2a..c9fb32d83 100644 --- a/examples/webenginewidgets/simplebrowser/tabwidget.cpp +++ b/examples/webenginewidgets/simplebrowser/tabwidget.cpp @@ -56,9 +56,8 @@ TabWidget::TabWidget(QWidget *parent) connect(tabBar, &QTabBar::customContextMenuRequested, this, &TabWidget::handleContextMenuRequested); connect(tabBar, &QTabBar::tabCloseRequested, this, &TabWidget::closeTab); connect(tabBar, &QTabBar::tabBarDoubleClicked, [this](int index) { - if (index != -1) - return; - createTab(); + if (index == -1) + createTab(); }); setDocumentMode(true); @@ -67,10 +66,6 @@ TabWidget::TabWidget(QWidget *parent) connect(this, &QTabWidget::currentChanged, this, &TabWidget::handleCurrentChanged); } -TabWidget::~TabWidget() -{ -} - void TabWidget::handleCurrentChanged(int index) { if (index != -1) { @@ -80,11 +75,7 @@ void TabWidget::handleCurrentChanged(int index) emit titleChanged(view->title()); emit loadProgress(view->loadProgress()); emit urlChanged(view->url()); - QIcon pageIcon = view->page()->icon(); - if (!pageIcon.isNull()) - emit iconChanged(pageIcon); - else - emit iconChanged(QIcon(QStringLiteral(":defaulticon.png"))); + emit favIconChanged(view->favIcon()); emit webActionEnabledChanged(QWebEnginePage::Back, view->isWebActionEnabled(QWebEnginePage::Back)); emit webActionEnabledChanged(QWebEnginePage::Forward, view->isWebActionEnabled(QWebEnginePage::Forward)); emit webActionEnabledChanged(QWebEnginePage::Stop, view->isWebActionEnabled(QWebEnginePage::Stop)); @@ -93,7 +84,7 @@ void TabWidget::handleCurrentChanged(int index) emit titleChanged(QString()); emit loadProgress(0); emit urlChanged(QUrl()); - emit iconChanged(QIcon(QStringLiteral(":defaulticon.png"))); + emit favIconChanged(QIcon()); emit webActionEnabledChanged(QWebEnginePage::Back, false); emit webActionEnabledChanged(QWebEnginePage::Forward, false); emit webActionEnabledChanged(QWebEnginePage::Stop, false); @@ -150,8 +141,10 @@ void TabWidget::setupView(WebView *webView) connect(webView, &QWebEngineView::titleChanged, [this, webView](const QString &title) { int index = indexOf(webView); - if (index != -1) + if (index != -1) { setTabText(index, title); + setTabToolTip(index, title); + } if (currentIndex() == index) emit titleChanged(title); }); @@ -170,26 +163,17 @@ void TabWidget::setupView(WebView *webView) if (currentIndex() == indexOf(webView)) emit linkHovered(url); }); - connect(webPage, &WebPage::iconChanged, [this, webView](const QIcon &icon) { + connect(webView, &WebView::favIconChanged, [this, webView](const QIcon &icon) { int index = indexOf(webView); - QIcon ico = icon.isNull() ? QIcon(QStringLiteral(":defaulticon.png")) : icon; - if (index != -1) - setTabIcon(index, ico); + setTabIcon(index, icon); if (currentIndex() == index) - emit iconChanged(ico); + emit favIconChanged(icon); }); connect(webView, &WebView::webActionEnabledChanged, [this, webView](QWebEnginePage::WebAction action, bool enabled) { if (currentIndex() == indexOf(webView)) emit webActionEnabledChanged(action,enabled); }); - connect(webView, &QWebEngineView::loadStarted, [this, webView]() { - int index = indexOf(webView); - if (index != -1) { - QIcon icon(QLatin1String(":view-refresh.png")); - setTabIcon(index, icon); - } - }); connect(webPage, &QWebEnginePage::windowCloseRequested, [this, webView]() { int index = indexOf(webView); if (index >= 0) @@ -197,15 +181,21 @@ void TabWidget::setupView(WebView *webView) }); } -WebView *TabWidget::createTab(bool makeCurrent) +WebView *TabWidget::createTab() +{ + WebView *webView = createBackgroundTab(); + setCurrentWidget(webView); + return webView; +} + +WebView *TabWidget::createBackgroundTab() { WebView *webView = new WebView; WebPage *webPage = new WebPage(QWebEngineProfile::defaultProfile(), webView); webView->setPage(webPage); setupView(webView); - addTab(webView, tr("(Untitled)")); - if (makeCurrent) - setCurrentWidget(webView); + int index = addTab(webView, tr("(Untitled)")); + setTabIcon(index, webView->favIcon()); return webView; } @@ -239,7 +229,7 @@ void TabWidget::closeTab(int index) void TabWidget::cloneTab(int index) { if (WebView *view = webView(index)) { - WebView *tab = createTab(false); + WebView *tab = createTab(); tab->setUrl(view->url()); } } -- cgit v1.2.1