aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mainwindow.cpp29
-rw-r--r--src/mainwindow.h3
-rw-r--r--src/widgets/webviewtabbar.cpp4
-rw-r--r--test/config.ini4
4 files changed, 31 insertions, 9 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());
}
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");
}
diff --git a/test/config.ini b/test/config.ini
index 71e308d..0c40a5f 100644
--- a/test/config.ini
+++ b/test/config.ini
@@ -1,5 +1,7 @@
[defaults]
-title=" -- QtWebEngine"
url=https://duckduckgo.com
+
+[window]
+title=" -- QtWebEngine"
width=1280
height=720