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 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'src/mainwindow.cpp') 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()); } -- cgit v1.2.1