diff options
Diffstat (limited to 'src/mainwindow.cpp')
-rw-r--r-- | src/mainwindow.cpp | 29 |
1 files changed, 21 insertions, 8 deletions
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 <QMenu>
+#include <QCloseEvent>
+#include <QMessageBox>
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());
}
|