From 94ea03c25d322812592a7684cb70a0c31a327772 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Wed, 11 Jan 2017 21:32:43 +0100 Subject: Minor changes Tabs now show the icon of the webpage Warning box when closing multiple tabs --- src/mainwindow.cpp | 29 +++++++++++++++++++++-------- src/mainwindow.h | 3 +++ src/widgets/webviewtabbar.cpp | 4 ++++ 3 files changed, 28 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 91d098f..763d192 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2,6 +2,8 @@ #include "ui_mainwindow.h" #include "settings.h" #include +#include +#include MainWindow::MainWindow(QUrl defaultUrl, QWidget *parent) : QMainWindow(parent), @@ -12,16 +14,17 @@ MainWindow::MainWindow(QUrl defaultUrl, QWidget *parent) : urlLineEdit(new QLineEdit(navigationToolBar)) { Settings settings; - settings.beginGroup("defaults"); ui->setupUi(this); - resize(settings.value("width", 800).toInt(), settings.value("height", 600).toInt()); + resize(settings.value("window/width", 800).toInt(), settings.value("window/height", 600).toInt()); // Populate the menu bar // Browser menu - with new window, new tab, open and quit - QMenu *browserMenu = new QMenu(tr("Browser"), ui->menuBar); - browserMenu->addAction(tr("Quit"), qApp, SLOT(quit()), QKeySequence(tr("Ctrl+Q"))); + QMenu *browserMenu = new QMenu(qApp->applicationName(), ui->menuBar); browserMenu->addAction(tr("New Tab"), this, SLOT(createNewTab()), QKeySequence(tr("Ctrl+T"))); + browserMenu->addAction(tr("New Window")); + browserMenu->addSeparator(); + browserMenu->addAction(tr("Quit"), qApp, SLOT(quit()), QKeySequence(tr("Ctrl+Q"))); ui->menuBar->addMenu(browserMenu); // View menu - fullscreen // Page menu - what page actions? @@ -40,9 +43,7 @@ MainWindow::MainWindow(QUrl defaultUrl, QWidget *parent) : if(!defaultUrl.isEmpty()) createNewTab(defaultUrl); else - createNewTab(settings.value("url", QUrl("http://duckduckgo.com")).toUrl()); - - settings.endGroup(); // "defaults" + createNewTab(settings.value("defaults/url", QUrl("http://duckduckgo.com")).toUrl()); } MainWindow::~MainWindow() @@ -57,6 +58,18 @@ void MainWindow::createNewTab(const QUrl &url) tabBar->addTab(view); } +void MainWindow::closeEvent(QCloseEvent *event) +{ + if(tabBar->count() > 1) { + int ret = QMessageBox::warning(this, tr("Close window?"), tr("Close multiple tabs?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No); + if(ret == QMessageBox::No) { + event->ignore(); + return; + } + } + QMainWindow::closeEvent(event); +} + void MainWindow::handleTabChanged(QWebEngineView *view) { centralWidget()->setParent(0); @@ -81,5 +94,5 @@ void MainWindow::handleUrlUpdated(const QUrl &url) void MainWindow::handleTitleUpdated(const QString &title) { Settings settings; - setWindowTitle(title + settings.value("defaults/title", "qtwebenginebrowser").toString()); + setWindowTitle(title + settings.value("window/title", "qtwebenginebrowser").toString()); } diff --git a/src/mainwindow.h b/src/mainwindow.h index 0ad24b0..48ce43f 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -23,6 +23,9 @@ public: public slots: void createNewTab(const QUrl &url = QUrl("")); +protected: + void closeEvent(QCloseEvent *event) override; + private slots: void handleTabChanged(QWebEngineView *view); void handleUrlChanged(); diff --git a/src/widgets/webviewtabbar.cpp b/src/widgets/webviewtabbar.cpp index 59e5c69..efc8fef 100644 --- a/src/widgets/webviewtabbar.cpp +++ b/src/widgets/webviewtabbar.cpp @@ -23,6 +23,10 @@ int WebViewTabBar::addTab(QWebEngineView *view) int index = m_views.indexOf(view); setTabText(index, title); }); + connect(view, &QWebEngineView::iconChanged, [this, view](const QIcon &icon) { + int index = m_views.indexOf(view); + setTabIcon(index, icon); + }); return QTabBar::addTab("New Tab"); } -- cgit v1.2.1